Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/inspector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
export { default as ScreenSelector } from './screen-selector';
export { default as LoopInspector } from './loop';
90 changes: 90 additions & 0 deletions src/components/inspector/loop.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<template>
<div>
<div class="form-group border-bottom pb-3">
<label for="type">{{ $t('Data Source') }}</label>
<b-form-select id="type" v-model="settings.type" :options="options"/>
</div>

<div class="form-group border-bottom">
<FormInput
v-model="settings.varname"
:label="$t('Variable Name')"
:name="$t('Variable Name')"
:helper="$t('This variable will contain an array of objects')"
validation="regex:/^(?:[A-Z_.a-z])(?:[0-9A-Z_.a-z])*$/|required"
>
</FormInput>
</div>


<div v-if="settings.type === 'new'" class="form-group border-bottom">
<FormInput
v-model="settings.times"
:label="$t('Default Loop Count')"
:name="$t('Default Loop Count')"
:helper="$t('Number of times to show the loop. Value must be greater than zero.')"
validation="required|integer|min:1|max:100"
>
</FormInput>
</div>

<form-checkbox name="add"
:label="$t('Allow additional loops')"
v-model="settings.add"
:helper="$t('Check this box to allow task assignee to add additional loops')">
</form-checkbox>
</div>
</template>

<script>
import { FormInput, FormCheckbox } from '@processmaker/vue-form-elements';
// import ValidationMixin from '@processmaker/vue-form-elements/src/components/mixins/validation';

export default {
components: { },
props: ['value', 'name', 'formConfig', 'inspectionConfig'],
// mixins: [ValidationMixin],
inheritAttrs: false,
components: { FormInput, FormCheckbox },
data() {
return {
options: [
{ value: 'new', text: this.$t('New Array of Objects')},
{ value: 'existing', text: this.$t('Existing Array')},
],
settings: {
type: 'new',
varname: '',
times: '3',
add: false,
}
}
},
watch: {
settings: {
handler() {
this.$emit('input', this.settings);
this.$emit('setName', this.settings.varname);
},
deep: true,
},
value: {
handler() {
this.settings = this.value;
},
immediate: true,
},
// 'inspectionConfig.name': {
// handler() {
// this.settings.varname = this.inspectionConfig.name;
// },
// immediate: true,
// }
},
computed: {
},
};
</script>

<style lang="scss">
</style>
49 changes: 40 additions & 9 deletions src/components/renderer/form-loop.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
@update="setMatrixValue(loopIndex, $event)"
/>
</form>
<b-row class="justify-content-md-center" v-if="config.settings.add">
<b-col md="auto">
<b-button size="sm" variant="secondary" class="ml-1 mr-1" @click="add" :title="$t('Add Item')">
<i class="fas fa-plus"/>
</b-button>
</b-col>
</b-row>
</div>
</template>

Expand All @@ -22,11 +29,12 @@ import Mustache from 'mustache';
export default {
name: 'FormLoop',
mixins: [],
props: ['value', 'name', 'config', 'transientData'],
props: ['value', 'config', 'transientData', 'name'],
data() {
return {
matrix: [],
items: [],
additionalItems: 0,
};
},
computed: {
Expand All @@ -38,17 +46,19 @@ 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) {
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.times;
let times = this.config.settings.times;

try {
times = Mustache.render(times, this.transientData);
Expand All @@ -64,6 +74,8 @@ export default {
times = 100;
}

times += this.additionalItems;

return [...Array(times).keys()];
},
},
Expand Down Expand Up @@ -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);
},
Expand All @@ -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 {
}
}
Expand Down
1 change: 1 addition & 0 deletions src/components/vue-form-builder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
v-bind="item.config"
v-model="inspection.config[item.field]"
@focusout.native="updateState"
@setName="inspection.config.name = $event"
/>
</b-collapse>
</template>
Expand Down
15 changes: 9 additions & 6 deletions src/form-builder-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
},
},
],
Expand Down