diff options
| author | Ho3ein <ho3ein.sanaei@gmail.com> | 2023-12-10 17:42:52 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-10 17:42:52 +0300 |
| commit | e3f1d3c892a1af48f27fdc36f273a55f38d13b40 (patch) | |
| tree | b11d0c1ed3c15c8f6f891a5e6df8e021d5db8ab6 /web/assets/js/util | |
| parent | 36cf7c0a8fda915b51e75958ce729fd9a61a5c90 (diff) | |
| parent | 9fbe80f87f950673058f0001b3704251fa8b9243 (diff) | |
huge changes
Diffstat (limited to 'web/assets/js/util')
| -rw-r--r-- | web/assets/js/util/common.js | 61 | ||||
| -rw-r--r-- | web/assets/js/util/utils.js | 20 |
2 files changed, 69 insertions, 12 deletions
diff --git a/web/assets/js/util/common.js b/web/assets/js/util/common.js index 8e30bce7..5f20d7d9 100644 --- a/web/assets/js/util/common.js +++ b/web/assets/js/util/common.js @@ -52,13 +52,15 @@ function safeBase64(str) { function formatSecond(second) { if (second < 60) { - return second.toFixed(0) + ' s'; + return second.toFixed(0) + 's'; } else if (second < 3600) { - return (second / 60).toFixed(0) + ' m'; + return (second / 60).toFixed(0) + 'm'; } else if (second < 3600 * 24) { - return (second / 3600).toFixed(0) + ' h'; + return (second / 3600).toFixed(0) + 'h'; } else { - return (second / 3600 / 24).toFixed(0) + ' d'; + day = Math.floor(second / 3600 / 24); + remain = ((second/3600) - (day*24)).toFixed(0); + return day + 'd' + (remain > 0 ? ' ' + remain + 'h' : ''); } } @@ -72,7 +74,7 @@ function addZero(num) { function toFixed(num, n) { n = Math.pow(10, n); - return Math.round(num * n) / n; + return Math.floor(num * n) / n; } function debounce(fn, delay) { @@ -115,15 +117,52 @@ function setCookie(cname, cvalue, exdays) { function usageColor(data, threshold, total) { switch (true) { case data === null: - return 'blue'; - case total <= 0: - return 'blue'; + return "purple"; + case total < 0: + return "green"; + case total == 0: + return "purple"; case data < total - threshold: - return 'cyan'; + return "green"; case data < total: - return 'orange'; + return "orange"; default: - return 'red'; + return "red"; + } +} + +function clientUsageColor(clientStats, trafficDiff) { + switch (true) { + case !clientStats || clientStats.total == 0: + return "#7a316f"; // purple + case clientStats.up + clientStats.down < clientStats.total - trafficDiff: + return "#008771"; // Green + case clientStats.up + clientStats.down < clientStats.total: + return "#f37b24"; // Orange + default: + return "#cf3c3c"; // Red + } +} + +function userExpiryColor(threshold, client, isDark = false) { + if (!client.enable) { + return isDark ? '#2c3950' : '#bcbcbc'; + } + now = new Date().getTime(), + expiry = client.expiryTime; + switch (true) { + case expiry === null: + return "#7a316f"; // purple + case expiry < 0: + return "#008771"; // Green + case expiry == 0: + return "#7a316f"; // purple + case now < expiry - threshold: + return "#008771"; // Green + case now < expiry: + return "#f37b24"; // Orange + default: + return "#cf3c3c"; // Red } } diff --git a/web/assets/js/util/utils.js b/web/assets/js/util/utils.js index 781e13a8..8bab58ec 100644 --- a/web/assets/js/util/utils.js +++ b/web/assets/js/util/utils.js @@ -1,3 +1,21 @@ +class Msg { + constructor(success, msg, obj) { + this.success = false; + this.msg = ""; + this.obj = null; + + if (success != null) { + this.success = success; + } + if (msg != null) { + this.msg = msg; + } + if (obj != null) { + this.obj = obj; + } + } +} + class HttpUtil { static _handleMsg(msg) { if (!(msg instanceof Msg)) { @@ -158,7 +176,7 @@ class ObjectUtil { } } } else { - return obj.toString().toLowerCase().indexOf(key.toLowerCase()) >= 0; + return this.isEmpty(obj) ? false : obj.toString().toLowerCase().indexOf(key.toLowerCase()) >= 0; } return false; } |
