LT-67: Migrating DIMSE inputs to components

This commit is contained in:
Bruno Alves de Faria 2016-08-31 08:09:27 -03:00
parent c3d7c2af09
commit e5eb98cbc0
6 changed files with 54 additions and 41 deletions

View File

@ -1,5 +1,5 @@
Template.serverInformationDicomWeb.onRendered(function() { Template.serverInformationDicomWeb.onRendered(() => {
var instance = Template.instance(); const instance = Template.instance();
instance.autorun(function() { instance.autorun(function() {
const mode = instance.data.mode.get(); const mode = instance.data.mode.get();
if (mode === 'edit') { if (mode === 'edit') {

View File

@ -5,39 +5,41 @@
<button class="btn btn-primary pull-right js-new-peer">New peer</button> <button class="btn btn-primary pull-right js-new-peer">New peer</button>
</div> </div>
<hr> <hr>
<div class="row"> {{#group class='row' key='peers' arrayValues=true}}
{{#each peer in instance.peers.get}} {{#each peer in instance.peers.get}}
<div class="col-lg-6"> {{#group class='col-lg-6'}}
<div class="panel panel-default panel-body"> <div class="panel panel-default panel-body">
<div class="row"> <div class="row">
{{>serverInformationFormField name=(concat "peers[]." @index ".aeTitle") label="AE title"}} <div class="col-lg-6">
{{>serverInformationFormField name=(concat "peers[]." @index ".hostAE") label="AE host"}} {{>inputText class='form-control' key='aeTitle'}}
{{>serverInformationFormField name=(concat "peers[]." @index ".host") label="Host"}} </div>
{{>serverInformationFormField name=(concat "peers[]." @index ".port") label="Port"}} <div class="col-lg-6">
{{>inputText class='form-control' key='hostAE'}}
</div>
<div class="col-lg-6">
{{>inputText class='form-control' key='host'}}
</div>
<div class="col-lg-6">
{{>inputText class='form-control' key='port'}}
</div>
<div class="col-lg-12"> <div class="col-lg-12">
<strong>Settings</strong> <strong>Settings</strong>
<div class="form-group"> <div class="form-group">
<div class="form-control clearfix"> <div class="form-control clearfix">
<div class="checkbox pull-left"> <div class="checkbox pull-left">
<label> {{>inputCheckbox key='default'}}
<input type="checkbox" name="peers[].{{@index}}.default">
<span>Default</span>
</label>
</div> </div>
<div class="checkbox pull-left"> <div class="checkbox pull-left">
<label> {{>inputCheckbox key='server'}}
<input type="checkbox" name="peers[].{{@index}}.server">
<span>Server</span>
</label>
</div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
{{/group}}
{{/each}} {{/each}}
</div> {{/group}}
</div> </div>
<hr> <hr>
</template> </template>

View File

@ -1,29 +1,29 @@
Template.serverInformationDimse.onCreated(function() { Template.serverInformationDimse.onCreated(() => {
var instance = Template.instance(); const instance = Template.instance();
instance.peers = new ReactiveVar([]); instance.peers = new ReactiveVar([]);
instance.autorun(function() { instance.autorun(() => {
var currentItem = instance.data.currentItem.get(); const currentItem = instance.data.currentItem.get();
if (currentItem) { if (currentItem) {
instance.peers.set(currentItem.peers || []); instance.peers.set(currentItem.peers || []);
} }
}); });
}); });
Template.serverInformationDimse.onRendered(function() { Template.serverInformationDimse.onRendered(() => {
var instance = Template.instance(); const instance = Template.instance();
instance.autorun(function() { instance.autorun(() => {
var mode = instance.data.mode.get(); const mode = instance.data.mode.get();
if (mode === 'edit') { if (mode === 'edit') {
var data = instance.data.currentItem.get(); const data = instance.data.currentItem.get();
FormUtils.setFormData(instance.data.$form, data); instance.data.form.value(data);
} }
}); });
}); });
Template.serverInformationDimse.events({ Template.serverInformationDimse.events({
'click .js-new-peer': function(event, instance) { 'click .js-new-peer'(event, instance) {
event.preventDefault(); event.preventDefault();
var peers = instance.peers.get(); const peers = instance.peers.get();
peers.push({}); peers.push({});
instance.peers.set(peers); instance.peers.set(peers);
} }

View File

@ -29,22 +29,30 @@ OHIF.mixins.group = new OHIF.Mixin({
// Get or set the child components values // Get or set the child components values
component.value = value => { component.value = value => {
const isGet = _.isUndefined(value); const isGet = _.isUndefined(value);
const isArray = instance.data.arrayValues;
const result = isArray ? [] : {};
if (isGet) { if (isGet) {
const result = {};
component.registeredItems.forEach(child => { component.registeredItems.forEach(child => {
if (!isArray) {
const key = child.templateInstance.data.key; const key = child.templateInstance.data.key;
if (key) { if (key) {
result[key] = child.value(); result[key] = child.value();
} }
} else {
result.push(child.value());
}
}); });
return result; return result;
} }
const groupValue = typeof value === 'object' ? value : {}; const groupValue = typeof value === 'object' ? value : result;
let i = 0;
component.registeredItems.forEach(child => { component.registeredItems.forEach(child => {
const key = child.templateInstance.data.key; const key = isArray ? i : child.templateInstance.data.key;
const childValue = _.isUndefined(groupValue[key]) ? null : groupValue[key]; const childValue = _.isUndefined(groupValue[key]) ? null : groupValue[key];
child.value(childValue); child.value(childValue);
i++;
}); });
component.$element.trigger('change'); component.$element.trigger('change');
}; };

View File

@ -52,10 +52,13 @@ OHIF.mixins.schemaData = new OHIF.Mixin({
const parent = OHIF.blaze.getParentComponent(Blaze.currentView); const parent = OHIF.blaze.getParentComponent(Blaze.currentView);
// Get he parent component key // Get he parent component key
let parentKey = parent && parent.templateInstance.data.pathKey; const parentKey = parent && parent.templateInstance.data.pathKey;
// Check if the parent is an array group
const isParentArray = parent && parent.templateInstance.data.arrayValues;
// Set the path key for this component // Set the path key for this component
data.pathKey = data.key || ''; data.pathKey = data.key || (isParentArray ? '$' : '');
if (data.pathKey && typeof parentKey === 'string') { if (data.pathKey && typeof parentKey === 'string') {
const prefix = parentKey ? `${parentKey}.` : ''; const prefix = parentKey ? `${parentKey}.` : '';
data.pathKey = `${prefix}${data.pathKey}`; data.pathKey = `${prefix}${data.pathKey}`;
@ -107,7 +110,7 @@ OHIF.mixins.schemaData = new OHIF.Mixin({
const component = instance.component; const component = instance.component;
// Get the current schema data using component's key // Get the current schema data using component's key
const currentSchema = getCurrentSchema(component.parent, instance.data.key); const currentSchema = getCurrentSchema(component.parent, instance.data.pathKey);
// Stop here if there's no schema data for current key // Stop here if there's no schema data for current key
if (!currentSchema) { if (!currentSchema) {

View File

@ -81,11 +81,11 @@ export const DICOMWebServer = new SimpleSchema({
export const DIMSEPeer = new SimpleSchema({ export const DIMSEPeer = new SimpleSchema({
aeTitle: { aeTitle: {
type: String, type: String,
label: 'Application Entity (AE) Title', label: 'AE Title',
}, },
hostAE: { hostAE: {
type: String, type: String,
label: 'Application Entity (AE) Host', label: 'AE Host',
optional: true optional: true
}, },
host: { host: {