Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugFix(issue163) #196

Merged
merged 1 commit into from
Jun 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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