diff --git a/src/store/modules/feature.js b/src/store/modules/feature.js index 974ee922ebc6016d1a10d1841575d1ae13adb989..3e248934f355806b289669ced8beaf24348457d8 100644 --- a/src/store/modules/feature.js +++ b/src/store/modules/feature.js @@ -19,6 +19,24 @@ const feature = { form: null, extra_form: [], linked_features: [], + statusChoices: [ + { + name: "Brouillon", + value: "draft", + }, + { + name: "Publié", + value: "published", + }, + { + name: "Archivé", + value: "archived", + }, + { + name: "En attente de publication", + value: "pending", + }, + ], }, mutations: { SET_FEATURES(state, features) { @@ -137,9 +155,9 @@ const feature = { if (routeName === "editer-signalement") { axios .put(`${rootState.configuration.VUE_APP_DJANGO_API_BASE}features/${state.form.feature_id}/?` + - `feature_type__slug=${rootState.feature_type.current_feature_type_slug}` + - `&project__slug=${rootState.project_slug}` - , geojson) + `feature_type__slug=${rootState.feature_type.current_feature_type_slug}` + + `&project__slug=${rootState.project_slug}` + , geojson) .then((response) => { if (response.status === 200 && response.data) { if (state.attachmentFormset.length > 0 || state.linkedFormset.length > 0) { @@ -189,7 +207,7 @@ const feature = { console.error(error); return error }); - + } } @@ -203,7 +221,7 @@ const feature = { if (attachment.title) data['info'] = attachment.info formdataToUpdate.append("data", JSON.stringify(data)); - let payload ={ + let payload = { 'attachmentsId': attachment.id, 'featureId': featureId, 'formdataToUpdate': formdataToUpdate @@ -213,7 +231,7 @@ const feature = { } function deleteAttachement(attachmentsId, featureId) { - let payload ={ + let payload = { 'attachmentsId': attachmentsId, 'featureId': featureId } @@ -224,7 +242,7 @@ const feature = { ...state.attachmentFormset.map((attachment) => postAttachement(attachment)), ...state.attachmentsToPut.map((attachments) => putAttachement(attachments, featureId)), ...state.attachmentsToDelete.map((attachmentsId) => deleteAttachement(attachmentsId, featureId)) - ] + ] ); state.attachmentsToDelete = [] state.attachmentsToPut = [] @@ -280,8 +298,8 @@ const feature = { DELETE_FEATURE({ state, rootState }, feature_id) { console.log("Deleting feature:", feature_id, state) 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}`; + `feature_type__slug=${rootState.feature_type.current_feature_type_slug}` + + `&project__slug=${rootState.project_slug}`; return axios .delete(url) .then((response) => response) diff --git a/src/views/feature/Feature_detail.vue b/src/views/feature/Feature_detail.vue index 62203ff90acf0230451cf02f0f3e22c85579c717..2a2951a8d3af652b8ac345312e54333aca278b37 100644 --- a/src/views/feature/Feature_detail.vue +++ b/src/views/feature/Feature_detail.vue @@ -71,17 +71,11 @@ <td> <b> <i - v-if=" - field.field_type === 'boolean' && field.value === true - " - class="olive check icon" - ></i> - <i - v-else-if=" - field.field_type === 'boolean' && - field.value === false - " - class="red times icon" + v-if="field.field_type === 'boolean'" + :class="[ + 'icon', + field.value ? 'olive check' : 'grey times', + ]" ></i> <span v-else> {{ field.value }} @@ -97,11 +91,8 @@ <tr> <td>Statut</td> <td> - <i - v-if="feature.status" - :class="getIconLabelStatus(feature.status, 'icon')" - ></i> - {{ getIconLabelStatus(feature.status, 'label') }} + <i v-if="feature.status" :class="['icon', statusIcon]"></i> + {{ statusLabel }} </td> </tr> <tr> @@ -143,20 +134,6 @@ <a @click="pushNgo(link)">{{ link.feature_to.title }} </a> ({{ link.feature_to.display_creator }} - {{ link.feature_to.created_on }}) - <!-- <router-link - :key="$route.fullPath" - :to="{ - name: 'details-signalement', - params: { - slug_type_signal: link.feature_to.feature_type_slug, - slug_signal: link.feature_to.feature_id, - }, - }" - >{{ link.feature_to.title }}</router-link - > - ({{ link.feature_to.display_creator }} - - {{ link.feature_to.created_on }}) - --> </td> </tr> </tbody> @@ -408,7 +385,7 @@ export default { computed: { ...mapState(["user"]), ...mapGetters(["permissions"]), - ...mapState("feature", ["linked_features"]), + ...mapState("feature", ["linked_features", "statusChoices"]), DJANGO_BASE_URL: function () { return this.$store.state.configuration.VUE_APP_DJANGO_BASE; }, @@ -417,7 +394,6 @@ export default { const result = this.$store.state.feature.features.find( (el) => el.feature_id === this.$route.params.slug_signal ); - console.log("result", result); return result; }, @@ -427,6 +403,28 @@ export default { } return false; }, + + statusIcon() { + switch (this.feature.status) { + case "archived": + return "grey archive"; + case "pending": + return "teal hourglass outline"; + case "published": + return "olive check"; + case "draft": + return "orange pencil alternate"; + default: + return ""; + } + }, + + statusLabel() { + const status = this.statusChoices.find( + (el) => el.value === this.feature.status + ); + return status ? status.name : ""; + }, }, filters: { @@ -438,24 +436,6 @@ export default { }, methods: { - getIconLabelStatus(status, type){ - if (status === 'archived') - if (type == 'icon') - return "grey archive icon"; - else return 'Archivé'; - else if (status === 'pending') - if (type == 'icon') - return "teal hourglass outline icon"; - else return 'En attente de publication'; - else if (status === 'published') - if (type == 'icon') - return "olive check icon"; - else return 'Publié'; - else if (status === 'draft') - if (type == 'icon') - return "orange pencil alternate icon"; - else return 'Brouillon'; - }, pushNgo(link) { this.$router.push({ name: "details-signalement", @@ -468,8 +448,6 @@ export default { this.getFeatureAttachments(); this.getLinkedFeatures(); this.addFeatureToMap(); - //this.initMap(); - //this.$router.go(); }, postComment() { @@ -489,7 +467,6 @@ export default { }) .then(() => { this.confirmComment(); - //this.getFeatureAttachments(); //* display new attachment from comment on the page }); } else { this.confirmComment(); @@ -533,7 +510,10 @@ export default { .dispatch("feature/DELETE_FEATURE", this.feature.feature_id) .then((response) => { if (response.status === 204) { - this.$store.dispatch("feature/GET_PROJECT_FEATURES", this.$route.params.slug); + this.$store.dispatch( + "feature/GET_PROJECT_FEATURES", + this.$route.params.slug + ); this.goBackToProject(); } }); @@ -599,7 +579,9 @@ export default { if (feature) { const currentFeature = [feature]; const featureGroup = mapUtil.addFeatures(currentFeature); - mapUtil.getMap().fitBounds(featureGroup.getBounds(), { padding: [25, 25] }); + mapUtil + .getMap() + .fitBounds(featureGroup.getBounds(), { padding: [25, 25] }); } }) .catch((error) => { @@ -629,9 +611,6 @@ export default { }, created() { - // if (!this.project) { - // this.$store.dispatch("GET_PROJECT_INFO", this.$route.params.slug); - // } this.$store.commit( "feature_type/SET_CURRENT_FEATURE_TYPE_SLUG", this.$route.params.slug_type_signal diff --git a/src/views/feature/Feature_edit.vue b/src/views/feature/Feature_edit.vue index 8ea11a374d2b479e2b5f15cd5ff689a56618ae1c..c948a71abe0305befdb0530801dd065422f99a9d 100644 --- a/src/views/feature/Feature_edit.vue +++ b/src/views/feature/Feature_edit.vue @@ -279,24 +279,6 @@ export default { erreurUploadMessage: null, attachmentDataKey: 0, linkedDataKey: 0, - statusChoices: [ - { - name: "Brouillon", - value: "draft", - }, - { - name: "Publié", - value: "published", - }, - { - name: "Archivé", - value: "archived", - }, - { - name: "En attente de publication", - value: "pending", - }, - ], form: { title: { errors: [], @@ -346,6 +328,7 @@ export default { "features", "extra_form", "linked_features", + "statusChoices" ]), field_title() {