From 20b49d5036f7f765fcf9504e3a5fc5ce44e9dd80 Mon Sep 17 00:00:00 2001 From: Bruno Alves de Faria Date: Sat, 3 Sep 2016 18:16:57 -0300 Subject: [PATCH] AWV-3: Transforming the CINE inputs in form components --- .../ohif-core/client/components/base/index.js | 4 ++ .../components/base/mixins/component.js | 8 +-- .../components/base/mixins/schemaData.js | 10 +++ .../components/base/section/section.html | 3 + .../client/components/base/section/section.js | 62 +++++++++++++++++++ .../client/components/base/template.js | 30 +++++---- .../components/base/templates/input.html | 4 ++ .../components/base/wrappers/label.html | 2 +- .../components/base/wrappers/title.html | 2 +- .../client/components/bootstrap/index.js | 1 + .../components/bootstrap/input/range.html | 13 ++++ Packages/ohif-core/client/lib/blaze.js | 6 +- .../viewer/cineDialog/cineDialog.html | 20 +++--- .../viewer/cineDialog/cineDialog.js | 16 +++++ Packages/viewerbase/lib/viewportFunctions.js | 2 + 15 files changed, 145 insertions(+), 38 deletions(-) create mode 100644 Packages/ohif-core/client/components/base/section/section.html create mode 100644 Packages/ohif-core/client/components/base/section/section.js create mode 100644 Packages/ohif-core/client/components/bootstrap/input/range.html diff --git a/Packages/ohif-core/client/components/base/index.js b/Packages/ohif-core/client/components/base/index.js index bc57de0ae..f0b164e50 100644 --- a/Packages/ohif-core/client/components/base/index.js +++ b/Packages/ohif-core/client/components/base/index.js @@ -3,6 +3,10 @@ import './component.js'; import './mixin.js'; import './template.js'; +// Section +import './section/section.html'; +import './section/section.js'; + // Mixins import './mixins/component.js'; import './mixins/form.js'; diff --git a/Packages/ohif-core/client/components/base/mixins/component.js b/Packages/ohif-core/client/components/base/mixins/component.js index 4b5b48f9b..0b9860b70 100644 --- a/Packages/ohif-core/client/components/base/mixins/component.js +++ b/Packages/ohif-core/client/components/base/mixins/component.js @@ -2,15 +2,9 @@ import { OHIF } from 'meteor/ohif:core'; import { Template } from 'meteor/templating'; /* - * component: create the base structure to aplly specific component mixins + * component: base component structure */ OHIF.mixins.component = new OHIF.Mixin({ composition: { - onCreated() { - const instance = Template.instance(); - - // Declare a property that will be shared among all dependent mixins - instance.component = new OHIF.Component(this); - } } }); diff --git a/Packages/ohif-core/client/components/base/mixins/schemaData.js b/Packages/ohif-core/client/components/base/mixins/schemaData.js index cf50265c2..6072eafb8 100644 --- a/Packages/ohif-core/client/components/base/mixins/schemaData.js +++ b/Packages/ohif-core/client/components/base/mixins/schemaData.js @@ -77,6 +77,16 @@ OHIF.mixins.schemaData = new OHIF.Mixin({ data.label = new ReactiveVar(currentSchema.label); } + // Set the min value + if (_.isUndefined(data.min) && currentSchema.min) { + data.min = currentSchema.min; + } + + // Set the max value + if (_.isUndefined(data.max) && currentSchema.max) { + data.max = currentSchema.max; + } + // Set the emptyOption data attribute if given on schema if (currentSchema.emptyOption) { data.emptyOption = currentSchema.emptyOption; diff --git a/Packages/ohif-core/client/components/base/section/section.html b/Packages/ohif-core/client/components/base/section/section.html new file mode 100644 index 000000000..6a6bec8e3 --- /dev/null +++ b/Packages/ohif-core/client/components/base/section/section.html @@ -0,0 +1,3 @@ + diff --git a/Packages/ohif-core/client/components/base/section/section.js b/Packages/ohif-core/client/components/base/section/section.js new file mode 100644 index 000000000..095221994 --- /dev/null +++ b/Packages/ohif-core/client/components/base/section/section.js @@ -0,0 +1,62 @@ +import { OHIF } from 'meteor/ohif:core'; + +Template.section.onCreated(() => { + const instance = Template.instance(); + + // Create the render function and section data as reactive objects + instance.renderFunction = new ReactiveVar(null); + instance.sectionData = new ReactiveVar(null); + + // Get the section name + const sectionName = instance.data; + + // Stop here if no section name was defined + if (!sectionName) { + return; + } + + // Get the content block + const templateContentBlock = instance.view.templateContentBlock; + + // Check if it is defining or printing the section content + if (templateContentBlock) { + // Get the parent component of this section + const component = OHIF.blaze.getParentComponent(instance.view, '_wrapperComponent'); + + // Stop here if this section is not inside a component + if (!component) { + return; + } + + // Define the content + component.templateInstance.sections[sectionName] = { + data: component.templateInstance.data, + renderFunction: templateContentBlock.renderFunction + }; + } else { + // Wait for re-rendering and print the section content + Tracker.afterFlush(() => { + // Get the parent component of this section + const component = OHIF.blaze.getParentComponent(instance.view, '_wrapperComponent'); + + // Stop here if this section is not inside a component + if (!component) { + return; + } + + // Get the defined section content + const section = component.templateInstance.sections[sectionName]; + + // Stop here if the section content is not defined yet + if (!section) { + return; + } + + // Set the section data on its respective reactive object + instance.sectionData.set(section.data); + + // Set the render function on its respective reactive object + instance.renderFunction.set(new Template(section.renderFunction)); + }); + } +}); diff --git a/Packages/ohif-core/client/components/base/template.js b/Packages/ohif-core/client/components/base/template.js index f940c470b..979e9189a 100644 --- a/Packages/ohif-core/client/components/base/template.js +++ b/Packages/ohif-core/client/components/base/template.js @@ -50,23 +50,27 @@ Template.baseComponent.constructView = function(contentFunc, elseFunc) { let contentFunction = () => { // Create the most inner content function const innerContentFunction = () => { - // Assign properties to all wrappers after template's creation - template.onCreated(() => { - const instance = Template.instance(); - - // Assign the template most outer wrapper - instance.wrapper = wrapperInstances[0] || instance; - - // Iterate over all wrappers and assign the component to them - wrapperInstances.forEach(wrappeInstance => { - wrappeInstance.component = instance.component; - }); - }); - // Return the view instance return template.constructView(contentFunc, elseFunc); }; + // Assign properties to all wrappers after template's creation + template.onCreated(() => { + const instance = Template.instance(); + + // create the base structure to aplly specific component mixins + instance.component = new OHIF.Component(instance); + + // Assign the template most outer wrapper + instance.wrapper = wrapperInstances[0] || instance; + + // Iterate over all wrappers and assign the component to them + wrapperInstances.forEach(wrapperInstance => { + wrapperInstance.view._wrapperComponent = instance.component; + wrapperInstance.component = instance.component; + }); + }); + // Apply the mixins to the component OHIF.Mixin.initAll(template, data); diff --git a/Packages/ohif-core/client/components/base/templates/input.html b/Packages/ohif-core/client/components/base/templates/input.html index 847826cef..1bd9fd159 100644 --- a/Packages/ohif-core/client/components/base/templates/input.html +++ b/Packages/ohif-core/client/components/base/templates/input.html @@ -6,6 +6,10 @@ name="{{this.name}}" value="{{reactive this.value}}" placeholder="{{this.placeholder}}" + checked="{{#if this.checked}}checked{{/if}}" + min="{{this.min}}" + max="{{this.max}}" + maxlength="{{choose this.maxlength this.max}}" {{this.tagAttributes}} > {{>UI.contentBlock}} diff --git a/Packages/ohif-core/client/components/base/wrappers/label.html b/Packages/ohif-core/client/components/base/wrappers/label.html index ba1bbd2dc..cfa371255 100644 --- a/Packages/ohif-core/client/components/base/wrappers/label.html +++ b/Packages/ohif-core/client/components/base/wrappers/label.html @@ -3,7 +3,7 @@ {{#if this.labelAfter}} {{>UI.contentBlock}} {{/if}} - {{reactive this.label}} + {{>section 'labelBeforeText'}}{{reactive this.label}}{{>section 'labelAfterText'}} {{#unless this.labelAfter}} {{>UI.contentBlock}} {{/unless}} diff --git a/Packages/ohif-core/client/components/base/wrappers/title.html b/Packages/ohif-core/client/components/base/wrappers/title.html index 0db25ccb5..2c4fedf06 100644 --- a/Packages/ohif-core/client/components/base/wrappers/title.html +++ b/Packages/ohif-core/client/components/base/wrappers/title.html @@ -3,7 +3,7 @@ {{#if this.labelAfter}} {{>UI.contentBlock}} {{/if}} - {{reactive this.label}} + {{>section 'labelBeforeText'}}{{reactive this.label}}{{>section 'labelAfterText'}} {{#unless this.labelAfter}} {{>UI.contentBlock}} {{/unless}} diff --git a/Packages/ohif-core/client/components/bootstrap/index.js b/Packages/ohif-core/client/components/bootstrap/index.js index 2baa5508b..31306d8bd 100644 --- a/Packages/ohif-core/client/components/bootstrap/index.js +++ b/Packages/ohif-core/client/components/bootstrap/index.js @@ -5,6 +5,7 @@ import './input/checkbox.html'; import './input/hidden.html'; import './input/groupRadio.html'; import './input/radio.html'; +import './input/range.html'; import './input/select.html'; import './input/text.html'; import './input/selectTree.html'; diff --git a/Packages/ohif-core/client/components/bootstrap/input/range.html b/Packages/ohif-core/client/components/bootstrap/input/range.html new file mode 100644 index 000000000..a78b010ac --- /dev/null +++ b/Packages/ohif-core/client/components/bootstrap/input/range.html @@ -0,0 +1,13 @@ + diff --git a/Packages/ohif-core/client/lib/blaze.js b/Packages/ohif-core/client/lib/blaze.js index a8a03763a..ed4cd99a5 100644 --- a/Packages/ohif-core/client/lib/blaze.js +++ b/Packages/ohif-core/client/lib/blaze.js @@ -31,12 +31,12 @@ OHIF.blaze.getParentView = (view, parentViewName) => { }; // Search for the parent component of the given view -OHIF.blaze.getParentComponent = view => { +OHIF.blaze.getParentComponent = (view, property='_component') => { let currentView = view; while (currentView) { currentView = currentView.originalParentView || currentView.parentView; - if (currentView && currentView._component) { - return currentView._component; + if (currentView && currentView[property]) { + return currentView[property]; } } }; diff --git a/Packages/viewerbase/client/components/viewer/cineDialog/cineDialog.html b/Packages/viewerbase/client/components/viewer/cineDialog/cineDialog.html index ba92ad778..4b0de1fbd 100644 --- a/Packages/viewerbase/client/components/viewer/cineDialog/cineDialog.html +++ b/Packages/viewerbase/client/components/viewer/cineDialog/cineDialog.html @@ -1,5 +1,5 @@ diff --git a/Packages/viewerbase/client/components/viewer/cineDialog/cineDialog.js b/Packages/viewerbase/client/components/viewer/cineDialog/cineDialog.js index fc7ed8406..14683b392 100644 --- a/Packages/viewerbase/client/components/viewer/cineDialog/cineDialog.js +++ b/Packages/viewerbase/client/components/viewer/cineDialog/cineDialog.js @@ -1,8 +1,24 @@ import { OHIF } from 'meteor/ohif:core'; +import { SimpleSchema } from 'meteor/aldeed:simple-schema'; Template.cineDialog.onCreated(() => { const instance = Template.instance(); + instance.schema = new SimpleSchema({ + loop: { + type: Boolean, + label: 'Loop', + defaultValue: true + }, + speed: { + type: Number, + label: 'Cine Speed', + defaultValue: 24, + min: 1, + max: 90 + } + }); + instance.updateFramerate = rate => { OHIF.viewer.cine.framesPerSecond = rate; diff --git a/Packages/viewerbase/lib/viewportFunctions.js b/Packages/viewerbase/lib/viewportFunctions.js index 614b1f43d..042f35621 100644 --- a/Packages/viewerbase/lib/viewportFunctions.js +++ b/Packages/viewerbase/lib/viewportFunctions.js @@ -134,3 +134,5 @@ isPlaying = () => { // Return true if the clip is playing return !_.isUndefined(clipState.intervalId); }; +// Create an event listener to update playing state when a clip stops playing +$(window).on('CornerstoneToolsClipStopped', () => Session.set('UpdateCINE', Random.id()));