Commit fd3e49d9 authored by Marco Sehrer's avatar Marco Sehrer
Browse files

Fix sample update/fetcher inconsistencies

Fix sample dirty state did not update after save
parent fa37b4d0
......@@ -102,7 +102,10 @@ module Chemotion
molecule_attributes: params[:molecule]
) unless params[:molecule].blank?
Sample.find(params[:id]).update(attributes)
if sample = Sample.find(params[:id])
sample.update(attributes)
sample
end
end
end
......
......@@ -49,7 +49,7 @@ export default class SampleDetails extends React.Component {
Aviator.navigate(`/collection/${uiState.currentCollectionId}`);
}
//todo: belongs to Action/Store
//todo: extract serialize method
createSampleObject() {
let uiState = UIStore.getState();
return {
......
......@@ -69,7 +69,7 @@ class ElementActions {
createSample(params) {
SamplesFetcher.create(params)
.then((result) => {
this.dispatch(result.sample)
this.dispatch(result)
});
}
......@@ -77,7 +77,7 @@ class ElementActions {
let _params = _.omit( params, _.isNull); //should be better done in SampleProxy#serialize
SamplesFetcher.update(_params)
.then((result) => {
this.dispatch(params)
this.dispatch(result)
}).catch((errorMessage) => {
console.log(errorMessage);
});
......
......@@ -63,7 +63,13 @@ export default class SamplesFetcher {
is_top_secret: params.is_top_secret,
molecule: { density: density, boiling_point: boiling_point, melting_point: melting_point }
})
})
}).then((response) => {
return response.json()
}).then((json) => {
return new SampleProxy(json.sample);
}).catch((errorMessage) => {
console.log(errorMessage);
});
return promise;
}
......@@ -95,7 +101,7 @@ export default class SamplesFetcher {
}).then((response) => {
return response.json()
}).then((json) => {
return json;
return new SampleProxy(json.sample);
}).catch((errorMessage) => {
console.log(errorMessage);
});
......
......@@ -5,7 +5,7 @@ export default class Element {
constructor(args) {
Object.assign(this, args);
this._checksum = this.checksum();
this.updateChecksum();
}
get isEdited() {
......@@ -20,4 +20,8 @@ export default class Element {
return this.id == '_new_'
}
updateChecksum() {
this._checksum = this.checksum();
}
}
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