From 2d16eabc6e751e6233154a082bb6ccd2f816ec41 Mon Sep 17 00:00:00 2001 From: MHSanaei Date: Wed, 17 May 2023 02:01:56 +0330 Subject: [PATCH] [feature] interactive deplete soon Co-Authored-By: Alireza Ahmadi --- web/assets/js/util/common.js | 17 ++++++++++++++++- web/html/xui/client_modal.html | 9 ++------- web/html/xui/inbound_client_table.html | 11 +++-------- web/html/xui/inbound_info_modal.html | 9 +++------ web/html/xui/inbounds.html | 8 ++++---- 5 files changed, 28 insertions(+), 26 deletions(-) diff --git a/web/assets/js/util/common.js b/web/assets/js/util/common.js index a695f081c8..20df4f4e85 100644 --- a/web/assets/js/util/common.js +++ b/web/assets/js/util/common.js @@ -91,6 +91,21 @@ function setCookie(cname, cvalue, exdays) { document.cookie = cname + '=' + cvalue + ';' + expires + ';path=/'; } +function usageColor(data, threshold, total) { + switch (true) { + case data === null: + return 'blue'; + case total <= 0: + return 'blue'; + case data < total - threshold: + return 'cyan'; + case data < total: + return 'orange'; + default: + return 'red'; + } +} + function doAllItemsExist(array1, array2) { for (let i = 0; i < array1.length; i++) { if (!array2.includes(array1[i])) { @@ -98,4 +113,4 @@ function doAllItemsExist(array1, array2) { } } return true; -} \ No newline at end of file +} diff --git a/web/html/xui/client_modal.html b/web/html/xui/client_modal.html index 2597432552..ba9fce31ad 100644 --- a/web/html/xui/client_modal.html +++ b/web/html/xui/client_modal.html @@ -20,7 +20,6 @@ oldClientId: "", index: null, clientIps: null, - isExpired: false, delayedStart: false, ok() { if (clientModal.isEdit) { @@ -38,7 +37,6 @@ this.inbound = dbInbound.toInbound(); this.clients = this.getClients(this.inbound.protocol, this.inbound.settings); this.index = index === null ? this.clients.length : index; - this.isExpired = isEdit ? this.inbound.isExpiry(this.index) : false; this.delayedStart = false; if (isEdit) { if (this.clients[index].expiryTime < 0) { @@ -109,13 +107,10 @@ return true }, get isExpiry() { - return this.clientModal.isExpired + return this.clientModal.isEdit && this.client.expiryTime >0 ? (this.client.expiryTime < new Date().getTime()) : false; }, get statsColor() { - if (!clientStats) return 'blue' - if (clientStats.total <= 0) return 'blue' - else if (clientStats.total > 0 && (clientStats.down + clientStats.up) < clientStats.total) return 'cyan' - else return 'red' + return usageColor(clientStats.up + clientStats.down, app.trafficDiff, this.client.totalGB); }, get delayedExpireDays() { return this.client && this.client.expiryTime < 0 ? this.client.expiryTime / -86400000 : 0; diff --git a/web/html/xui/inbound_client_table.html b/web/html/xui/inbound_client_table.html index 3143fe18bc..43491c45f4 100644 --- a/web/html/xui/inbound_client_table.html +++ b/web/html/xui/inbound_client_table.html @@ -29,20 +29,15 @@ {{ i18n "depleted" }}