2020-03-10 14:53:23 +01:00
|
|
|
<script>
|
2021-09-29 11:33:55 +02:00
|
|
|
import { fade } from "svelte/transition"
|
2021-09-23 17:08:47 +02:00
|
|
|
import { tables } from "stores/backend"
|
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"
|
2021-11-01 22:15:46 +01:00
|
|
|
import ExistingRelationshipButton from "./buttons/ExistingRelationshipButton.svelte"
|
2020-10-03 22:06:58 +02:00
|
|
|
import ExportButton from "./buttons/ExportButton.svelte"
|
2021-11-12 19:26:57 +01:00
|
|
|
import ImportButton from "./buttons/ImportButton.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"
|
2021-09-29 10:05:04 +02:00
|
|
|
import TableFilterButton from "./buttons/TableFilterButton.svelte"
|
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"
|
2022-08-01 19:56:59 +02:00
|
|
|
import {
|
|
|
|
Pagination,
|
|
|
|
Heading,
|
|
|
|
Body,
|
2023-03-02 18:20:51 +01:00
|
|
|
Modal,
|
2022-08-01 19:56:59 +02:00
|
|
|
Layout,
|
|
|
|
notifications,
|
|
|
|
} from "@budibase/bbui"
|
2023-02-26 22:29:46 +01:00
|
|
|
import { fetchData, Sheet } from "@budibase/frontend-core"
|
2022-01-26 18:43:48 +01:00
|
|
|
import { API } from "api"
|
2023-03-02 18:20:51 +01:00
|
|
|
import CreateEditColumn from "components/backend/DataTable/modals/CreateEditColumn.svelte"
|
2020-03-10 17:06:30 +01:00
|
|
|
|
2023-03-02 18:20:51 +01:00
|
|
|
let createColumnModal
|
|
|
|
|
|
|
|
let hideAutocolumns = true
|
|
|
|
let filters
|
|
|
|
let hasRows = true
|
|
|
|
|
|
|
|
$: isUsersTable = $tables.selected?._id === TableNames.USERS
|
|
|
|
$: type = $tables.selected?.type
|
|
|
|
$: isInternal = type !== "external"
|
|
|
|
$: schema = $tables.selected?.schema
|
|
|
|
$: enrichedSchema = enrichSchema($tables.selected?.schema)
|
|
|
|
$: id = $tables.selected?._id
|
|
|
|
$: hasCols = checkHasCols(schema)
|
|
|
|
$: id, (filters = null)
|
|
|
|
|
|
|
|
let appliedFilter
|
|
|
|
let rawFilter
|
|
|
|
let appliedSort
|
|
|
|
let selectedRows = []
|
|
|
|
|
|
|
|
$: enrichedSchema,
|
|
|
|
() => {
|
|
|
|
appliedFilter = null
|
|
|
|
rawFilter = null
|
|
|
|
appliedSort = null
|
|
|
|
selectedRows = []
|
|
|
|
}
|
|
|
|
|
|
|
|
const enrichSchema = schema => {
|
|
|
|
let tempSchema = { ...schema }
|
|
|
|
tempSchema._id = {
|
|
|
|
type: "internal",
|
|
|
|
editable: false,
|
|
|
|
displayName: "ID",
|
|
|
|
autocolumn: true,
|
|
|
|
}
|
|
|
|
if (isInternal) {
|
|
|
|
tempSchema._rev = {
|
|
|
|
type: "internal",
|
|
|
|
editable: false,
|
|
|
|
displayName: "Revision",
|
|
|
|
autocolumn: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tempSchema
|
|
|
|
}
|
|
|
|
|
|
|
|
const checkHasCols = schema => {
|
|
|
|
if (!schema || Object.keys(schema).length === 0) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
let fields = Object.values(schema)
|
|
|
|
for (let field of fields) {
|
|
|
|
if (!field.autocolumn) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fetch data whenever sorting option changes
|
|
|
|
const onSort = async e => {
|
|
|
|
const sort = {
|
|
|
|
sortColumn: e.detail.column,
|
|
|
|
sortOrder: e.detail.order,
|
|
|
|
}
|
|
|
|
appliedSort = { ...sort }
|
|
|
|
appliedSort.sortOrder = appliedSort.sortOrder.toLowerCase()
|
|
|
|
selectedRows = []
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fetch data whenever filters change
|
|
|
|
const onFilter = e => {
|
|
|
|
filters = e.detail
|
|
|
|
appliedFilter = e.detail
|
|
|
|
}
|
2020-03-10 14:53:23 +01:00
|
|
|
</script>
|
|
|
|
|
2023-03-02 18:20:51 +01:00
|
|
|
<div class="wrapper">
|
2023-03-06 12:20:47 +01:00
|
|
|
<Sheet
|
|
|
|
tableId={$tables.selected?._id}
|
|
|
|
{API}
|
|
|
|
filter={filters}
|
|
|
|
on:add-column={createColumnModal.show}
|
|
|
|
>
|
|
|
|
<svelte:fragment slot="controls">
|
2023-03-02 18:20:51 +01:00
|
|
|
<CreateColumnButton
|
|
|
|
highlighted={!hasCols || !hasRows}
|
|
|
|
on:updatecolumns={null}
|
|
|
|
/>
|
2023-03-03 09:34:26 +01:00
|
|
|
{#if !isUsersTable}
|
|
|
|
<CreateRowButton
|
|
|
|
on:updaterows={null}
|
|
|
|
title="Create row"
|
|
|
|
modalContentComponent={CreateEditRow}
|
|
|
|
disabled={!hasCols}
|
|
|
|
highlighted={hasCols && !hasRows}
|
|
|
|
/>
|
|
|
|
{/if}
|
2023-03-02 18:20:51 +01:00
|
|
|
{#if isInternal}
|
|
|
|
<CreateViewButton disabled={!hasCols || !hasRows} />
|
|
|
|
{/if}
|
|
|
|
<ManageAccessButton resourceId={$tables.selected?._id} />
|
|
|
|
{#if isUsersTable}
|
|
|
|
<EditRolesButton />
|
|
|
|
{/if}
|
|
|
|
{#if !isInternal}
|
|
|
|
<ExistingRelationshipButton
|
|
|
|
table={$tables.selected}
|
|
|
|
on:updatecolumns={null}
|
|
|
|
/>
|
|
|
|
{/if}
|
|
|
|
<ImportButton
|
|
|
|
disabled={$tables.selected?._id === "ta_users"}
|
|
|
|
tableId={$tables.selected?._id}
|
|
|
|
on:importrows={null}
|
|
|
|
/>
|
|
|
|
<ExportButton
|
|
|
|
disabled={!hasRows || !hasCols}
|
|
|
|
view={$tables.selected?._id}
|
|
|
|
filters={appliedFilter}
|
|
|
|
sorting={appliedSort}
|
|
|
|
{selectedRows}
|
|
|
|
/>
|
|
|
|
{#key id}
|
|
|
|
<TableFilterButton
|
|
|
|
{schema}
|
|
|
|
{filters}
|
|
|
|
on:change={onFilter}
|
|
|
|
disabled={!hasCols}
|
|
|
|
tableId={id}
|
|
|
|
/>
|
|
|
|
{/key}
|
2023-03-06 12:20:47 +01:00
|
|
|
</svelte:fragment>
|
|
|
|
</Sheet>
|
2021-09-23 17:08:47 +02:00
|
|
|
</div>
|
|
|
|
|
2023-02-26 22:29:46 +01:00
|
|
|
<!--<div>-->
|
|
|
|
<!-- <Table-->
|
|
|
|
<!-- title={$tables.selected?.name}-->
|
|
|
|
<!-- schema={enrichedSchema}-->
|
|
|
|
<!-- {type}-->
|
|
|
|
<!-- tableId={id}-->
|
|
|
|
<!-- data={$fetch.rows}-->
|
|
|
|
<!-- bind:hideAutocolumns-->
|
|
|
|
<!-- loading={!$fetch.loaded}-->
|
|
|
|
<!-- on:sort={onSort}-->
|
|
|
|
<!-- allowEditing-->
|
|
|
|
<!-- disableSorting-->
|
|
|
|
<!-- on:updatecolumns={onUpdateColumns}-->
|
|
|
|
<!-- on:updaterows={onUpdateRows}-->
|
|
|
|
<!-- on:selectionUpdated={e => {-->
|
|
|
|
<!-- selectedRows = e.detail-->
|
|
|
|
<!-- }}-->
|
|
|
|
<!-- customPlaceholder-->
|
|
|
|
<!-- >-->
|
|
|
|
<!-- <div slot="placeholder">-->
|
|
|
|
<!-- <Layout gap="S">-->
|
|
|
|
<!-- {#if !hasCols}-->
|
|
|
|
<!-- <Heading>Let's create some columns</Heading>-->
|
|
|
|
<!-- <Body>-->
|
|
|
|
<!-- Start building out your table structure<br />-->
|
|
|
|
<!-- by adding some columns-->
|
|
|
|
<!-- </Body>-->
|
|
|
|
<!-- {:else}-->
|
|
|
|
<!-- <Heading>Now let's add a row</Heading>-->
|
|
|
|
<!-- <Body>-->
|
|
|
|
<!-- Add some data to your table<br />-->
|
|
|
|
<!-- by adding some rows-->
|
|
|
|
<!-- </Body>-->
|
|
|
|
<!-- {/if}-->
|
|
|
|
<!-- </Layout>-->
|
|
|
|
<!-- </div>-->
|
|
|
|
<!-- </Table>-->
|
|
|
|
<!-- {#key id}-->
|
|
|
|
<!-- <div in:fade={{ delay: 200, duration: 100 }}>-->
|
|
|
|
<!-- <div class="pagination">-->
|
|
|
|
<!-- <Pagination-->
|
|
|
|
<!-- page={$fetch.pageNumber + 1}-->
|
|
|
|
<!-- hasPrevPage={$fetch.hasPrevPage}-->
|
|
|
|
<!-- hasNextPage={$fetch.hasNextPage}-->
|
|
|
|
<!-- goToPrevPage={$fetch.loading ? null : fetch.prevPage}-->
|
|
|
|
<!-- goToNextPage={$fetch.loading ? null : fetch.nextPage}-->
|
|
|
|
<!-- />-->
|
|
|
|
<!-- </div>-->
|
|
|
|
<!-- </div>-->
|
|
|
|
<!-- {/key}-->
|
|
|
|
|
|
|
|
<!--</div>-->
|
2023-03-02 18:20:51 +01:00
|
|
|
|
|
|
|
<Modal bind:this={createColumnModal}>
|
|
|
|
<CreateEditColumn on:updatecolumns />
|
|
|
|
</Modal>
|
|
|
|
|
2021-09-23 17:08:47 +02:00
|
|
|
<style>
|
2023-03-02 18:20:51 +01:00
|
|
|
.wrapper {
|
2023-02-26 22:29:46 +01:00
|
|
|
flex: 1 1 auto;
|
|
|
|
margin: -28px -40px -40px -40px;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
2023-03-02 18:20:51 +01:00
|
|
|
background: var(--background);
|
|
|
|
}
|
2021-09-23 17:08:47 +02:00
|
|
|
</style>
|