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

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 { ...@@ -75,6 +75,8 @@ class GenericModule extends MyComponent {
state = { state = {
editorOpen: false, editorOpen: false,
historyOpen: false, historyOpen: false,
rawModelDataForEditor: this.props.rawModelData,
forceSave: false,
}; };
handleOpenEditor = () => { handleOpenEditor = () => {
...@@ -93,6 +95,23 @@ class GenericModule extends MyComponent { ...@@ -93,6 +95,23 @@ class GenericModule extends MyComponent {
this.setState({ historyOpen: true }); 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) => ( renderTitle = (rawModelData) => (
<div> <div>
{renderTitle(rawModelData, this.props.classes, this.props.buildTitle)} {renderTitle(rawModelData, this.props.classes, this.props.buildTitle)}
...@@ -105,6 +124,7 @@ class GenericModule extends MyComponent { ...@@ -105,6 +124,7 @@ class GenericModule extends MyComponent {
{renderUsefulLinks(rawModelData, this.props.classes, this.props.theme)} {renderUsefulLinks(rawModelData, this.props.classes, this.props.theme)}
</div> </div>
) )
myRender() { myRender() {
const { classes } = this.props; const { classes } = this.props;
return ( return (
...@@ -112,13 +132,15 @@ class GenericModule extends MyComponent { ...@@ -112,13 +132,15 @@ class GenericModule extends MyComponent {
<this.props.editor <this.props.editor
open={this.state.editorOpen} open={this.state.editorOpen}
handleCloseEditor={this.handleCloseEditor} handleCloseEditor={this.handleCloseEditor}
modelData={this.props.parseRawModelData(this.props.rawModelData)} modelData={this.props.parseRawModelData(this.state.rawModelDataForEditor)}
userData={this.props.userDataEl} userData={this.props.userDataEl}
forceSave={this.state.forceSave}
/> />
<History <History
factory={this} factory={this}
open={this.state.historyOpen} open={this.state.historyOpen}
handleCloseHistory={this.handleCloseHistory} handleCloseHistory={this.handleCloseHistory}
handleRestoreVersion={this.handleRestoreVersion}
/> />
<Paper className={classes.root} square={true}> <Paper className={classes.root} square={true}>
{renderFirstRow.bind(this)()} {renderFirstRow.bind(this)()}
......
...@@ -104,8 +104,14 @@ class History extends React.Component { ...@@ -104,8 +104,14 @@ class History extends React.Component {
} }
return ( return (
<div> <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> <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 Éditer à partir de cette version
</Button> </Button>
<Divider /> <Divider />
...@@ -189,6 +195,7 @@ class History extends React.Component { ...@@ -189,6 +195,7 @@ class History extends React.Component {
History.propTypes = { History.propTypes = {
classes: PropTypes.object.isRequired, classes: PropTypes.object.isRequired,
factory: PropTypes.object.isRequired, factory: PropTypes.object.isRequired,
handleRestoreVersion: PropTypes.func.isRequired,
}; };
History.defaultProps = { History.defaultProps = {
......
...@@ -94,7 +94,7 @@ class Editor extends MyComponent { ...@@ -94,7 +94,7 @@ class Editor extends MyComponent {
if ((!formHasError.status) && (!formFieldsHaveError.status)) { if ((!formHasError.status) && (!formFieldsHaveError.status)) {
const formData = this.getDataFromFields(); const formData = this.getDataFromFields();
const { modelData } = this.props; 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) const tmp = Object.assign({}, this.props.modelData, formData)
this.setState({ this.setState({
notification: { notification: {
...@@ -290,10 +290,12 @@ Editor.propTypes = { ...@@ -290,10 +290,12 @@ Editor.propTypes = {
savingHasError: PropTypes.object.isRequired, savingHasError: PropTypes.object.isRequired,
saveData: PropTypes.func.isRequired, saveData: PropTypes.func.isRequired,
lastUpdateTime: PropTypes.string, lastUpdateTime: PropTypes.string,
forceSave: PropTypes.bool.isRequired
}; };
Editor.defaultProps = { Editor.defaultProps = {
open: false, open: false,
forceSave: false,
handleCloseEditor: () => console.log("Dev forgot something...") handleCloseEditor: () => console.log("Dev forgot something...")
}; };
......
...@@ -55,7 +55,7 @@ export default function renderFirstRow() { ...@@ -55,7 +55,7 @@ export default function renderFirstRow() {
<Tooltip title={editTooltip} placement="top"> <Tooltip title={editTooltip} placement="top">
<div style={{ display: 'inline-block' }}> {/* Needed to fire events for the tooltip when below is disabled!! */} <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]} /> <CreateIcon className={classes[editClass]} />
</IconButton> </IconButton>
</div> </div>
......
...@@ -6,7 +6,7 @@ export default function renderUpdateInfo() { ...@@ -6,7 +6,7 @@ export default function renderUpdateInfo() {
const { rawModelData } = this.props; const { rawModelData } = this.props;
const { updated_by, updated_on } = rawModelData; const { updated_by, updated_on } = rawModelData;
const readOnly = rawModelData.model_config.read_only; const readOnly = rawModelData.model_config.read_only;
console.log("icissqdqsd")
if (readOnly) { if (readOnly) {
return ( return (
<Typography variant='caption'>Ils s'agit de donner automatiquement récupérer et non modifiables.</Typography> <Typography variant='caption'>Ils s'agit de donner automatiquement récupérer et non modifiables.</Typography>
...@@ -14,7 +14,9 @@ export default function renderUpdateInfo() { ...@@ -14,7 +14,9 @@ export default function renderUpdateInfo() {
} else { } else {
if (updated_on) { if (updated_on) {
const { date, time } = dateTimeStrToStr(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 { } else {
return ( return (
<Typography variant='caption'>Mis à jour par <em>{updated_by}</em> à une date inconnue.</Typography> <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