LT-332: Fixed tool color and shadow for target tool. Moved client-only utilities to client-folder in viewerbase to speed up reloading

This commit is contained in:
Erik Ziegler committed 2016-11-16 12:17:07 +01:00
1 parent c04c70b325
commit 8cf6666bb1
46 files changed
+67 -57

No files matched your search

@@ -0,0 +1,14 @@
/**
* A global Blaze UI helper to capitalizes the first letter of an input String
*
* Credit to:
*
* http://stackoverflow.com/questions/1026069/capitalize-the-first-letter-of-string-in-javascript
*/
UI.registerHelper('capitalizeFirstLetter', function (context) {
if (!context) {
return;
}
return context.charAt(0).toUpperCase() + context.slice(1);
});
@@ -0,0 +1,14 @@
/**
* A global Blaze UI helper function to format DICOM Dates using the Moment library
*/
UI.registerHelper('formatDA', function (context, format, options) {
if (!context) {
return undefined;
}
var dateAsMoment = moment(context, "YYYYMMDD");
var strFormat = "MMM D, YYYY";
if (options) {
strFormat = format;
}
return dateAsMoment.format(strFormat);
});
@@ -0,0 +1,16 @@
/**
* A global Blaze UI helper function to format JavaScript Dates using the Moment library
*/
UI.registerHelper('formatJSDate', function(context, format, options) {
if (!context) {
return;
}
var dateAsMoment = moment(new Date(context));
var strFormat = 'MMM D, YYYY';
if (options) {
strFormat = format;
}
return dateAsMoment.format(strFormat);
});
@@ -0,0 +1,8 @@
/**
* A global Blaze UI helper to format a float value to a specified precision
*/
UI.registerHelper('formatNumberPrecision', function(context, precision) {
if (context) {
return parseFloat(context).toFixed(precision);
}
});
@@ -0,0 +1,14 @@
/**
* Formats a patient name for display purposes
*/
formatPN = function(context) {
if (!context) {
return;
}
return context.replace('^', ', ');
};
/**
* A global Blaze UI helper to format a patient name for display purposes
*/
UI.registerHelper('formatPN', formatPN);
@@ -0,0 +1,24 @@
/**
* A global Blaze UI helper to format a DICOM Time for display using the Moment library
*/
UI.registerHelper('formatTM', function(context, options) {
if (!context) {
return;
}
// DICOM Time is stored as HHmmss.SSS, where:
// HH 24 hour time:
// m mm 0..59 Minutes
// s ss 0..59 Seconds
// S SS SSS 0..999 Fractional seconds
//
// See MomentJS: http://momentjs.com/docs/#/parsing/string-format/
var dateTime = moment(context, 'HHmmss.SSS');
var format = "HH:mm:ss";
if (options && options.format) {
format = options.format;
}
return dateTime.format(format);
});
@@ -0,0 +1,12 @@
/**
* Helper for retrieving username given userId
*/
UI.registerHelper('getUsername', function(userId) {
var user = Meteor.users.findOne({
userId: userId
});
if (user && user.name) {
return user.name;
}
});
@@ -0,0 +1,10 @@
/**
* Helper for checking datatype of a variable
*/
UI.registerHelper('ifTypeIs', function(value, match, attributeName) {
if (typeof(value) === match) {
return attributeName;
}
return '';
});
@@ -0,0 +1,3 @@
UI.registerHelper('inc', function(value) {
return parseInt(value) + 1;
});
@@ -0,0 +1,49 @@
/**
* Boolean helper to identify if a series instance is active in some viewport
*/
Template.registerHelper('isDisplaySetActive', (displaySetInstanceUid, viewportIndex) => {
// Run this computation every time the viewports are updated
Session.get('LayoutManagerUpdated');
// Stop here if layoutManager is not defined yet
if (!window.layoutManager) {
return;
}
// Check if the display set is current visible in any of the layout
// manager's displayed viewports. Note that we have to check the
// onscreen number of viewports here, since the layout manager will
// keep the viewport data of old viewports, even after the layout is changed.
//
// This behaviour is intentional. If the user displays four viewports, then assigns
// display sets to them, and then switches to / from another layout configuration,
// we don't want them to lose their specified viewports.
let result = false;
if (_.isUndefined(viewportIndex)) {
// Get the number of viewports that are currently displayed
// (Note, viewportData may have more entries!)
const currentNumberOfViewports = layoutManager.getNumberOfViewports();
// Loop through the viewport data up until the currently displayed
// number of viewports
let viewportData = window.layoutManager.viewportData;
for (let i = 0; i < currentNumberOfViewports; i++) {
const data = viewportData[i];
// If the display set is displayed in this viewport, stop here
if (data && data.displaySetInstanceUid === displaySetInstanceUid) {
result = true;
break;
}
}
} else {
const data = window.layoutManager.viewportData[viewportIndex];
// If the display set is displayed in this viewport, stop here
if (data && data.displaySetInstanceUid === displaySetInstanceUid) {
result = true;
}
}
return result;
});
@@ -0,0 +1,20 @@
/**
* Helper function to determine if the current client devices
* is touch-capable. This can be used to modify certain aspects of the UI.
*
* The check may not work on all devices!
*
* @returns {boolean} true if the client device is touch-capable, false otherwise
*/
isTouchDevice = function() {
return (('ontouchstart' in window) ||
(navigator.MaxTouchPoints > 0) ||
(navigator.msMaxTouchPoints > 0));
};
/**
* Blaze helper for checking if the current device is touch capable
*
* @returns {boolean} true if the client device is touch-capable, false otherwise
*/
UI.registerHelper('isTouchDevice', isTouchDevice);
@@ -0,0 +1,13 @@
/**
* A global Blaze UI helper function to format JavaScript Dates using the Moment library
*/
UI.registerHelper('jsDateFromNow', function(context, format, options) {
if (!context) {
return;
}
Session.get('timeAgoVariable');
var dateAsMoment = moment(new Date(context));
return dateAsMoment.fromNow();
});
@@ -0,0 +1,6 @@
UI.registerHelper('objectEach', function(object) {
// http://stackoverflow.com/questions/30234732/how-to-print-key-and-values-in-meteor-template
return _.map(object, function(value, key) {
return _.extend({key: key}, value);
});
});
@@ -0,0 +1,9 @@
UI.registerHelper('objectToPairs', function(object) {
// http://stackoverflow.com/questions/30234732/how-to-print-key-and-values-in-meteor-template
return _.map(object, function(value, key) {
return {
key: key,
value: value
};
});
});
@@ -0,0 +1,19 @@
/**
* A global Blaze UI helper to Stringify a JavaScript object
*
* Credit to:
*
* http://stackoverflow.com/questions/1026069/capitalize-the-first-letter-of-string-in-javascript
*/
UI.registerHelper('prettyPrintStringify', function(context) {
if (!context) {
return;
}
var string = JSON.stringify(context, null, 2);
string = string.replace(/['"]+/g, '');
string = string.replace('{', '');
string = string.replace('}', '');
string = string.replace(',', '\n');
return string;
});
@@ -0,0 +1,57 @@
import { _ } from 'meteor/underscore';
import { Template } from 'meteor/templating';
/**
* Global Blaze UI helper to sort array elements
* by an array element's property (property) or deep object property (property.childProperty)
* Sorts ascending as default
*/
Template.registerHelper('sort', (array, sortBy, sortType) => {
if (!sortBy) {
return array;
}
// To keep the order for the same values of the field which is used to sort:
// 1. Group the array by the field
// 2. Sort the grouped array
// 3. Ungroup the sorted array
const groupedArray = _.groupBy(array, (element) => {
if (sortBy) {
var groupingElement = getKeyValue(element, sortBy);
if (groupingElement) {
return groupingElement;
}
}
return element;
});
const sortedArray = _.sortBy(groupedArray, (element) => {
if (sortBy) {
var sortingElement = getKeyValue(element[0], sortBy);
if (sortingElement) {
return sortingElement;
}
}
return element;
});
if (sortType === 'desc') {
return _.flatten(sortedArray.reverse(), true);
}
return _.flatten(sortedArray, true);
});
function getKeyValue(object, keyPath) {
keyPath = keyPath.split('.');
for (var i = 0; i < keyPath.length; i++) {
if (object && _.has(object, keyPath[i])) {
object = object[keyPath[i]];
}
else {
return undefined;
}
}
return object;
}
@@ -0,0 +1,24 @@
/**
* A global Blaze UI helper to get the thumbnails for the given study
*/
Template.registerHelper('studyThumbnails', study => {
if (!study) {
return;
}
// Find the study's stacks
const stacks = study.displaySets;
// Defines the resulting thumbnails list
const thumbnails = [];
// Iterate over the stacks and add one by one with its index
_.each(stacks, (stack, index) => {
thumbnails.push({
thumbnailIndex: index,
stack: stack
});
});
return thumbnails;
});