From ca7ee3205251c27525b2a588157518517561f032 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?V=C3=B5=20Ho=C3=A0ng?=
<92570598+hoangneeee@users.noreply.github.com>
Date: Sat, 17 Aug 2024 00:40:24 +0700
Subject: [PATCH] feat(www): add sort clients by name (#1227)
Co-authored-by: Philip H. <47042125+pheiduck@users.noreply.github.com>
---
README.md | 1 +
docker-compose.yml | 1 +
src/config.js | 1 +
src/lib/Server.js | 8 +++++++-
src/www/index.html | 9 +++++++++
src/www/js/api.js | 7 +++++++
src/www/js/app.js | 25 +++++++++++++++++++++++++
src/www/js/i18n.js | 10 +++++++++-
8 files changed, 60 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 913de64..199ae82 100644
--- a/README.md
+++ b/README.md
@@ -123,6 +123,7 @@ These options can be configured by setting environment variables using `-e KEY="
| `UI_CHART_TYPE` | `0` | `1` | UI_CHART_TYPE=0 # Charts disabled, UI_CHART_TYPE=1 # Line chart, UI_CHART_TYPE=2 # Area chart, UI_CHART_TYPE=3 # Bar chart |
| `UI_SHOW_LINKS` | `false` | `true` | Enable display of a short download link in Web UI |
| `MAX_AGE` | `0` | `1440` | The maximum age of Web UI sessions in minutes. `0` means that the session will exist until the browser is closed. |
+| `UI_ENABLE_SORT_CLIENTS` | `false` | `true` | Enable UI sort clients by name |
> If you change `WG_PORT`, make sure to also change the exposed port.
diff --git a/docker-compose.yml b/docker-compose.yml
index dd135fd..379c0d5 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -28,6 +28,7 @@ services:
# - UI_TRAFFIC_STATS=true
# - UI_CHART_TYPE=0 # (0 Charts disabled, 1 # Line chart, 2 # Area chart, 3 # Bar chart)
# - UI_SHOW_LINKS=true
+ # - UI_ENABLE_SORT_CLIENTS=true
image: ghcr.io/wg-easy/wg-easy
container_name: wg-easy
diff --git a/src/config.js b/src/config.js
index 7941845..d7a7831 100644
--- a/src/config.js
+++ b/src/config.js
@@ -39,3 +39,4 @@ module.exports.LANG = process.env.LANG || 'en';
module.exports.UI_TRAFFIC_STATS = process.env.UI_TRAFFIC_STATS || 'false';
module.exports.UI_CHART_TYPE = process.env.UI_CHART_TYPE || 0;
module.exports.UI_SHOW_LINKS = process.env.UI_SHOW_LINKS || 'false';
+module.exports.UI_ENABLE_SORT_CLIENTS = process.env.UI_ENABLE_SORT_CLIENTS || 'false';
diff --git a/src/lib/Server.js b/src/lib/Server.js
index 3bee349..aeaff6c 100644
--- a/src/lib/Server.js
+++ b/src/lib/Server.js
@@ -34,6 +34,7 @@ const {
UI_TRAFFIC_STATS,
UI_CHART_TYPE,
UI_SHOW_LINKS,
+ UI_ENABLE_SORT_CLIENTS,
} = require('../config');
const requiresPassword = !!PASSWORD_HASH;
@@ -101,7 +102,12 @@ module.exports = class Server {
.get('/api/ui-show-links', defineEventHandler((event) => {
setHeader(event, 'Content-Type', 'application/json');
- return `${UI_SHOW_LINKS}`;
+ return `"${UI_SHOW_LINKS}"`;
+ }))
+
+ .get('/api/ui-sort-clients', defineEventHandler((event) => {
+ setHeader(event, 'Content-Type', 'application/json');
+ return `"${UI_ENABLE_SORT_CLIENTS}"`;
}))
// Authentication
diff --git a/src/www/index.html b/src/www/index.html
index 2867a59..3dd7030 100644
--- a/src/www/index.html
+++ b/src/www/index.html
@@ -112,6 +112,15 @@
{{$t("backup")}}
+
+
+
+
+