From d75f63ddfaa797c284380d7d5faf39ab9fabb834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Poussard?= <tpoussard@neogeo.fr> Date: Thu, 20 Jan 2022 11:31:54 +0100 Subject: [PATCH] fix project_edit, feature_list, feature_symbiology --- src/store/modules/projects.store.js | 1 + src/views/feature/Feature_list.vue | 8 ++- .../feature_type/Feature_type_symbology.vue | 8 ++- src/views/project/Project_edit.vue | 59 +++++++++++-------- 4 files changed, 45 insertions(+), 31 deletions(-) diff --git a/src/store/modules/projects.store.js b/src/store/modules/projects.store.js index 1679664f..5b0bee88 100644 --- a/src/store/modules/projects.store.js +++ b/src/store/modules/projects.store.js @@ -103,6 +103,7 @@ const projects = { const baseUrl = rootState.configuration.VUE_APP_DJANGO_API_BASE; const project = await projectAPI.getProject(baseUrl, slug); commit('SET_PROJECT', project); + return project; }, async GET_PROJECT_INFO({ rootState, dispatch }, slug) { diff --git a/src/views/feature/Feature_list.vue b/src/views/feature/Feature_list.vue index 9d394e7e..eb359d3c 100644 --- a/src/views/feature/Feature_list.vue +++ b/src/views/feature/Feature_list.vue @@ -316,7 +316,10 @@ export default { computed: { ...mapState(['user', 'USER_LEVEL_PROJECTS']), ...mapGetters([ - 'project', 'permissions' + 'permissions', + ]), + ...mapState('projects', [ + 'project', ]), ...mapState('feature', [ 'checkedFeatures' @@ -441,8 +444,9 @@ export default { mounted() { if (!this.project) { // Chargements des features et infos projet en cas d'arrivée directe sur la page ou de refresh + this.$store.dispatch('projects/GET_PROJECT', this.$route.params.slug); this.$store - .dispatch('GET_PROJECT_INFO', this.$route.params.slug) + .dispatch('projects/GET_PROJECT_INFO', this.$route.params.slug) .then(() => this.initMap()); } else { this.initMap(); diff --git a/src/views/feature_type/Feature_type_symbology.vue b/src/views/feature_type/Feature_type_symbology.vue index d2b101ce..e7bf4aad 100644 --- a/src/views/feature_type/Feature_type_symbology.vue +++ b/src/views/feature_type/Feature_type_symbology.vue @@ -155,7 +155,7 @@ export default { }, computed: { - ...mapGetters('projects', [ + ...mapState('projects', [ 'project' ]), ...mapState('feature_type', [ @@ -200,6 +200,7 @@ export default { created() { if (!this.project) { + this.GET_PROJECT(this.$route.params.slug); this.GET_PROJECT_INFO(this.$route.params.slug); } this.SET_CURRENT_FEATURE_TYPE_SLUG(this.$route.params.slug_type_signal); @@ -226,8 +227,9 @@ export default { 'SEND_FEATURE_SYMBOLOGY', 'GET_PROJECT_FEATURE_TYPES' ]), - ...mapActions([ - 'GET_PROJECT_INFO' + ...mapActions('projects', [ + 'GET_PROJECT', + 'GET_PROJECT_INFO', ]), initForm() { diff --git a/src/views/project/Project_edit.vue b/src/views/project/Project_edit.vue index e257676a..1a79afaf 100644 --- a/src/views/project/Project_edit.vue +++ b/src/views/project/Project_edit.vue @@ -305,16 +305,15 @@ export default { return this.$store.state.configuration.VUE_APP_DJANGO_BASE; }, levelPermissions(){ - let self = this; let levels = new Array(); - if(self.levelsPermissions){ - self.levelsPermissions.map(function(item) { + if(this.levelsPermissions){ + this.levelsPermissions.forEach((item) => { if (item.user_type_id != 'super_contributor') levels.push({ - name: self.traslateRoleToFrench(item.user_type_id), + name: this.translateRoleToFrench(item.user_type_id), value: item.user_type_id, }); - if (!self.form.moderation && item.user_type_id == 'moderator'){ + if (!this.form.moderation && item.user_type_id == 'moderator'){ levels.pop(); } }); @@ -322,15 +321,14 @@ export default { return levels; }, levelPermissionsPub(){ - let self = this; let levels = new Array(); - if(self.levelsPermissions){ - self.levelsPermissions.map(function(item) { + if(this.levelsPermissions){ + this.levelsPermissions.forEach((item) => { if (item.user_type_id != 'super_contributor' && item.user_type_id != 'admin' && item.user_type_id != 'moderator'){ levels.push({ - name: self.traslateRoleToFrench(item.user_type_id), + name: this.translateRoleToFrench(item.user_type_id), value: item.user_type_id, }); } @@ -352,7 +350,14 @@ export default { if (this.action === 'create') { this.thumbnailFileSrc = require('@/assets/img/default.png'); } else if (this.action === 'edit' || this.action === 'create_from') { - this.fillProjectForm(); + if (!this.project) { + this.$store.dispatch('projects/GET_PROJECT', this.$route.params.slug) + .then((projet) => { + if (projet) this.fillProjectForm(); + }); + } else { + this.fillProjectForm(); + } } }, @@ -370,12 +375,19 @@ export default { } }, - traslateRoleToFrench(role){ - if (role == 'admin') return 'Administrateur projet'; - if (role == 'moderator') return 'Modérateur'; - if (role == 'contributor') return 'Contributeur'; - if (role == 'logged_user') return 'Utilisateur connecté'; - if (role == 'anonymous') return 'Utilisateur anonyme'; + translateRoleToFrench(role){ + switch (role) { + case 'admin': + return 'Administrateur projet'; + case 'moderator': + return 'Modérateur'; + case 'contributor': + return 'Contributeur'; + case 'logged_user': + return 'Utilisateur connecté'; + case 'anonymous': + return 'Utilisateur anonyme'; + } }, truncate(n, len) { @@ -567,11 +579,8 @@ export default { } }, fillProjectForm() { - if (!this.project) { - this.$store.dispatch('GET_PROJECT_INFO', this.$route.params.slug); - } this.form = { ...this.project }; //* create a new object to avoid modifying original one - if (this.action === 'create_from') { + if (this.action === 'create_from') { //* if duplication of project, generate new name this.form.title = this.project.title + ` (Copie-${new Date() @@ -581,9 +590,8 @@ export default { this.form.is_project_type = false; } //* transform string values to objects for dropdowns display (could be in a computed) - if(this.levelPermissionsPub){ - let value = {}; - value = this.levelPermissionsPub.find( + if (this.levelPermissionsPub) { + let value = this.levelPermissionsPub.find( (el) => el.name === this.project.access_level_pub_feature ); if(value){ @@ -593,9 +601,8 @@ export default { }; } } - if(this.levelPermissions){ - let value = {}; - value = this.levelPermissions.find( + if (this.levelPermissions) { + let value = this.levelPermissions.find( (el) => el.name === this.project.access_level_arch_feature ); if(value){ -- GitLab