Commit d253df31 authored by MARCO Jonathan's avatar MARCO Jonathan
Browse files

Add the condition

parent abaf508e
......@@ -8121,16 +8121,22 @@ const useFormSettingsStore = defineStore("UsfFormSettings", {
autoCompletionIsActive: false,
isHybrideForm: true,
isAdmin: true,
templates: {}
templates: {},
user: {}
}),
getters: {
userTokenInfo: (state2) => Object.keys(state2.templates) || [],
templatesNames: (state2) => Object.keys(state2.templates) || [],
templateAttributes: (state2) => {
isAttributeArray(state2) {
return (templateName, attribute) => {
return has(state2.templates, templateName) && has(state2.templates[templateName], attribute) && state2.templates[templateName][attribute].type.constructor === Function && state2.templates[templateName][attribute].type.name === "Array";
};
},
templateAttributes(state2) {
return (templateName) => {
return has(state2.templates, templateName) ? Object.keys(state2.templates[templateName]).map((attribute) => ({ name: attribute, id: `${templateName}.${attribute}` })) : [];
};
}
},
templatesNames: (state2) => Object.keys(state2.templates) || [],
userTokenInfo: (state2) => Object.keys(state2.templates.user || {}) || []
}
});
const useFieldReader = (field) => {
......@@ -12423,6 +12429,14 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
}
});
var DraggableContainer = /* @__PURE__ */ _export_sfc(_sfc_main$x, [["__scopeId", "data-v-2846cf38"]]);
const useSubmissionStore = defineStore("UsfSubmission", {
state: () => ({}),
getters: {
getValue: (state2) => {
return (fieldName) => state2[fieldName];
}
}
});
const useConditions = () => {
const { field } = useSettingDialog();
const afterItemIsCondition = (conditions, i) => {
......@@ -12600,28 +12614,31 @@ const useConditions = () => {
return false;
};
function fieldCheck(condition, conditions) {
var _a, _b;
var _a, _b, _c, _d;
if (condition.id.startsWith("user.")) {
condition.id.split(".");
return true;
const [userTemplate, attribute] = condition.id.split(".");
const formSettingsStore = useFormSettingsStore();
return formSettingsStore.isAttributeArray(userTemplate, attribute) ? ((_a = formSettingsStore.user[attribute]) == null ? void 0 : _a.includes(condition.value)) || false : formSettingsStore.user[attribute] === condition.value;
} else if (condition.value === "child") {
return check(
(_b = (_a = conditions == null ? void 0 : conditions.find((conditionSearched) => {
(_c = (_b = conditions == null ? void 0 : conditions.find((conditionSearched) => {
var _a2;
return "child" in conditionSearched && ((_a2 = conditionSearched == null ? void 0 : conditionSearched.child) == null ? void 0 : _a2.id) === condition.id;
})) == null ? void 0 : _a.child) == null ? void 0 : _b.subConditions
})) == null ? void 0 : _b.child) == null ? void 0 : _c.subConditions
);
} else {
const linkedInputValue = {
value: {}
};
const submissionStore = useSubmissionStore();
const formStore = useFormStore();
const linkedInputValue = submissionStore.getValue(
formStore.fields[condition.id].name || formStore.fields[condition.id].id
);
if (isArray(condition == null ? void 0 : condition.value) && isPlainObject$1(linkedInputValue) && isArray(linkedInputValue == null ? void 0 : linkedInputValue.value)) {
return linkedInputValue.value.some((value) => {
return (_d = linkedInputValue == null ? void 0 : linkedInputValue.value) == null ? void 0 : _d.some((value) => {
return condition.value.includes(value);
});
}
if (isArray(condition == null ? void 0 : condition.value) && isPlainObject$1(linkedInputValue) && isString(linkedInputValue == null ? void 0 : linkedInputValue.value)) {
return condition.value.includes(linkedInputValue.value);
return condition.value.includes(linkedInputValue == null ? void 0 : linkedInputValue.value);
}
if (isArray(condition == null ? void 0 : condition.value) && isString(linkedInputValue)) {
return condition.value.includes(linkedInputValue);
......
This diff is collapsed.
......@@ -12,7 +12,7 @@ export interface FieldCondition {
export interface ConditionItemTranslated {
id: string;
value: string;
value: string | string[];
}
export interface ConditionTranslated {
......
......@@ -156,3 +156,22 @@ export interface FieldAddedInformation {
export type FormTemplate = Record<string, Record<'type', typeof String | typeof Array | typeof Number>>;
export type FormTemplates = Record<string, FormTemplate>;
export interface User {
affiliations?: string[];
directory_id?: string;
exp?: number;
iss?: string;
jti?: string;
nbf?: number;
organization?: string;
sub?: string;
token_type?: string;
user_id?: string;
username?: string;
}
export type SubmissionBaseType = string | number
export type SubmissionBaseArrayType = string[]
export type SubmissionObjectType = Record<string, SubmissionBaseType | SubmissionBaseArrayType | undefined | null>
export type SubmissionType = SubmissionBaseType | SubmissionBaseArrayType | SubmissionObjectType | undefined | null
export type SubmissionStoreState = Record<string, SubmissionType>
......@@ -16,7 +16,7 @@
"import": "./dist/formbuilder-plugin.es.js",
"require": "./dist/formbuilder-plugin.umd.js"
},
"./dist/style.css": {
"./style.css": {
"import": "./dist/style.css",
"require": "./dist/style.css"
}
......
import type { FieldWithId } from '#/Form'
import type { FieldWithId, SubmissionBaseArrayType, SubmissionObjectType, User } from '#/Form'
import { computed } from 'vue'
import type {
ConditionItemTranslated,
......@@ -12,6 +12,8 @@ import { useFormStore } from '@/stores/useFormStore'
import { isArray, isPlainObject, isString } from '@/utils/typeCheck'
import { idGenerator } from '@/utils/code'
import { useSettingDialog } from '@/composables/tabSettings/useSettingDialog'
import { useFormSettingsStore } from '@/stores/useFormSettingsStore'
import { useSubmissionStore } from '@/stores/useSubmissionStore'
export const useConditions = () => {
const { field } = useSettingDialog()
......@@ -103,7 +105,7 @@ export const useConditions = () => {
arrayParent.push({
fieldA: { id, value: 'child' },
operator: conditions[subI + 1].value as ConditionOperators,
fieldB: { id: <string>conditions[subI + 2].id, value: <string>conditions[subI + 2].value },
fieldB: { id: conditions[subI + 2].id as string, value: conditions[subI + 2].value as string },
})
subI += 2
......@@ -202,7 +204,7 @@ export const useConditions = () => {
if (!fieldASaved) {
parentArray.push({
id: fieldChecked.id,
value: fieldChecked.value,
value: fieldChecked.value as string,
type: fieldChecked.id.startsWith('user.') ? 'token' : 'field',
})
}
......@@ -317,10 +319,10 @@ export const useConditions = () => {
if (condition.id.startsWith('user.')) {
const [userTemplate, attribute] = condition.id.split('.')
// TODO: récupérer les informations ici
return true
/*return store.getters['user/isAttributeArray'](userTemplate, attribute)
? store.getters['user/getUser'][attribute]?.includes(condition.value)
: store.getters['user/getUser'][attribute] === condition.value*/
const formSettingsStore = useFormSettingsStore()
return formSettingsStore.isAttributeArray(userTemplate, attribute)
? (formSettingsStore.user[attribute as keyof User] as string[] | undefined)?.includes(condition.value as string) || false
: formSettingsStore.user[attribute as keyof User] === condition.value
} else if (condition.value === 'child') {
return check(
conditions?.find((conditionSearched: ConditionTranslated) => {
......@@ -329,38 +331,55 @@ export const useConditions = () => {
})?.child?.subConditions,
)
} else {
// TODO : récupérer la valeur de soumission pour la checker
const linkedInputValue = {
value: {},
}
/*const linkedInputValue = store.getters['submission/getValue'](store.getters['form/getFieldById'](condition.id).name)*/
const submissionStore = useSubmissionStore()
const formStore = useFormStore()
const linkedInputValue = submissionStore.getValue(
formStore.fields[condition.id].name || formStore.fields[condition.id].id,
)
if (isArray(condition?.value) && isPlainObject(linkedInputValue) && isArray(linkedInputValue?.value)) {
return linkedInputValue.value.some((value: string) => {
return condition.value.includes(value)
if (
// TODO: voir dans quel cas condition.value peut être un tableau
isArray(condition?.value) &&
isPlainObject(linkedInputValue) &&
isArray((linkedInputValue as SubmissionObjectType)?.value)
) {
return ((linkedInputValue as SubmissionObjectType)?.value as SubmissionBaseArrayType)?.some(value => {
return (condition.value as string[]).includes(value)
})
}
if (isArray(condition?.value) && isPlainObject(linkedInputValue) && isString(linkedInputValue?.value)) {
return condition.value.includes(linkedInputValue.value)
if
(isArray(condition?.value) &&
isPlainObject(linkedInputValue) &&
isString((linkedInputValue as SubmissionObjectType)?.value)
) {
return (condition.value as string[]).includes((linkedInputValue as SubmissionObjectType)?.value as string)
}
if (isArray(condition?.value) && isString(linkedInputValue)) {
return condition.value.includes(linkedInputValue)
return (condition.value as string[]).includes(linkedInputValue as string)
}
if (isString(condition?.value) && isPlainObject(linkedInputValue) && isArray(linkedInputValue?.value)) {
return linkedInputValue.value.some((value: string) => {
return condition.value === value
if (
isString(condition?.value) &&
isPlainObject(linkedInputValue) &&
isArray((linkedInputValue as SubmissionObjectType)?.value)
) {
return ((linkedInputValue as SubmissionObjectType).value as SubmissionBaseArrayType).some(value => {
return (condition.value as string) === value
})
}
if (isString(condition?.value) && isPlainObject(linkedInputValue) && isString(linkedInputValue?.value)) {
return condition.value === linkedInputValue.value
if (
isString(condition?.value) &&
isPlainObject(linkedInputValue) &&
isString((linkedInputValue as SubmissionObjectType)?.value)
) {
return (condition.value as string) === (linkedInputValue as SubmissionObjectType).value as string
}
if (isString(condition?.value)) {
return condition.value === String(linkedInputValue)
return (condition.value as string) === String(linkedInputValue as string)
}
}
......
import { defineStore } from 'pinia'
import type { FormTemplates } from '#/Form'
import type { FormTemplates, User } from '#/Form'
import { has } from '@/utils/typeCheck'
export interface FormSettingsStoreState {
autoCompletionIsActive: boolean;
isHybrideForm: boolean;
isAdmin: boolean;
templates: FormTemplates
templates: FormTemplates;
user: User;
}
export const useFormSettingsStore = defineStore('UsfFormSettings', {
......@@ -15,12 +16,19 @@ export const useFormSettingsStore = defineStore('UsfFormSettings', {
isHybrideForm: true,
isAdmin: true,
templates: {},
user: {},
}),
getters: {
userTokenInfo: (state: FormSettingsStoreState) => Object.keys(state.templates) || [],
templatesNames: (state: FormSettingsStoreState) => Object.keys(state.templates) || [],
templateAttributes: (state: FormSettingsStoreState): (templateName: string) => { name: string, id: string }[] => {
isAttributeArray(state: FormSettingsStoreState): (templateName: string, attribute: string) => boolean {
return (templateName, attribute): boolean => {
return has(state.templates, templateName) &&
has(state.templates[templateName], attribute) &&
state.templates[templateName][attribute].type.constructor === Function &&
state.templates[templateName][attribute].type.name === 'Array'
}
},
templateAttributes(state: FormSettingsStoreState): (templateName: string) => { name: string, id: string }[] {
return (templateName) => {
return has(state.templates, templateName)
? Object
......@@ -29,5 +37,7 @@ export const useFormSettingsStore = defineStore('UsfFormSettings', {
: []
}
},
templatesNames: (state: FormSettingsStoreState) => Object.keys(state.templates) || [],
userTokenInfo: (state: FormSettingsStoreState) => Object.keys(state.templates.user || {}) || [],
},
})
import { defineStore } from 'pinia'
import type { SubmissionStoreState, SubmissionType } from '#/Form'
export const useSubmissionStore = defineStore('UsfSubmission', {
state: (): SubmissionStoreState => ({}),
getters: {
getValue: (state: SubmissionStoreState): (fieldName: string) => SubmissionType => {
return (fieldName) => state[fieldName]
},
},
})
export const isArray = (value: string | Array<any> | Record<string, any> | number | null | undefined): boolean => Array.isArray(value)
import type { SubmissionType } from '#/Form'
export const isString = (value: string | Array<any> | Record<string, any> | number | null | undefined): boolean => typeof value === 'string'
export const isArray = (value: SubmissionType): boolean => Array.isArray(value)
export const isPlainObject = (value: string | Array<any> | Record<string, any> | number | null | undefined): boolean => {
export const isString = (value: SubmissionType): boolean => typeof value === 'string'
export const isPlainObject = (value: SubmissionType): boolean => {
if (typeof value !== 'object' || value === null) return false
let proto = value
......
......@@ -12,7 +12,7 @@ export interface FieldCondition {
export interface ConditionItemTranslated {
id: string;
value: string;
value: string | string[];
}
export interface ConditionTranslated {
......
......@@ -156,3 +156,22 @@ export interface FieldAddedInformation {
export type FormTemplate = Record<string, Record<'type', typeof String | typeof Array | typeof Number>>;
export type FormTemplates = Record<string, FormTemplate>;
export interface User {
affiliations?: string[];
directory_id?: string;
exp?: number;
iss?: string;
jti?: string;
nbf?: number;
organization?: string;
sub?: string;
token_type?: string;
user_id?: string;
username?: string;
}
export type SubmissionBaseType = string | number
export type SubmissionBaseArrayType = string[]
export type SubmissionObjectType = Record<string, SubmissionBaseType | SubmissionBaseArrayType | undefined | null>
export type SubmissionType = SubmissionBaseType | SubmissionBaseArrayType | SubmissionObjectType | undefined | null
export type SubmissionStoreState = Record<string, SubmissionType>
Supports Markdown
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