Remove: admin row from table

This commit is contained in:
hyzen
2026-06-13 12:15:34 +05:30
parent bae7bd8325
commit 50b6d25917
4 changed files with 26 additions and 50 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1401,10 +1401,6 @@
background: #d4edda; background: #d4edda;
color: #155724; color: #155724;
} }
.admin-badge--admin {
background: #dbeafe;
color: #1e3a8a;
}
.admin-badge--blocked { .admin-badge--blocked {
background: #f8d7da; background: #f8d7da;
color: #721c24; color: #721c24;

View File

@@ -57,47 +57,31 @@
return; return;
} }
var adminIndex = users.findIndex(function (u) {
return u.username === username;
});
var adminUser = adminIndex === -1 ? null : users[adminIndex];
var otherUsers = users.filter(function (u) {
return u.username !== username;
});
var html = var html =
'<table class="admin-table">' + '<table class="admin-table">' +
'<tbody><tr class="admin-table__header">' + '<tbody><tr class="admin-table__header">' +
'<th>#</th><th>Username</th><th>Email</th><th>Joined</th><th>Status</th>' + '<th>#</th><th>Username</th><th>Email</th><th>Joined</th><th>Status</th><th>Actions</th>' +
(adminUser ? '<th rowspan="2">Actions</th>' : '<th>Actions</th>') +
'</tr>'; '</tr>';
function userRow(u, isCurrentUser) { function userRow(u) {
var joined = new Date(u.created_at).toLocaleDateString(); var joined = new Date(u.created_at).toLocaleDateString();
var blocked = u.blocked === true || u.blocked === 't' || u.blocked === '1'; var blocked = u.blocked === true || u.blocked === 't' || u.blocked === '1';
var status = isCurrentUser var status = blocked
? '<span class="admin-badge admin-badge--admin">Admin</span>'
: blocked
? '<span class="admin-badge admin-badge--blocked">Blocked</span>' ? '<span class="admin-badge admin-badge--blocked">Blocked</span>'
: '<span class="admin-badge admin-badge--active">Active</span>'; : '<span class="admin-badge admin-badge--active">Active</span>';
var blockBtn = ''; var blockBtn = blocked
var deleteBtn = '';
if (!isCurrentUser) {
blockBtn = blocked
? '<button class="admin-btn admin-btn--unblock" data-id="' + ? '<button class="admin-btn admin-btn--unblock" data-id="' +
u.id + u.id +
'" data-action="unblock_user">Unblock</button>' '" data-action="unblock_user">Unblock</button>'
: '<button class="admin-btn admin-btn--block" data-id="' + : '<button class="admin-btn admin-btn--block" data-id="' +
u.id + u.id +
'" data-action="block_user">Block</button>'; '" data-action="block_user">Block</button>';
var deleteBtn =
deleteBtn =
'<button class="admin-btn admin-btn--delete" data-id="' + '<button class="admin-btn admin-btn--delete" data-id="' +
u.id + u.id +
'" data-username="' + '" data-username="' +
escHtml(u.username) + escHtml(u.username) +
'" data-action="delete_user">Delete Records</button>'; '" data-action="delete_user">Delete Records</button>';
}
return ( return (
'<tr id="user-row-' + '<tr id="user-row-' +
@@ -118,18 +102,17 @@
'<td>' + '<td>' +
status + status +
'</td>' + '</td>' +
(isCurrentUser '<td class="admin-actions">' +
? '' blockBtn +
: '<td class="admin-actions">' + blockBtn + ' ' + deleteBtn + '</td>') + ' ' +
deleteBtn +
'</td>' +
'</tr>' '</tr>'
); );
} }
if (adminUser) { users.forEach(function (u) {
html += userRow(adminUser, true); html += userRow(u);
}
otherUsers.forEach(function (u) {
html += userRow(u, false);
}); });
html += '</tbody></table>'; html += '</tbody></table>';
@@ -220,9 +203,10 @@
var query = search.value.trim().toLowerCase(); var query = search.value.trim().toLowerCase();
var users = allUsers.filter(function (u) { var users = allUsers.filter(function (u) {
return ( return (
!query || u.username !== username &&
(!query ||
String(u.username).toLowerCase().includes(query) || String(u.username).toLowerCase().includes(query) ||
String(u.email).toLowerCase().includes(query) String(u.email).toLowerCase().includes(query))
); );
}); });
renderTable(users); renderTable(users);

View File

@@ -1401,10 +1401,6 @@
background: #d4edda; background: #d4edda;
color: #155724; color: #155724;
} }
.admin-badge--admin {
background: #dbeafe;
color: #1e3a8a;
}
.admin-badge--blocked { .admin-badge--blocked {
background: #f8d7da; background: #f8d7da;
color: #721c24; color: #721c24;