Commit 31cbe019 authored by Florent Chehab's avatar Florent Chehab

History connected

and bug removed in rendering model update info
parent fd4200f2
Pipeline #27303 passed with stages
in 2 minutes and 41 seconds
......@@ -75,6 +75,8 @@ class GenericModule extends MyComponent {
state = {
editorOpen: false,
historyOpen: false,
rawModelDataForEditor: this.props.rawModelData,
forceSave: false,
};
handleOpenEditor = () => {
......@@ -93,6 +95,23 @@ class GenericModule extends MyComponent {
this.setState({ historyOpen: true });
};
handleEditCurrent = () => {
this.setState({
rawModelDataForEditor: this.props.rawModelData,
forceSave: false,
});
this.handleOpenEditor();
}
handleRestoreVersion = (rawModelData) => {
this.setState({
rawModelDataForEditor: rawModelData,
forceSave: true,
})
this.handleCloseHistory();
this.handleOpenEditor();
}
renderTitle = (rawModelData) => (
<div>
{renderTitle(rawModelData, this.props.classes, this.props.buildTitle)}
......@@ -105,6 +124,7 @@ class GenericModule extends MyComponent {
{renderUsefulLinks(rawModelData, this.props.classes, this.props.theme)}
</div>
)
myRender() {
const { classes } = this.props;
return (
......@@ -112,13 +132,15 @@ class GenericModule extends MyComponent {
<this.props.editor
open={this.state.editorOpen}
handleCloseEditor={this.handleCloseEditor}
modelData={this.props.parseRawModelData(this.props.rawModelData)}
modelData={this.props.parseRawModelData(this.state.rawModelDataForEditor)}
userData={this.props.userDataEl}
forceSave={this.state.forceSave}
/>
<History
factory={this}
open={this.state.historyOpen}
handleCloseHistory={this.handleCloseHistory}
handleRestoreVersion={this.handleRestoreVersion}
/>
<Paper className={classes.root} square={true}>
{renderFirstRow.bind(this)()}
......
......@@ -104,8 +104,14 @@ class History extends React.Component {
}
return (
<div>
<Typography variant='caption' align='center'>Les versions successives d'un même utilisateur ne sont pas enregistrés (dans de tels cas, seul la dernière est conservée).</Typography>
<Typography variant='title' align='center'>Version n°{this.state.versionInView + 1} du {dateInfo}</Typography>
<Button variant='outlined' color="primary" className={this.props.classes.editButton} onClick={() => console.log("ici")}>
<Button
variant='outlined'
color="primary"
className={this.props.classes.editButton}
onClick={() => this.props.handleRestoreVersion(rawModelData)}
>
Éditer à partir de cette version
</Button>
<Divider />
......@@ -189,6 +195,7 @@ class History extends React.Component {
History.propTypes = {
classes: PropTypes.object.isRequired,
factory: PropTypes.object.isRequired,
handleRestoreVersion: PropTypes.func.isRequired,
};
History.defaultProps = {
......
......@@ -94,7 +94,7 @@ class Editor extends MyComponent {
if ((!formHasError.status) && (!formFieldsHaveError.status)) {
const formData = this.getDataFromFields();
const { modelData } = this.props;
if (this.hasChangesToSave(formData, modelData)) {
if (this.props.forceSave || this.hasChangesToSave(formData, modelData)) {
const tmp = Object.assign({}, this.props.modelData, formData)
this.setState({
notification: {
......@@ -290,10 +290,12 @@ Editor.propTypes = {
savingHasError: PropTypes.object.isRequired,
saveData: PropTypes.func.isRequired,
lastUpdateTime: PropTypes.string,
forceSave: PropTypes.bool.isRequired
};
Editor.defaultProps = {
open: false,
forceSave: false,
handleCloseEditor: () => console.log("Dev forgot something...")
};
......
......@@ -55,7 +55,7 @@ export default function renderFirstRow() {
<Tooltip title={editTooltip} placement="top">
<div style={{ display: 'inline-block' }}> {/* Needed to fire events for the tooltip when below is disabled!! */}
<IconButton aria-label="Éditer" className={classes.button} disabled={editClass == 'disabled'} onClick={this.handleOpenEditor}>
<IconButton aria-label="Éditer" className={classes.button} disabled={editClass == 'disabled'} onClick={this.handleEditCurrent}>
<CreateIcon className={classes[editClass]} />
</IconButton>
</div>
......
......@@ -6,7 +6,7 @@ export default function renderUpdateInfo() {
const { rawModelData } = this.props;
const { updated_by, updated_on } = rawModelData;
const readOnly = rawModelData.model_config.read_only;
console.log("icissqdqsd")
if (readOnly) {
return (
<Typography variant='caption'>Ils s'agit de donner automatiquement récupérer et non modifiables.</Typography>
......@@ -14,7 +14,9 @@ export default function renderUpdateInfo() {
} else {
if (updated_on) {
const { date, time } = dateTimeStrToStr(updated_on);
<Typography variant='caption'>Mis à jour par <em>{updated_by}</em> le {date} à {time}</Typography>
return (
<Typography variant='caption'>Mis à jour par <em>{updated_by}</em> le {date} à {time}</Typography>
)
} else {
return (
<Typography variant='caption'>Mis à jour par <em>{updated_by}</em> à une date inconnue.</Typography>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment