Template.lesionTable.onCreated(() => { const instance = Template.instance(); instance.data.lesionTableLayout = new ReactiveVar('comparison'); instance.data.timepoints = new ReactiveVar([]); instance.autorun(() => { // Get the current table layout const tableLayout = instance.data.lesionTableLayout.get(); // Get all the timepoints const allTimepoints = Timepoints.find({}, { sort: { latestDate: -1 } }).fetch(); // Get the last 2 timepoints let timepoints = allTimepoints.slice(0, 2); // Concatenate the baseline if the table layout is for key timepoints if (tableLayout === 'key' && allTimepoints.length > 2) { timepoints = timepoints.concat(_.last(allTimepoints)); } // Return key timepoints instance.data.timepoints.set(timepoints); }); }); Template.lesionTable.onRendered(() => { const instance = Template.instance(); instance.autorun(() => { // Run this computation everytime the lesion table layout is changed instance.data.lesionTableLayout.dep.depend(); if(instance.data.state.get('rightSidebar') !== 'lesions') { // Remove the amount attribute from sidebar element tag instance.$('#lesionTableContainer').closest('.sidebarMenu').removeAttr('data-timepoints'); return; } // Get the amount of timepoints being shown const timepointAmount = instance.data.timepoints.get().length; // Set the amount in an attribute on sidebar element tag instance.$('#lesionTableContainer').closest('.sidebarMenu').attr('data-timepoints', timepointAmount); }); }); // Temporary until we have a real window manager with events for series/study changed Session.setDefault('NewSeriesLoaded', false); Template.lesionTable.onRendered(() => { // Find the first measurement by Lesion Number var firstLesion = Measurements.findOne({}, { sort: { lesionNumber: 1 } }); // Create an object to store the ContentId inside var templateData = { contentId: Session.get('activeContentId') }; // Activate the first lesion if (firstLesion) { activateLesion(firstLesion._id, templateData); } }); Template.lesionTable.events({ /** * Retrieve the lesion id from the DOM data for this row */ /*'click table#tblLesion tbody tr': function(e, template) { var measurementId = $(e.currentTarget).data('measurementid'); activateLesion(measurementId, template.data); },*/ }); Template.lesionTable.helpers({ dataContainer() { return {}; }, buttonGroupData() { const instance = Template.instance(); return { value: instance.data.lesionTableLayout, options: [{ value: 'comparison', text: 'Comparison' }, { value: 'key', text: 'Key Timepoints' }] }; } });