diff --git a/src/components/Feature/Detail/FeatureHeader.vue b/src/components/Feature/Detail/FeatureHeader.vue index 6355f6e24d5098a7c9341005ca2a12df5b6563ca..0da226c012194aebc3d6842deefa00fbac1f6f43 100644 --- a/src/components/Feature/Detail/FeatureHeader.vue +++ b/src/components/Feature/Detail/FeatureHeader.vue @@ -61,7 +61,7 @@ :class="['ui button button-hover-orange tiny-margin', { disabled: false }]" data-tooltip="Enregistrer les modifications" data-position="bottom center" - @click="toFeature('previous')" + @click="saveFastEdition" > <i class="save fitted icon" @@ -212,6 +212,10 @@ export default { offset: this.queryparams[direction] } }); + }, + saveFastEdition() { + this.$store.dispatch('feature/SEND_FEATURE', this.currentRouteName) + .then(() => console.log('sent')); } } }; diff --git a/src/components/Feature/Detail/FeatureTable.vue b/src/components/Feature/Detail/FeatureTable.vue index ce19426b2854da96502073c75f30a52f06c90b76..d5ba20657e209dfcd30a38fd5fbff9eb534d2488 100644 --- a/src/components/Feature/Detail/FeatureTable.vue +++ b/src/components/Feature/Detail/FeatureTable.vue @@ -22,8 +22,12 @@ </td> <td> <strong> + <FeatureExtraForm + v-if="fastEditionMode && extra_forms.length > 0" + :field="getExtraForm(field)" + /> <i - v-if="field.field_type === 'boolean'" + v-else-if="field.field_type === 'boolean'" :class="[ 'icon', field.value ? 'olive check' : 'grey times', @@ -110,6 +114,7 @@ import { mapState } from 'vuex'; import FeatureTypeLink from '@/components/FeatureType/FeatureTypeLink'; +import FeatureExtraForm from '@/components/Feature/Edit/FeatureExtraForm'; import { statusChoices } from '@/utils'; export default { @@ -117,7 +122,8 @@ export default { name: 'FeatureTable', components: { - FeatureTypeLink + FeatureTypeLink, + FeatureExtraForm, }, filters: { @@ -133,12 +139,17 @@ export default { type: Object, default: () => {}, }, + fastEditionMode: { + type: Boolean, + default: false, + } }, computed: { ...mapState('feature', [ 'currentFeature', 'linked_features', + 'extra_forms', ]), statusIcon() { @@ -172,6 +183,10 @@ export default { slug_signal: link.feature_to.feature_id, }, }); + }, + + getExtraForm(field) { + return this.extra_forms.find(exF => exF.label === field.label); } } diff --git a/src/store/modules/feature.store.js b/src/store/modules/feature.store.js index 5d7858136b77be43e1d4362d4bd887a924ea6fb8..ec5b373b1069b0ef5d927329d82e0d528f2aeb4d 100644 --- a/src/store/modules/feature.store.js +++ b/src/store/modules/feature.store.js @@ -8,7 +8,7 @@ const feature = { attachmentsToDelete: [], checkedFeatures: [], clickedFeatures: [], - extra_form: [], + extra_forms: [], features: [], features_count: 0, currentFeature: null, @@ -33,16 +33,16 @@ const feature = { state.form = payload; }, UPDATE_EXTRA_FORM(state, extra_form) { - const index = state.extra_form.findIndex(el => el.label === extra_form.label); + const index = state.extra_forms.findIndex(el => el.label === extra_form.label); if (index !== -1) { - state.extra_form[index] = extra_form; + state.extra_forms[index] = extra_form; } }, - SET_EXTRA_FORM(state, extra_form) { - state.extra_form = extra_form; + SET_EXTRA_FORMS(state, extra_forms) { + state.extra_forms = extra_forms; }, CLEAR_EXTRA_FORM(state) { - state.extra_form = []; + state.extra_forms = []; }, ADD_ATTACHMENT_FORM(state, attachmentFormset) { state.attachmentFormset = [...state.attachmentFormset, attachmentFormset]; @@ -191,7 +191,7 @@ const feature = { params: { slug_type_signal: rootState['feature-type'].current_feature_type_slug, slug_signal: featureId, - message: routeName === 'editer-signalement' ? 'Le signalement a été mis à jour' : 'Le signalement a été crée' + message: routeName === 'ajouter-signalement' ? 'Le signalement a été crée' : 'Le signalement a été mis à jour' }, }); dispatch('projects/GET_ALL_PROJECTS', null, { root:true }); //* & refresh project list @@ -206,7 +206,7 @@ const feature = { function createGeojson() { //* prepare feature data to send const extraFormObject = {}; //* prepare an object to be flatten in properties of geojson - for (const field of state.extra_form) { + for (const field of state.extra_forms) { extraFormObject[field.name] = field.value; } return { @@ -226,7 +226,7 @@ const feature = { const geojson = createGeojson(); let url = `${rootState.configuration.VUE_APP_DJANGO_API_BASE}features/`; - if (routeName === 'editer-signalement') { + if (routeName !== 'ajouter-signalement') { url += `${state.form.feature_id}/? feature_type__slug=${rootState['feature-type'].current_feature_type_slug} &project__slug=${rootState.projects.project.slug}`; @@ -237,7 +237,7 @@ const feature = { //* which could create regression return axios({ url, - method: routeName === 'editer-signalement' ? 'PUT' : 'POST', + method: routeName === 'ajouter-signalement' ? 'POST' : 'PUT', data: geojson }).then((response) => { if ((response.status === 200 || response.status === 201) && response.data) { @@ -259,7 +259,7 @@ const feature = { } const updateMsg = { project: rootState.projects.project.slug, - type: routeName === 'editer-signalement' ? 'put' : 'post', + type: routeName === 'ajouter-signalement' ? 'post' : 'put', featureId: state.form.feature_id, geojson: geojson }; @@ -385,6 +385,26 @@ const feature = { return false; }); }, + + INIT_EXTRA_FORMS({ state, rootGetters, commit }) { + const feature = state.currentFeature; + function findCurrentValue(label) { + const field = feature.feature_data.find((el) => el.label === label); + return field ? field.value : null; + } + //* retrieve 'name', 'options', 'position' from current feature_type data to display in the form + const extraForm = rootGetters['feature-type/feature_type'].customfield_set.map((field) => { + return { + ...field, + //* add value field to extra forms from feature_type and existing values if feature is defined + value: + feature && feature.feature_data + ? findCurrentValue(field.label) + : null, + }; + }); + commit('SET_EXTRA_FORMS', extraForm); + }, }, }; diff --git a/src/views/Feature/FeatureDetail.vue b/src/views/Feature/FeatureDetail.vue index 7c2c418c11a785e2ab290353d42129a56c8386cf..1b88ecf9671c0aec13c1e60471ee710469483a88 100644 --- a/src/views/Feature/FeatureDetail.vue +++ b/src/views/Feature/FeatureDetail.vue @@ -21,7 +21,9 @@ <div class="row"> <div class="eight wide column"> <FeatureTable + v-if="project" :feature-type="featureType" + :fast-edition-mode="project.fast_edition_mode" @tofeature="pushNgo" /> </div> @@ -179,7 +181,7 @@ export default { 'feature_type', ]), ...mapState('feature', [ - 'currentFeature' + 'currentFeature', ]), }, @@ -191,12 +193,6 @@ export default { }, }, - created() { - if (this.$route.params.slug_type_signal) { - this.SET_CURRENT_FEATURE_TYPE_SLUG(this.$route.params.slug_type_signal); - } - }, - mounted() { this.initPage(); // when this is available, set the value with previously stored value in windows to pass it as a prop @@ -233,7 +229,8 @@ export default { }, async getPageInfo() { - if (this.$route.params.slug_signal) { // if coming from the route with an id + if (this.$route.params.slug_signal && this.$route.params.slug_type_signal) { // if coming from the route with an id + this.SET_CURRENT_FEATURE_TYPE_SLUG(this.$route.params.slug_type_signal); this.slugSignal = this.$route.params.slug_signal; this.featureType = this.feature_type; } //* else it would be retrieve after fetchFilteredFeature with offset @@ -262,6 +259,7 @@ export default { this.getFeatureAttachments(); this.getLinkedFeatures(); this.DISCARD_LOADER(); + if (this.project.fast_edition_mode) this.$store.dispatch('feature/INIT_EXTRA_FORMS'); }, confirmLeave() { @@ -311,6 +309,7 @@ export default { const { feature_id, feature_type } = data.results[0]; this.slugSignal = feature_id; this.featureType = feature_type; + this.SET_CURRENT_FEATURE_TYPE_SLUG(feature_type.slug); return { feature_id }; } return; diff --git a/src/views/Feature/FeatureEdit.vue b/src/views/Feature/FeatureEdit.vue index 992e012f76928dbad713a13f6e8002dfd4302009..ce39380330ef83d5ac10aa38060f513bc8308e56 100644 --- a/src/views/Feature/FeatureEdit.vue +++ b/src/views/Feature/FeatureEdit.vue @@ -438,7 +438,7 @@ export default { 'attachmentFormset', 'linkedFormset', 'features', - 'extra_form', + 'extra_forms', ]), ...mapState('feature-type', [ 'feature_types' @@ -469,7 +469,7 @@ export default { }, orderedCustomFields() { - return [...this.extra_form].sort((a, b) => a.position - b.position); + return [...this.extra_forms].sort((a, b) => a.position - b.position); }, geoRefFileLabel() { @@ -545,7 +545,7 @@ export default { this.initForm(); this.initMap(); this.onFeatureTypeLoaded(); - this.initExtraForms(this.feature); + this.$store.dispatch('feature/INIT_EXTRA_FORMS'); }); }, @@ -666,24 +666,6 @@ export default { }); }, - initExtraForms(feature) { - function findCurrentValue(label) { - const field = feature.feature_data.find((el) => el.label === label); - return field ? field.value : null; - } - const extraForm = this.feature_type.customfield_set.map((field) => { - return { - ...field, - //* add value field to extra forms from feature_type and existing values if feature is defined - value: - feature && feature.feature_data - ? findCurrentValue(field.label) - : null, - }; - }); - this.$store.commit('feature/SET_EXTRA_FORM', extraForm); - }, - add_attachement_formset() { this.$store.commit('feature/ADD_ATTACHMENT_FORM', { dataKey: this.attachmentDataKey,