diff --git a/ui/src/locales/fr.json b/ui/src/locales/fr.json index 57ffd4f276941a643e4a30c61edbd50f7e15d5f6..f0a3560187aca294528a479bcd0566fbcab6869b 100644 --- a/ui/src/locales/fr.json +++ b/ui/src/locales/fr.json @@ -117,7 +117,7 @@ "authorizationScopeVariableComponentWrongChecker": "Le composant <code>{component}</code> de la variable <code>{variable}</code> ne peut pas être utilisé comme portant l’information temporelle car ce n’est pas une donnée déclarée comme <code>{expectedChecker}</code>", "authorizationVariableComponentKeyMissingComponent": "Il faut indiquer le composant de la variable <code>{variable}</code> dans laquelle on recueille les informations spatiales à laquelle rattacher la donnée pour le gestion des droits jeu de données <code>{dataType}</code> pour l'autorisation <code>{authorizationName}</code>. Valeurs possibles <code>{knownComponents}</code>", "authorizationVariableComponentKeyUnknownComponent": "<code>{component}</code> ne fait pas partie des composants connus pour la variable <code>{variable}</code>. Composants connus : <code>{knownComponents}</code>", - "badauthorizationscopeforrepository": "L'autorisation <code>{authorization}</code>) doit être <code>{expectedValue}/code> et non <code>{givenValue}</code>", + "badauthorizationscopeforrepository": "L'autorisation (<code>{authorization}</code>) doit être <code>{expectedValue}</code> et non <code>{givenValue}</code>", "checkerExpressionReturnedFalse": "La contrainte suivante n'est pas respectée : <code>{expression}</code>", "csvBoundToUnknownVariable": "Dans le format CSV, l’entête <code>{header}</code> est lié à la variable <code>{variable}</code> qui n’est pas connue. Variables connues <code>{variables}</code>", "csvBoundToUnknownVariableComponent": "Dans le format CSV, l’entête <code>{header}</code> est lié à la variable <code>{variable}</code> mais elle n’a pas de composant <code>{component}</code>. Composants connus <code>{components}</code>", diff --git a/ui/src/services/AlertService.js b/ui/src/services/AlertService.js index 3b4aada75b398d87c8c627164e41fc9f74d146e8..e21c81b55ef551103fef76ca621a57f905cf8623 100644 --- a/ui/src/services/AlertService.js +++ b/ui/src/services/AlertService.js @@ -1,6 +1,6 @@ -import {i18n} from "@/main"; -import {BuefyTypes} from "@/utils/BuefyUtils"; -import {ToastProgrammatic, DialogProgrammatic} from "buefy"; +import { i18n } from "@/main"; +import { BuefyTypes } from "@/utils/BuefyUtils"; +import { ToastProgrammatic, DialogProgrammatic } from "buefy"; const TOAST_INFO_DURATION = 3000; const TOAST_ERROR_DURATION = 8000; @@ -10,66 +10,66 @@ const TOAST_POSITION = "is-top"; * Un service pour gérer les différents messages d'alerte et popup d'info s'affichant sur l'application */ export class AlertService { - static INSTANCE = new AlertService(); + static INSTANCE = new AlertService(); - toastSuccess(message) { - ToastProgrammatic.open({ - message: message, - type: BuefyTypes.SUCCESS, - duration: TOAST_INFO_DURATION, - position: TOAST_POSITION, - }); - } + toastSuccess(message) { + ToastProgrammatic.open({ + message: message, + type: BuefyTypes.SUCCESS, + duration: TOAST_INFO_DURATION, + position: TOAST_POSITION, + }); + } + + toastWarn(message, error) { + console.warn("[WARNING] " + message, error); + ToastProgrammatic.open({ + message: message, + type: BuefyTypes.WARNING, + duration: TOAST_ERROR_DURATION, + position: TOAST_POSITION, + }); + } - toastWarn(message, error) { - console.warn("[WARNING] " + message, error); + toastError(message, error) { + if (error.content) { + error.content.then((t) => { ToastProgrammatic.open({ - message: message, - type: BuefyTypes.WARNING, - duration: TOAST_ERROR_DURATION, - position: TOAST_POSITION, + message: i18n.t("exceptionMessage." + t.message, t.params), + type: BuefyTypes.DANGER, + duration: TOAST_ERROR_DURATION, + position: TOAST_POSITION, }); + }); + } else { + ToastProgrammatic.open({ + message: message, + type: BuefyTypes.DANGER, + duration: TOAST_ERROR_DURATION, + position: TOAST_POSITION, + }); } + } - toastError(message, error) { - if (error.content) { - error.content.then((t) => { - ToastProgrammatic.open({ - message: i18n.t('exceptionMessage.' + t.message, t.params), - type: BuefyTypes.DANGER, - duration: TOAST_ERROR_DURATION, - position: TOAST_POSITION, - }); - }) - } else { - ToastProgrammatic.open({ - message: message, - type: BuefyTypes.DANGER, - duration: TOAST_ERROR_DURATION, - position: TOAST_POSITION, - }); - } + toastServerError(error) { + if (error.content != null) { + error.content.then((value) => this.toastError(value.message, error)); + } else { + this.toastError(i18n.t("alert.server-error"), error); } + } - toastServerError(error) { - if (error.content != null) { - error.content.then((value) => this.toastError(value.message, error)); - } else { - this.toastError(i18n.t("alert.server-error"), error); - } - } - - dialog(title, message, confirmText, type, onConfirmCb) { - DialogProgrammatic.confirm({ - title: title, - message: message, - confirmText: confirmText, - type: type, - hasIcon: true, - cancelText: this.cancelMsg, - onConfirm: () => { - onConfirmCb(); - }, - }); - } -} \ No newline at end of file + dialog(title, message, confirmText, type, onConfirmCb) { + DialogProgrammatic.confirm({ + title: title, + message: message, + confirmText: confirmText, + type: type, + hasIcon: true, + cancelText: this.cancelMsg, + onConfirm: () => { + onConfirmCb(); + }, + }); + } +} diff --git a/ui/src/services/ErrorsService.js b/ui/src/services/ErrorsService.js index 2497aefdd7d4038ce23811c5c970b3a59f856bc1..5ce86195336509ed99da279955d64e905bc23c0b 100644 --- a/ui/src/services/ErrorsService.js +++ b/ui/src/services/ErrorsService.js @@ -139,7 +139,18 @@ export class ErrorsService { const func = ERRORS[csvError.validationCheckResult.message]; if (csvError.validationCheckResult.messageParams.target != null) { if (csvError.validationCheckResult.messageParams.target.column != null) { - csvError.validationCheckResult.messageParams.target = csvError.validationCheckResult.messageParams.target.column; + csvError.validationCheckResult.messageParams.target = + csvError.validationCheckResult.messageParams.target.column; + } + } + if(csvError.validationCheckResult.messageParams.expectedValue != null || csvError.validationCheckResult.messageParams.givenValue != null) { + if (csvError.validationCheckResult.messageParams.expectedValue.sql != null) { + csvError.validationCheckResult.messageParams.expectedValue = + csvError.validationCheckResult.messageParams.expectedValue.sql; + } + if(csvError.validationCheckResult.messageParams.givenValue.sql != null) { + csvError.validationCheckResult.messageParams.givenValue = + csvError.validationCheckResult.messageParams.givenValue.sql; } } if (!func) { @@ -153,4 +164,4 @@ export class ErrorsService { return func(params); }); } -} \ No newline at end of file +} diff --git a/ui/src/views/datatype/DataTypesRepositoryView.vue b/ui/src/views/datatype/DataTypesRepositoryView.vue index 1af62cef77cf470fc30ff67ed9e80e923bc1dbe2..816e9c71bebeec4094aa084c63fde20a0b510a8f 100644 --- a/ui/src/views/datatype/DataTypesRepositoryView.vue +++ b/ui/src/views/datatype/DataTypesRepositoryView.vue @@ -191,7 +191,21 @@ {{ currentDataset[0].periode }} + <div v-if="errorsMessages.length" style="margin: 10px"> + <div v-for="msg in errorsMessages" v-bind:key="msg"> + <b-message + :title="$t('message.data-type-config-error')" + type="is-danger" + has-icon + :aria-close-label="$t('message.close')" + class="mt-4 DataTypesManagementView-message" + > + <span v-html="msg" /> + </b-message> + </div> + </div> </caption> + <tr> <th align>{{ $t("dataTypesRepository.table-file-data-id") }}</th> <th align>{{ $t("dataTypesRepository.table-file-data-size") }}</th> @@ -272,6 +286,7 @@ import { Dataset } from "@/model/file/Dataset"; import { InternationalisationService } from "@/services/InternationalisationService"; import { LOCAL_STORAGE_LANG } from "@/services/Fetcher"; import DropDownMenu from "@/components/common/DropDownMenu"; +import {HttpStatusCodes} from "@/utils/HttpUtils"; @Component({ components: { DropDownMenu, CollapsibleTree, PageView, SubMenu }, @@ -305,6 +320,7 @@ export default class DataTypesRepositoryView extends Vue { endDate = null; comment = ""; currentDataset = null; + errorsMessages = []; mounted() { this.$on("authorizationChanged", this.updateDatasets); @@ -471,29 +487,67 @@ export default class DataTypesRepositoryView extends Vue { this.file, fileOrId ); - console.log(fileOrId); this.$emit("uploaded", uuid); } } async publish(dataset, pusblished) { + this.errorsMessages = []; dataset.params.published = pusblished; let requiredauthorizations = dataset.params.binaryFiledataset.requiredauthorizations; requiredauthorizations = Object.keys(requiredauthorizations).reduce(function (acc, key) { acc[key] = acc[key] ? acc[key].sql : ""; return acc; }, requiredauthorizations); - console.log("requiredauthorizations", requiredauthorizations); dataset.params.binaryFiledataset.requiredauthorizations = requiredauthorizations; - console.log("binaryFiledataset", dataset.params.binaryFiledataset); var fileOrId = new FileOrUUID(dataset.id, dataset.params.binaryFiledataset, pusblished); - var uuid = await this.dataService.addData( - this.applicationName, - this.dataTypeId, - null, - fileOrId - ); - this.$emit("published", uuid.fileId); + try { + var uuid = await this.dataService.addData( + this.applicationName, + this.dataTypeId, + null, + fileOrId + ); + this.$emit("published", uuid.fileId); + this.alertService.toastSuccess(this.$t("alert.data-updated")); + } catch (error) { + this.checkMessageErrors(error); + } + } + + checkMessageErrors(error) { + let message = []; + if (error.httpResponseCode === HttpStatusCodes.BAD_REQUEST) { + if (error.content != null) { + this.errorsList = []; + error.content.then((value) => { + for (let i = 0; i < value.length; i++) { + if (message.length > 0) { + if (JSON.stringify(value[i]) !== JSON.stringify(value[i-message.length])) { + console.log(message) + this.errorsList.push(value[i]); + } + for(let j = 0; j < message.length; j++) { + if (!message.includes(value[i].validationCheckResult.message)) { + message.push(value[i].validationCheckResult.message); + } + } + } else { + message.push(value[i].validationCheckResult.message); + this.errorsList.push(value[i]); + } + } + console.log(this.errorsList) + if (this.errorsList.length !== 0) { + this.errorsMessages = this.errorsService.getCsvErrorsMessages(this.errorsList); + } else { + this.errorsMessages = this.errorsService.getErrorsMessages(error); + } + }); + } + } else { + this.alertService.toastServerError(error); + } } selectAuthorization(key, event) {