2022-08-03 20:57:56 -04:00
|
|
|
import {html, render} from './lit.min.js';
|
|
|
|
import * as tfrpc from '/static/tfrpc.js';
|
|
|
|
|
|
|
|
function delete_user(user) {
|
|
|
|
if (confirm(`Are you sure you want to delete the user "${user}"?`)) {
|
|
|
|
tfrpc.rpc.delete_user(user).then(function() {
|
|
|
|
alert(`User "${user}" deleted successfully.`);
|
|
|
|
}).catch(function(error) {
|
|
|
|
alert(`Failed to delete user "${user}": ${JSON.stringify(error, null, 2)}.`);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener('load', function() {
|
2022-08-13 15:39:29 -04:00
|
|
|
const permission_template = (permission) =>
|
|
|
|
html` <code>${permission}</code>`;
|
|
|
|
const user_template = (user, permissions) => html`
|
|
|
|
<li>
|
|
|
|
<button @click=${(e) => delete_user(user)}>
|
|
|
|
Delete
|
|
|
|
</button>
|
|
|
|
${user}:
|
|
|
|
${permissions.map(x => permission_template(x))}
|
|
|
|
</li>
|
|
|
|
`;
|
2022-08-03 20:57:56 -04:00
|
|
|
const users_template = (users) =>
|
|
|
|
html`<ul>
|
2022-08-13 15:39:29 -04:00
|
|
|
${users.map(u => user_template(u[0], u[1]))}
|
2022-08-03 20:57:56 -04:00
|
|
|
</ul>`;
|
2022-08-13 15:39:29 -04:00
|
|
|
render(users_template(Object.entries(g_data.users)), document.body);
|
2022-08-03 20:57:56 -04:00
|
|
|
});
|