Files
lucent-laravel/front/js/svelte/content/tools/Tools.svelte
T

139 lines
4.1 KiB
Svelte
Raw Normal View History

2023-10-02 23:10:49 +03:00
<script>
import FilterFields from "./FilterFields.svelte";
import Icon from "../../common/Icon.svelte";
import SortFields from "./SortFields.svelte";
import AppliedFilter from "./AppliedFilter.svelte";
2026-04-29 19:40:37 +03:00
import { createEventDispatcher, getContext } from "svelte";
2024-08-15 14:44:53 +03:00
import Dropdown from "../../common/Dropdown.svelte";
2024-08-17 21:10:01 +03:00
import AppliedFilterNotLinked from "./AppliedFilterNotLinked.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-23 19:43:59 +03:00
export let sortParam;
export let sortField;
2023-10-02 23:10:49 +03:00
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;
2023-11-17 20:21:45 +02:00
export let graph;
2023-10-02 23:10:49 +03:00
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-02 23:10:49 +03:00
</script>
2024-08-15 14:44:53 +03:00
<div class="toolbar">
<div class="toolbar-filters">
2023-10-02 23:10:49 +03:00
<SortFields
2026-04-29 19:40:37 +03:00
{schema}
{sortParam}
{sortField}
{systemFields}
{inModal}
{modalUrl}
on:refresh
2023-10-02 23:10:49 +03:00
/>
<FilterFields
2026-04-29 19:40:37 +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}>
2026-04-29 19:40:37 +03:00
<input
type="search"
name="filter[search_regex]"
placeholder="Search"
class="search"
required
/>
2023-10-08 02:02:59 +03:00
</form>
2023-10-02 23:10:49 +03:00
</div>
2024-08-15 18:52:53 +03:00
<div style="display:flex;align-items: center;gap:4px">
2026-04-29 19:40:37 +03:00
{#if !inModal && isWritable}
<a
href="{channel.lucentUrl}/records/new?schema={schema.name}"
class="button"
>
New Record
</a>
2023-10-02 23:10:49 +03:00
{/if}
2026-04-29 19:40:37 +03:00
2023-10-02 23:10:49 +03:00
{#if !inModal}
2024-08-15 14:44:53 +03:00
<Dropdown orientation="right">
<div slot="button">
2026-04-29 19:40:37 +03:00
<Icon icon="ellipsis-vertical" />
2024-08-15 14:44:53 +03:00
</div>
{#if filter["status_in"] === "trashed"}
{#if isWritable}
<a
2026-04-29 19:40:37 +03:00
class="dropdown-item"
href="{channel.lucentUrl}/content/{schema.name}/emptyTrash"
2024-08-15 14:44:53 +03:00
>
Empty trash
</a>
2023-10-15 23:40:34 +03:00
{/if}
2024-08-15 14:44:53 +03:00
{:else}
2026-04-29 19:40:37 +03:00
<a class="dropdown-item" href={csvUrl}>Export to CSV</a>
2024-08-15 14:44:53 +03:00
<a
2026-04-29 19:40:37 +03:00
class="dropdown-item"
href="{channel.lucentUrl}/content/{schema.name}?filter[status_in]=trashed"
>View trashed records</a
2024-08-15 14:44:53 +03:00
>
2024-08-16 17:38:26 +03:00
<a
2026-04-29 19:40:37 +03:00
class="dropdown-item"
href="{channel.lucentUrl}/content/{schema.name}?notlinked=*"
>View unlinked records</a
2024-08-16 17:38:26 +03:00
>
2024-08-15 14:44:53 +03:00
{/if}
</Dropdown>
2023-10-02 23:10:49 +03:00
{/if}
</div>
</div>
2024-08-23 18:15:18 +03:00
<div class="applied-filters">
2026-04-29 19:40:37 +03:00
<AppliedFilterNotLinked {inModal} {modalUrl} on:refresh
2024-08-23 18:15:18 +03:00
></AppliedFilterNotLinked>
{#if Object.entries(filter).length > 0}
2023-10-08 02:02:59 +03:00
{#each Object.entries(filter) as [k, v]}
<AppliedFilter
2026-04-29 19:40:37 +03:00
{schema}
{operators}
key={k}
value={v}
{inModal}
{modalUrl}
{graph}
on:refresh
2023-10-08 02:02:59 +03:00
/>
{/each}
2024-08-23 18:15:18 +03:00
{/if}
</div>