2023-10-02 23:10:49 +03:00
|
|
|
<script>
|
|
|
|
|
import FilterFields from "./FilterFields.svelte";
|
|
|
|
|
import Uploader from "../../files/Uploader.svelte";
|
|
|
|
|
import Icon from "../../common/Icon.svelte";
|
|
|
|
|
import SortFields from "./SortFields.svelte";
|
|
|
|
|
import AppliedFilter from "./AppliedFilter.svelte";
|
2023-10-15 23:40:34 +03:00
|
|
|
import {getContext, createEventDispatcher} from "svelte";
|
2023-10-02 23:10:49 +03:00
|
|
|
|
|
|
|
|
const channel = getContext("channel");
|
2023-10-13 21:06:23 +03:00
|
|
|
|
|
|
|
|
const dispatch = createEventDispatcher();
|
2023-10-02 23:10:49 +03:00
|
|
|
export let sort;
|
|
|
|
|
export let schema;
|
|
|
|
|
export let operators;
|
|
|
|
|
export let filter;
|
|
|
|
|
export let inModal;
|
|
|
|
|
export let modalUrl;
|
2023-10-17 22:57:25 +03:00
|
|
|
export let isWritable;
|
2023-10-02 23:10:49 +03:00
|
|
|
export let records;
|
|
|
|
|
export let systemFields = [];
|
2023-10-06 18:47:50 +03:00
|
|
|
// export let visibleFields = [];
|
2023-10-02 23:10:49 +03:00
|
|
|
|
|
|
|
|
let url = new URL(window.location.href);
|
|
|
|
|
|
|
|
|
|
let csvUrl = url.pathname + "/csv?" + url.searchParams.toString();
|
|
|
|
|
|
2023-10-15 23:40:34 +03:00
|
|
|
function search(e) {
|
2023-10-13 21:06:23 +03:00
|
|
|
e.preventDefault();
|
|
|
|
|
const data = new FormData(e.target);
|
|
|
|
|
let filterKey = data.keys().next().value;
|
|
|
|
|
let filterValue = data.values().next().value;
|
|
|
|
|
const url = new URL(modalUrl ?? window.location.href);
|
|
|
|
|
url.searchParams.set("skip", "0");
|
|
|
|
|
url.searchParams.set(filterKey, filterValue);
|
|
|
|
|
if (inModal) {
|
|
|
|
|
dispatch("refresh", url);
|
|
|
|
|
} else {
|
|
|
|
|
window.location = url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2023-10-15 23:40:34 +03:00
|
|
|
|
2023-10-02 23:10:49 +03:00
|
|
|
function uploadComplete(e) {
|
|
|
|
|
records = e.detail;
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<div class="mb-3 d-flex align-items-center justify-content-between">
|
2023-10-08 02:02:59 +03:00
|
|
|
<div class=" d-flex align-items-center">
|
2023-10-02 23:10:49 +03:00
|
|
|
|
|
|
|
|
<SortFields
|
2023-10-08 02:02:59 +03:00
|
|
|
{schema}
|
|
|
|
|
{sort}
|
|
|
|
|
{systemFields}
|
|
|
|
|
{inModal}
|
|
|
|
|
{modalUrl}
|
|
|
|
|
on:refresh
|
2023-10-02 23:10:49 +03:00
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<FilterFields
|
2023-10-08 02:02:59 +03:00
|
|
|
bind:schema
|
|
|
|
|
{systemFields}
|
|
|
|
|
{operators}
|
|
|
|
|
{filter}
|
|
|
|
|
{inModal}
|
|
|
|
|
{modalUrl}
|
|
|
|
|
on:refresh
|
2023-10-02 23:10:49 +03:00
|
|
|
/>
|
|
|
|
|
|
2023-10-15 23:40:34 +03:00
|
|
|
<form method="GET" on:submit={search}>
|
2023-10-13 21:06:23 +03:00
|
|
|
{#if schema.fields[0]?.name}
|
|
|
|
|
<input type="search" name="filter[data.{schema.fields[0].name }_regex]" placeholder="Search"
|
|
|
|
|
class="form-control" required>
|
2023-10-15 23:40:34 +03:00
|
|
|
{:else}
|
2023-10-13 21:06:23 +03:00
|
|
|
<input type="search" name="filter[_file.originalName_regex]" placeholder="Search"
|
|
|
|
|
class="form-control" required>
|
2023-10-15 23:40:34 +03:00
|
|
|
{/if}
|
2023-10-13 21:06:23 +03:00
|
|
|
|
2023-10-08 02:02:59 +03:00
|
|
|
</form>
|
|
|
|
|
|
|
|
|
|
|
2023-10-02 23:10:49 +03:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="d-flex align-items-center ">
|
|
|
|
|
{#if schema.type === "collection"}
|
2023-10-17 22:57:25 +03:00
|
|
|
{#if !inModal && isWritable}
|
2023-10-02 23:10:49 +03:00
|
|
|
<a
|
2023-10-08 02:02:59 +03:00
|
|
|
href="{channel.lucentUrl}/records/new?schema={schema.name}"
|
|
|
|
|
class="btn btn-sm btn-primary"
|
2023-10-02 23:10:49 +03:00
|
|
|
>
|
|
|
|
|
New Record
|
|
|
|
|
</a>
|
|
|
|
|
{/if}
|
|
|
|
|
{:else }
|
|
|
|
|
<div class="d-inline-block ms-1">
|
|
|
|
|
<Uploader {schema} on:uploadComplete={uploadComplete}/>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
{#if !inModal}
|
|
|
|
|
<div class="dropdown d-inline-block">
|
|
|
|
|
<button
|
2023-10-08 02:02:59 +03:00
|
|
|
class="btn btn-link btn-sm"
|
|
|
|
|
type="button"
|
|
|
|
|
data-bs-toggle="dropdown"
|
|
|
|
|
aria-expanded="false"
|
2023-10-02 23:10:49 +03:00
|
|
|
>
|
|
|
|
|
<Icon icon="ellipsis-vertical"/>
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
<ul class="dropdown-menu">
|
2023-10-15 23:40:34 +03:00
|
|
|
{#if filter["status_in"] === "trashed"}
|
2023-10-17 22:57:25 +03:00
|
|
|
{#if isWritable}
|
|
|
|
|
<li>
|
|
|
|
|
<a
|
|
|
|
|
class="dropdown-item"
|
|
|
|
|
href="{channel.lucentUrl}/content/{schema.name}/emptyTrash"
|
|
|
|
|
>
|
|
|
|
|
Empty trash
|
|
|
|
|
</a>
|
|
|
|
|
</li>
|
|
|
|
|
{/if}
|
2023-10-15 23:40:34 +03:00
|
|
|
{:else}
|
|
|
|
|
|
|
|
|
|
<li>
|
|
|
|
|
<a
|
|
|
|
|
class="dropdown-item"
|
|
|
|
|
href={csvUrl}
|
|
|
|
|
>Export to CSV</a
|
|
|
|
|
>
|
|
|
|
|
</li>
|
|
|
|
|
<li>
|
|
|
|
|
<a
|
|
|
|
|
class="dropdown-item"
|
|
|
|
|
href="{channel.lucentUrl}/content/{schema.name}?filter[status_in]=trashed"
|
|
|
|
|
>View trashed records</a
|
|
|
|
|
>
|
|
|
|
|
</li>
|
|
|
|
|
{/if}
|
|
|
|
|
|
2023-10-02 23:10:49 +03:00
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
2023-10-08 02:02:59 +03:00
|
|
|
{#if Object.entries(filter).length > 0}
|
|
|
|
|
<div class=" d-flex mb-3">
|
|
|
|
|
{#each Object.entries(filter) as [k, v]}
|
|
|
|
|
<AppliedFilter
|
|
|
|
|
{schema}
|
|
|
|
|
{operators}
|
|
|
|
|
key={k}
|
|
|
|
|
value={v}
|
|
|
|
|
{inModal}
|
|
|
|
|
{modalUrl}
|
|
|
|
|
{systemFields}
|
|
|
|
|
on:refresh
|
|
|
|
|
/>
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
|