From e048d28ad3262b21d43e1317efefc2d20663ffc8 Mon Sep 17 00:00:00 2001 From: Chord Date: Mon, 30 Dec 2019 13:50:32 -0500 Subject: [PATCH] Make ActionModal to component --- api/db.js | 14 +--- api/user.js | 1 + app/App.svelte | 2 + app/components/ActionButtons.svelte | 38 ++++++++++ app/components/ActionModal.svelte | 74 ++++++++++++++++++++ app/views/Profile.svelte | 17 ++++- app/views/UserList.svelte | 103 ++-------------------------- 7 files changed, 137 insertions(+), 112 deletions(-) create mode 100644 app/components/ActionButtons.svelte create mode 100644 app/components/ActionModal.svelte diff --git a/api/db.js b/api/db.js index e44d051..dc5ff10 100644 --- a/api/db.js +++ b/api/db.js @@ -229,15 +229,11 @@ export async function get_characters(pagination, sort, order) { try { const char_count = await get_row_count(CHARACTER.THIS); - const chars = await pool.query(`SELECT id, name, faction_id, created, last_login FROM characters ORDER BY ${to_sql(sort)} ${to_sql(order)} OFFSET $1 LIMIT $2`, values); + const chars = await pool.query(`SELECT id, account_id, name, faction_id, created, last_login FROM characters ORDER BY ${to_sql(sort)} ${to_sql(order)} OFFSET $1 LIMIT $2`, values); pagination.item_count = char_count; pagination.page_count = Math.ceil(pagination.item_count / pagination.items_per_page); - chars.rows.forEach((r) => { - delete r.account_id; - }); - return chars.rows; } catch (e) { if (e.code) @@ -302,8 +298,7 @@ export async function get_stats() { try { const account_count = await get_row_count(ACCOUNT.THIS); const character_count = await get_row_count(CHARACTER.THIS); - const last_account = await pool.query('SELECT id, username, created FROM accounts ORDER BY id DESC LIMIT 1'); - const last_character = await pool.query('SELECT id, name, faction_id, created FROM characters ORDER BY id DESC LIMIT 1'); + const last_character = await pool.query('SELECT id, account_id, name, faction_id, created FROM characters ORDER BY id DESC LIMIT 1'); const empires = await pool.query('SELECT faction_id, COUNT(*) FROM characters GROUP BY faction_id'); const stats = {} @@ -311,9 +306,6 @@ export async function get_stats() { stats.characters = character_count; stats.last = {}; stats.last.character = last_character.rows[0]; - stats.last.account = last_account.rows[0]; - stats.last.account.name = stats.last.account.username - delete stats.last.account.username; stats.empires = {}; empires.rows.forEach((r) => @@ -354,7 +346,7 @@ export async function search(term, pagination) { const accounts = await pool.query('SELECT id, username, gm FROM accounts ' + 'WHERE upper(username) LIKE $1 '+ ` ORDER BY username OFFSET $2 LIMIT $3`, values); - const characters = await pool.query('SELECT id, name, faction_id FROM characters ' + + const characters = await pool.query('SELECT id, name, account_id, faction_id FROM characters ' + 'WHERE name LIKE $1 '+ ` ORDER BY upper(name) OFFSET $2 LIMIT $3`, values); diff --git a/api/user.js b/api/user.js index b22c52c..684b936 100644 --- a/api/user.js +++ b/api/user.js @@ -35,6 +35,7 @@ api.get('/user/:user/profile', async (req, res, next) => { email : "bademail@email.com", account_created : account.created, admin : account.gm, + inactive: account.inactive, characters: characters, }); } catch (e) { diff --git a/app/App.svelte b/app/App.svelte index f208ff6..3462444 100644 --- a/app/App.svelte +++ b/app/App.svelte @@ -124,4 +124,6 @@ All other trademarks or tradenames are properties of their respective owners. + {/if} + diff --git a/app/components/ActionButtons.svelte b/app/components/ActionButtons.svelte new file mode 100644 index 0000000..7f95816 --- /dev/null +++ b/app/components/ActionButtons.svelte @@ -0,0 +1,38 @@ + + +{#if account.inactive} + +{:else} + +{#if account.admin} + +{:else} + +{/if} +{/if} diff --git a/app/components/ActionModal.svelte b/app/components/ActionModal.svelte new file mode 100644 index 0000000..d62f1df --- /dev/null +++ b/app/components/ActionModal.svelte @@ -0,0 +1,74 @@ + + + diff --git a/app/views/Profile.svelte b/app/views/Profile.svelte index f0e9d17..5d95c3e 100644 --- a/app/views/Profile.svelte +++ b/app/views/Profile.svelte @@ -1,12 +1,16 @@ @@ -56,6 +64,8 @@ {#if account}

Account:

+ +
@@ -73,7 +83,7 @@

Characters

- {#if characters.length > 1} + {#if characters.length >= 1}

{#each characters as char, i}
@@ -90,3 +100,4 @@

{/if} + diff --git a/app/views/UserList.svelte b/app/views/UserList.svelte index 39d385c..7d936f0 100644 --- a/app/views/UserList.svelte +++ b/app/views/UserList.svelte @@ -1,16 +1,13 @@ @@ -86,65 +47,11 @@ Never logged in {/if} - - {#if user.inactive} - - {:else} - - {#if user.admin} - - {:else} - - {/if} - {/if} - + {/each} - +