LT-275: Enabling labels selection by the common section

This commit is contained in:
Bruno Alves de Faria 2016-08-18 17:15:59 -03:00
parent d5ecfbdd39
commit 8fdf9c2b1c
6 changed files with 87 additions and 48 deletions

View File

@ -217,7 +217,7 @@ $gray6 = #303030
.content
margin-left: 0
&.interacted
&.interacted, &.selected
.select-tree-common
z-index: 1

View File

@ -55,25 +55,33 @@ Template.measureFlow.onCreated(() => {
}];
const items = [
'Abdomen/Chest Wall',
'Adrenal',
'Muscle',
'Bladder',
'Neck',
'Bone',
'Other Soft Tissue',
'Brain',
'Ovary',
'Breast',
'Pancreas',
'Colon',
'Prostate',
'Esophagus',
'Small Bowel',
'Extremities',
'Spleen',
'Gallbladder',
'Stomach',
'Kidney',
'Liver',
'Lung',
'Lymph Node',
'Mediastinum/Hilum',
'Muscle',
'Neck',
'Other Soft Tissue',
'Ovary',
'Pancreas',
'Pelvis',
'Peritoneum/Omentum',
'Prostate',
'Retroperitoneum',
'Small Bowel',
'Spleen',
'Stomach',
'Subcutaneous'
];
@ -130,6 +138,7 @@ Template.measureFlow.events({
key: 'label',
items: instance.items,
commonItems: instance.commonItems,
hideCommon: instance.data.hideCommon,
label: 'Assign label',
searchPlaceholder: 'Search labels',
storageKey: 'measureLabelCommon',

View File

@ -121,6 +121,15 @@
.select-tree-root
&.interacted .select-tree-common .content
animation-name: none
&.selected .select-tree-common .content
animation-name: selectTreeCommonCloseLeft
.tree-search input
display: none
.select-tree-common
padding-left: 0
padding-right: 6px

View File

@ -11,6 +11,45 @@ import transition from 'meteor/ohif:core/client/lib/third-party/transition-to-fr
Template.selectTree.onCreated(() => {
const instance = Template.instance();
// Return the common items
instance.getCommonItems = () => {
const instance = Template.instance();
// Return the common items if given
if (instance.data.commonItems) {
return instance.data.commonItems;
}
// Get all the tree leaves
const leaves = instance.data.component.getLeaves();
// Generate an object with encoded keys from the tree leaves
leavesObject = {};
_.each(leaves, leaf => {
leavesObject[OHIF.string.encodeId(leaf.value)] = leaf;
});
// Get the current items ranking
const ranking = OHIF.user.getData(instance.data.storageKey);
// Sort the items based on how many times each one was used
const sorted = [];
_.each(ranking, (count, key) => sorted.push([key, count]));
sorted.sort((a, b) => b[1] - a[1]);
// Create the result and push every item respecting the ranking order
const result = [];
_.each(sorted, item => {
const current = leavesObject[item[0]];
if (current) {
result.push(current);
}
});
// Return the resulting array
return result;
};
// Create a reactive variable to control the search
instance.searchTerm = new ReactiveVar('');
});
@ -270,6 +309,23 @@ Template.selectTree.helpers({
// Filter only the tree leaves
items = _.filter(items, item => !item.items);
} else if (instance.data.hideCommon) {
// Get the values of common items
const commonValues = _.pluck(instance.getCommonItems(), 'value');
// Filter only the items that are not common
items = _.filter(items, item => !_.contains(commonValues, item.value));
}
// Return the items sorted for tree columns
if (instance.data.treeColumns) {
const begin = items.splice(0, Math.ceil(items.length / 2));
const sortedItems = [];
_.each(begin, (item, index) => {
sortedItems.push(item);
items[index] && sortedItems.push(items[index]);
});
items = sortedItems;
}
// Return the tree items

View File

@ -28,44 +28,9 @@ Template.selectTreeCommon.events({
}
});
Template.selectTreeCommon.helpers({
// Get the common items ordered by use history
// Get the common items
items() {
const instance = Template.instance();
// Return the common items if given
if (instance.data.commonItems) {
return instance.data.commonItems;
}
// Get all the tree leaves
const leaves = instance.data.component.getLeaves();
// Generate an object with encoded keys from the tree leaves
leavesObject = {};
_.each(leaves, leaf => {
leavesObject[OHIF.string.encodeId(leaf.value)] = leaf;
});
// Get the current items ranking
const ranking = OHIF.user.getData(instance.data.storageKey);
// Sort the items based on how many times each one was used
const sorted = [];
_.each(ranking, (count, key) => sorted.push([key, count]));
sorted.sort((a, b) => b[1] - a[1]);
// Create the result and push every item respecting the ranking order
const result = [];
_.each(sorted, item => {
const current = leavesObject[item[0]];
if (current) {
result.push(current);
}
});
// Return the resulting array
return result;
return Template.instance().data.treeInstance.getCommonItems();
}
});

View File

@ -1,6 +1,6 @@
<template name="componentPlayground">
<div class="component-playground">
{{>measureFlow treeColumns=true}}
{{>measureFlow treeColumns=true hideCommon=true}}
<!--
<div class="p-a-3">
{{>selectTree