Commit 74194d99 authored by MARCO Jonathan's avatar MARCO Jonathan
Browse files

馃攢 Merge branch 'bugfix/condition_array' into develop

parents a193e84c 2449629b
Pipeline #61796 passed with stage
in 15 seconds
......@@ -39,10 +39,13 @@ import vue, { PropType } from 'vue';
import { StartField } from '#form-plugin/models/form';
import { Messages } from '#form-plugin/models/messages';
import { UserTemplates } from '#form-plugin/models/user';
import builderRendererMixin from '@form-plugin/mixins/builderRendererMixin';
export default vue.extend({
name: 'UsfBuilder',
mixins: [builderRendererMixin],
components: {
UsfEditor,
UsfControls,
......@@ -61,66 +64,6 @@ export default vue.extend({
required: false,
default: () => [],
},
isHybridForm: {
type: Boolean as PropType<boolean>,
required: false,
default: false,
},
fields: {
type: Array as PropType<StartField[]>,
required: false,
default: () => [],
},
messages: {
type: Object as PropType<Messages>,
required: false,
default: () => ({}),
},
userTemplates: {
required: false,
default: () => ({}),
type: Object as PropType<UserTemplates>,
validator: (templates: UserTemplates): boolean => {
const isValidType = (value, type, name = undefined): boolean => {
return !!value && value.constructor === type && (name ? value.name === name : true);
};
return isValidType(templates, Object) &&
Object.values(templates)
.reduce<boolean>((isPreviousTemplateValid: boolean, template) => {
return isPreviousTemplateValid &&
isValidType(template, Object) &&
Object.values(template)
.reduce<boolean>((isPreviousAttributeValid, attribute) => {
const requiredKeys = {
type: {
type: Function,
name: ['String', 'Array'],
},
};
const hasValidKeys = (keys) => {
return Object.entries(keys)
.reduce<boolean>(
(isPreviousKeyValid,
[key, type]: [string, { type: ArrayConstructor | ObjectConstructor | FunctionConstructor, name: any }],
) => {
return isPreviousKeyValid
&& Object.keys(attribute).includes(key)
&& (type.name
? type.name.reduce((isPreviousTypeValid, currentType) => {
return isPreviousTypeValid ||
isValidType(attribute[key], type.type, currentType);
}, false)
: isValidType(attribute[key], type.type));
}, true);
};
return isPreviousAttributeValid
&& isValidType(attribute, Object)
&& hasValidKeys(requiredKeys);
}, true);
}, true);
},
},
admin: {
type: Boolean as PropType<boolean>,
required: false,
......@@ -148,34 +91,6 @@ export default vue.extend({
}),
watch: {
isHybridForm: {
immediate: true,
deep: false,
handler(value: boolean) {
this.$store.dispatch('form/setHybridStatus', value);
},
},
fields: {
deep: true,
immediate: true,
handler(value: StartField[]) {
this.$store.dispatch('form/setFields', value);
},
},
messages: {
deep: true,
immediate: true,
handler(value: Messages) {
this.$store.dispatch('form/setMessages', value);
},
},
userTemplates: {
deep: true,
immediate: true,
handler(value) {
this.$store.dispatch('user/updateTemplates', value);
},
},
admin: {
immediate: true,
handler(value) {
......
......@@ -114,7 +114,6 @@ export default {
return this.getFieldById(this.fieldId).component
},
isBoxInput () {
console.log(this.getControlById(this.component));
return this.getControlById(this.component)
.usfSubtypes
.includes('boxInput')
......
......@@ -36,20 +36,19 @@ import { mapActions, mapGetters, mapState } from 'vuex';
import { UsfField } from '../../fields';
import Vue, { PropType } from 'vue';
import { Field } from '#form-plugin/models/form';
import { UserTemplates } from '#form-plugin/models/user';
import builderRendererMixin from '@form-plugin/mixins/builderRendererMixin';
export default Vue.extend({
name: 'UsfRenderer',
mixins: [builderRendererMixin],
components: {
UsfField,
},
props: {
isHybridForm: {
type: Boolean as PropType<boolean>,
required: false,
default: false,
},
isSubmitButtonDisplayed: {
type: Boolean as PropType<boolean>,
default: true,
......@@ -70,16 +69,6 @@ export default Vue.extend({
type: String as PropType<string>,
default: 'Valider',
},
fields: {
type: Array as PropType<Field[]>,
required: false,
default: () => [],
},
messages: {
type: Object,
required: false,
default: () => ({}),
},
user: {
type: Object,
default: () => ({}),
......@@ -105,27 +94,6 @@ export default Vue.extend({
},
watch: {
isHybridForm: {
deep: false,
immediate: true,
handler(value: boolean): void {
this.$store.dispatch('form/setHybridStatus', value);
},
},
fields: {
deep: true,
immediate: true,
handler(value) {
this.$store.dispatch('form/setFields', value);
},
},
messages: {
deep: true,
immediate: true,
handler(value) {
this.$store.dispatch('form/setMessages', value);
},
},
user: {
deep: true,
immediate: true,
......
import Vue, { PropType } from 'vue';
import { StartField } from '#form-plugin/models/form';
import { UserTemplates } from '#form-plugin/models/user';
export default Vue.extend({
props: {
fields: {
type: Array as PropType<StartField[]>,
required: false,
default: () => [],
},
isHybridForm: {
type: Boolean as PropType<boolean>,
required: false,
default: false,
},
messages: {
type: Object,
required: false,
default: () => ({}),
},
userTemplates: {
required: false,
default: () => ({}),
type: Object as PropType<UserTemplates>,
validator: (templates: UserTemplates): boolean => {
const isValidType = (value, type, name = undefined): boolean => {
return !!value && value.constructor === type && (name ? value.name === name : true);
};
return isValidType(templates, Object) &&
Object.values(templates)
.reduce<boolean>((isPreviousTemplateValid: boolean, template) => {
return isPreviousTemplateValid &&
isValidType(template, Object) &&
Object.values(template)
.reduce<boolean>((isPreviousAttributeValid, attribute) => {
const requiredKeys = {
type: {
type: Function,
name: ['String', 'Array'],
},
};
const hasValidKeys = (keys) => {
return Object.entries(keys)
.reduce<boolean>(
(isPreviousKeyValid,
[key, type]: [string, { type: ArrayConstructor | ObjectConstructor | FunctionConstructor, name: any }],
) => {
return isPreviousKeyValid
&& Object.keys(attribute).includes(key)
&& (type.name
? type.name.reduce((isPreviousTypeValid,
currentType,
) => {
return isPreviousTypeValid ||
isValidType(attribute[key], type.type, currentType);
}, false)
: isValidType(attribute[key], type.type));
}, true);
};
return isPreviousAttributeValid
&& isValidType(attribute, Object)
&& hasValidKeys(requiredKeys);
}, true);
}, true);
},
},
},
watch: {
fields: {
deep: true,
immediate: true,
handler(value: StartField[]) {
this.$store.dispatch('form/setFields', value);
},
},
isHybridForm: {
immediate: true,
deep: false,
handler(value: boolean) {
this.$store.dispatch('form/setHybridStatus', value);
},
},
userTemplates: {
deep: true,
immediate: true,
handler(value) {
this.$store.dispatch('user/updateTemplates', value);
},
},
messages: {
deep: true,
immediate: true,
handler(value) {
this.$store.dispatch('form/setMessages', value);
},
},
},
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment