diff --git a/public/config/config.json b/public/config/config.json index 275568d5a43aa92e567616ae2807d45246b3c34e..ee7aa62a1c2c1c2d60eb17cb670c2f7002f2a753 100644 --- a/public/config/config.json +++ b/public/config/config.json @@ -7,8 +7,8 @@ "VUE_APP_APPLICATION_FAVICO":"/geocontrib/img/geo2f.ico", "VUE_APP_APPLICATION_ABSTRACT":"Application de saisie d'informations géographiques contributive", "VUE_APP_LOGO_PATH":"/geocontrib/img/logo-neogeo-circle.png", - "VUE_APP_DJANGO_BASE":"http://localhost/", - "VUE_APP_DJANGO_API_BASE":"http://localhost/api/", + "VUE_APP_DJANGO_BASE":"http://localhost:8010", + "VUE_APP_DJANGO_API_BASE":"http://localhost:8010/api/", "VUE_APP_CATALOG_NAME": "Datasud", "VUE_APP_IDGO": true, "VUE_APP_RELOAD_INTERVAL": 15000, diff --git a/src/App.vue b/src/App.vue index 073e338a7fd3a5074f92b26ac89743b65b4d22c0..35f6b5813208e656bc7afb8fc9ac27db8d15cae6 100644 --- a/src/App.vue +++ b/src/App.vue @@ -260,7 +260,7 @@ <script> import frag from 'vue-frag'; -import { mapMutations, mapState, mapGetters } from 'vuex'; +import { mapMutations, mapState } from 'vuex'; export default { name: 'App', @@ -287,10 +287,8 @@ export default { 'loader', ]), ...mapState('projects', [ - 'projects' - ]), - ...mapGetters('projects', [ - 'project' + 'projects', + 'project', ]), APPLICATION_NAME() { return this.configuration.VUE_APP_APPLICATION_NAME; diff --git a/src/assets/styles/base.css b/src/assets/styles/base.css index a088fed4ce227bfceb4ba0c3c15e80b7294e16ee..2d3c85ba3384bcb962968ca6fb483ea8e94ff82b 100644 --- a/src/assets/styles/base.css +++ b/src/assets/styles/base.css @@ -26,6 +26,10 @@ main { text-overflow: ellipsis; overflow: hidden; } + +.important-flex { + display: flex !important; +} /* ---------------------------------- */ /* MAIN */ /* ---------------------------------- */ diff --git a/src/components/Projects/DropdownMenuItem.vue b/src/components/Projects/DropdownMenuItem.vue index 6d43d80ee7abc2f2b81008bb68ad6a2fe0cd7cd4..d2dd36901f01d4ec950df772e12b39a9af356323 100644 --- a/src/components/Projects/DropdownMenuItem.vue +++ b/src/components/Projects/DropdownMenuItem.vue @@ -15,17 +15,7 @@ :preserve-search="true" @select="select" @close="close" - > - <!-- <template slot="clear"> - <div - v-if="selection" - class="multiselect__clear" - @click.prevent.stop="selection = options[0]" - > - <i class="close icon"></i> - </div> - </template> --> - </Multiselect> + /> </template> <script> @@ -84,6 +74,3 @@ export default { }; </script> -<style lang="less" scoped> - -</style> diff --git a/src/components/Projects/ProjectsMenu.vue b/src/components/Projects/ProjectsMenu.vue index de5b0e284f76143e05580c7f941467abdd5797a5..536a0332d7f9c660da18b0ebbc24331490492aa0 100644 --- a/src/components/Projects/ProjectsMenu.vue +++ b/src/components/Projects/ProjectsMenu.vue @@ -10,10 +10,7 @@ /> </div> </div> - <div - :class="isFiltersVisible ? '' : 'hidden'" - class="ui menu filters" - > + <div :class="['ui menu filters', isFiltersVisible ? '' : 'hidden']"> <div class="item"> <label> Niveau d'autorisation requis @@ -151,11 +148,12 @@ export default { const icon = document.getElementsByClassName('caret'); icon[0].classList.toggle('right'); const content = document.getElementsByClassName('filters'); - content[0].classList.toggle('hidden'); if (content[0].style.maxHeight){ content[0].style.maxHeight = null; + this.isFiltersVisible = false; } else { content[0].style.maxHeight = content[0].scrollHeight + 5 + 'px'; + this.isFiltersVisible = true; } }); }, diff --git a/src/components/feature/FeatureListTable.vue b/src/components/feature/FeatureListTable.vue index 8ffb28445963d7d2dc03b3e5582fb95ae362989f..f9fc303eda1d4d5745921d7bcc3a042ce86139ab 100644 --- a/src/components/feature/FeatureListTable.vue +++ b/src/components/feature/FeatureListTable.vue @@ -339,12 +339,9 @@ export default { }, computed: { - ...mapState(['user']), ...mapGetters(['permissions']), - ...mapGetters('projects', [ - 'project' - ]), ...mapState(['user', 'USER_LEVEL_PROJECTS']), + ...mapState('projects', ['project']), checked: { get() { diff --git a/src/services/project-api.js b/src/services/project-api.js index 6c9239decfdb6bcbd63d9a65595b930ea212d223..92355eacd009a6c6729e5f2dd7e8b39cbb055b86 100644 --- a/src/services/project-api.js +++ b/src/services/project-api.js @@ -2,6 +2,20 @@ import axios from '@/axios-client.js'; const projectAPI = { + async getProject( baseUrl, projectSlug ) { + const response = await axios.get( + `${baseUrl}projects/${projectSlug}` + ); + if ( + response.status === 200 && + response.data + ) { + return response.data; + } else { + return null; + } + }, + async getProjectSubscription({ baseUrl, projectSlug }) { const response = await axios.get( `${baseUrl}projects/${projectSlug}/subscription/` diff --git a/src/store/index.js b/src/store/index.js index 35756ced35d1657b0e5c3e550621d3124bea8c92..4635faacb006801588174eedf8f8bc9de42b4e62 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -28,7 +28,6 @@ export default new Vuex.Store({ logged: false, user: false, configuration: null, - last_comments: [], staticPages: null, USER_LEVEL_PROJECTS: null, user_permissions: null, @@ -65,9 +64,7 @@ export default new Vuex.Store({ SET_LOGGED(state, value) { state.logged = value; }, - SET_PROJECT_COMMENTS(state, last_comments) { - state.last_comments = last_comments; - }, + SET_USER_PERMISSIONS(state, userPermissions) { state.user_permissions = userPermissions; }, @@ -117,7 +114,9 @@ export default new Vuex.Store({ }, getters: { - permissions: state => state.user_permissions ? state.user_permissions[state.projects.project_slug] : noPermissions, + permissions: state => state.user_permissions && state.projects.project ? + state.user_permissions[state.projects.project.slug] : + noPermissions }, actions: { @@ -262,33 +261,6 @@ export default new Vuex.Store({ throw error; }); }, - - async GET_PROJECT_INFO({ state, commit, dispatch }, slug) { - commit('projects/SET_PROJECT_SLUG', slug, { root: true }); - let promises = [ - dispatch('GET_PROJECT_LAST_MESSAGES', slug).then(response => response), - dispatch('feature_type/GET_PROJECT_FEATURE_TYPES', slug).then(response => response), - // dispatch("feature/GET_PROJECT_FEATURES", slug).then(response => response), - ]; - if (state.user) promises.push(dispatch('map/GET_BASEMAPS', slug).then(response => response)); - - const promiseResult = await Promise.all(promises); - return promiseResult; - }, - - GET_PROJECT_LAST_MESSAGES({ commit }, project_slug) { - return axios - .get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}projects/${project_slug}/comments/`) - .then((response) => { - if (response && response.status === 200) { - commit('SET_PROJECT_COMMENTS', response.data.last_comments); - } - return response; - }) - .catch((error) => { - throw error; - }); - }, } }); diff --git a/src/store/modules/feature.store.js b/src/store/modules/feature.store.js index 398c1ee9a02b77802665d86d7ac8661a475d81b3..3039126bf92273a558eacab63830e5599198ed99 100644 --- a/src/store/modules/feature.store.js +++ b/src/store/modules/feature.store.js @@ -183,7 +183,7 @@ const feature = { dispatch( 'GET_PROJECT_FEATURE', { - project_slug: rootState.project_slug, + project_slug: rootState.projects.project.slug, feature_id: featureId } ) @@ -220,7 +220,7 @@ const feature = { title: state.form.title, description: state.form.description.value, status: state.form.status.value, - project: rootState.project_slug, + project: rootState.projects.project.slug, feature_type: rootState.feature_type.current_feature_type_slug, ...extraFormObject } @@ -232,7 +232,7 @@ const feature = { if (routeName === 'editer-signalement') { url += `${state.form.feature_id}/? feature_type__slug=${rootState.feature_type.current_feature_type_slug} - &project__slug=${rootState.project_slug}`; + &project__slug=${rootState.projects.project.slug}`; } return axios({ @@ -259,7 +259,7 @@ const feature = { arraysOffline = JSON.parse(localStorageArray); } let updateMsg = { - project: rootState.project_slug, + project: rootState.projects.project.slug, type: routeName === 'editer-signalement' ? 'put' : 'post', featureId: state.form.feature_id, geojson: geojson @@ -375,7 +375,7 @@ const feature = { DELETE_FEATURE({ rootState }, feature_id) { const url = `${rootState.configuration.VUE_APP_DJANGO_API_BASE}features/${feature_id}/?` + `feature_type__slug=${rootState.feature_type.current_feature_type_slug}` + - `&project__slug=${rootState.project_slug}`; + `&project__slug=${rootState.projects.project.slug}`; return axios .delete(url) .then((response) => response) diff --git a/src/store/modules/feature_type.store.js b/src/store/modules/feature_type.store.js index 9398f60838996c09a421b24697d7c081f11a9929..f8ac20f86e412b09156b6ee26261a92fc5e30c42 100644 --- a/src/store/modules/feature_type.store.js +++ b/src/store/modules/feature_type.store.js @@ -96,14 +96,14 @@ const feature_type = { }); }, - async SEND_FEATURE_TYPE({ state, getters, rootGetters }, requestType) { + async SEND_FEATURE_TYPE({ state, getters, rootState }, requestType) { const data = { title: state.form.title.value, title_optional: state.form.title_optional.value, geom_type: state.form.geom_type.value, color: state.form.color.value, colors_style: state.form.colors_style.value, - project: rootGetters['projects/project'].slug, + project: rootState.projects.project.slug, customfield_set: state.customForms.map(el => { return { position: el.position, @@ -145,10 +145,10 @@ const feature_type = { } }, - async SEND_FEATURE_SYMBOLOGY({ getters, rootGetters }, symbology) { + async SEND_FEATURE_SYMBOLOGY({ getters, rootState }, symbology) { const data = { title: getters.feature_type.title, - project: rootGetters['projects/project'].slug, + project: rootState.projects.project.slug, ...symbology }; return axios diff --git a/src/store/modules/map.store.js b/src/store/modules/map.store.js index 9e6d73c3673daf505cbf6ca5864771e7ad404626..3de93c65fc2e300642d82de0803e80eaf44afe9e 100644 --- a/src/store/modules/map.store.js +++ b/src/store/modules/map.store.js @@ -1,12 +1,6 @@ import axios from '@/axios-client.js'; import { mapUtil } from '@/assets/js/map-util.js'; -// axios.defaults.headers.common['X-CSRFToken'] = (name => { -// var re = new RegExp(name + "=([^;]+)"); -// var value = re.exec(document.cookie); -// return (value !== null) ? unescape(value[1]) : null; -// })('csrftoken'); - const map = { namespaced: true, @@ -163,7 +157,7 @@ const map = { async SAVE_BASEMAPS({ state, rootState, dispatch }, newBasemapIds) { const DJANGO_API_BASE = this.state.configuration.VUE_APP_DJANGO_API_BASE; function postOrPut(basemap) { - basemap['project'] = rootState.project_slug; + basemap['project'] = rootState.projects.project.slug; if (newBasemapIds.includes(basemap.id)) { return axios .post(`${DJANGO_API_BASE}base-maps/`, basemap) diff --git a/src/store/modules/projects.store.js b/src/store/modules/projects.store.js index fbe495300f69b356fa4a5718a77785a4a5954dd4..5b0bee8858d4d1ae74a249db702849683a665831 100644 --- a/src/store/modules/projects.store.js +++ b/src/store/modules/projects.store.js @@ -6,22 +6,23 @@ const projects = { namespaced: true, state: { - currentPage: 1, - projects: [], count: 0, - project_slug: null, + currentPage: 1, filters: { moderation: null, access_level: null, user_access_level: null, accessible: null }, - searchProjectsFilter: null, isProjectsListSearched: null, + last_comments: [], + projects: [], + project: null, + project_slug: null, + searchProjectsFilter: null, }, getters: { - project: state => state.projects.find((project) => project.slug === state.project_slug), project_types: state => state.projects.filter(projet => projet.is_project_type), project_user: state => state.projects.filter(projet => projet.creator === state.user.id), }, @@ -45,8 +46,8 @@ const projects = { state.projects = [project, ...state.projects]; }, - SET_PROJECT_SLUG(state, slug) { - state.project_slug = slug; + SET_PROJECT(state, project) { + state.project = project; }, SET_PROJECTS_FILTER(state, payload) { @@ -57,6 +58,10 @@ const projects = { state.isProjectsListSearched = payload.isSearched; state.searchProjectsFilter = payload.text; }, + + SET_PROJECT_COMMENTS(state, last_comments) { + state.last_comments = last_comments; + }, }, actions: { @@ -65,7 +70,6 @@ const projects = { const response = await axios .get(`${rootState.configuration.VUE_APP_DJANGO_API_BASE}projects/`); if (response.status === 200 && response.data) { - // const orderedProjects = response.data.sort((a, b) => parseDate(b.created_on) - parseDate(a.created_on)); commit('SET_PROJECTS', response.data); } } catch (error) { @@ -95,6 +99,38 @@ const projects = { } }, + async GET_PROJECT({ rootState, commit }, slug) { + 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) { + let promises = [ + dispatch('GET_PROJECT_LAST_MESSAGES', slug).then(response => response), + dispatch('feature_type/GET_PROJECT_FEATURE_TYPES', slug, { root: true }).then(response => response), + ]; + if (rootState.user) promises.push(dispatch('map/GET_BASEMAPS', slug, { root: true }).then(response => response)); + + const promiseResult = await Promise.all(promises); + return promiseResult; + }, + + GET_PROJECT_LAST_MESSAGES({ commit }, project_slug) { + return axios + .get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}projects/${project_slug}/comments/`) + .then((response) => { + if (response && response.status === 200) { + commit('SET_PROJECT_COMMENTS', response.data.last_comments); + } + return response; + }) + .catch((error) => { + throw error; + }); + }, + async HANDLE_PROJECTS_SEARCH_REQUEST({ state, rootState, commit }, text) { if (rootState.cancellableSearchRequest.length > 0) { diff --git a/src/views/Catalog.vue b/src/views/Catalog.vue index feccd0390fb5e8858ca7446b1ac0cc9a3aaec6b0..812199628d0a79629da5edc1a0b1eaec832cbe7b 100644 --- a/src/views/Catalog.vue +++ b/src/views/Catalog.vue @@ -120,11 +120,8 @@ export default { computed: { ...mapState(['user']), - ...mapGetters(['permissions']), - ...mapGetters('projects', [ - 'project' - ]), - ...mapGetters('feature_type', ['feature_type']), + ...mapGetters('projects', ['permissions']), + ...mapState('projects', ['project']), paginatedResources() { return this.resources.slice(this.pagination.start, this.pagination.end); @@ -148,7 +145,7 @@ export default { mounted() { this.$store.commit('DISPLAY_LOADER', 'Interrogation du catologue datasud.'); - this.$store.dispatch('GET_PROJECT_INFO', this.$route.params.slug); + this.$store.dispatch('projects/GET_PROJECT', this.$route.params.slug); miscAPI.getIdgoCatalog(this.user.username).then((data) => { if (data && data.layers) this.resources = data.layers; this.$store.commit('DISCARD_LOADER'); diff --git a/src/views/My_account.vue b/src/views/My_account.vue index 6043f4fcf238996d08a87b0e412bcc3553566a58..02e07ea6567e51c5ec2ffa90d5357bdb36d0156d 100644 --- a/src/views/My_account.vue +++ b/src/views/My_account.vue @@ -64,7 +64,6 @@ :key="project.slug" class="item" > - <!-- {% if permissions|lookup:project.slug %} --> <div v-if="user_permissions[project.slug].can_view_project" v-frag diff --git a/src/views/Projects.vue b/src/views/Projects.vue index c89ca11bc0759f75489a98c3a25c34150827f2da..0aee4cb7a9a9aad710100851c68d712fc33d7a39 100644 --- a/src/views/Projects.vue +++ b/src/views/Projects.vue @@ -24,7 +24,7 @@ </div> <!-- FILTRES DES PROJETS --> - <projects-menu + <ProjectsMenu @filter="setProjectsFilters" /> @@ -208,15 +208,12 @@ export default { }, created() { + this.$store.commit('projects/SET_PROJECT', null); this.SET_PROJECTS_FILTER({ filter: 'accessible', value: 'true' }); this.displayForbiddenProjects = this.configuration.DISPLAY_FORBIDDEN_PROJECTS_DEFAULT; - - if (this.$store.getters.project) { - this.$store.commit('SET_PROJECT_SLUG', null); - } }, methods: { diff --git a/src/views/feature/Feature_detail.vue b/src/views/feature/Feature_detail.vue index 0307adb9eba2834778b19205d7aba29970174fe3..c5c54648752fbf820e066eb184433cd8b0c4c9d6 100644 --- a/src/views/feature/Feature_detail.vue +++ b/src/views/feature/Feature_detail.vue @@ -434,12 +434,12 @@ export default { 'user', 'USER_LEVEL_PROJECTS' ]), + ...mapState('projects', [ + 'project' + ]), ...mapGetters([ 'permissions', ]), - ...mapGetters('projects', [ - 'project' - ]), ...mapState('feature', [ 'linked_features', 'statusChoices' @@ -506,7 +506,9 @@ export default { // Chargements des features et infos projet en cas d'arrivée directe sur la page ou de refresh axios.all([ this.$store - .dispatch('GET_PROJECT_INFO', this.$route.params.slug), + .dispatch('projects/GET_PROJECT', this.$route.params.slug), + this.$store + .dispatch('projects/GET_PROJECT_INFO', this.$route.params.slug), this.$store.dispatch('feature/GET_PROJECT_FEATURE', { project_slug: this.$route.params.slug, feature_id: this.$route.params.slug_signal @@ -651,7 +653,7 @@ export default { this.$router.push({ name: 'project_detail', params: { - slug: this.$store.state.project_slug, + slug: this.$route.params.slug, message, }, }); diff --git a/src/views/feature/Feature_edit.vue b/src/views/feature/Feature_edit.vue index 7fc6e51ac18cc4cfd2ce148947ddea292c6401d7..e9eb16bfafcc3dbab36d2e8c4436fb70efc3383d 100644 --- a/src/views/feature/Feature_edit.vue +++ b/src/views/feature/Feature_edit.vue @@ -370,9 +370,10 @@ export default { }, computed: { - ...mapGetters(['project', 'permissions']), + ...mapGetters(['permissions']), ...mapGetters('feature_type', ['feature_type']), ...mapState(['user', 'USER_LEVEL_PROJECTS']), + ...mapState('projects', ['project']), ...mapState('map', ['basemaps']), ...mapState('feature', [ 'attachmentFormset', @@ -486,7 +487,8 @@ export default { mounted() { let promises = [ - this.$store.dispatch('GET_PROJECT_INFO', this.$route.params.slug), + this.$store.dispatch('projects/GET_PROJECT', this.$route.params.slug), + this.$store.dispatch('projects/GET_PROJECT_INFO', this.$route.params.slug), ]; if (this.$route.params.slug_signal) { promises.push( diff --git a/src/views/feature/Feature_list.vue b/src/views/feature/Feature_list.vue index a95169c18223de41ccbaa2d41f48072f0501b358..eb359d3c0601fe00cc197e219fc05b577bc712e1 100644 --- a/src/views/feature/Feature_list.vue +++ b/src/views/feature/Feature_list.vue @@ -316,10 +316,10 @@ export default { computed: { ...mapState(['user', 'USER_LEVEL_PROJECTS']), ...mapGetters([ - 'permissions' + 'permissions', ]), - ...mapGetters('projects', [ - 'project' + ...mapState('projects', [ + 'project', ]), ...mapState('feature', [ 'checkedFeatures' @@ -444,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(); @@ -536,7 +537,7 @@ export default { .then(() => { if (!this.modalAllDeleteOpen) { this.GET_PROJECT_FEATURES({ - project_slug: this.project.slug, + project_slug: this.$route.params.slug, }) .then(() => { this.fetchPagedFeatures(); diff --git a/src/views/feature_type/Feature_type_detail.vue b/src/views/feature_type/Feature_type_detail.vue index afc5d0ba995cd1cfb98763208d166ad8d51e9625..fd9ff464f2159f5c1d43fbff72331d4da21f3bac 100644 --- a/src/views/feature_type/Feature_type_detail.vue +++ b/src/views/feature_type/Feature_type_detail.vue @@ -110,7 +110,7 @@ :to="{ name: 'catalog-import', params: { - slug: project.slug, + slug, feature_type_slug: $route.params.feature_type_slug }, }" @@ -238,8 +238,8 @@ :to="{ name: 'details-signalement', params: { - slug: project.slug, - slug_type_signal: feature.feature_type.slug, + slug, + slug_type_signal: $route.params.feature_type_slug, slug_signal: feature.feature_id, }, }" @@ -264,7 +264,7 @@ </div> <router-link v-if="project" - :to="{ name: 'liste-signalements', params: { slug: project.slug } }" + :to="{ name: 'liste-signalements', params: { slug } }" class="ui right labeled icon button margin-25" > <i class="right arrow icon" /> @@ -322,6 +322,7 @@ export default { size: 0, }, showImport: false, + slug: this.$route.params.slug, featuresLoading: true, loadingImportFile: false, waitMessage: false, @@ -337,15 +338,16 @@ export default { 'project' ]), ...mapState([ - 'reloadIntervalId' + 'reloadIntervalId', + 'configuration', + ]), + ...mapState('projects', [ + 'project' ]), ...mapState('feature', [ 'features', 'features_count' ]), - ...mapState([ - 'configuration', - ]), ...mapState('feature_type', [ 'feature_types', 'importFeatureTypeData' @@ -413,7 +415,7 @@ export default { }); }, this.$store.state.configuration.VUE_APP_RELOAD_INTERVAL); } else if (oldValue && oldValue.some(el => el.status === 'pending')) { - this.getFeatures(); + this.getLastFeatures(); } } }, @@ -421,10 +423,11 @@ export default { created() { if (!this.project) { - this.GET_PROJECT_INFO(this.$route.params.slug); + this.$store.dispatch('projects/GET_PROJECT', this.slug); + this.$store.dispatch('projects/GET_PROJECT_INFO', this.slug); } this.$store.commit('feature/SET_FEATURES', []); //* empty remaining features in case they were in geojson format and will be fetch anyway - this.getFeatures(); + this.getLastFeatures(); this.SET_CURRENT_FEATURE_TYPE_SLUG( this.$route.params.feature_type_slug ); @@ -435,7 +438,6 @@ export default { methods: { ...mapMutations('feature_type', ['SET_CURRENT_FEATURE_TYPE_SLUG']), - ...mapActions(['GET_PROJECT_INFO']), ...mapActions('feature_type', ['GET_IMPORTS']), ...mapActions('feature', ['GET_PROJECT_FEATURES']), toggleShowImport() { @@ -534,7 +536,7 @@ export default { importGeoJson() { this.waitMessage = true; let payload = { - slug: this.$route.params.slug, + slug: this.slug, feature_type_slug: this.$route.params.feature_type_slug, }; if (this.$route.params.geojson) { @@ -552,7 +554,7 @@ export default { }, exportFeatures() { - const url = `${this.$store.state.configuration.VUE_APP_DJANGO_API_BASE}projects/${this.$route.params.slug}/feature-type/${this.$route.params.feature_type_slug}/export/`; + const url = `${this.$store.state.configuration.VUE_APP_DJANGO_API_BASE}projects/${this.slug}/feature-type/${this.$route.params.feature_type_slug}/export/`; featureAPI.getFeaturesBlob(url).then((blob) => { if (blob) { const link = document.createElement('a'); @@ -563,12 +565,13 @@ export default { } }); }, - async getFeatures() { - const response = await this.GET_PROJECT_FEATURES({ - project_slug: this.$route.params.slug, - feature_type__slug: this.$route.params.feature_type_slug, + async getLastFeatures(){ + const response = await + this.GET_PROJECT_FEATURES({ + project_slug: this.slug, + feature_type__slug : this.$route.params.feature_type_slug, ordering: '-created_on', - limit: '5', + limit: '5' }); if (response) { diff --git a/src/views/feature_type/Feature_type_edit.vue b/src/views/feature_type/Feature_type_edit.vue index 212f498f4debc69c37afe6dfd3d4b0c1b02ce189..498ec87a1307fda61f8b985d0eaf321d26a9d46d 100644 --- a/src/views/feature_type/Feature_type_edit.vue +++ b/src/views/feature_type/Feature_type_edit.vue @@ -19,6 +19,7 @@ <div class="ui loader" /> </div> <form + v-if="project" id="form-type-edit" action="" method="post" @@ -271,6 +272,7 @@ export default { value: 'point', }, }, + slug: this.$route.params.slug, reservedKeywords: [ // todo : add keywords for mapstyle (strokewidth...) 'title', @@ -290,9 +292,7 @@ export default { }, computed: { - ...mapGetters('projects', [ - 'project' - ]), + ...mapState('projects', ['project']), ...mapState('feature_type', ['customForms', 'colorsStyleList', 'fileToImport']), ...mapGetters('feature_type', ['feature_type']), selectedGeomType: { @@ -368,7 +368,8 @@ export default { created() { if (!this.project) { - this.$store.dispatch('GET_PROJECT_INFO', this.$route.params.slug); + this.$store.dispatch('projects/GET_PROJECT', this.$route.params.slug); + this.$store.dispatch('projects/GET_PROJECT_INFO', this.$route.params.slug); } this.$store.commit( 'feature_type/SET_CURRENT_FEATURE_TYPE_SLUG', @@ -526,7 +527,7 @@ export default { this.$router.push({ name: 'project_detail', params: { - slug: this.project.slug, + slug: this.slug, message, }, }); @@ -555,7 +556,7 @@ export default { postFeatures(feature_type_slug) { this.$store .dispatch('feature_type/SEND_FEATURES_FROM_GEOJSON', { - slug: this.$route.params.slug, + slug: this.slug, feature_type_slug, geojson: this.geojson }) diff --git a/src/views/feature_type/Feature_type_symbology.vue b/src/views/feature_type/Feature_type_symbology.vue index ca88dcd6dfd1e729cbc0f3a63b3824c2592cbfd0..901769dc84dc9a8182adc466e0a23bda1a99b91a 100644 --- a/src/views/feature_type/Feature_type_symbology.vue +++ b/src/views/feature_type/Feature_type_symbology.vue @@ -35,7 +35,7 @@ enctype="multipart/form-data" class="ui form" > - <h1 v-if="feature_type"> + <h1 v-if="project && feature_type"> Éditer la symbologie du type de signalement "{{ feature_type.title }}" pour le projet "{{ project.title }}" </h1> @@ -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() { @@ -272,7 +274,7 @@ export default { this.$router.push({ name: 'project_detail', params: { - slug: this.$store.state.project_slug, + slug: this.$route.params.slug, }, }); }, 1500); diff --git a/src/views/project/Project_detail.vue b/src/views/project/Project_detail.vue index 5394dce86b3a96cc4071ec8653d1220ba5edb4e3..089980c86dd06cbf77be1ceb022f6ac82eb7d4a8 100644 --- a/src/views/project/Project_detail.vue +++ b/src/views/project/Project_detail.vue @@ -818,7 +818,7 @@ export default { ...mapGetters([ 'permissions' ]), - ...mapGetters('projects', [ + ...mapState('projects', [ 'project' ]), ...mapState([ @@ -934,9 +934,9 @@ export default { 'CLEAR_RELOAD_INTERVAL_ID', 'DISPLAY_MESSAGE', ]), - ...mapActions([ + ...mapActions('projects', [ 'GET_PROJECT_INFO', - 'GET_ALL_PROJECTS', + 'GET_PROJECT', ]), ...mapActions('map', [ 'INITIATE_MAP' @@ -984,6 +984,7 @@ export default { }, retrieveProjectInfo() { + this.GET_PROJECT(this.slug); this.GET_PROJECT_INFO(this.slug) .then(() => { this.projectInfoLoading = false; @@ -1146,11 +1147,15 @@ export default { projectAPI.deleteProject(this.API_BASE_URL, this.project.slug) .then((response) => { if (response === 'success') { - this.GET_ALL_PROJECTS(); this.$router.push('/'); - this.DISPLAY_MESSAGE(`Le projet ${this.project.title} a bien été supprimé.`); + this.DISPLAY_MESSAGE({ + comment: `Le projet ${this.project.title} a bien été supprimé.`, level: 'positive' + }); } else { - this.DISPLAY_MESSAGE(`Une erreur est survenu lors de la suppression du projet ${this.project.title}.`); + this.DISPLAY_MESSAGE({ + comment: `Une erreur est survenu lors de la suppression du projet ${this.project.title}.`, + level: 'negative' + }); } }); }, @@ -1160,11 +1165,17 @@ export default { .then((response) => { this.modalType = false; if (response === 'success') { - this.GET_ALL_PROJECTS(); + this.GET_PROJECT(); this.retrieveProjectInfo(); - this.DISPLAY_MESSAGE(`Le type de signalement ${this.featureTypeToDelete.title} a bien été supprimé.`); + this.DISPLAY_MESSAGE({ + comment: `Le type de signalement ${this.featureTypeToDelete.title} a bien été supprimé.`, + level: 'positive', + }); } else { - this.DISPLAY_MESSAGE(`Une erreur est survenu lors de la suppression du type de signalement ${this.featureTypeToDelete.title}.`); + this.DISPLAY_MESSAGE({ + comment: `Une erreur est survenu lors de la suppression du type de signalement ${this.featureTypeToDelete.title}.`, + level: 'negative', + }); } this.featureTypeToDelete = null; }); diff --git a/src/views/project/Project_edit.vue b/src/views/project/Project_edit.vue index a1db8b44d3d96909f67f21be712a8780ed3eb3e5..1a79afafd8116a6b2c39be98acad18a4b3566518 100644 --- a/src/views/project/Project_edit.vue +++ b/src/views/project/Project_edit.vue @@ -246,7 +246,7 @@ import axios from '@/axios-client.js'; import Dropdown from '@/components/Dropdown.vue'; -import { mapState, mapGetters, mapActions } from 'vuex'; +import { mapState, mapActions } from 'vuex'; export default { name: 'ProjectEdit', @@ -300,23 +300,20 @@ export default { ...mapState([ 'levelsPermissions', ]), - ...mapGetters('projects', [ - 'project' - ]), + ...mapState('projects', ['project']), DJANGO_BASE_URL: function () { 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(); } }); @@ -324,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, }); } @@ -354,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(); + } } }, @@ -372,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) { @@ -569,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() @@ -583,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){ @@ -595,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){ diff --git a/src/views/project/Project_members.vue b/src/views/project/Project_members.vue index 981d6e8288fc4f3dc39ffa63fd3ab2d01ca75bcd..07c510004e27a229968fadb02d65fc12b12c6b03 100644 --- a/src/views/project/Project_members.vue +++ b/src/views/project/Project_members.vue @@ -128,7 +128,7 @@ <script> import axios from '@/axios-client.js'; import frag from 'vue-frag'; -import { mapGetters } from 'vuex'; +import { mapState } from 'vuex'; import Dropdown from '@/components/Dropdown.vue'; export default { @@ -170,9 +170,7 @@ export default { }, computed: { - ...mapGetters('projects', [ - 'project' - ]), + ...mapState('projects', ['project']), userOptions: function () { return this.projectUsers @@ -192,7 +190,7 @@ export default { levelOptions: function () { return this.options.filter( (el) => - (this.project.moderation ? el : el.value !== 'moderator') && + (this.project && this.project.moderation ? el : el.value !== 'moderator') && el.value !== 'logged_user' ); }, @@ -228,7 +226,8 @@ export default { created() { if (!this.project) { - this.$store.dispatch('GET_PROJECT_INFO', this.$route.params.slug); + this.$store.dispatch('projects/GET_PROJECT', this.$route.params.slug); + this.$store.dispatch('projects/GET_PROJECT_INFO', this.$route.params.slug); } this.populateMembers(); }, diff --git a/src/views/registration/Login.vue b/src/views/registration/Login.vue index 2e5d99c9f8c7477feb667c2b0b99e00edf8ed992..77999234edfc163742fdb7e3e131f7416b566ce8 100644 --- a/src/views/registration/Login.vue +++ b/src/views/registration/Login.vue @@ -103,7 +103,7 @@ export default { if (this.$store.state.user) { this.$store.commit( 'DISPLAY_MESSAGE', - "Vous êtes déjà connecté, vous allez être redirigé vers la page d'accueil." + { comment: "Vous êtes déjà connecté, vous allez être redirigé vers la page d'accueil." } ); setTimeout(() => this.$router.push('/'), 3100); }