Update vcard_api.html

This commit is contained in:
Lizandro Guarnizo
2026-06-11 20:16:47 -05:00
parent 89021f2e77
commit fd410b3afc
+34 -11
View File
@@ -1791,14 +1791,33 @@ function vcardApiApp() {
const r = await fetch(this.buildEndpoint());
const d = await r.json();
if (!r.ok) { this.errorMsg = d.error || `Error ${r.status}`; this.loading = false; return; }
if (d.data && Array.isArray(d.data)) {
this.items = d.data;
this.total = d.total || d.data.length;
if (this.tab === 'usuarios') { this._collectRoles(d.data); this._collectPlanes(d.data); }
// Buscar el array de datos en distintos formatos posibles
let dataArr = null;
let dataTotal = 0;
// Formato estándar paginado: { data: [...], total: N }
if (Array.isArray(d.data)) {
dataArr = d.data;
dataTotal = d.total || dataArr.length;
// Formato plano: [{...}, {...}]
} else if (Array.isArray(d)) {
this.items = d;
this.total = d.length;
if (this.tab === 'usuarios') { this._collectRoles(d); this._collectPlanes(d); }
dataArr = d;
dataTotal = d.length;
// Formato doble anidado: { data: { data: [...], total: N } }
} else if (d.data && d.data.data && Array.isArray(d.data.data)) {
dataArr = d.data.data;
dataTotal = d.data.total || d.total || dataArr.length;
// Formato con key items: { items: [...], total: N }
} else if (Array.isArray(d.items)) {
dataArr = d.items;
dataTotal = d.total || dataArr.length;
}
if (dataArr) {
this.items = dataArr;
this.total = dataTotal;
if (this.tab === 'usuarios') { this._collectRoles(dataArr); this._collectPlanes(dataArr); }
} else {
this.items = [];
this.total = 0;
@@ -1998,7 +2017,7 @@ function vcardApiApp() {
const r = await fetch('/app/vcard-api/planes');
const d = await r.json();
if (Array.isArray(d)) this.planes = d;
else if (d.data) this.planes = d.data;
else if (d.data && Array.isArray(d.data)) this.planes = d.data;
} catch(e) {}
},
@@ -2032,8 +2051,11 @@ function vcardApiApp() {
const id = u.id || u._id;
const r = await fetch(`/app/vcard-api/usuarios/${id}/vcards`);
const d = await r.json();
if (d.data && Array.isArray(d.data)) this.desactivarVcardsItems = d.data;
else if (Array.isArray(d)) this.desactivarVcardsItems = d;
let arr = null;
if (Array.isArray(d.data)) arr = d.data;
else if (Array.isArray(d)) arr = d;
else if (d.data && d.data.data && Array.isArray(d.data.data)) arr = d.data.data;
this.desactivarVcardsItems = arr || [];
} catch(e) { this.desactivarVcardsError = 'No se pudieron cargar las VCards: ' + e.message; }
this.desactivarVcardsLoading = false;
},
@@ -2231,8 +2253,9 @@ function vcardApiApp() {
const r = await fetch(map[section]);
const d = await r.json();
if (!r.ok) {}
else if (d.data && Array.isArray(d.data)) { this.verSectionItems = d.data; }
else if (Array.isArray(d.data)) { this.verSectionItems = d.data; }
else if (Array.isArray(d)) { this.verSectionItems = d; }
else if (d.data && d.data.data && Array.isArray(d.data.data)) { this.verSectionItems = d.data.data; }
} catch(e) {}
this.verSectionLoading = false;
},