Browse Source

sorting lists

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
main
Stephan Richter 1 month ago
parent
commit
8711b3e491
  1. 2
      de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/ClientController.java
  2. 2
      de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/UserController.java
  3. 12
      de.srsoftware.oidc.web/src/main/resources/en/scripts/clients.js
  4. 21
      de.srsoftware.oidc.web/src/main/resources/en/scripts/users.js

2
de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/ClientController.java

@ -182,7 +182,7 @@ public class ClientController extends Controller { @@ -182,7 +182,7 @@ public class ClientController extends Controller {
if (optUser.isEmpty()) return invalidSessionUser(ex);
if (!optUser.get().hasPermission(MANAGE_CLIENTS)) return sendEmptyResponse(HTTP_FORBIDDEN, ex);
var json = new JSONObject();
clients.listClients().stream().sorted(Comparator.comparing(Client::name)).forEach(client -> json.put(client.id(), client.map()));
clients.listClients().forEach(client -> json.put(client.id(), client.map()));
return sendContent(ex, json);
}

2
de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/UserController.java

@ -187,7 +187,7 @@ public class UserController extends Controller { @@ -187,7 +187,7 @@ public class UserController extends Controller {
private boolean list(HttpExchange ex, User user) throws IOException {
if (!user.hasPermission(MANAGE_USERS)) return sendEmptyResponse(HTTP_FORBIDDEN, ex);
var json = new JSONObject();
users.list().stream().sorted(Comparator.comparing(User::username)).forEach(u -> json.put(u.uuid(), u.map(false)));
users.list().forEach(u -> json.put(u.uuid(), u.map(false)));
return sendContent(ex, json);
}

12
de.srsoftware.oidc.web/src/main/resources/en/scripts/clients.js

@ -8,17 +8,19 @@ function handleClients(response){ @@ -8,17 +8,19 @@ function handleClients(response){
return;
}
var clients = response.json().then(clients => {
var arr = [];
for (let id in clients) arr.push(clients[id]);
arr.sort((a,b) => a.name < b.name ? -1 : 1);
var bottom = document.getElementById('bottom');
for (let id in clients){
for (let client of arr){
var row = document.createElement("tr");
var client = clients[id];
row.innerHTML = `<td>${client.name}</td>
<td>${id}</td>
<td>${client.id}</td>
<td>${client.redirect_uris.join("<br/>")}</td>
<td>${link(client.landing_page)}</td>
<td>
<button type="button" onclick="edit('${id}')">Edit</button>
<button class="danger" onclick="remove('${id}')" type="button">Remove</button>
<button type="button" onclick="edit('${client.id}')">Edit</button>
<button class="danger" onclick="remove('${client.id}')" type="button">Remove</button>
</td>`;
bottom.parentNode.insertBefore(row,bottom);
}

21
de.srsoftware.oidc.web/src/main/resources/en/scripts/users.js

@ -39,10 +39,13 @@ function handleUsers(response){ @@ -39,10 +39,13 @@ function handleUsers(response){
return;
}
response.json().then(users => {
var arr = [];
for (let id in users) arr.push(users[id]);
arr.sort((a,b) => a.username < b.username ? -1 : 1);
var bottom = document.getElementById('bottom');
for (let id in users){
for (var u of arr){
var row = document.createElement("tr");
var u = users[id];
//var u = users[id];
var manage = {
clients : u.permissions.includes('MANAGE_CLIENTS'),
perms : u.permissions.includes('MANAGE_PERMISSIONS'),
@ -52,16 +55,16 @@ function handleUsers(response){ @@ -52,16 +55,16 @@ function handleUsers(response){
row.innerHTML = `<td>${u.username}</td>
<td>${u.realname}</td>
<td>${u.email}</td>
<td>${id}</td>
<td>${u.uuid}</td>
<td style="display: none" class="permissions">
<button onclick="editPermission('${id}','MANAGE_CLIENTS',${manage.clients})">${manage.clients ?'-':'+'} <span>Manage</span> Clients</button>
<button onclick="editPermission('${id}','MANAGE_PERMISSIONS',${manage.perms})">${manage.perms ?'-':'+'} <span>Manage</span> Permissions</button>
<button onclick="editPermission('${id}','MANAGE_SMTP',${manage.smtp})">${manage.smtp ?'-':'+'} <span>Manage</span> SMTP</button>
<button onclick="editPermission('${id}','MANAGE_USERS',${manage.users})">${manage.users ?'-':'+'} <span>Manage</span> Users</button>
<button onclick="editPermission('${u.uuid}','MANAGE_CLIENTS',${manage.clients})">${manage.clients ?'-':'+'} <span>Manage</span> Clients</button>
<button onclick="editPermission('${u.uuid}','MANAGE_PERMISSIONS',${manage.perms})">${manage.perms ?'-':'+'} <span>Manage</span> Permissions</button>
<button onclick="editPermission('${u.uuid}','MANAGE_SMTP',${manage.smtp})">${manage.smtp ?'-':'+'} <span>Manage</span> SMTP</button>
<button onclick="editPermission('${u.uuid}','MANAGE_USERS',${manage.users})">${manage.users ?'-':'+'} <span>Manage</span> Users</button>
</td>
<td>
<button type="button" onclick="reset_password('${id}')" id="reset-${id}">Reset password</button>
<button id="remove-${u.uuid}" class="danger" onclick="remove('${id}','${u.realname}')" type="button">Remove</button>
<button type="button" onclick="reset_password('${u.uuid}')" id="reset-${u.uuid}">Reset password</button>
<button id="remove-${u.uuid}" class="danger" onclick="remove('${u.uuid}','${u.realname}')" type="button">Remove</button>
</td>`;
bottom.parentNode.insertBefore(row,bottom);
if (user.permissions.includes('MANAGE_PERMISSIONS')) showAll('permissions');

Loading…
Cancel
Save