2020-03-10 14:53:23 +01:00
|
|
|
<script>
|
2021-04-01 11:29:47 +02:00
|
|
|
import { tables, views } from "stores/backend"
|
2021-03-23 12:16:54 +01:00
|
|
|
|
2020-10-02 13:00:17 +02:00
|
|
|
import CreateRowButton from "./buttons/CreateRowButton.svelte"
|
|
|
|
import CreateColumnButton from "./buttons/CreateColumnButton.svelte"
|
|
|
|
import CreateViewButton from "./buttons/CreateViewButton.svelte"
|
2020-10-03 22:06:58 +02:00
|
|
|
import ExportButton from "./buttons/ExportButton.svelte"
|
2020-12-04 09:27:42 +01:00
|
|
|
import EditRolesButton from "./buttons/EditRolesButton.svelte"
|
2021-02-10 19:18:31 +01:00
|
|
|
import ManageAccessButton from "./buttons/ManageAccessButton.svelte"
|
2021-02-16 14:56:40 +01:00
|
|
|
import HideAutocolumnButton from "./buttons/HideAutocolumnButton.svelte"
|
2020-03-12 15:23:29 +01:00
|
|
|
import * as api from "./api"
|
2020-10-01 08:19:38 +02:00
|
|
|
import Table from "./Table.svelte"
|
2020-12-04 09:27:42 +01:00
|
|
|
import { TableNames } from "constants"
|
2020-12-07 20:05:39 +01:00
|
|
|
import CreateEditRow from "./modals/CreateEditRow.svelte"
|
2020-03-10 17:06:30 +01:00
|
|
|
|
2021-02-16 19:29:38 +01:00
|
|
|
let hideAutocolumns = true
|
2020-03-24 12:35:46 +01:00
|
|
|
let data = []
|
2020-10-07 11:45:26 +02:00
|
|
|
let loading = false
|
2021-03-23 12:16:54 +01:00
|
|
|
$: isUsersTable = $tables.selected?._id === TableNames.USERS
|
|
|
|
$: title = $tables.selected.name
|
|
|
|
$: schema = $tables.selected.schema
|
2020-10-09 19:49:23 +02:00
|
|
|
$: tableView = {
|
2020-10-03 22:06:58 +02:00
|
|
|
schema,
|
2021-03-23 12:27:10 +01:00
|
|
|
name: $views.selected?.name,
|
2020-10-03 22:06:58 +02:00
|
|
|
}
|
2021-06-17 00:27:38 +02:00
|
|
|
$: isInternal = $tables.selected.type === "internal"
|
2020-10-01 08:19:38 +02:00
|
|
|
|
2020-10-09 20:10:28 +02:00
|
|
|
// Fetch rows for specified table
|
2020-04-20 17:17:11 +02:00
|
|
|
$: {
|
2021-06-15 14:32:11 +02:00
|
|
|
loading = true
|
|
|
|
const loadingTableId = $tables.selected?._id
|
|
|
|
api.fetchDataForTable($tables.selected._id).then(rows => {
|
|
|
|
loading = false
|
2021-04-13 16:10:49 +02:00
|
|
|
|
2021-06-15 14:32:11 +02:00
|
|
|
// If we started a slow request then quickly change table, sometimes
|
|
|
|
// the old data overwrites the new data.
|
|
|
|
// This check ensures that we don't do that.
|
|
|
|
if (loadingTableId !== $tables.selected?._id) {
|
|
|
|
return
|
|
|
|
}
|
2021-04-13 16:10:49 +02:00
|
|
|
|
2021-06-15 14:32:11 +02:00
|
|
|
data = rows || []
|
|
|
|
})
|
2020-03-16 19:54:48 +01:00
|
|
|
}
|
2020-03-10 14:53:23 +01:00
|
|
|
</script>
|
|
|
|
|
2020-12-07 20:05:39 +01:00
|
|
|
<Table
|
|
|
|
{title}
|
|
|
|
{schema}
|
2021-03-23 12:16:54 +01:00
|
|
|
tableId={$tables.selected?._id}
|
2020-12-07 20:05:39 +01:00
|
|
|
{data}
|
|
|
|
allowEditing={true}
|
2021-02-16 14:56:40 +01:00
|
|
|
bind:hideAutocolumns
|
2021-05-04 12:04:42 +02:00
|
|
|
{loading}
|
|
|
|
>
|
2020-10-02 13:00:17 +02:00
|
|
|
<CreateColumnButton />
|
2020-11-23 13:12:03 +01:00
|
|
|
{#if schema && Object.keys(schema).length > 0}
|
2021-05-19 19:46:15 +02:00
|
|
|
{#if !isUsersTable}
|
|
|
|
<CreateRowButton
|
|
|
|
title={"Create row"}
|
|
|
|
modalContentComponent={CreateEditRow}
|
|
|
|
/>
|
|
|
|
{/if}
|
2021-06-17 00:27:38 +02:00
|
|
|
{#if isInternal}
|
|
|
|
<CreateViewButton />
|
|
|
|
{/if}
|
2021-03-23 12:16:54 +01:00
|
|
|
<ManageAccessButton resourceId={$tables.selected?._id} />
|
2021-02-16 16:41:50 +01:00
|
|
|
{#if isUsersTable}
|
|
|
|
<EditRolesButton />
|
|
|
|
{/if}
|
2021-06-17 00:27:38 +02:00
|
|
|
{#if isInternal}
|
|
|
|
<HideAutocolumnButton bind:hideAutocolumns />
|
|
|
|
{/if}
|
2021-02-16 16:41:50 +01:00
|
|
|
<!-- always have the export last -->
|
|
|
|
<ExportButton view={tableView} />
|
2020-10-01 08:19:38 +02:00
|
|
|
{/if}
|
|
|
|
</Table>
|