From f6179c2fa1933896a0dafededcc26e103d1f5aff Mon Sep 17 00:00:00 2001 From: tofulm Date: Fri, 3 Jul 2020 14:02:50 +0200 Subject: [PATCH] Pour charger le modele html du bloc, on ne passe plus par l'AJAX mais on via une prop --- inclure/gamutable.html | 1 + js/gamutable.es6.js | 12 ++---------- js/gamutable.js | 44 ++++++++++++++++-------------------------- 3 files changed, 20 insertions(+), 37 deletions(-) diff --git a/inclure/gamutable.html b/inclure/gamutable.html index 7deea2f..28cb32b 100644 --- a/inclure/gamutable.html +++ b/inclure/gamutable.html @@ -8,6 +8,7 @@ champcsv="#ENV{champcsv,html}" delimitercsv="#ENV{delimitercsv,','}" namecsv="#ENV{namecsv,export.csv}" + vuebloc="#ENV{vuebloc}" ref="montableau" > diff --git a/js/gamutable.es6.js b/js/gamutable.es6.js index 4d5b58d..0ca3884 100644 --- a/js/gamutable.es6.js +++ b/js/gamutable.es6.js @@ -150,8 +150,9 @@ let monTableau = { namecsv: { type: String, }, - toto: { + vuebloc: { type: String, + default: '', }, }, data: function () { @@ -170,19 +171,10 @@ let monTableau = { selectTr: [], champ_search: 'html', chargement: true, - vuebloc: '', }; }, mounted() { this.chargerJson(); - let url = 'spip.php?page=vuebloc'; - fetch(url) - .then((response) => response.text()) - .then((data) => { - if (data) { - this.vuebloc = data; - } - }); }, computed: { tableau: function () { diff --git a/js/gamutable.js b/js/gamutable.js index 549e174..0364cad 100644 --- a/js/gamutable.js +++ b/js/gamutable.js @@ -195,8 +195,9 @@ var monTableau = { namecsv: { type: String }, - toto: { - type: String + vuebloc: { + type: String, + default: '' } }, data: function data() { @@ -214,26 +215,15 @@ var monTableau = { triProps: [], selectTr: [], champ_search: 'html', - chargement: true, - vuebloc: '' + chargement: true }; }, mounted: function mounted() { - var _this = this; - this.chargerJson(); - var url = 'spip.php?page=vuebloc'; - fetch(url).then(function (response) { - return response.text(); - }).then(function (data) { - if (data) { - _this.vuebloc = data; - } - }); }, computed: { tableau: function tableau() { - var _this2 = this; + var _this = this; this.setPages(); @@ -242,7 +232,7 @@ var monTableau = { } return this.pagination(this.table.filter(function (ligne) { - return Object.values(ligne[_this2.champ_search]).toString().toLowerCase().indexOf(_this2.search.toLowerCase()) < 0 ? false : true; + return Object.values(ligne[_this.champ_search]).toString().toLowerCase().indexOf(_this.search.toLowerCase()) < 0 ? false : true; })); } }, @@ -266,7 +256,7 @@ var monTableau = { }, methods: { chargerJson: function chargerJson(id) { - var _this3 = this; + var _this2 = this; var url = this.apiuri; @@ -302,32 +292,32 @@ var monTableau = { return response.json(); }).then(function (data) { var config = data.shift(); - _this3.header = config.header; + _this2.header = config.header; if (config.crayons !== undefined) { - _this3.crayons = config.crayons; + _this2.crayons = config.crayons; } if (config.classes !== undefined) { - _this3.classes = config.classes; + _this2.classes = config.classes; } if (parseInt(id) > 0) { - var i = _this3.table.findIndex(function (ligne) { + var i = _this2.table.findIndex(function (ligne) { return ligne.html.id === parseInt(id); }); - Vue.set(_this3.table, i, data[0]); + Vue.set(_this2.table, i, data[0]); } else { - _this3.table = data; + _this2.table = data; if (data[0] && data[0].search) { - _this3.champ_search = 'search'; + _this2.champ_search = 'search'; } } Vue.nextTick(function () { - _this3.chargement = false; + _this2.chargement = false; console.timeEnd('Chargement de VueJs APRES Ajax'); }); }).catch(function (error) { @@ -392,7 +382,7 @@ var monTableau = { } }, exportCSV: function exportCSV() { - var _this4 = this; + var _this3 = this; var $csv = []; var $header = []; @@ -402,7 +392,7 @@ var monTableau = { }); $tableau = this.tableau.reduce(function (acc, ligne) { var $uneLigne = []; - Object.values(ligne[_this4.champcsv]).forEach(function (l) { + Object.values(ligne[_this3.champcsv]).forEach(function (l) { return $uneLigne.push(l); }); return [].concat(_toConsumableArray(acc), [[].concat($uneLigne)]);