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

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';
import withStyles from '@material-ui/core/styles/withStyles';
import compose from 'recompose/compose';
import { connect } from "react-redux";
import _ from 'underscore';
import Table from '@material-ui/core/Table';
import TableBody from '@material-ui/core/TableBody';
import TableCell from '@material-ui/core/TableCell';
......@@ -20,7 +20,6 @@ import GenericModule from './GenericModule';
import MyComponent from '../../MyComponent';
import dateStrToStr from '../../../utils/dateStrToStr';
import dateStrToDate from '../../../utils/dateStrToDate';
import UniversitySemestersDatesEditor from './editors/UniversitySemestersDatesEditor';
......@@ -54,34 +53,24 @@ function convertDateStrToStr(date) {
}
function convertDateStrToDate(date) {
if (date) {
return dateStrToDate(date);
} else {
return null
}
}
class UniversitySemestersDates extends MyComponent {
idToUse = "univId";
parse(rawModelData) {
// reverse serialization
const semestersDates = this.getFetchedData('universitiesSemestersDatesEl');
let { autumn_begin, autumn_end, spring_begin, spring_end,
comment, useful_links, id, university, obj_moderation_level } = semestersDates;
const modelData = {
autumn_begin: convertDateStrToDate(autumn_begin),
autumn_end: convertDateStrToDate(autumn_end),
spring_begin: convertDateStrToDate(spring_begin),
spring_end: convertDateStrToDate(spring_end),
useful_links,
comment,
university,
obj_moderation_level,
id,
}
const modelData = _.pick(semestersDates,
[
"autumn_begin",
"autumn_end",
"spring_begin",
"spring_end",
"useful_links",
"comment",
"university",
"obj_moderation_level",
"id"
]);
return modelData;
}
......
......@@ -62,10 +62,24 @@ class Editor extends MyComponent {
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() {
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);
} else {
console.log("ici")
......
......@@ -12,6 +12,7 @@ import DateField from './fields/DateField';
import UsefulLinksField from './fields/UsefulLinksField';
import MarkdownField from './fields/MarkdownField';
import dateStrToDate from '../../../../utils/dateStrToDate';
import {
universitiesSemestersDatesElSaveData,
......@@ -32,22 +33,22 @@ class UniversitySemestersDatesEditor extends Editor {
<div>
{this.renderObjModerationLevelField()}
<DateField label={"Date de début du semestre de printemps"}
value={modelData.spring_begin}
value={dateStrToDate(modelData.spring_begin)}
formManager={this}
fieldMapping={'spring_begin'}
/>
<DateField label={"Date de fin du semestre de printemps"}
value={modelData.spring_end}
value={dateStrToDate(modelData.spring_end)}
formManager={this}
fieldMapping={'spring_end'}
/>
<DateField label={"Date de début du semestre d'automne"}
value={modelData.autumn_begin}
value={dateStrToDate(modelData.autumn_begin)}
formManager={this}
fieldMapping={'autumn_begin'}
/>
<DateField label={"Date de fin du semestre d'automne"}
value={modelData.autumn_end}
value={dateStrToDate(modelData.autumn_end)}
formManager={this}
fieldMapping={'autumn_end'}
/>
......
const reg = /(\d{4})-(\d{2})-(\d{2})/;
export default function dateStrToDate(dateTime) {
if (!dateTime){
return null;
}
const res = reg.exec(dateTime);
let yyyy = res[1],
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