From 11e86170843087a452fd34c0f0fe420267864c21 Mon Sep 17 00:00:00 2001 From: Nolan Ehrstrom Date: Wed, 4 Mar 2020 19:54:59 -0800 Subject: [PATCH 1/2] Add new options to loop inspector --- src/components/inspector/index.js | 3 +- src/components/inspector/loop.vue | 85 +++++++++++++++++++++++++++ src/components/renderer/form-loop.vue | 6 +- src/components/vue-form-builder.vue | 1 + src/form-builder-controls.js | 15 +++-- 5 files changed, 100 insertions(+), 10 deletions(-) create mode 100644 src/components/inspector/loop.vue diff --git a/src/components/inspector/index.js b/src/components/inspector/index.js index 55392528b..619ba5fdc 100644 --- a/src/components/inspector/index.js +++ b/src/components/inspector/index.js @@ -6,4 +6,5 @@ export { default as OptionsList } from './options-list'; export { default as ColumnSetup } from './column-setup'; export { default as PageSelect } from './page-select'; export { default as ValidationSelect } from './validation-select'; -export { default as ScreenSelector } from './screen-selector'; \ No newline at end of file +export { default as ScreenSelector } from './screen-selector'; +export { default as LoopInspector } from './loop'; \ No newline at end of file diff --git a/src/components/inspector/loop.vue b/src/components/inspector/loop.vue new file mode 100644 index 000000000..9c1124b0a --- /dev/null +++ b/src/components/inspector/loop.vue @@ -0,0 +1,85 @@ + + + + + diff --git a/src/components/renderer/form-loop.vue b/src/components/renderer/form-loop.vue index 4eae8cb2f..dd40aeca5 100644 --- a/src/components/renderer/form-loop.vue +++ b/src/components/renderer/form-loop.vue @@ -22,7 +22,7 @@ import Mustache from 'mustache'; export default { name: 'FormLoop', mixins: [], - props: ['value', 'name', 'config', 'transientData'], + props: ['value', 'config', 'transientData', 'name'], data() { return { matrix: [], @@ -44,11 +44,11 @@ export default { return [...itemsFromData.keys()]; } - if (!this.config) { + if (!this.config.settings) { return []; } - let times = this.config.times; + let times = this.config.settings.times; try { times = Mustache.render(times, this.transientData); diff --git a/src/components/vue-form-builder.vue b/src/components/vue-form-builder.vue index 55ce68353..f91b0a14d 100644 --- a/src/components/vue-form-builder.vue +++ b/src/components/vue-form-builder.vue @@ -199,6 +199,7 @@ v-bind="item.config" v-model="inspection.config[item.field]" @focusout.native="updateState" + @setName="inspection.config.name = $event" /> diff --git a/src/form-builder-controls.js b/src/form-builder-controls.js index 546d14389..04a9f406f 100644 --- a/src/form-builder-controls.js +++ b/src/form-builder-controls.js @@ -364,17 +364,20 @@ export default [ // Default items container items: [], config: { + name: '', icon: 'fas fa-redo', - times: '2', + settings: { + type: 'new', + varname: '', + times: '3', + add: false, + }, }, inspector: [ - keyNameProperty, { - type: 'FormInput', - field: 'times', + type: 'LoopInspector', + field: 'settings', config: { - label: 'Default Number Of Times', - helper: 'Enter the number of times to repeat if the data does not exist.', }, }, ], From 7e96f43a1081e2a73d9144efd79bbe197ea3f039 Mon Sep 17 00:00:00 2001 From: Nolan Ehrstrom Date: Thu, 5 Mar 2020 14:16:28 -0800 Subject: [PATCH 2/2] Add ability to add additional loop rows --- src/components/inspector/loop.vue | 47 +++++++++++++++------------ src/components/renderer/form-loop.vue | 45 +++++++++++++++++++++---- 2 files changed, 64 insertions(+), 28 deletions(-) diff --git a/src/components/inspector/loop.vue b/src/components/inspector/loop.vue index 9c1124b0a..00469b974 100644 --- a/src/components/inspector/loop.vue +++ b/src/components/inspector/loop.vue @@ -1,27 +1,32 @@ @@ -27,6 +34,7 @@ export default { return { matrix: [], items: [], + additionalItems: 0, }; }, computed: { @@ -38,14 +46,16 @@ export default { }]; }, times() { - // If there is existing data, set the length to what ever it is - const itemsFromData = _.get(this.transientData, this.name, null); - if (Array.isArray(itemsFromData)) { - return [...itemsFromData.keys()]; + if (!this.config || !this.config.settings) { + return []; } - if (!this.config.settings) { - return []; + if (this.config.settings.type === 'existing') { + const itemsFromData = _.get(this.transientData, this.name, null); + if (!itemsFromData) { + return []; + } + return [...itemsFromData.keys()]; } let times = this.config.settings.times; @@ -64,6 +74,8 @@ export default { times = 100; } + times += this.additionalItems; + return [...Array(times).keys()]; }, }, @@ -94,8 +106,27 @@ export default { times() { this.setupMatrix(); }, + 'config.settings.times': { + handler() { + this.additionalItems = 0; + } + } }, methods: { + add() { + if (this.config.settings.type === 'existing') { + this.setMatrixValue(this.matrix.length, {}); + } else { + this.additionalItems++; + } + }, + remove() { + if (this.config.settings.type === 'existing') { + this.$delete(this.matrix, this.matrix.length - 1); + } else { + this.additionalItems--; + } + }, setMatrixValue(i, v) { this.$set(this.matrix, i, v); }, @@ -109,7 +140,7 @@ export default { setupMatrix() { for (const i of this.times) { if (typeof this.matrix[i] === 'undefined') { - this.$set(this.matrix, i, {}); + this.setMatrixValue(i, {}); } else { } }