2022-07-07 05:19:05 +08:00
|
|
|
<script>
|
2022-08-01 19:20:21 +08:00
|
|
|
import { replace, querystring } from "svelte-spa-router";
|
2022-07-07 05:19:05 +08:00
|
|
|
import {
|
|
|
|
collections,
|
|
|
|
activeCollection,
|
|
|
|
isCollectionsLoading,
|
|
|
|
loadCollections,
|
|
|
|
} from "@/stores/collections";
|
|
|
|
import tooltip from "@/actions/tooltip";
|
2022-07-19 00:44:10 +08:00
|
|
|
import { pageTitle } from "@/stores/app";
|
2022-07-07 05:19:05 +08:00
|
|
|
import Searchbar from "@/components/base/Searchbar.svelte";
|
2022-07-13 00:56:22 +08:00
|
|
|
import RefreshButton from "@/components/base/RefreshButton.svelte";
|
2022-07-07 05:19:05 +08:00
|
|
|
import CollectionsSidebar from "@/components/collections/CollectionsSidebar.svelte";
|
|
|
|
import CollectionUpsertPanel from "@/components/collections/CollectionUpsertPanel.svelte";
|
|
|
|
import CollectionDocsPanel from "@/components/collections/docs/CollectionDocsPanel.svelte";
|
|
|
|
import RecordUpsertPanel from "@/components/records/RecordUpsertPanel.svelte";
|
|
|
|
import RecordsList from "@/components/records/RecordsList.svelte";
|
|
|
|
|
2022-07-19 00:44:10 +08:00
|
|
|
$pageTitle = "Collections";
|
|
|
|
|
2022-08-01 19:20:21 +08:00
|
|
|
const queryParams = new URLSearchParams($querystring);
|
|
|
|
|
2022-07-07 05:19:05 +08:00
|
|
|
let collectionUpsertPanel;
|
|
|
|
let collectionDocsPanel;
|
|
|
|
let recordPanel;
|
|
|
|
let recordsList;
|
2022-08-01 19:20:21 +08:00
|
|
|
let filter = queryParams.get("filter") || "";
|
|
|
|
let sort = queryParams.get("sort") || "-created";
|
|
|
|
let selectedCollectionId = queryParams.get("collectionId") || "";
|
2022-07-07 05:19:05 +08:00
|
|
|
|
|
|
|
$: viewableCollections = $collections.filter((c) => c.name != import.meta.env.PB_PROFILE_COLLECTION);
|
|
|
|
|
|
|
|
// reset filter and sort on collection change
|
|
|
|
$: if ($activeCollection?.id && selectedCollectionId != $activeCollection.id) {
|
2022-07-19 00:44:10 +08:00
|
|
|
reset();
|
2022-07-07 05:19:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// keep the url params in sync
|
|
|
|
$: if (sort || filter || $activeCollection?.id) {
|
2022-08-01 19:20:21 +08:00
|
|
|
const query = new URLSearchParams({
|
|
|
|
collectionId: $activeCollection?.id || "",
|
2022-07-07 05:19:05 +08:00
|
|
|
filter: filter,
|
|
|
|
sort: sort,
|
2022-08-01 19:20:21 +08:00
|
|
|
}).toString();
|
|
|
|
replace("/collections?" + query);
|
2022-07-07 05:19:05 +08:00
|
|
|
}
|
|
|
|
|
2022-07-19 00:44:10 +08:00
|
|
|
function reset() {
|
|
|
|
selectedCollectionId = $activeCollection.id;
|
|
|
|
sort = "-created";
|
|
|
|
filter = "";
|
|
|
|
}
|
2022-07-07 05:19:05 +08:00
|
|
|
|
|
|
|
loadCollections(selectedCollectionId);
|
|
|
|
</script>
|
|
|
|
|
|
|
|
{#if $isCollectionsLoading}
|
|
|
|
<div class="placeholder-section m-b-base">
|
|
|
|
<span class="loader loader-lg" />
|
|
|
|
<h1>Loading collections...</h1>
|
|
|
|
</div>
|
|
|
|
{:else if !viewableCollections.length}
|
|
|
|
<div class="placeholder-section m-b-base">
|
|
|
|
<div class="icon">
|
|
|
|
<i class="ri-database-2-line" />
|
|
|
|
</div>
|
|
|
|
<h1 class="m-b-10">Create your first collection to add records!</h1>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
class="btn btn-expanded-lg btn-lg"
|
|
|
|
on:click={() => collectionUpsertPanel?.show()}
|
|
|
|
>
|
|
|
|
<i class="ri-add-line" />
|
|
|
|
<span class="txt">Create new collection</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
{:else}
|
|
|
|
<CollectionsSidebar />
|
|
|
|
|
|
|
|
<main class="page-wrapper">
|
|
|
|
<header class="page-header">
|
|
|
|
<nav class="breadcrumbs">
|
|
|
|
<div class="breadcrumb-item">Collections</div>
|
|
|
|
<div class="breadcrumb-item">{$activeCollection.name}</div>
|
|
|
|
</nav>
|
|
|
|
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
class="btn btn-secondary btn-circle"
|
|
|
|
use:tooltip={{ text: "Edit collection", position: "right" }}
|
|
|
|
on:click={() => collectionUpsertPanel?.show($activeCollection)}
|
|
|
|
>
|
|
|
|
<i class="ri-settings-4-line" />
|
|
|
|
</button>
|
2022-07-13 00:56:22 +08:00
|
|
|
|
|
|
|
<RefreshButton on:refresh={() => recordsList?.load()} />
|
2022-07-07 05:19:05 +08:00
|
|
|
|
|
|
|
<div class="btns-group">
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
class="btn btn-outline"
|
|
|
|
on:click={() => collectionDocsPanel?.show($activeCollection)}
|
|
|
|
>
|
|
|
|
<i class="ri-code-s-slash-line" />
|
|
|
|
<span class="txt">API Preview</span>
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<button type="button" class="btn btn-expanded" on:click={() => recordPanel?.show()}>
|
|
|
|
<i class="ri-add-line" />
|
|
|
|
<span class="txt">New record</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</header>
|
|
|
|
|
|
|
|
<Searchbar
|
|
|
|
value={filter}
|
|
|
|
autocompleteCollection={$activeCollection}
|
|
|
|
on:submit={(e) => (filter = e.detail)}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<RecordsList
|
|
|
|
bind:this={recordsList}
|
|
|
|
collection={$activeCollection}
|
|
|
|
bind:filter
|
|
|
|
bind:sort
|
|
|
|
on:select={(e) => recordPanel?.show(e?.detail)}
|
|
|
|
/>
|
|
|
|
</main>
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
<CollectionUpsertPanel bind:this={collectionUpsertPanel} />
|
2022-07-19 00:44:10 +08:00
|
|
|
|
2022-07-07 05:19:05 +08:00
|
|
|
<CollectionDocsPanel bind:this={collectionDocsPanel} />
|
|
|
|
|
|
|
|
<RecordUpsertPanel
|
|
|
|
bind:this={recordPanel}
|
|
|
|
collection={$activeCollection}
|
|
|
|
on:save={() => recordsList?.load()}
|
|
|
|
on:delete={() => recordsList?.load()}
|
|
|
|
/>
|