feat: factorisation de la geration des config

This commit is contained in:
Christophe 2023-01-12 11:48:45 +01:00
parent a28dcfa118
commit 910cf503d8

View file

@ -627,18 +627,7 @@ watch(filtreColSelected, () => {
//~~~~~~~~~~~~~~~~~~~~~~~~~
// les methodes
//~~~~~~~~~~~~~~~~~~~~~~~~~
function chargerJson(id) {
console.log("chargerJson pour ", id);
chargement.value = true;
let url = props.apiuri;
if (parseInt(id) > 0) {
url += "&id=" + id;
} else if (id === "maj") {
url += "&maj=" + maj.value;
} else {
let config = localStorage.getItem("header_" + nameLocalStorage.value);
config = recupJson(config);
if (config && config.header !== undefined) {
function gererConfig(config) {
header.value = config.header;
if (config.crayons !== undefined) {
crayons.value = config.crayons;
@ -662,6 +651,21 @@ function chargerJson(id) {
if (config.filtreCol !== undefined) {
filtreCol = config.filtreCol;
}
return filtreCol;
}
function chargerJson(id) {
console.log("chargerJson pour ", id);
chargement.value = true;
let url = props.apiuri;
if (parseInt(id) > 0) {
url += "&id=" + id;
} else if (id === "maj") {
url += "&maj=" + maj.value;
} else {
let config = localStorage.getItem("header_" + nameLocalStorage.value);
config = recupJson(config);
if (config && config.header !== undefined) {
let filtreColRecup = gererConfig(config);
localforage
.getItem(nameLocalStorage.value)
.then(function (data) {
@ -671,8 +675,8 @@ function chargerJson(id) {
if (data[0].search) {
champ_search.value = "search";
}
if (filtreCol !== undefined) {
filtreColType.value = filtreCol;
if (filtreColRecup !== undefined) {
filtreColType.value = filtreColRecup;
Object.keys(filtreColType.value).forEach((col) => {
let Tval = [];
// let Tval = [''];
@ -682,6 +686,7 @@ function chargerJson(id) {
Tval.push(valCol);
}
});
// filtreCol.value.push(col);
filtreColVal.value[col] = Tval.sort();
filtreColSelected.value[col] = [];
});
@ -700,31 +705,32 @@ function chargerJson(id) {
.then((response) => response.json())
.then((data) => {
let config = data.shift();
header.value = config.header;
if (config.maj !== undefined) {
maj.value = config.maj?.lastMAJ;
}
if (config.crayons !== undefined) {
crayons.value = config.crayons;
} else {
crayons.value = [];
}
if (config.classes !== undefined) {
classes.value = config.classes;
} else {
classes.value = [];
}
if (config.checkbox !== undefined) {
checkbox.value = config.checkbox;
Object.keys(checkbox.value).forEach((head) => {
Tcheckbox.value[head] = [];
});
}
if (config.ordreCol !== undefined) {
ordreCol.value = config.ordreCol;
} else {
ordreCol.value = [];
}
let filtreColRecup = gererConfig(config);
// header.value = config.header;
// if (config.maj !== undefined) {
// maj.value = config.maj?.lastMAJ;
// }
// if (config.crayons !== undefined) {
// crayons.value = config.crayons;
// } else {
// crayons.value = [];
// }
// if (config.classes !== undefined) {
// classes.value = config.classes;
// } else {
// classes.value = [];
// }
// if (config.checkbox !== undefined) {
// checkbox.value = config.checkbox;
// Object.keys(checkbox.value).forEach((head) => {
// Tcheckbox.value[head] = [];
// });
// }
// if (config.ordreCol !== undefined) {
// ordreCol.value = config.ordreCol;
// } else {
// ordreCol.value = [];
// }
if (parseInt(id) > 0) {
if (data.length > 0) {
let i = trouver_index(table.value, id);
@ -743,8 +749,8 @@ function chargerJson(id) {
champ_search.value = "search";
}
}
if (config.filtreCol !== undefined) {
filtreColType.value = config.filtreCol;
if (filtreColRecup !== undefined) {
filtreColType.value = filtreColRecup;
filtreCol.value = [];
Object.keys(filtreColType.value).forEach((col) => {
let Tval = [];