LT-337 Associate context menu enable/disable logic problems

This commit is contained in:
Emanuel F. Oliveira 2016-11-16 13:06:43 -02:00
parent 2b88fc4c7a
commit 995f21071e

View File

@ -4,14 +4,62 @@ import { OHIF } from 'meteor/ohif:core';
StudyListSelectedStudies = new Meteor.Collection(null); StudyListSelectedStudies = new Meteor.Collection(null);
StudyListSelectedStudies._debugName = 'StudyListSelectedStudies'; StudyListSelectedStudies._debugName = 'StudyListSelectedStudies';
function isStudySelected(study) {
// Search StudyListSelectedStudies for given study and return true if found
let count = StudyListSelectedStudies.find({
studyInstanceUid: study.studyInstanceUid
}).count();
return count > 0;
}
function doClearStudySelections() {
// Clear all selected studies
StudyListSelectedStudies.remove({});
$('tr.studylistStudy').removeClass('active');
}
function doSelectRow(studyRow, data) {
// Insert current study into selection list if it's not there already...
if (!isStudySelected(data)) {
StudyListSelectedStudies.insert(data);
}
// Make sure the study row has "active" class
studyRow.addClass('active');
// Set this as the previously selected row, so the user can
// use Shift to select from this point onwards
StudyList.previouslySelected = studyRow;
}
function doSelectSingleRow(studyRow, data) {
// Clear all selected studies
doClearStudySelections();
// ... And add selected row to selection list
doSelectRow(studyRow, data);
}
function doUnselectRow(studyRow, data) {
// Find the current studyInstanceUid in the stored list and remove it
StudyListSelectedStudies.remove({
studyInstanceUid: data.studyInstanceUid
});
studyRow.removeClass('active');
}
function handleShiftClick(studyRow, data) { function handleShiftClick(studyRow, data) {
//OHIF.log.info('shiftKey'); //OHIF.log.info('shiftKey');
var studyInstanceUid = studyRow.attr('studyInstanceUid');
let study, previous = StudyList.previouslySelected ? $(StudyList.previouslySelected) : null;
if (previous && previous.length > 0) {
study = Blaze.getData(previous.get(0));
if (!isStudySelected(study)) {
previous = void 0; // undefined
StudyList.previouslySelected = previous;
}
}
// Select all rows in between these two rows // Select all rows in between these two rows
if (StudyList.previouslySelected) { if (previous) {
var previous = $(StudyList.previouslySelected); let rowsInBetween;
var rowsInBetween;
if (previous.index() < studyRow.index()) { if (previous.index() < studyRow.index()) {
// The previously selected row is above (lower index) the // The previously selected row is above (lower index) the
// currently selected row. // currently selected row.
@ -25,16 +73,14 @@ function handleShiftClick(studyRow, data) {
// Fill in the rows upwards from the previously selected row // Fill in the rows upwards from the previously selected row
rowsInBetween = previous.prevAll('tr'); rowsInBetween = previous.prevAll('tr');
} else { } else {
// The rows are the same, deselect the current row. // nothing to do since previous.index() === studyRow.index()
// TODO: CHECK THIS, pretty sure this is the wrong behaviour // the user is shift-clicking the same row...
StudyListSelectedStudies.remove({});
StudyList.previouslySelected = undefined;
return; return;
} }
// Loop through the rows in between current and previous selected studies // Loop through the rows in between current and previous selected studies
rowsInBetween.each(function() { rowsInBetween.each(function() {
var row = $(this); let row = $(this);
if (row.hasClass('active')) { if (row.hasClass('active')) {
// If we find one that is already selected, do nothing // If we find one that is already selected, do nothing
@ -42,63 +88,54 @@ function handleShiftClick(studyRow, data) {
} }
// Get the relevant studyInstanceUid // Get the relevant studyInstanceUid
var studyInstanceUid = row.attr('studyInstanceUid'); let studyInstanceUid = row.attr('studyInstanceUid');
// Retrieve the data context through Blaze // Retrieve the data context through Blaze
var data = Blaze.getData(this); let data = Blaze.getData(this);
// Set the current study as selected // Set the current study as selected
StudyListSelectedStudies.insert(data); doSelectRow(row, data);
row.addClass('active');
// When we reach the currently clicked-on row, stop the loop // When we reach the currently clicked-on row, stop the loop
return !row.is(studyRow); return !row.is(studyRow);
}); });
} else { } else {
// Set the current study as selected // Set the current study as selected
StudyListSelectedStudies.insert(data); doSelectSingleRow(studyRow, data);
studyRow.addClass('active');
} }
} }
function handleCtrlClick(studyRow, data) { function handleCtrlClick(studyRow, data) {
//OHIF.log.info('ctrlKey'); //OHIF.log.info('ctrlKey');
var studyInstanceUid = studyRow.attr('studyInstanceUid'); if (isStudySelected(data)) {
doUnselectRow(studyRow, data);
if (studyRow.hasClass('active')) {
studyRow.removeClass('active');
// Find the current studyInstanceUid in the stored list and remove it
StudyListSelectedStudies.remove({
studyInstanceUid: data.studyInstanceUid
});
} else { } else {
// Set the current study as selected doSelectRow(studyRow, data);
StudyListSelectedStudies.insert(data);
studyRow.addClass('active');
// Set this as the previously selected row, so the user can
// use Shift to select from this point onwards
StudyList.previouslySelected = studyRow;
OHIF.log.info('StudyList PreviouslySelected set: ' + studyRow.index()); OHIF.log.info('StudyList PreviouslySelected set: ' + studyRow.index());
} }
} }
Template.studylistStudy.onRendered(function() { Template.studylistStudy.onRendered(function() {
var instance = this; let instance = this,
var elem = instance.$('tr.studylistStudy').get(0); data = instance.data,
row = instance.$('tr.studylistStudy').first();
// Enable HammerJS to allow touch support // Enable HammerJS to allow touch support
var mc = new Hammer.Manager(elem); let mc = new Hammer.Manager(row.get(0)),
var doubleTapRecognizer = new Hammer.Tap({ doubleTapRecognizer = new Hammer.Tap({
event: 'doubletap', event: 'doubletap',
taps: 2, taps: 2,
interval: 500, interval: 500,
threshold: 30, threshold: 30,
posThreshold: 30 posThreshold: 30
}); });
mc.add(doubleTapRecognizer); mc.add(doubleTapRecognizer);
// Check if current row has been previously selected
if (isStudySelected(data)) {
doSelectRow(row, data);
}
}); });
Template.studylistStudy.events({ Template.studylistStudy.events({
@ -114,20 +151,7 @@ Template.studylistStudy.events({
} else if (e.ctrlKey || e.metaKey) { } else if (e.ctrlKey || e.metaKey) {
handleCtrlClick(studyRow, data); handleCtrlClick(studyRow, data);
} else { } else {
// Select a single study doSelectSingleRow(studyRow, data);
//OHIF.log.info('Regular click');
// Clear all selected studies
StudyListSelectedStudies.remove({});
$('tr.studylistStudy').removeClass('active');
// Set the previous study to the currently clicked-on study
StudyList.previouslySelected = studyRow;
//OHIF.log.info('StudyList PreviouslySelected set: ' + studyRow.index());
// Set the current study as selected
StudyListSelectedStudies.insert(data);
studyRow.addClass('active');
} }
}, },
'mousedown tr.studylistStudy': function(e) { 'mousedown tr.studylistStudy': function(e) {
@ -155,11 +179,16 @@ Template.studylistStudy.events({
} }
}, },
'contextmenu tr.studylistStudy, press tr.studylistStudy': function(e, template) { 'contextmenu tr.studylistStudy, press tr.studylistStudy': function(e, template) {
$(e.currentTarget).addClass('active');
if (openStudyContextMenu && typeof openStudyContextMenu === 'function') { var studyRow = $(e.currentTarget),
data = this;
if (!isStudySelected(data)) {
doSelectSingleRow(studyRow, data);
}
if (typeof openStudyContextMenu === 'function') {
e.preventDefault(); e.preventDefault();
openStudyContextMenu(e, template); openStudyContextMenu(e, template);
return false; return false;
} }