Commit 3060798e authored by Florent Chehab's avatar Florent Chehab
Browse files

Saving test and cleaning

parent 1c435959
Pipeline #27277 passed with stages
in 2 minutes and 39 seconds
...@@ -3,7 +3,7 @@ import PropTypes from 'prop-types'; ...@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import withStyles from '@material-ui/core/styles/withStyles'; import withStyles from '@material-ui/core/styles/withStyles';
import compose from 'recompose/compose'; import compose from 'recompose/compose';
import { connect } from "react-redux"; import { connect } from "react-redux";
import _ from 'underscore';
import Table from '@material-ui/core/Table'; import Table from '@material-ui/core/Table';
import TableBody from '@material-ui/core/TableBody'; import TableBody from '@material-ui/core/TableBody';
import TableCell from '@material-ui/core/TableCell'; import TableCell from '@material-ui/core/TableCell';
...@@ -20,7 +20,6 @@ import GenericModule from './GenericModule'; ...@@ -20,7 +20,6 @@ import GenericModule from './GenericModule';
import MyComponent from '../../MyComponent'; import MyComponent from '../../MyComponent';
import dateStrToStr from '../../../utils/dateStrToStr'; import dateStrToStr from '../../../utils/dateStrToStr';
import dateStrToDate from '../../../utils/dateStrToDate';
import UniversitySemestersDatesEditor from './editors/UniversitySemestersDatesEditor'; import UniversitySemestersDatesEditor from './editors/UniversitySemestersDatesEditor';
...@@ -54,34 +53,24 @@ function convertDateStrToStr(date) { ...@@ -54,34 +53,24 @@ function convertDateStrToStr(date) {
} }
function convertDateStrToDate(date) {
if (date) {
return dateStrToDate(date);
} else {
return null
}
}
class UniversitySemestersDates extends MyComponent { class UniversitySemestersDates extends MyComponent {
idToUse = "univId"; idToUse = "univId";
parse(rawModelData) { parse(rawModelData) {
// reverse serialization // reverse serialization
const semestersDates = this.getFetchedData('universitiesSemestersDatesEl'); const semestersDates = this.getFetchedData('universitiesSemestersDatesEl');
let { autumn_begin, autumn_end, spring_begin, spring_end, const modelData = _.pick(semestersDates,
comment, useful_links, id, university, obj_moderation_level } = semestersDates; [
"autumn_begin",
const modelData = { "autumn_end",
autumn_begin: convertDateStrToDate(autumn_begin), "spring_begin",
autumn_end: convertDateStrToDate(autumn_end), "spring_end",
spring_begin: convertDateStrToDate(spring_begin), "useful_links",
spring_end: convertDateStrToDate(spring_end), "comment",
useful_links, "university",
comment, "obj_moderation_level",
university, "id"
obj_moderation_level, ]);
id,
}
return modelData; return modelData;
} }
......
...@@ -62,10 +62,24 @@ class Editor extends MyComponent { ...@@ -62,10 +62,24 @@ class Editor extends MyComponent {
return data; return data;
} }
hasChangesToSave(formData, modelData) {
for (let fieldKey in formData) {
if (formData[fieldKey] != modelData[fieldKey]) {
console.log(fieldKey, formData[fieldKey], modelData[fieldKey]);
return true;
}
}
return false;
}
handleSaveEditor() { handleSaveEditor() {
if (this.formIsValid()) { if (this.formIsValid()) {
const tmp = Object.assign({}, this.props.modelData, this.getDataFromFields()) const formData = this.getDataFromFields();
const { modelData } = this.props;
console.log("send required", this.hasChangesToSave(formData, modelData));
const tmp = Object.assign({}, this.props.modelData, formData)
this.props.saveData(tmp); this.props.saveData(tmp);
} else { } else {
console.log("ici") console.log("ici")
......
...@@ -12,6 +12,7 @@ import DateField from './fields/DateField'; ...@@ -12,6 +12,7 @@ import DateField from './fields/DateField';
import UsefulLinksField from './fields/UsefulLinksField'; import UsefulLinksField from './fields/UsefulLinksField';
import MarkdownField from './fields/MarkdownField'; import MarkdownField from './fields/MarkdownField';
import dateStrToDate from '../../../../utils/dateStrToDate';
import { import {
universitiesSemestersDatesElSaveData, universitiesSemestersDatesElSaveData,
...@@ -32,22 +33,22 @@ class UniversitySemestersDatesEditor extends Editor { ...@@ -32,22 +33,22 @@ class UniversitySemestersDatesEditor extends Editor {
<div> <div>
{this.renderObjModerationLevelField()} {this.renderObjModerationLevelField()}
<DateField label={"Date de début du semestre de printemps"} <DateField label={"Date de début du semestre de printemps"}
value={modelData.spring_begin} value={dateStrToDate(modelData.spring_begin)}
formManager={this} formManager={this}
fieldMapping={'spring_begin'} fieldMapping={'spring_begin'}
/> />
<DateField label={"Date de fin du semestre de printemps"} <DateField label={"Date de fin du semestre de printemps"}
value={modelData.spring_end} value={dateStrToDate(modelData.spring_end)}
formManager={this} formManager={this}
fieldMapping={'spring_end'} fieldMapping={'spring_end'}
/> />
<DateField label={"Date de début du semestre d'automne"} <DateField label={"Date de début du semestre d'automne"}
value={modelData.autumn_begin} value={dateStrToDate(modelData.autumn_begin)}
formManager={this} formManager={this}
fieldMapping={'autumn_begin'} fieldMapping={'autumn_begin'}
/> />
<DateField label={"Date de fin du semestre d'automne"} <DateField label={"Date de fin du semestre d'automne"}
value={modelData.autumn_end} value={dateStrToDate(modelData.autumn_end)}
formManager={this} formManager={this}
fieldMapping={'autumn_end'} fieldMapping={'autumn_end'}
/> />
......
const reg = /(\d{4})-(\d{2})-(\d{2})/; const reg = /(\d{4})-(\d{2})-(\d{2})/;
export default function dateStrToDate(dateTime) { export default function dateStrToDate(dateTime) {
if (!dateTime){
return null;
}
const res = reg.exec(dateTime); const res = reg.exec(dateTime);
let yyyy = res[1], let yyyy = res[1],
mm = res[2], mm = res[2],
......
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