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}"?`)) {
|
2024-02-23 04:35:39 -05:00
|
|
|
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)}.`);
|
|
|
|
});
|
2022-08-03 20:57:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-16 20:29:57 -04:00
|
|
|
function global_settings_set(key, value) {
|
2024-02-23 04:35:39 -05:00
|
|
|
tfrpc.rpc.global_settings_set(key, value).then(function() {
|
|
|
|
alert(`Set "${key}" to "${value}".`);
|
|
|
|
}).catch(function(error) {
|
|
|
|
alert(`Failed to set "${key}": ${JSON.stringify(error, null, 2)}.`);
|
|
|
|
});
|
2022-08-16 20:29:57 -04:00
|
|
|
}
|
|
|
|
|
2024-02-23 04:35:39 -05:00
|
|
|
window.addEventListener('load', function() {
|
|
|
|
const permission_template = (permission) =>
|
|
|
|
html` <code>${permission}</code>`;
|
2022-11-30 19:39:05 -05:00
|
|
|
function input_template(key, description) {
|
|
|
|
if (description.type === 'boolean') {
|
|
|
|
return html`
|
2023-08-04 21:22:27 -04:00
|
|
|
<div style="margin-top: 1em">
|
|
|
|
<label for=${'gs_' + key} style="font-weight: bold">${key}: </label>
|
|
|
|
<div>
|
|
|
|
<input type="checkbox" ?checked=${description.value} id=${'gs_' + key}></input>
|
2023-09-01 12:26:24 -04:00
|
|
|
<button @click=${(e) => global_settings_set(key, e.srcElement.previousElementSibling.checked)}>Set</button>
|
2023-08-04 21:22:27 -04:00
|
|
|
<div>${description.description}</div>
|
|
|
|
</div>
|
2022-12-28 12:16:50 -05:00
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
} else if (description.type === 'textarea') {
|
|
|
|
return html`
|
2023-08-04 21:22:27 -04:00
|
|
|
<div style="margin-top: 1em"">
|
|
|
|
<label for=${'gs_' + key} style="font-weight: bold">${key}: </label>
|
|
|
|
<div style="width: 100%; padding: 0; margin: 0">
|
|
|
|
<div style="width: 90%; padding: 0 margin: 0">
|
|
|
|
<textarea style="vertical-align: top; width: 100%" rows=20 cols=80 id=${'gs_' + key}>${description.value}</textarea>
|
|
|
|
</div>
|
2023-09-01 12:26:24 -04:00
|
|
|
<button @click=${(e) => global_settings_set(key, e.srcElement.previousElementSibling.firstElementChild.value)}>Set</button>
|
2023-08-04 21:22:27 -04:00
|
|
|
<div>${description.description}</div>
|
|
|
|
</div>
|
2022-12-28 12:16:50 -05:00
|
|
|
</div>
|
2022-11-30 19:39:05 -05:00
|
|
|
`;
|
|
|
|
} else {
|
|
|
|
return html`
|
2023-08-04 21:22:27 -04:00
|
|
|
<div style="margin-top: 1em">
|
|
|
|
<label for=${'gs_' + key} style="font-weight: bold">${key}: </label>
|
|
|
|
<div>
|
|
|
|
<input type="text" value="${description.value}" id=${'gs_' + key}></input>
|
2023-09-01 12:26:24 -04:00
|
|
|
<button @click=${(e) => global_settings_set(key, e.srcElement.previousElementSibling.value)}>Set</button>
|
2023-08-04 21:22:27 -04:00
|
|
|
<div>${description.description}</div>
|
|
|
|
</div>
|
2022-12-28 12:16:50 -05:00
|
|
|
</div>
|
2022-11-30 19:39:05 -05:00
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|
2022-08-13 15:39:29 -04:00
|
|
|
const user_template = (user, permissions) => html`
|
|
|
|
<li>
|
2024-02-23 04:35:39 -05:00
|
|
|
<button @click=${(e) => delete_user(user)}>
|
|
|
|
Delete
|
|
|
|
</button>
|
|
|
|
${user}:
|
|
|
|
${permissions.map(x => permission_template(x))}
|
2022-08-13 15:39:29 -04:00
|
|
|
</li>
|
|
|
|
`;
|
2022-08-03 20:57:56 -04:00
|
|
|
const users_template = (users) =>
|
2022-08-16 20:29:57 -04:00
|
|
|
html`<h2>Users</h2>
|
2024-02-23 04:35:39 -05:00
|
|
|
<ul>
|
|
|
|
${Object.entries(users).map(u => user_template(u[0], u[1]))}
|
|
|
|
</ul>`;
|
2022-08-16 20:29:57 -04:00
|
|
|
const page_template = (data) =>
|
2023-08-04 21:22:27 -04:00
|
|
|
html`<div style="padding: 0; margin: 0; width: 100%; max-width: 100%">
|
|
|
|
<h2>Global Settings</h2>
|
|
|
|
<div>
|
2024-02-23 04:35:39 -05:00
|
|
|
${Object.keys(data.settings).sort().map(x => html`${input_template(x, data.settings[x])}`)}
|
2023-08-04 21:22:27 -04:00
|
|
|
</div>
|
|
|
|
${users_template(data.users)}
|
2024-02-23 04:35:39 -05:00
|
|
|
</div>
|
|
|
|
`;
|
2022-08-16 20:29:57 -04:00
|
|
|
render(page_template(g_data), document.body);
|
2024-02-23 04:35:39 -05:00
|
|
|
});
|