Skip to content

Commit

Permalink
bugFix(issue163) Save button not appearing and saved measurements not…
Browse files Browse the repository at this point in the history
… getting drawn in canvas (#196)
  • Loading branch information
galelis authored and swederik committed Jun 8, 2018
1 parent 5785d19 commit b8506b5
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
58 changes: 58 additions & 0 deletions LesionTracker/client/components/toolbarSection/toolbarSection.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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();
Expand All @@ -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);
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@
min-width: 30px
theme('stroke', '$defaultColor')
text-align: center

.saveMeasurements
display: inline-block
margin-left: 22px
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b8506b5

Please sign in to comment.