2019-12-30 14:27:49 +00:00
|
|
|
<script>
|
|
|
|
|
import axios from 'axios'
|
|
|
|
|
import AccountLink from '../components/AccountLink'
|
|
|
|
|
import PaginatedList from '../components/PaginatedList'
|
2019-12-30 18:50:32 +00:00
|
|
|
import ActionButtons from '../components/ActionButtons'
|
|
|
|
|
import ActionModal from '../components/ActionModal.svelte'
|
2019-12-30 14:27:49 +00:00
|
|
|
import moment from 'moment'
|
|
|
|
|
|
2019-12-31 14:46:34 +00:00
|
|
|
export let setURLParam = false;
|
2019-12-30 14:27:49 +00:00
|
|
|
export let appAlert
|
2019-12-30 18:50:32 +00:00
|
|
|
let userList;
|
2019-12-30 14:27:49 +00:00
|
|
|
|
|
|
|
|
async function fetch(page) {
|
|
|
|
|
try {
|
|
|
|
|
const resp = await axios.get("/api/users?page="+page)
|
|
|
|
|
appAlert.message("")
|
|
|
|
|
return [resp.data.users, resp.data.page];
|
|
|
|
|
} catch (e) {
|
|
|
|
|
appAlert.message(e.message)
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
2019-12-31 14:46:34 +00:00
|
|
|
<PaginatedList {setURLParam} bind:this={userList} bind:fetch={fetch} let:data={users} let:pagination={pagination}>
|
2019-12-30 14:27:49 +00:00
|
|
|
<div slot="header">
|
|
|
|
|
<p>{pagination.item_count.toLocaleString()} users in the database</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
2019-12-31 14:46:34 +00:00
|
|
|
<table slot="body" class="table table-sm table-dark table-responsive-md table-striped table-hover">
|
|
|
|
|
<thead class="thead-light">
|
|
|
|
|
<th>ID</th>
|
|
|
|
|
<th>Username</th>
|
|
|
|
|
<th>User Created</th>
|
|
|
|
|
<th>Last Login</th>
|
|
|
|
|
<th>Actions</th>
|
2019-12-30 14:27:49 +00:00
|
|
|
</thead>
|
|
|
|
|
<tbody>
|
|
|
|
|
{#each users as user, i}
|
|
|
|
|
<tr>
|
2019-12-31 14:46:34 +00:00
|
|
|
<th>#{user.id}</th>
|
2019-12-30 14:27:49 +00:00
|
|
|
<td><AccountLink account={user} /></td>
|
|
|
|
|
<td>{moment(user.created).fromNow()}</td>
|
|
|
|
|
<td>{#if user.last_login.time}
|
|
|
|
|
{moment(user.last_login.time).fromNow()}<br/>
|
|
|
|
|
<code>{user.last_login.hostname} - {user.last_login.ip}</code>
|
|
|
|
|
{:else}
|
|
|
|
|
Never logged in
|
|
|
|
|
{/if}
|
|
|
|
|
</td>
|
2019-12-30 18:50:32 +00:00
|
|
|
<td><ActionButtons account={user} /></td>
|
2019-12-30 14:27:49 +00:00
|
|
|
</tr>
|
|
|
|
|
{/each}
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
</PaginatedList>
|
|
|
|
|
|
2019-12-30 18:50:32 +00:00
|
|
|
<ActionModal on:action={userList.refresh} />
|