diff --git a/web/assets/js/util/common.js b/web/assets/js/util/common.js index b3ebc0bd..c1aa1266 100644 --- a/web/assets/js/util/common.js +++ b/web/assets/js/util/common.js @@ -56,7 +56,7 @@ function toFixed(num, n) { return Math.round(num * n) / n; } -function debounce (fn, delay) { +function debounce(fn, delay) { var timeoutID = null return function () { clearTimeout(timeoutID) @@ -66,4 +66,19 @@ function debounce (fn, delay) { fn.apply(that, args) }, delay) } - } \ No newline at end of file +} + +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'; + } +} \ No newline at end of file diff --git a/web/html/xui/client_modal.html b/web/html/xui/client_modal.html index 1a369763..ad840df2 100644 --- a/web/html/xui/client_modal.html +++ b/web/html/xui/client_modal.html @@ -19,7 +19,6 @@ clientStats: [], oldClientId: "", index: null, - isExpired: false, delayedStart: false, ok() { if(clientModal.isEdit){ @@ -37,7 +36,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){ @@ -108,13 +106,10 @@ return true }, get isExpiry() { - return this.clientModal.isExpired + return this.clientModal.isEdit ? (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 6100cd9b..2d0fe9ed 100644 --- a/web/html/xui/inbound_client_table.html +++ b/web/html/xui/inbound_client_table.html @@ -29,16 +29,15 @@ {{ i18n "depleted" }}