From ed810a80d307225f504c664cee9c89834255c2a8 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Tue, 16 Feb 2021 10:04:55 +0900 Subject: [PATCH] Add object field for custom rest request --- .../settings/ConfigCreationForm.vue | 10 +- .../containers/settings/ObjectField.vue | 202 ++++++++++++++++++ frontend/models/config/config-item-list.ts | 7 +- frontend/models/config/config-template.ts | 8 + 4 files changed, 225 insertions(+), 2 deletions(-) create mode 100644 frontend/components/containers/settings/ObjectField.vue diff --git a/frontend/components/containers/settings/ConfigCreationForm.vue b/frontend/components/containers/settings/ConfigCreationForm.vue index fe922138..f64a151b 100644 --- a/frontend/components/containers/settings/ConfigCreationForm.vue +++ b/frontend/components/containers/settings/ConfigCreationForm.vue @@ -64,6 +64,12 @@ outlined :key="item.name" /> +

Set mapping template

@@ -147,10 +153,12 @@ import { ConfigTemplateItem } from '@/models/config/config-template' import { ConfigItem } from '@/models/config/config-item-list' import { StepCounter } from '@/models/stepper' import LabelMapping from '@/components/containers/settings/LabelMapping.vue' +import ObjectField from '@/components/containers/settings/ObjectField.vue' export default Vue.extend({ components: { - LabelMapping + LabelMapping, + ObjectField }, data() { diff --git a/frontend/components/containers/settings/ObjectField.vue b/frontend/components/containers/settings/ObjectField.vue new file mode 100644 index 00000000..3df5d2b2 --- /dev/null +++ b/frontend/components/containers/settings/ObjectField.vue @@ -0,0 +1,202 @@ + + + + + diff --git a/frontend/models/config/config-item-list.ts b/frontend/models/config/config-item-list.ts index 9e2cdaf9..6755a595 100644 --- a/frontend/models/config/config-item-list.ts +++ b/frontend/models/config/config-item-list.ts @@ -36,7 +36,12 @@ export class ConfigItem { } ): ConfigItem { const mapping = labelMapping.reduce((a, x) => ({...a, [x.from]: x.to}), {}) - const attributes = modelAttrs.reduce((a, x) => ({...a, [x.name]: x.value}), {}) + const attributes: {[key: string]: any} = modelAttrs.reduce((a, x) => ({...a, [x.name]: x.value}), {}) + for (const [key, value] of Object.entries(attributes)) { + if (Array.isArray(value)) { + attributes[key] = value.reduce((a, x) => ({...a, [x.key]: x.value}), {}) + } + } return new ConfigItem(99999, modelName, attributes, template, mapping) } diff --git a/frontend/models/config/config-template.ts b/frontend/models/config/config-template.ts index 1f18fa5b..7b2afe99 100644 --- a/frontend/models/config/config-template.ts +++ b/frontend/models/config/config-template.ts @@ -43,6 +43,14 @@ export class ConfigTemplateItem { ) } ) + } else if ('type' in value && value.type === 'object') { + response.push( + { + name: key, + type: 'objectField', + value: [] + } + ) } } return response