LT-67: Creating data parser and styling components with validation error
This commit is contained in:
parent
e9ec386e72
commit
6e84a388b6
@ -37,7 +37,8 @@ Package.onUse(function(api) {
|
|||||||
api.addFiles([
|
api.addFiles([
|
||||||
'styles/components/radio.styl',
|
'styles/components/radio.styl',
|
||||||
'styles/components/select2.styl',
|
'styles/components/select2.styl',
|
||||||
'styles/components/selectTree.styl'
|
'styles/components/selectTree.styl',
|
||||||
|
'styles/components/states.styl'
|
||||||
], 'client');
|
], 'client');
|
||||||
|
|
||||||
// Rounded Button Group
|
// Rounded Button Group
|
||||||
|
|||||||
7
Packages/design/styles/components/states.styl
Normal file
7
Packages/design/styles/components/states.styl
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
@import "{design}/app"
|
||||||
|
|
||||||
|
.state-error:not(.component-group)
|
||||||
|
&.form-control, .form-control
|
||||||
|
theme('background-color', '$uiStateError')
|
||||||
|
theme('border-color', '$uiStateErrorBorder')
|
||||||
|
theme('color', '$uiStateErrorText')
|
||||||
@ -3,6 +3,11 @@ $themes['tide'] = {
|
|||||||
$uiYellow: #E29E4A
|
$uiYellow: #E29E4A
|
||||||
$uiSkyBlue: #6FBDE2
|
$uiSkyBlue: #6FBDE2
|
||||||
|
|
||||||
|
// State pallete
|
||||||
|
$uiStateError: #FFCCCC
|
||||||
|
$uiStateErrorBorder: #993333
|
||||||
|
$uiStateErrorText: #661111
|
||||||
|
|
||||||
$uiLightGray: #516873
|
$uiLightGray: #516873
|
||||||
$uiGray: #263340
|
$uiGray: #263340
|
||||||
$uiGrayDark: #16202B
|
$uiGrayDark: #16202B
|
||||||
|
|||||||
@ -3,6 +3,11 @@ $themes['tigerlilly'] = {
|
|||||||
$uiYellow: #E29E4A
|
$uiYellow: #E29E4A
|
||||||
$uiSkyBlue: #6FBDE2
|
$uiSkyBlue: #6FBDE2
|
||||||
|
|
||||||
|
// State pallete
|
||||||
|
$uiStateError: #FFCCCC
|
||||||
|
$uiStateErrorBorder: #CC6666
|
||||||
|
$uiStateErrorText: #661111
|
||||||
|
|
||||||
$uiLightGray: #516873
|
$uiLightGray: #516873
|
||||||
$uiGray: #263340
|
$uiGray: #263340
|
||||||
$uiGrayDark: #16202B
|
$uiGrayDark: #16202B
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<template name="serverInformationDimse">
|
<template name="serverInformationDimse">
|
||||||
<div class="panel panel-default panel-body">
|
<div class="panel panel-default panel-body">
|
||||||
<div class="clearfix">
|
<div class="clearfix">
|
||||||
<h4 class="pull-left">Peer list</h4>
|
<h4 class="pull-left">Peer List</h4>
|
||||||
<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>
|
||||||
|
|||||||
@ -16,7 +16,7 @@ OHIF.mixins.checkbox = new OHIF.Mixin({
|
|||||||
component.value = value => {
|
component.value = value => {
|
||||||
const isGet = _.isUndefined(value);
|
const isGet = _.isUndefined(value);
|
||||||
if (isGet) {
|
if (isGet) {
|
||||||
return component.$element.is(':checked');
|
return component.parseData(component.$element.is(':checked'));
|
||||||
}
|
}
|
||||||
|
|
||||||
component.$element.prop('checked', value);
|
component.$element.prop('checked', value);
|
||||||
|
|||||||
@ -31,7 +31,7 @@ OHIF.mixins.formItem = new OHIF.Mixin({
|
|||||||
component.value = value => {
|
component.value = value => {
|
||||||
const isGet = _.isUndefined(value);
|
const isGet = _.isUndefined(value);
|
||||||
if (isGet) {
|
if (isGet) {
|
||||||
return component.$element.val();
|
return component.parseData(component.$element.val());
|
||||||
}
|
}
|
||||||
|
|
||||||
component.$element.val(value).trigger('change');
|
component.$element.val(value).trigger('change');
|
||||||
|
|||||||
@ -98,21 +98,27 @@ OHIF.mixins.group = new OHIF.Mixin({
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Check if the form data is valid in its schema
|
// Check if the form data is valid in its schema
|
||||||
|
const validateSelf = component.validate;
|
||||||
component.validate = () => {
|
component.validate = () => {
|
||||||
// Assume validation result as true
|
// Assume validation result as true
|
||||||
let result = true;
|
let result = true;
|
||||||
|
|
||||||
// Return true if there's no data schema defined
|
// Return true if there's no data schema defined
|
||||||
if (!component.schema) {
|
if (component.isForm && !component.schema) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validate the component itself if it has a key
|
||||||
|
if (instance.data.pathKey && !validateSelf()) {
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Iterate over each registered form item and validate it
|
// Iterate over each registered form item and validate it
|
||||||
component.registeredItems.forEach(child => {
|
component.registeredItems.forEach(child => {
|
||||||
const key = child.templateInstance.data.key;
|
const key = child.templateInstance.data.key;
|
||||||
|
|
||||||
// Change result to false if any form item is invalid
|
// Change result to false if any form item is invalid
|
||||||
if (key && !child.validate()) {
|
if ((key || instance.data.arrayValues) && !child.validate()) {
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -21,7 +21,7 @@ OHIF.mixins.groupRadio = new OHIF.Mixin({
|
|||||||
component.registeredItems.forEach(child => elements.push(child.$element[0]));
|
component.registeredItems.forEach(child => elements.push(child.$element[0]));
|
||||||
const $elements = $(elements);
|
const $elements = $(elements);
|
||||||
if (isGet) {
|
if (isGet) {
|
||||||
return $elements.filter(':checked').val();
|
return component.parseData($elements.filter(':checked').val());
|
||||||
}
|
}
|
||||||
|
|
||||||
$elements.filter(`[value='${value}']`).prop('checked', true).trigger('change');
|
$elements.filter(`[value='${value}']`).prop('checked', true).trigger('change');
|
||||||
|
|||||||
@ -30,6 +30,7 @@ const getCurrentSchema = (parentComponent, key) => {
|
|||||||
|
|
||||||
// Merge the sub-schema properties if it's an array
|
// Merge the sub-schema properties if it's an array
|
||||||
if (Array.isArray(currentSchema.type())) {
|
if (Array.isArray(currentSchema.type())) {
|
||||||
|
console.warn('>>>>IS ARRAY', currentSchema);
|
||||||
_.extend(currentSchema, schema._schema[key + '.$']);
|
_.extend(currentSchema, schema._schema[key + '.$']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,6 +106,35 @@ OHIF.mixins.schemaData = new OHIF.Mixin({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onCreated() {
|
||||||
|
const instance = Template.instance();
|
||||||
|
const component = instance.component;
|
||||||
|
|
||||||
|
// Create a data parser according to current schema key
|
||||||
|
component.parseData = value => {
|
||||||
|
// Get the current schema data using component's key
|
||||||
|
const currentSchema = getCurrentSchema(component.parent, instance.data.pathKey);
|
||||||
|
|
||||||
|
// Stop here if there's no schema data for current key
|
||||||
|
if (!currentSchema) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the schema is a Number
|
||||||
|
if (currentSchema.type === Number) {
|
||||||
|
return parseFloat(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the schema is a Boolean
|
||||||
|
if (currentSchema.type === Boolean) {
|
||||||
|
return !!value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the original value if none of the checks matched
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
onMixins() {
|
onMixins() {
|
||||||
const instance = Template.instance();
|
const instance = Template.instance();
|
||||||
const component = instance.component;
|
const component = instance.component;
|
||||||
|
|||||||
@ -30,7 +30,7 @@ OHIF.mixins.selectTree = new OHIF.Mixin({
|
|||||||
|
|
||||||
// Return the current value
|
// Return the current value
|
||||||
if (isGet) {
|
if (isGet) {
|
||||||
return rootInstance.currentValue;
|
return component.parseData(rootInstance.currentValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change the current value
|
// Change the current value
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
<div
|
<div
|
||||||
id="{{this.id}}"
|
id="{{this.id}}"
|
||||||
class="{{this.class}}"
|
class="{{this.class}}"
|
||||||
|
data-key="{{this.pathKey}}"
|
||||||
{{this.tagAttributes}}
|
{{this.tagAttributes}}
|
||||||
>
|
>
|
||||||
{{>UI.contentBlock}}
|
{{>UI.contentBlock}}
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
name="{{this.name}}"
|
name="{{this.name}}"
|
||||||
value="{{reactive this.value}}"
|
value="{{reactive this.value}}"
|
||||||
placeholder="{{this.placeholder}}"
|
placeholder="{{this.placeholder}}"
|
||||||
data-key="{{this.key}}"
|
data-key="{{this.pathKey}}"
|
||||||
{{this.tagAttributes}}
|
{{this.tagAttributes}}
|
||||||
>
|
>
|
||||||
{{>UI.contentBlock}}
|
{{>UI.contentBlock}}
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
name="{{this.name}}"
|
name="{{this.name}}"
|
||||||
multiple="{{#if this.multiple}}multiple{{/if}}"
|
multiple="{{#if this.multiple}}multiple{{/if}}"
|
||||||
disabled="{{#if this.disabled}}disabled{{/if}}"
|
disabled="{{#if this.disabled}}disabled{{/if}}"
|
||||||
data-key="{{this.key}}"
|
data-key="{{this.pathKey}}"
|
||||||
{{this.tagAttributes}}
|
{{this.tagAttributes}}
|
||||||
>
|
>
|
||||||
{{>UI.contentBlock}}
|
{{>UI.contentBlock}}
|
||||||
|
|||||||
@ -23,18 +23,18 @@ export const DICOMWebRequestOptions = new SimpleSchema({
|
|||||||
logRequests: {
|
logRequests: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
defaultValue: true,
|
defaultValue: true,
|
||||||
label: 'Requests',
|
label: 'Requests'
|
||||||
},
|
},
|
||||||
logResponses: {
|
logResponses: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
defaultValue: false,
|
defaultValue: false,
|
||||||
label: 'Responses',
|
label: 'Responses'
|
||||||
},
|
},
|
||||||
logTiming: {
|
logTiming: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
defaultValue: true,
|
defaultValue: true,
|
||||||
label: 'Timing',
|
label: 'Timing'
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export const DICOMWebServer = new SimpleSchema({
|
export const DICOMWebServer = new SimpleSchema({
|
||||||
@ -81,7 +81,7 @@ export const DICOMWebServer = new SimpleSchema({
|
|||||||
export const DIMSEPeer = new SimpleSchema({
|
export const DIMSEPeer = new SimpleSchema({
|
||||||
aeTitle: {
|
aeTitle: {
|
||||||
type: String,
|
type: String,
|
||||||
label: 'AE Title',
|
label: 'AE Title'
|
||||||
},
|
},
|
||||||
hostAE: {
|
hostAE: {
|
||||||
type: String,
|
type: String,
|
||||||
@ -90,7 +90,7 @@ export const DIMSEPeer = new SimpleSchema({
|
|||||||
},
|
},
|
||||||
host: {
|
host: {
|
||||||
type: String,
|
type: String,
|
||||||
label: 'Host Domain/IP',
|
label: 'Host Domain/IP'
|
||||||
},
|
},
|
||||||
port: {
|
port: {
|
||||||
type: Number,
|
type: Number,
|
||||||
@ -120,8 +120,9 @@ export const DIMSEServer = new SimpleSchema({
|
|||||||
name: serverNameDefinitions,
|
name: serverNameDefinitions,
|
||||||
type: serverTypeDefinitions,
|
type: serverTypeDefinitions,
|
||||||
peers: {
|
peers: {
|
||||||
type: [ DIMSEPeer ],
|
type: [DIMSEPeer],
|
||||||
label: 'DIMSE Peers',
|
label: 'Peer List',
|
||||||
|
minCount: 1
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -147,12 +148,12 @@ export const PublicServerConfig = new SimpleSchema({
|
|||||||
|
|
||||||
export const Servers = new SimpleSchema({
|
export const Servers = new SimpleSchema({
|
||||||
dicomWeb: {
|
dicomWeb: {
|
||||||
type: [ DICOMWebServer ],
|
type: [DICOMWebServer],
|
||||||
label: 'DICOMWeb Servers',
|
label: 'DICOMWeb Servers',
|
||||||
optional: true
|
optional: true
|
||||||
},
|
},
|
||||||
dimse: {
|
dimse: {
|
||||||
type: [ DIMSEServer ],
|
type: [DIMSEServer],
|
||||||
label: 'DIMSE Servers',
|
label: 'DIMSE Servers',
|
||||||
optional: true
|
optional: true
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user