LT-247: Adding behavior for All timepoints option

This commit is contained in:
Bruno Alves de Faria authored and Erik Ziegler committed 2016-07-22 11:00:16 +02:00
1 parent 4e6f46f876
commit d014c72aa4
2 files changed
+27 -5

No files matched your search

@@ -1,3 +1,18 @@
Template.studyTimepointBrowser.onRendered(() => {
const instance = Template.instance();
instance.autorun(() => {
// Runs this computation everytime the timepointViewType is changed
const type = instance.data.timepointViewType.get();
// Removes all active classes to collapse the timepoints and studies
instance.$('.timepointEntry, .studyTimepointStudy').removeClass('active');
if (type === 'key') {
// Show only first timepoint expanded for key timepoints
instance.$('.timepointEntry:first').addClass('active');
}
});
});
Template.studyTimepointBrowser.events({
'click .timepointHeader'(event, instance) {
const $timepoint = $(event.currentTarget).closest('.timepointEntry');
@@ -11,21 +26,28 @@ Template.studyTimepointBrowser.events({
});
Template.studyTimepointBrowser.helpers({
timepoints: function() {
timepoints() {
// Sort timepoints based on timeline and type
const sort = {
sort: {
earliestDate: -1
earliestDate: -1,
timepointType: -1
}
};
// Returns all timepoints with sorting
return Timepoints.find({}, sort);
},
// Decides if a timepoint should be shown or omitted
shouldShowTimepoint(timepoint, index) {
const instance = Template.instance();
// Show all timepoints when view type is all
if (instance.data.timepointViewType.get() === 'all') {
return true;
}
return index < 4 || timepoint.timepointType === 'baseline';
// Show only the latest timepoints and baseline
return index < 3 || timepoint.timepointType === 'baseline';
},
// Build the timepoint title based on its date
timepointTitle(timepoint, total, index) {
@@ -39,7 +61,7 @@ Template.studyTimepointBrowser.helpers({
2: '(Nadir)'
};
// TODO: [design] find out how to define the nadir timepoint
const followUp = total - index - 1;
const followUp = total - index;
const parenthesis = states[index] || '';
return `Follow-up ${followUp} ${parenthesis}`;
}