From 1f5bd34be27722ac2ac036c5b5bdfbe8116a1887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Poussard?= <tpoussard@neogeo.fr> Date: Tue, 14 Sep 2021 16:28:59 +0200 Subject: [PATCH] update thumbnails src format and add user_permissions fetch --- src/main.js | 1 + src/store/index.js | 27 ++++++++++++++++++++----- src/views/My_account.vue | 16 +++++++++++++-- src/views/project/Project_type_list.vue | 15 +++++++++++++- 4 files changed, 51 insertions(+), 8 deletions(-) diff --git a/src/main.js b/src/main.js index 8fa1df52..0a983144 100644 --- a/src/main.js +++ b/src/main.js @@ -13,6 +13,7 @@ store.dispatch("GET_ALL_PROJECTS"), store.dispatch("GET_STATIC_PAGES"), store.dispatch("GET_USER_LEVEL_PROJECTS"), store.dispatch("map/GET_LAYERS"), +store.dispatch("GET_USER_LEVEL_PERMISSIONS"), ]).then(axios.spread(function () { new Vue({ router, diff --git a/src/store/index.js b/src/store/index.js index f1fceb11..a75f0cab 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -38,7 +38,8 @@ export default new Vuex.Store({ last_comments: [], staticPages: null, SSO_SETTED: false, - USER_LEVEL_PROJECTS: null + USER_LEVEL_PROJECTS: null, + user_permissions: null, }, mutations: { @@ -75,6 +76,9 @@ export default new Vuex.Store({ SET_PROJECT_COMMENTS(state, last_comments) { state.last_comments = last_comments }, + SET_USER_PERMISSIONS(state, userPermissions) { + state.user_permissions = userPermissions + }, }, getters: { @@ -139,18 +143,18 @@ export default new Vuex.Store({ if (response && response.status === 200) { const user = response.data.user; commit("SET_USER", user); - window.localStorage.setItem("user", JSON.stringify(user)); + window.localStorage.setItem("user", JSON.stringify(user)); //? toujours nécessaire ? } - }) // todo: ajouter au localestorage + }) .catch(() => { router.push({ name: "login" }); }); }, - LOGOUT({ commit }) { // ? logout bien dans django ? + LOGOUT({ commit }) { // ? logout se fait bien dans django ? axios .get(`${DJANGO_API_BASE}logout/`) - .then((response) => { // todo: check status + .then((response) => { if (response && response.status === 200) { commit("SET_USER", false); // ? better false or null commit("SET_USER_LEVEL_PROJECTS", null); @@ -175,6 +179,19 @@ export default new Vuex.Store({ }); }, + GET_USER_LEVEL_PERMISSIONS({ commit }) { + axios + .get(`${DJANGO_API_BASE}user-permissions/`) + .then((response) => { + if (response && response.status === 200) { + commit("SET_USER_PERMISSIONS", response.data) + } + }) + .catch((error) => { + throw error; + }); + }, + GET_PROJECT_INFO({ commit, dispatch }, slug) { commit("SET_PROJECT_SLUG", slug); dispatch("GET_PROJECT_LAST_MESSAGES", slug); diff --git a/src/views/My_account.vue b/src/views/My_account.vue index e679b7d5..c05a6d27 100644 --- a/src/views/My_account.vue +++ b/src/views/My_account.vue @@ -19,7 +19,7 @@ <div class="item"> <div class="right floated content"> <div class="description"> - {{ user.get_full_name }} + {{ userFullname }} </div> </div> <div class="content">Nom complet</div> @@ -56,7 +56,7 @@ :src=" project.thumbnail.includes('default') ? require('@/assets/img/default.png') - : project.thumbnail + : DJANGO_BASE_URL + project.thumbnail + refreshId() " height="200" /> @@ -288,6 +288,18 @@ export default { computed: { // todo : filter projects to user ...mapState(["user", "projects", "USER_LEVEL_PROJECTS"]), + DJANGO_BASE_URL: () => process.env.VUE_APP_DJANGO_BASE, + userFullname: function () { + if (this.user.first_name || this.user.last_name) + return this.user.first_name + " " + this.user.last_name; + return null; + }, + }, + + methods: { + refreshId() { + return "?ver=" + Math.random(); + }, }, }; </script> \ No newline at end of file diff --git a/src/views/project/Project_type_list.vue b/src/views/project/Project_type_list.vue index addbd989..3909eab7 100644 --- a/src/views/project/Project_type_list.vue +++ b/src/views/project/Project_type_list.vue @@ -7,7 +7,13 @@ <div class="ui divided items"> <div v-for="project in project_types" :key="project.slug" class="item"> <div class="ui tiny image"> - <img :src="project.thumbnail" /> + <img + :src=" + project.thumbnail.includes('default') + ? require('@/assets/img/default.png') + : DJANGO_BASE_URL + project.thumbnail + refreshId() + " + /> </div> <div class="middle aligned content"> <div class="description"> @@ -67,6 +73,13 @@ export default { computed: { ...mapGetters(["project_types"]), + DJANGO_BASE_URL: () => process.env.VUE_APP_DJANGO_BASE, + }, + + methods: { + refreshId() { + return "?ver=" + Math.random(); + }, }, }; </script> \ No newline at end of file -- GitLab