Skip to content

Commit

Permalink
map layer + restitution fix max
Browse files Browse the repository at this point in the history
  • Loading branch information
joelclems committed Jun 15, 2021
1 parent 5d639f4 commit bf33bb5
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 26 deletions.
1 change: 1 addition & 0 deletions TODO.md
Expand Up @@ -2,6 +2,7 @@ TODO

- restitution
- bug (en cours)
- max
- cartes, ne charger qu'une seule fois les layers

- in
Expand Down
3 changes: 1 addition & 2 deletions data/patchs/patch_chasse.sql
@@ -1,3 +1,2 @@
-- passer especes de in à oeasc
ALTER TABLE oeasc_in.t_especes SET SCHEMA oeasc_commons;
CREATE EXTENSION unaccent;
CREATE EXTENSION unaccent;
5 changes: 5 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve --host localhost",
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/admin.vue
Expand Up @@ -42,7 +42,6 @@ export default {
$route(to, from) {
to;
from;
console.log("route", to, from);
this.init();
},
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/modules/chasse/config/store-attribution.js
Expand Up @@ -37,7 +37,7 @@ export default {
returnObject: true,
},
zone_indicative_affectee: {
label: 'Zone intérêt affectée',
label: 'Zone indicative affectée',
storeName: 'chasseZoneIndicative',
type: 'list_form',
list_type: 'autocomplete',
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/modules/chasse/config/store-lieu-tir.js
Expand Up @@ -20,7 +20,7 @@ export default {
required: true
},
zone_indicative: {
label: "Zone d'intérêt",
label: "Zone indicative",
type: 'list_form',
list_type: "autocomplete",
dataReloadOnSearch: true,
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/modules/chasse/config/store-realisation.js
Expand Up @@ -42,7 +42,7 @@ export default {
]
},
{
title: "Zone d'intérêt",
title: "Zone indicative",
forms: ["zone_indicative_affectee", "zone_indicative_realisee"]
},
{
Expand Down Expand Up @@ -251,7 +251,7 @@ export default {
returnObject: true
},
zone_indicative_affectee: {
label: "Zone d'intérêt affectée",
label: "Zone indicative affectée",
storeName: "chasseZoneIndicative",
type: "list_form",
list_type: "autocomplete",
Expand All @@ -260,7 +260,7 @@ export default {
disabled: true
},
zone_indicative_realisee: {
label: "Zone d'intérêt réalisée",
label: "Zone indicative réalisée",
storeName: "chasseZoneIndicative",
type: "list_form",
list_type: "autocomplete",
Expand Down
Expand Up @@ -15,7 +15,7 @@ export default {
},
degat_gravite_label: {
text: "Dégâts - gravité",
order: ["Faibles", "Modérés", "Importants", "Indéfini"],
order: ["Indéfini", "Faibles", "Modérés", "Importants"],
colors: {
Importants: "red",
Modérés: "orange",
Expand All @@ -24,15 +24,21 @@ export default {
},
degat_etendue_label: {
text: "Dégâts - étendue",
order: ["Généralisés", "Localisés"],
order: ['Indéfini', "Localisés", "Généralisés"],
colors: {
"Généralisés": "red",
"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'],
order: [
'Indéfini',
"Ne sais pas",
"Anciens (années antérieures)",
"Récurrents",
"Récents (année en cours)",
],
colors: {
"Récents (année en cours)": "red",
"Récurrents": "orange",
Expand Down
32 changes: 23 additions & 9 deletions frontend/src/modules/map/map-elements/map-layer.js
Expand Up @@ -6,7 +6,13 @@ import { apiRequest } from "@/core/js/data/api.js";

const L = window.L;


const mapLayer = {
/**
* Pour garder en mémoire les layers déjà charger et ne pas faire plusieurs appels aux api
*/
_layersData: {},

/**
* pour pouvoir gérer les url de façon dynamique:
*
Expand All @@ -15,13 +21,13 @@ const mapLayer = {
* - url est une fonction qui sera appelée avec le parametre urlParams
*
* */

getUrl: function(layerConfig) {
return typeof layerConfig.url == "function"
? layerConfig.url(layerConfig.urlParams)
: layerConfig.url;
},


/**
* Ajoute un layer à partir de sa configuration
*/
Expand All @@ -30,14 +36,22 @@ const mapLayer = {
const url = this.getUrl(layerConfig);

// requete
apiRequest("GET", url).then(
layerData => {
this.processLayer(layerConfig, layerData);
},
error => {
console.error(`MapLayer Error : ${error}`)
}
);
if(this._layersData[url]) {
const layerData = this._layersData[url];
setTimeout(()=> {
this.processLayer(layerConfig, layerData)
});
} else {
apiRequest("GET", url).then(
layerData => {
this._layersData[url] = layerData;
this.processLayer(layerConfig, layerData);
},
error => {
console.error(`MapLayer Error : ${error}`)
}
);
}
},

/**
Expand Down
17 changes: 12 additions & 5 deletions frontend/src/modules/restitution/restitution.js
Expand Up @@ -105,7 +105,6 @@ class Restitution {
dataList(key, filters = null) {
let dataList = [];
const item = this.item(key);

const dataToProcess = this.groupBy(
this.filteredData(filters),
this._options.groupByKey,
Expand Down Expand Up @@ -142,7 +141,7 @@ class Restitution {
data.color = "grey";
}
} else {
dataList = dataList.sort((a, b) => b.count - a.count);
dataList = item.order ? dataList.sort((a, b) => item.order.indexOf(b.text) - item.order.indexOf(a.text)) : dataList.sort((a, b) => b.count - a.count);
dataList = this.cutDataList(dataList);

for (const data of dataList) {
Expand Down Expand Up @@ -179,7 +178,7 @@ class Restitution {
keep[r[key_item_patch]] = r;
}
} else {
keep[r.degat_type_label] = r;
keep[r[key_item_patch]] = r;
}
}
d.res = Object.keys(keep).map(key => keep[key]);
Expand All @@ -190,6 +189,7 @@ class Restitution {
* out: [...{ groupByKey: grouByValue, res: process(dataGroup, processArgs) }...]
*/
groupBy(data, groupByKey = null, keys = [], action = null) {

// si pas de groupByKey on renvoie data
if (!groupByKey) {
return data;
Expand All @@ -203,19 +203,25 @@ class Restitution {
}
}


// out: [...{ groupByKey: grouByValue, res: process(dataGroup, processArgs) }...]
const out = Object.entries(dataDict).map(([groupByValue, dataGroup]) => {
const d = {};

d[groupByKey] = groupByValue;


if (!keys.length) {
return d;
}

const listGroup = this._options.markersGroupByReduceKeys || [];

for (const key of keys.filter(key => !listGroup.includes(key) && !!key)) {
const order = this.item(key).order;
if(order) {
dataGroup = dataGroup.sort((a, b) => order.indexOf(a[key]) - order.indexOf(b[key]));
}
d[key] = dataGroup[0][key];
}

Expand All @@ -229,6 +235,7 @@ class Restitution {
}
return res;
});

if (action == "concat") {
for (const r of d.res) {
for (const key of Object.keys(r).filter(key =>
Expand All @@ -239,13 +246,13 @@ class Restitution {
}
}


if (action == "max") {
this.patchMaxDegat(d);
}

return d;
});

return out;
}

Expand Down Expand Up @@ -372,10 +379,10 @@ class Restitution {
}

data() {

if (this._data && this._data.length) {
return this._data;
}

this._data =
this._rawData && this._rawData.length
? this.filterData(
Expand Down

0 comments on commit bf33bb5

Please sign in to comment.