diff --git a/LesionTracker/client/components/toolbarSection/toolbarSection.html b/LesionTracker/client/components/toolbarSection/toolbarSection.html index f58f8520947..4f4e28e4860 100644 --- a/LesionTracker/client/components/toolbarSection/toolbarSection.html +++ b/LesionTracker/client/components/toolbarSection/toolbarSection.html @@ -7,6 +7,12 @@ {{>toolbarSectionTools toolbarButtons=toolbarButtons}} +
+ {{#form (extend api=instance.api)}} + {{#button class='btn p-x-2' action='save' disabled=(isFinishDisabled)}}Save{{/button}} + {{/form}} +
+
{{>roundedButtonGroup rightSidebarToggleButtonData}}
diff --git a/LesionTracker/client/components/toolbarSection/toolbarSection.js b/LesionTracker/client/components/toolbarSection/toolbarSection.js index 56edee0f09d..db0845e4354 100644 --- a/LesionTracker/client/components/toolbarSection/toolbarSection.js +++ b/LesionTracker/client/components/toolbarSection/toolbarSection.js @@ -1,9 +1,21 @@ import { Template } from 'meteor/templating'; import { Session } from 'meteor/session'; +import { Tracker } from 'meteor/tracker'; import { OHIF } from 'meteor/ohif:core'; import { Viewerbase } from 'meteor/ohif:viewerbase'; Template.toolbarSection.helpers({ + isFinishDisabled() { + const instance = Template.instance(); + + // Run this computation on save or every time any measurement / timepoint suffer changes + OHIF.ui.unsavedChanges.depend(); + instance.saveObserver.depend(); + Session.get('LayoutManagerUpdated'); + + return OHIF.ui.unsavedChanges.probe('viewer.*') === 0; + }, + leftSidebarToggleButtonData() { const instance = Template.instance(); return { @@ -235,6 +247,46 @@ Template.toolbarSection.events({ } }); +Template.toolbarSection.onCreated( function() { + const instance = Template.instance(); + + instance.path = 'viewer.studyViewer.measurements'; + instance.saveObserver = new Tracker.Dependency(); + instance.api = { + save() { + // Clear signaled unsaved changes... + const successHandler = () => { + OHIF.ui.unsavedChanges.clear(`${instance.path}.*`); + instance.saveObserver.changed(); + }; + + // Display the error messages + const errorHandler = data => { + OHIF.ui.showDialog('dialogInfo', Object.assign({ class: 'themed' }, data)); + }; + + const promise = instance.data.measurementApi.storeMeasurements(); + promise.then(successHandler).catch(errorHandler); + OHIF.ui.showDialog('dialogLoading', { + promise, + text: 'Saving measurement data' + }); + + return promise; + } + }; + + instance.unsavedChangesHandler = () => { + const isNotDisabled = !instance.$('.js-finish-case').hasClass('disabled'); + if (isNotDisabled && instance.progressPercent.get() === 100) { + instance.api.save(); + } + }; + + // Attach handler for unsaved changes dialog... + OHIF.ui.unsavedChanges.attachHandler(instance.path, 'save', instance.unsavedChangesHandler); +}); + Template.toolbarSection.onRendered(function() { // Set disabled/enabled tool buttons that are set in toolManager const states = Viewerbase.toolManager.getToolDefaultStates(); @@ -259,3 +311,9 @@ Template.toolbarSection.onRendered(function() { } } }); + +Template.caseProgress.onDestroyed(() => { + const instance = Template.instance(); + // Remove unsaved changes handler after this view has been destroyed... + OHIF.ui.unsavedChanges.removeHandler(instance.path, 'save', instance.unsavedChangesHandler); +}); diff --git a/LesionTracker/client/components/toolbarSection/toolbarSection.styl b/LesionTracker/client/components/toolbarSection/toolbarSection.styl index f68e4a56de4..885e1e7c110 100644 --- a/LesionTracker/client/components/toolbarSection/toolbarSection.styl +++ b/LesionTracker/client/components/toolbarSection/toolbarSection.styl @@ -21,3 +21,7 @@ min-width: 30px theme('stroke', '$defaultColor') text-align: center + + .saveMeasurements + display: inline-block + margin-left: 22px diff --git a/Packages/ohif-measurements/client/lib/syncMeasurementAndToolData.js b/Packages/ohif-measurements/client/lib/syncMeasurementAndToolData.js index 7a23f7e2852..c61e18dbd30 100644 --- a/Packages/ohif-measurements/client/lib/syncMeasurementAndToolData.js +++ b/Packages/ohif-measurements/client/lib/syncMeasurementAndToolData.js @@ -8,7 +8,7 @@ OHIF.measurements.syncMeasurementAndToolData = measurement => { // Stop here if the metadata for the measurement's study is not loaded yet const { studyInstanceUid } = measurement; - const metadata = OHIF.viewer.StudyMetadataList.findBy({ studyInstanceUid }); + const metadata = OHIF.viewer.StudyMetadataList.findBy({ "studyInstanceUID": studyInstanceUid }); if (!metadata) return; // Iterate each child tool if the current tool has children