Skip to content

Commit

Permalink
protection (fix replace) & anteriorite etendue => ref #36
Browse files Browse the repository at this point in the history
  • Loading branch information
joelclems committed Jan 12, 2021
1 parent ebda230 commit fae74e6
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 25 deletions.
52 changes: 35 additions & 17 deletions frontend/src/modules/declaration/config/restitution-declaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,54 @@ export default {
type: "date"
},
degat_gravite_label: {
text: "Dégâts - gravite",
text: "Dégâts - gravité",
order: ["Faibles", "Modérés", "Importants"],
colors: {
Importants: "red",
Modérés: "orange",
Faibles: "yellow"
}
},
degat_etendue_label: {
text: "Dégâts - étendue",
order: ["Généralisés", "Localisés"],
colors: {
"Généralisés": "red",
// Modérés: "orange",
"Localisés": "yellow"
}
},
degat_anteriorite_label: {
text: "Dégâts - anteriorité",
order: ["Récents (année en cours)", "Récurrents", "Anciens (années antérieures)", "Ne sais pas", 'Indéfini'],
colors: {
"Récents (année en cours)": "red",
"Récurrents": "orange",
"Anciens (années antérieures)": "yellow"
}
},
degat_gravite_label_max: {
source: 'degat_gravite_label',
text: "Dégâts - gravite (max)",
order: ["Faibles", "Modérés", "Importants"],
patch: 'degat_type_label',
colors: {
Importants: "red",
Modérés: "orange",
Faibles: "yellow"
}
},
degat_etendue_label_max: {
source: 'degat_etendue_label',
text: "Dégâts - étendue (max)",
patch: 'degat_type_label',
},
degat_anteriorite_label_max: {
source: 'degat_anteriorite_label',
text: "Dégâts - antériorité (max)",
patch: 'degat_type_label',
},

// degat_gravite_label: {
// text: "Dégâts - gravite",
// // order: ["Faibles", "Modérés", "Importants"],
// colors: {
// Importants: "red",
// Modérés: "orange",
// Faibles: "yellow"
// }
// },
degat_essence_label: {
text: "Dégâts - essence"
},
peuplement_type_label: {
text: "Peuplement - type"
},
degat_type_label: {
text: "Dégâts - type"
},
Expand Down Expand Up @@ -124,6 +140,8 @@ export default {
markersGroupByReduceKeys: [
"degat_type_label",
"degat_gravite_label",
"degat_etendue_label",
"degat_anteriorite_label",
"degat_essence_label"
],
dataType: "declaration",
Expand All @@ -133,7 +151,7 @@ export default {
typeGraph: "column",
nbMax1: 7,
nbMax2: 7,
choix1: 'declaration_date',
choix1: 'b_peuplement_paturage_presence',
// choix1: "degat_gravite_label_max",
// choix2: "degat_essence_label",
// choix2: "degat_type_label",
Expand Down
19 changes: 13 additions & 6 deletions frontend/src/modules/restitution/restitution.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,21 @@ class Restitution {
key => this.item(key) && this.item(key).patch
);
if (key_item_patch) {
const item = this.item(key_item_patch);
const patch = item.patch;
const keep = {};
for (const r of d.res) {
if (
keep[r.degat_type_label] &&
keep[r.degat_type_label].degat_gravite_label
keep[patch] &&
keep[patch][key_item_patch]
) {
const prev = keep[r.degat_type_label].degat_gravite_label[0];
const cur = r.degat_gravite_label[0];
const prev = keep[patch][key_item_patch][0];
const cur = r[key_item_patch][0];
const order = this.item(key_item_patch).order;
const ind_prev = order.indexOf(prev);
const ind_cur = order.indexOf(cur);
if (ind_cur < ind_prev) {
keep[r.degat_gravite_label] = r;
keep[r[key_item_patch]] = r;
}
} else {
keep[r.degat_type_label] = r;
Expand Down Expand Up @@ -444,7 +446,12 @@ class Restitution {
}

item(key) {
return { ...(this.items[key] || {}), key };
let item = { ...(this.items[key] || {}), key };
if(item.source) {
const itemSource = this.items[item.source];
item = {...itemSource, ...item}
}
return item;
}

/** type : icon ou color */
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/modules/restitution/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ const split = separator => (d, item) => {
const replace = replaceList => (d, item) => {
let val = d[item.key];
for (const replace of replaceList) {
if (replace[0] == val);
val = replace[1];
if (replace[0] == val) {
val = replace[1];
}
}
return val;
};
Expand Down

0 comments on commit fae74e6

Please sign in to comment.