Skip to content
Snippets Groups Projects
Commit 0cb60528 authored by Timothee P's avatar Timothee P :sunflower:
Browse files

fill feature_edit linkedForm with existing linked_features (adapt data for dropdown with object

parent 54050631
No related branches found
No related tags found
No related merge requests found
...@@ -54,12 +54,55 @@ export default { ...@@ -54,12 +54,55 @@ export default {
Dropdown, Dropdown,
}, },
data() {
return {
form: {
errors: null,
relation_type: {
errors: null,
id_for_label: "relation_type",
field: {
choices: ["Doublon", "Remplace", "Est remplacé par", "Dépend de"],
},
html_name: "relation_type",
label: "Type de liaison",
value: "Doublon",
},
feature_to: {
errors: null,
id_for_label: "feature_to",
field: {
max_length: 30,
},
html_name: "feature_to",
label: "Signalement lié",
value: {
name: "",
value: "",
},
},
},
};
},
computed: { computed: {
featureOptions: function () { featureOptions: function () {
return this.features.map( return this.features
(el) => `${el.title} (${el.display_creator} - ${el.created_on})` .filter(
); (el) =>
el.feature_type.slug === this.$route.params.slug_type_signal && //* filter only for the same feature
el.feature_id !== this.$route.params.slug_signal //* filter out current feature
)
.map((el) => {
return {
name: `${el.title} (${el.display_creator} - ${this.formatDate(
el.created_on
)})`,
value: el.feature_id,
};
});
}, },
selected_relation_type: { selected_relation_type: {
// getter // getter
get() { get() {
...@@ -71,10 +114,11 @@ export default { ...@@ -71,10 +114,11 @@ export default {
this.updateStore(); this.updateStore();
}, },
}, },
selected_feature_to: { selected_feature_to: {
// getter // getter
get() { get() {
return this.form.feature_to.value; return this.form.feature_to.value.name;
}, },
// setter // setter
set(newValue) { set(newValue) {
...@@ -84,44 +128,33 @@ export default { ...@@ -84,44 +128,33 @@ export default {
}, },
}, },
data() { watch: {
return { featureOptions(newValue) {
form: { if (newValue) {
errors: null, this.getExistingFeature_to(newValue);
relation_type: { }
errors: null, },
id_for_label: "relation_type",
field: {
choices: ["Doublon", "Remplace", "Est remplacé par", "Dépend de"],
},
html_name: "relation_type",
label: "Type de liaison",
value: "Doublon",
},
feature_to: {
errors: null,
id_for_label: "feature_to",
field: {
max_length: 30,
},
html_name: "feature_to",
label: "Signalement lié",
value: "",
},
},
};
}, },
methods: { methods: {
formatDate(value) {
let date = new Date(value);
date = date.toLocaleString().replace(",", "");
return date.substr(0, date.length - 3); //* quick & dirty way to remove seconds from date
},
remove_linked_formset() { remove_linked_formset() {
this.$store.commit("feature/REMOVE_LINKED_FORM", this.linkedForm.dataKey); this.$store.commit("feature/REMOVE_LINKED_FORM", this.linkedForm.dataKey);
}, },
updateStore() { updateStore() {
this.$store.commit("feature/UPDATE_LINKED_FORM", { this.$store.commit("feature/UPDATE_LINKED_FORM", {
dataKey: this.linkedForm.dataKey, dataKey: this.linkedForm.dataKey,
relation_type: this.form.relation_type.value, relation_type: this.form.relation_type.value,
feature_to: this.form.feature_to.value, feature_to: this.form.feature_to.value.value,
}); });
}, },
checkForm() { checkForm() {
if (this.form.feature_to.value === "") { if (this.form.feature_to.value === "") {
this.form.errors = [ this.form.errors = [
...@@ -135,6 +168,20 @@ export default { ...@@ -135,6 +168,20 @@ export default {
this.form.errors = []; this.form.errors = [];
return true; return true;
}, },
getExistingFeature_to(featureOptions) {
const feature_to = featureOptions.find(
(el) => el.value === this.linkedForm.feature_to.feature_id
);
console.log(
featureOptions,
this.linkedForm.feature_to.feature_id,
feature_to
);
if (feature_to) {
this.form.feature_to.value = feature_to;
}
},
}, },
}; };
</script> </script>
\ No newline at end of file
...@@ -47,8 +47,8 @@ const feature = { ...@@ -47,8 +47,8 @@ const feature = {
CLEAR_ATTACHMENT_FORM(state) { CLEAR_ATTACHMENT_FORM(state) {
state.attachmentFormset = []; state.attachmentFormset = [];
}, },
ADD_LINKED_FORM(state, dataKey) { ADD_LINKED_FORM(state, linkedFormset) {
state.linkedFormset = [...state.linkedFormset, { dataKey }]; state.linkedFormset = [...state.linkedFormset, linkedFormset];
}, },
UPDATE_LINKED_FORM(state, payload) { UPDATE_LINKED_FORM(state, payload) {
const index = state.linkedFormset.findIndex((el) => el.dataKey === payload.dataKey); const index = state.linkedFormset.findIndex((el) => el.dataKey === payload.dataKey);
...@@ -60,6 +60,9 @@ const feature = { ...@@ -60,6 +60,9 @@ const feature = {
SET_LINKED_FEATURES(state, payload) { SET_LINKED_FEATURES(state, payload) {
state.linked_features = payload; state.linked_features = payload;
}, },
CLEAR_LINKED_FORM(state) {
state.linkedFormset = [];
},
}, },
getters: { getters: {
}, },
...@@ -159,11 +162,11 @@ const feature = { ...@@ -159,11 +162,11 @@ const feature = {
} }
}, },
/* GET_FEATURE_LINK({ commit }, featureId) { /* GET_FEATURE_LINK({ commit }, featureId) {
featureAPI featureAPI
.getlinked_features(featureId) .getlinked_features(featureId)
.then((data) => commit("SET_FEATURE_LINKS", data)); .then((data) => commit("SET_FEATURE_LINKS", data));
} */ } */
//DELETE_FEATURE({ state }, feature_slug) { //DELETE_FEATURE({ state }, feature_slug) {
//console.log("Deleting feature:", feature_slug, state) //console.log("Deleting feature:", feature_slug, state)
......
...@@ -323,6 +323,7 @@ export default { ...@@ -323,6 +323,7 @@ export default {
"linkedFormset", "linkedFormset",
"features", "features",
"extra_form", "extra_form",
"linked_features",
]), ]),
...mapGetters("feature_type", ["feature_type"]), ...mapGetters("feature_type", ["feature_type"]),
...@@ -460,7 +461,6 @@ export default { ...@@ -460,7 +461,6 @@ export default {
}); // * create an object with the counter in store }); // * create an object with the counter in store
this.attachmentDataKey += 1; // * increment counter for key in v-for this.attachmentDataKey += 1; // * increment counter for key in v-for
}, },
addExistingAttachementFormset(attachementFormset) { addExistingAttachementFormset(attachementFormset) {
for (const attachment of attachementFormset) { for (const attachment of attachementFormset) {
console.log("attachment", attachment); console.log("attachment", attachment);
...@@ -476,9 +476,22 @@ export default { ...@@ -476,9 +476,22 @@ export default {
}, },
add_linked_formset() { add_linked_formset() {
this.$store.commit("feature/ADD_LINKED_FORM", this.linkedDataKey); // * create an object with the counter in store this.$store.commit("feature/ADD_LINKED_FORM", {
dataKey: this.linkedDataKey,
}); // * create an object with the counter in store
this.linkedDataKey += 1; // * increment counter for key in v-for this.linkedDataKey += 1; // * increment counter for key in v-for
}, },
addExistingLinkedFormset(linkedFormset) {
for (const linked of linkedFormset) {
console.log("linked", linked);
this.$store.commit("feature/ADD_LINKED_FORM", {
dataKey: this.linkedDataKey,
relation_type: linked.relation_type,
feature_to: linked.feature_to,
});
this.linkedDataKey += 1;
}
},
updateStore() { updateStore() {
this.$store.commit("feature/UPDATE_FORM", { this.$store.commit("feature/UPDATE_FORM", {
...@@ -837,11 +850,16 @@ export default { ...@@ -837,11 +850,16 @@ export default {
}, },
getFeatureAttachments() { getFeatureAttachments() {
// todo : mutualize in store with feature_detail.vue
featureAPI featureAPI
.getFeatureAttachments(this.$route.params.slug_signal) .getFeatureAttachments(this.$route.params.slug_signal)
.then((data) => this.addExistingAttachementFormset(data)); .then((data) => this.addExistingAttachementFormset(data));
}, },
getLinkedFeatures() {
featureAPI
.getFeatureLinks(this.$route.params.slug_signal)
.then((data) => this.addExistingLinkedFormset(data));
},
}, },
created() { created() {
...@@ -855,9 +873,11 @@ export default { ...@@ -855,9 +873,11 @@ export default {
if (this.$route.params.slug_signal) { if (this.$route.params.slug_signal) {
this.getFeatureAttachments(); this.getFeatureAttachments();
this.getLinkedFeatures();
} else { } else {
//* be sure that previous attachemntFormset has been cleared for creation //* be sure that previous Formset have been cleared for creation
this.$store.commit("feature/CLEAR_ATTACHMENT_FORM"); this.$store.commit("feature/CLEAR_ATTACHMENT_FORM");
this.$store.commit("feature/CLEAR_LINKED_FORM");
} }
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment