up
This commit is contained in:
@@ -238,7 +238,18 @@ function telegramApp() {
|
|||||||
|
|
||||||
async loadConfigs() {
|
async loadConfigs() {
|
||||||
const res = await fetch('/app/loadtelegram');
|
const res = await fetch('/app/loadtelegram');
|
||||||
this.configs = await res.json();
|
const data = await res.json();
|
||||||
|
this.configs = data;
|
||||||
|
// Pre-inicializar claves reactivas para cada config.
|
||||||
|
// Sin esto Alpine.js no detecta las asignaciones dinámicas cfg.ID -> value.
|
||||||
|
const tl = {}, tr = {}, to = {};
|
||||||
|
const wl = {}, wr = {}, wo = {};
|
||||||
|
for (const cfg of data) {
|
||||||
|
tl[cfg.ID] = false; tr[cfg.ID] = ''; to[cfg.ID] = false;
|
||||||
|
wl[cfg.ID] = false; wr[cfg.ID] = ''; wo[cfg.ID] = false;
|
||||||
|
}
|
||||||
|
this.testLoading = tl; this.testResult = tr; this.testOk = to;
|
||||||
|
this.webhookLoading = wl; this.webhookResult = wr; this.webhookOk = wo;
|
||||||
},
|
},
|
||||||
|
|
||||||
openAdd() {
|
openAdd() {
|
||||||
|
|||||||
@@ -1811,7 +1811,15 @@ function vcardApiApp() {
|
|||||||
|
|
||||||
// ─── Ordenar por vencimiento ─────────────────────────────────────────
|
// ─── Ordenar por vencimiento ─────────────────────────────────────────
|
||||||
|
|
||||||
|
// Retorna true para planes de pago (emprendimiento / normal).
|
||||||
|
// Estos planes no tienen vencimiento relevante en el contexto de membresía premium.
|
||||||
|
_isPaidPlan(u) {
|
||||||
|
const nombre = ((u.plan && u.plan.nombre) || '').toLowerCase();
|
||||||
|
return nombre.includes('emprendimiento') || nombre.includes('normal');
|
||||||
|
},
|
||||||
|
|
||||||
diasHastaVencer(u) {
|
diasHastaVencer(u) {
|
||||||
|
if (this._isPaidPlan(u)) return null; // plan de pago: sin vencimiento
|
||||||
const id = u.id || u._id;
|
const id = u.id || u._id;
|
||||||
const m = this.membresiaMap[id];
|
const m = this.membresiaMap[id];
|
||||||
if (!m || !m.fecha_fin) return null;
|
if (!m || !m.fecha_fin) return null;
|
||||||
@@ -1837,6 +1845,7 @@ function vcardApiApp() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
vencimientoTexto(u) {
|
vencimientoTexto(u) {
|
||||||
|
if (this._isPaidPlan(u)) return '—'; // plan de pago: no aplica vencimiento
|
||||||
const id = u.id || u._id;
|
const id = u.id || u._id;
|
||||||
const m = this.membresiaMap[id];
|
const m = this.membresiaMap[id];
|
||||||
if (this.loadingVenc && !m) return '...';
|
if (this.loadingVenc && !m) return '...';
|
||||||
@@ -1851,8 +1860,10 @@ function vcardApiApp() {
|
|||||||
async _fetchAndSortVenc() {
|
async _fetchAndSortVenc() {
|
||||||
this.loadingVenc = true;
|
this.loadingVenc = true;
|
||||||
const batchSize = 5;
|
const batchSize = 5;
|
||||||
for (let i = 0; i < this.items.length; i += batchSize) {
|
// Solo buscar membresía para usuarios free (los de plan de pago no tienen vencimiento relevante)
|
||||||
const batch = this.items.slice(i, i + batchSize);
|
const usersToFetch = this.items.filter(u => !this._isPaidPlan(u));
|
||||||
|
for (let i = 0; i < usersToFetch.length; i += batchSize) {
|
||||||
|
const batch = usersToFetch.slice(i, i + batchSize);
|
||||||
await Promise.all(batch.map(async u => {
|
await Promise.all(batch.map(async u => {
|
||||||
const id = u.id || u._id;
|
const id = u.id || u._id;
|
||||||
if (this.membresiaMap[id]) return;
|
if (this.membresiaMap[id]) return;
|
||||||
@@ -1863,15 +1874,32 @@ function vcardApiApp() {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
this.loadingVenc = false;
|
this.loadingVenc = false;
|
||||||
|
// Orden: 0 = free+premium (más urgente, por fecha), 1 = plan pagado, 2 = free sin premium
|
||||||
this.items = [...this.items].sort((a, b) => {
|
this.items = [...this.items].sort((a, b) => {
|
||||||
const ma = this.membresiaMap[a.id || a._id];
|
const paidA = this._isPaidPlan(a);
|
||||||
const mb = this.membresiaMap[b.id || b._id];
|
const paidB = this._isPaidPlan(b);
|
||||||
const fa = ma?.fecha_fin ? new Date(ma.fecha_fin) : null;
|
const premA = a.premium === true || a.premium === 'true';
|
||||||
const fb = mb?.fecha_fin ? new Date(mb.fecha_fin) : null;
|
const premB = b.premium === true || b.premium === 'true';
|
||||||
if (!fa && !fb) return 0;
|
const grp = (isPaid, isPrem) => {
|
||||||
if (!fa) return 1;
|
if (!isPaid && isPrem) return 0; // free + premium → primero
|
||||||
if (!fb) return -1;
|
if (isPaid) return 1; // plan pagado → en medio
|
||||||
return fa - fb;
|
return 2; // free sin premium → al final
|
||||||
|
};
|
||||||
|
const ga = grp(paidA, premA);
|
||||||
|
const gb = grp(paidB, premB);
|
||||||
|
if (ga !== gb) return ga - gb;
|
||||||
|
// Dentro del grupo 0 (free+premium), ordenar por fecha_fin (más próxima primero)
|
||||||
|
if (ga === 0) {
|
||||||
|
const ma = this.membresiaMap[a.id || a._id];
|
||||||
|
const mb = this.membresiaMap[b.id || b._id];
|
||||||
|
const fa = ma?.fecha_fin ? new Date(ma.fecha_fin) : null;
|
||||||
|
const fb = mb?.fecha_fin ? new Date(mb.fecha_fin) : null;
|
||||||
|
if (!fa && !fb) return 0;
|
||||||
|
if (!fa) return 1;
|
||||||
|
if (!fb) return -1;
|
||||||
|
return fa - fb;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user