bugFix(issue163) Save button not appearing and saved measurements not getting drawn in canvas (#196)

This commit is contained in:
Gustavo André Lelis 2018-06-08 05:45:07 -03:00 committed by Erik Ziegler
parent 5785d19ee1
commit b8506b5dae
4 changed files with 69 additions and 1 deletions

View File

@ -7,6 +7,12 @@
{{>toolbarSectionTools toolbarButtons=toolbarButtons}}
<div class="pull-right m-t-1 rm-x-1">
{{#form (extend api=instance.api)}}
{{#button class='btn p-x-2' action='save' disabled=(isFinishDisabled)}}Save{{/button}}
{{/form}}
</div>
<div id="toggleMeasurements" class="pull-right m-t-1 rm-x-1">
{{>roundedButtonGroup rightSidebarToggleButtonData}}
</div>

View File

@ -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);
});

View File

@ -21,3 +21,7 @@
min-width: 30px
theme('stroke', '$defaultColor')
text-align: center
.saveMeasurements
display: inline-block
margin-left: 22px

View File

@ -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