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)}.` ); }); } } async function add_block() { await tfrpc.rpc.addBlock(document.getElementById('add_block').value); } async function remove_block(id) { await tfrpc.rpc.removeBlock(id); } function global_settings_set(key, value) { 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)}.`); }); } function title_case(name) { return name .split('_') .map((x) => x.charAt(0).toUpperCase() + x.substring(1)) .join(' '); } window.addEventListener('load', function () { const permission_template = (permission) => html` ${permission}`; function input_template(key, description) { if (description.type === 'boolean') { return html`
  • ${description.description}
  • `; } else if (description.type === 'textarea') { return html`
  • ${description.description}
  • `; } else if (description.type != 'hidden') { return html`
  • ${description.description}
  • `; } } const user_template = (user, permissions) => html`
  • ${user}: ${permissions.map((x) => permission_template(x))}
  • `; const block_template = (block) => html`
  • ${block.id} ${new Date(block.timestamp)}
  • `; const users_template = (users) => html`

    Users

    `; const blocks_template = (blocks) => html`

    Blocks

    `; const page_template = (data) => html`

    Global Settings

    ${users_template(data.users)} ${blocks_template(data.blocks)}
    `; render(page_template(g_data), document.body); });