2023-10-02 23:10:49 +03:00
|
|
|
<script>
|
2026-01-08 23:23:48 +02:00
|
|
|
import Icon from "../../../common/Icon.svelte";
|
|
|
|
|
import { createEventDispatcher } from "svelte";
|
2024-08-15 14:44:53 +03:00
|
|
|
import Dropdown from "../../common/Dropdown.svelte";
|
2023-10-02 23:10:49 +03:00
|
|
|
|
|
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
|
export let schema;
|
2023-10-23 19:43:59 +03:00
|
|
|
export let sortParam;
|
|
|
|
|
export let sortField;
|
2023-10-02 23:10:49 +03:00
|
|
|
export let inModal;
|
|
|
|
|
export let modalUrl;
|
|
|
|
|
export let systemFields = [];
|
|
|
|
|
|
|
|
|
|
$: sortableFields = schema.fields.filter(
|
2026-01-08 23:23:48 +02:00
|
|
|
(f) =>
|
|
|
|
|
![
|
|
|
|
|
"reference",
|
|
|
|
|
"file",
|
|
|
|
|
"json",
|
|
|
|
|
"id",
|
|
|
|
|
"rich",
|
|
|
|
|
"markdown",
|
|
|
|
|
"block",
|
|
|
|
|
].includes(f.info.name),
|
2023-10-02 23:10:49 +03:00
|
|
|
);
|
|
|
|
|
$: systemFieldsFiltered = systemFields;
|
|
|
|
|
$: if (schema.type === "collection") {
|
|
|
|
|
systemFieldsFiltered = systemFields.filter((f) => f.files === false);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-23 19:43:59 +03:00
|
|
|
function triggerSortField(fieldSort) {
|
2023-10-02 23:10:49 +03:00
|
|
|
const url = new URL(modalUrl ?? window.location.href);
|
|
|
|
|
url.searchParams.set("sort", fieldSort);
|
|
|
|
|
if (inModal) {
|
|
|
|
|
dispatch("refresh", url);
|
|
|
|
|
} else {
|
|
|
|
|
window.location = url;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function sortAsc(e, field) {
|
|
|
|
|
e.preventDefault();
|
2026-01-08 23:23:48 +02:00
|
|
|
let prefix = systemFields.map((el) => el.name).includes(field.name)
|
|
|
|
|
? ""
|
|
|
|
|
: "data.";
|
2023-10-23 19:43:59 +03:00
|
|
|
return triggerSortField(prefix + field.name);
|
2023-10-02 23:10:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function sortDesc(e, field) {
|
|
|
|
|
e.preventDefault();
|
2026-01-08 23:23:48 +02:00
|
|
|
let prefix = systemFields.map((el) => el.name).includes(field.name)
|
|
|
|
|
? ""
|
|
|
|
|
: "data.";
|
2023-10-23 19:43:59 +03:00
|
|
|
return triggerSortField("-" + prefix + field.name);
|
2023-10-02 23:10:49 +03:00
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
2024-08-15 14:44:53 +03:00
|
|
|
<Dropdown>
|
|
|
|
|
<div slot="button">
|
2023-10-23 19:43:59 +03:00
|
|
|
{#if sortParam.startsWith("-")}
|
2026-01-08 23:23:48 +02:00
|
|
|
<Icon icon="arrow-down-wide-short" />
|
2023-10-02 23:10:49 +03:00
|
|
|
{:else}
|
2026-01-08 23:23:48 +02:00
|
|
|
<Icon icon="arrow-up-short-wide" />
|
2023-10-02 23:10:49 +03:00
|
|
|
{/if}
|
2023-10-23 19:43:59 +03:00
|
|
|
<span class="ms-1">{sortField.label}</span>
|
2024-08-15 14:44:53 +03:00
|
|
|
</div>
|
|
|
|
|
<div>
|
2026-01-08 23:23:48 +02:00
|
|
|
{#each sortableFields as field}
|
|
|
|
|
<div class="dropdown-item">
|
|
|
|
|
<button
|
2024-08-15 14:44:53 +03:00
|
|
|
on:click={(e) => sortAsc(e, field)}
|
|
|
|
|
title="Sort Ascending"
|
2026-01-08 23:23:48 +02:00
|
|
|
class="button button-icon {field.name == sortField.name &&
|
|
|
|
|
!sortParam.startsWith('-')
|
|
|
|
|
? 'active'
|
|
|
|
|
: ''} "
|
|
|
|
|
>
|
|
|
|
|
<Icon icon="arrow-up-short-wide" />
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
2024-08-15 14:44:53 +03:00
|
|
|
on:click={(e) => sortDesc(e, field)}
|
|
|
|
|
title="Sort Descending"
|
2026-01-08 23:23:48 +02:00
|
|
|
class="button button-icon {field.name == sortField.name &&
|
|
|
|
|
sortParam.startsWith('-')
|
|
|
|
|
? 'active'
|
|
|
|
|
: ''} "
|
|
|
|
|
>
|
|
|
|
|
<Icon icon="arrow-down-wide-short" />
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
2024-08-15 14:44:53 +03:00
|
|
|
title="Sort Ascending"
|
|
|
|
|
on:click={(e) => sortAsc(e, field)}
|
|
|
|
|
class="button"
|
2026-01-08 23:23:48 +02:00
|
|
|
>
|
|
|
|
|
{field.label}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
{/each}
|
|
|
|
|
<h6 class="dropdown-header">System</h6>
|
|
|
|
|
{#each systemFieldsFiltered as field}
|
|
|
|
|
<div class="dropdown-item">
|
|
|
|
|
<button
|
2024-08-15 14:44:53 +03:00
|
|
|
on:click={(e) => sortAsc(e, field)}
|
|
|
|
|
title="Sort Ascending"
|
2026-01-08 23:23:48 +02:00
|
|
|
class="button button-icon {field.name == sortParam
|
|
|
|
|
? 'active'
|
|
|
|
|
: ''} "
|
|
|
|
|
>
|
|
|
|
|
<Icon icon="arrow-up-short-wide" />
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
2024-08-15 14:44:53 +03:00
|
|
|
on:click={(e) => sortDesc(e, field)}
|
|
|
|
|
title="Sort Descending"
|
2026-01-08 23:23:48 +02:00
|
|
|
class="button button-icon {'-' + field.name == sortParam
|
|
|
|
|
? 'active'
|
|
|
|
|
: ''} "
|
|
|
|
|
>
|
|
|
|
|
<Icon icon="arrow-down-wide-short" />
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
2024-08-15 14:44:53 +03:00
|
|
|
title="Sort Ascending"
|
|
|
|
|
on:click={(e) => sortAsc(e, field)}
|
|
|
|
|
class="button"
|
2026-01-08 23:23:48 +02:00
|
|
|
>
|
|
|
|
|
{field.label}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
{/each}
|
2023-10-02 23:10:49 +03:00
|
|
|
</div>
|
2024-08-15 14:44:53 +03:00
|
|
|
</Dropdown>
|