Commit 9ad2f042 authored by MARCO Jonathan's avatar MARCO Jonathan
Browse files

馃悰 Add a error message when the condition not valid

parent ed322b9f
{
"name": "@vue-unistra/formbuilder",
"version": "3.0.21",
"version": "3.0.25",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@vue-unistra/formbuilder",
"version": "3.0.21",
"version": "3.0.25",
"license": "MIT",
"dependencies": {
"@vue/cli-service": "^4.5.13",
......@@ -45,6 +45,9 @@
@add="onAddItemLinked"
/>
</header>
<v-alert type="error" v-show="errorDisplayed">
{{ _uct('builder.tabs.conditional.error.format') }}
</v-alert>
<usf-tab-conditional-draggable-container :items="items" @move-item="onMoveItem"/>
</v-card-text>
<v-card-actions>
......@@ -74,6 +77,7 @@ import {Control} from '#form-plugin/models/control';
interface ComponentData {
items: FieldCondition[];
errorDisplayed: boolean;
types: {
text: string;
value: string;
......@@ -114,6 +118,7 @@ export default Vue.extend({
data: function (): ComponentData {
return {
items: [],
errorDisplayed: false,
types: [
{
// @ts-ignore
......@@ -189,6 +194,7 @@ export default Vue.extend({
if (this.displayed && this.type) {
this.typeSelected = this.type;
this.items.splice(0, this.items.length);
this.errorDisplayed = false;
const conditions = ConditionService.getConditions(this.field.conditional.basic[this.type]);
if (conditions) {
......@@ -201,7 +207,7 @@ export default Vue.extend({
},
methods: {
...mapActions('form', ['updateField', 'getFieldById']),
...mapActions('form', ['updateField']),
/**
* Add an chip item in the text area container.
*
......@@ -233,7 +239,7 @@ export default Vue.extend({
},
});
this.items.splice(0, this.items.length)
this.items.splice(0, this.items.length);
},
/**
* Used when user clicks on the "Valid" button.
......@@ -247,6 +253,9 @@ export default Vue.extend({
.then(() => {
this.resetDialog();
this.$emit('update:displayed', false);
})
.catch(() => {
this.errorDisplayed = true;
});
} else {
this.typeErrorMessage = this._uct('builder.tabs.conditional.types.error');
......
import { AppMessages } from '#form-plugin/index';
import {AppMessages} from '#form-plugin/index';
export const fr: AppMessages = {
builder: {
......@@ -34,11 +34,11 @@ export const fr: AppMessages = {
dialog: {
buttons: {
cancel: 'Annuler',
delete: 'Supprimer'
delete: 'Supprimer',
},
text: 'Confirmez-vous la suppression de ce champ ?',
title: 'Supprimer un champ',
}
},
},
duplicate: {
dialog: {
......@@ -65,6 +65,9 @@ export const fr: AppMessages = {
valid: 'Valider',
},
emptyInformation: 'Vide toutes les conditions pour ce type.',
error: {
format: 'La condition n\'a pas le bon format.',
},
fieldSelection: {
otherFields: 'Les autres champs',
user: 'Donn茅es de l\'utilisateur',
......
......@@ -95,6 +95,10 @@ const conditionsCheckOneByOne = (
});
parentArray.push(subConditionArray[0]);
i = subConditionIFinal;
} else {
if (i !== conditions.length - 1) {
throw new Error('Invalid condition');
}
}
return i;
......@@ -190,36 +194,44 @@ class ConditionService {
* @returns {Promise<void>}
*/
async translate(conditions: FieldCondition[], fieldId: string, type: string): Promise<void> {
const translation: ConditionTranslated[] = [];
return new Promise<void>((resolve, reject) => {
const translation: ConditionTranslated[] = [];
if (conditions.length === 1) {
translation.push({
fieldA: {
id: <string>conditions[0].id,
value: <string>conditions[0].value,
},
});
} else {
for (let i = 0; i < conditions.length; i++) {
i = conditionsCheckOneByOne(conditions, i, translation,);
if (conditions.length === 1) {
translation.push({
fieldA: {
id: <string>conditions[0].id,
value: <string>conditions[0].value,
},
});
} else {
for (let i = 0; i < conditions.length; i++) {
try {
i = conditionsCheckOneByOne(conditions, i, translation);
} catch (e) {
reject(e);
}
}
}
}
store.getters['form/getFieldById'](fieldId);
await store.dispatch(
'form/updateField',
{
id: fieldId,
attribute: 'conditional',
value: {
basic: {
...store.getters['form/getFieldById'](fieldId)?.conditional?.basic,
[type]: translation,
store.getters['form/getFieldById'](fieldId);
store.dispatch(
'form/updateField',
{
id: fieldId,
attribute: 'conditional',
value: {
basic: {
...store.getters['form/getFieldById'](fieldId)?.conditional?.basic,
[type]: translation,
},
},
},
},
);
).then(() => {
resolve();
});
});
}
/**
......
import CustomLink from './tiptapcustom/CustomLink'
import CustomLink from './tiptapcustom/CustomLink.js'
export { CustomLink }
export default CustomLink
import { Link } from 'tiptap-extensions';
import { Link } from 'tiptap-extensions'
// @ts-ignore
export default class CustomLink extends Link {
// @ts-ignore
get schema() {
get schema () {
return {
attrs: {
href: {
......@@ -28,6 +26,6 @@ export default class CustomLink extends Link {
target: '_blank',
rel: 'noopener noreferrer nofollow',
}, 0],
};
}
}
};
}
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