@mapomodule/uikit 2.0.0-beta.12 → 2.0.0-beta.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -174
- package/dist/__tests__/MapoConfirmDialog.component.test.d.ts +2 -0
- package/dist/__tests__/MapoConfirmDialog.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoDetail.component.test.d.ts +2 -0
- package/dist/__tests__/MapoDetail.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoDetailLangSwitch.component.test.d.ts +2 -0
- package/dist/__tests__/MapoDetailLangSwitch.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoListTable.component.test.d.ts +2 -0
- package/dist/__tests__/MapoListTable.component.test.d.ts.map +1 -0
- package/dist/__tests__/__mocks__/nuxt-app.d.ts +9 -0
- package/dist/__tests__/__mocks__/nuxt-app.d.ts.map +1 -0
- package/dist/__tests__/listTable.test.d.ts +2 -0
- package/dist/__tests__/listTable.test.d.ts.map +1 -0
- package/dist/__tests__/mediaLanguages.test.d.ts +2 -0
- package/dist/__tests__/mediaLanguages.test.d.ts.map +1 -0
- package/dist/module.json +1 -1
- package/dist/runtime/assets/main.css +1 -1
- package/dist/runtime/components/MapoConfirmDialog.vue +18 -1
- package/dist/runtime/components/MapoConfirmDialog.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoDetail.vue +43 -11
- package/dist/runtime/components/MapoDetail.vue.d.ts +76 -0
- package/dist/runtime/components/MapoDetail.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoDetailLangSwitch.vue +21 -25
- package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts +4 -3
- package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoList.vue +3 -2
- package/dist/runtime/components/MapoList.vue.d.ts +9 -4
- package/dist/runtime/components/MapoList.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoListTable.vue +98 -32
- package/dist/runtime/components/MapoListTable.vue.d.ts +11 -6
- package/dist/runtime/components/MapoListTable.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaEditor.vue +10 -4
- package/dist/runtime/components/MapoMediaEditor.vue.d.ts +1 -0
- package/dist/runtime/components/MapoMediaEditor.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaPreview.vue.d.ts +1 -1
- package/dist/runtime/components/MapoMediaPreview.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaUploader.vue +21 -21
- package/dist/runtime/components/MapoMediaUploader.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMenuTreeview.vue.d.ts +1 -1
- package/dist/runtime/components/MapoMenuTreeview.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMenuTreeviewNode.vue.d.ts +2 -2
- package/dist/runtime/stores/media.d.ts +8 -2
- package/dist/runtime/stores/media.d.ts.map +1 -1
- package/dist/runtime/stores/media.js +16 -0
- package/dist/runtime/types/list.d.ts +10 -2
- package/dist/runtime/types/list.d.ts.map +1 -1
- package/dist/runtime/utils/listTable.d.ts +29 -0
- package/dist/runtime/utils/listTable.d.ts.map +1 -0
- package/dist/runtime/utils/listTable.js +21 -0
- package/package.json +6 -6
- package/src/__tests__/MapoConfirmDialog.component.test.ts +165 -0
- package/src/__tests__/MapoDetail.component.test.ts +293 -0
- package/src/__tests__/MapoDetailLangSwitch.component.test.ts +145 -0
- package/src/__tests__/MapoListTable.component.test.ts +504 -0
- package/src/__tests__/__mocks__/nuxt-app.ts +8 -0
- package/src/__tests__/listTable.test.ts +82 -0
- package/src/__tests__/mediaLanguages.test.ts +66 -0
- package/src/runtime/assets/main.css +9 -0
- package/src/runtime/components/MapoConfirmDialog.vue +28 -1
- package/src/runtime/components/MapoDetail.vue +78 -11
- package/src/runtime/components/MapoDetailLangSwitch.vue +26 -27
- package/src/runtime/components/MapoList.vue +13 -5
- package/src/runtime/components/MapoListTable.vue +128 -41
- package/src/runtime/components/MapoMediaEditor.vue +17 -4
- package/src/runtime/components/MapoMediaUploader.vue +25 -21
- package/src/runtime/stores/media.ts +32 -0
- package/src/runtime/types/list.ts +10 -2
- package/src/runtime/utils/listTable.ts +54 -0
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
h,
|
|
8
8
|
resolveComponent,
|
|
9
9
|
useSlots,
|
|
10
|
+
onBeforeUnmount,
|
|
10
11
|
} from "vue";
|
|
11
12
|
import type { Ref } from "vue";
|
|
12
13
|
import { useI18n } from "vue-i18n";
|
|
@@ -18,8 +19,20 @@ import { useConfirmStore } from "@mapomodule/store/runtime/stores/confirm";
|
|
|
18
19
|
import { usePermissions } from "@mapomodule/store/runtime/composables/usePermissions";
|
|
19
20
|
import { useCrud } from "@mapomodule/core/runtime/api/crud";
|
|
20
21
|
import type { AnyFieldDescriptor, FieldRegistry } from "@mapomodule/form/types";
|
|
21
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
debounce,
|
|
24
|
+
getNestedValue,
|
|
25
|
+
splitEndpointParams,
|
|
26
|
+
} from "@mapomodule/utils";
|
|
22
27
|
import { useRoute, useRouter } from "#app";
|
|
28
|
+
import {
|
|
29
|
+
ALL_ROWS,
|
|
30
|
+
formatPageSize,
|
|
31
|
+
nextSorting,
|
|
32
|
+
orderingParam,
|
|
33
|
+
parsePageSize,
|
|
34
|
+
toPageSize,
|
|
35
|
+
} from "../utils/listTable.js";
|
|
23
36
|
|
|
24
37
|
const props = withDefaults(
|
|
25
38
|
defineProps<{
|
|
@@ -44,10 +57,14 @@ const props = withDefaults(
|
|
|
44
57
|
* and tab params without baking them into the endpoint string.
|
|
45
58
|
*/
|
|
46
59
|
filterParams?: Record<string, unknown>;
|
|
47
|
-
/** Initial page size
|
|
48
|
-
defaultPageSize?: number;
|
|
49
|
-
/**
|
|
50
|
-
|
|
60
|
+
/** Initial page size: a number, or `"all"`. Default: 20. */
|
|
61
|
+
defaultPageSize?: number | "all";
|
|
62
|
+
/**
|
|
63
|
+
* Options of the per-page selector. `"all"` adds an option that requests
|
|
64
|
+
* the list without pagination params, like `clientSide` does: the backend
|
|
65
|
+
* has to return the whole collection then. Default: [10, 20, 50, 100].
|
|
66
|
+
*/
|
|
67
|
+
pageSizeOptions?: (number | "all")[];
|
|
51
68
|
/**
|
|
52
69
|
* Custom response parser. When provided it replaces the built-in DRF / flat-array
|
|
53
70
|
* detection. Return `{ items, total }` from any shape your backend returns.
|
|
@@ -70,6 +87,7 @@ const props = withDefaults(
|
|
|
70
87
|
* still hit the backend, then re-fetch. Ignored when `items` is provided.
|
|
71
88
|
*/
|
|
72
89
|
clientSide?: boolean;
|
|
90
|
+
/** Column definitions. A dotted `key` (`category.name`) reads a field of a related object. */
|
|
73
91
|
columns: ListColumn<T>[];
|
|
74
92
|
lookup?: string;
|
|
75
93
|
searchable?: boolean;
|
|
@@ -135,10 +153,11 @@ defineSlots<
|
|
|
135
153
|
|
|
136
154
|
const slots = useSlots();
|
|
137
155
|
|
|
138
|
-
//
|
|
139
|
-
//
|
|
140
|
-
//
|
|
141
|
-
const atKey = (item: T, key: string): T[keyof T] =>
|
|
156
|
+
// A key can be a dotted path into a related object (`category.name`). The cast to
|
|
157
|
+
// T[keyof T] gives the call sites the union of the row's property types rather
|
|
158
|
+
// than `unknown`.
|
|
159
|
+
const atKey = (item: T, key: string): T[keyof T] =>
|
|
160
|
+
getNestedValue(item, key) as T[keyof T];
|
|
142
161
|
|
|
143
162
|
const { t } = useI18n();
|
|
144
163
|
const snack = useSnackStore();
|
|
@@ -187,14 +206,24 @@ function toPositiveNumber(value: unknown, fallback: number): number {
|
|
|
187
206
|
}
|
|
188
207
|
|
|
189
208
|
// --- Pagination (restored from URL) ---
|
|
209
|
+
// "All rows" is stored as the ALL_ROWS page size and written as `page_size=all`.
|
|
210
|
+
const defaultPageSize = toPageSize(props.defaultPageSize);
|
|
190
211
|
const pagination = ref<PaginationState>({
|
|
191
212
|
pageIndex: route.query.page
|
|
192
213
|
? Math.max(0, toPositiveNumber(route.query.page, 1) - 1)
|
|
193
214
|
: 0,
|
|
194
215
|
pageSize: route.query.page_size
|
|
195
|
-
?
|
|
196
|
-
:
|
|
216
|
+
? parsePageSize(route.query.page_size, defaultPageSize)
|
|
217
|
+
: defaultPageSize,
|
|
197
218
|
});
|
|
219
|
+
const showsAllRows = computed(() => pagination.value.pageSize === ALL_ROWS);
|
|
220
|
+
const pageSizeItems = computed(() =>
|
|
221
|
+
props.pageSizeOptions.map((option) =>
|
|
222
|
+
option === "all"
|
|
223
|
+
? { label: t("mapo.listTable.allRows"), value: ALL_ROWS }
|
|
224
|
+
: { label: t("mapo.listTable.perPage", { n: option }), value: option },
|
|
225
|
+
),
|
|
226
|
+
);
|
|
198
227
|
|
|
199
228
|
// --- Sorting (restored from URL) ---
|
|
200
229
|
const sorting = ref<SortingState>(
|
|
@@ -226,8 +255,8 @@ const writeUrlState = debounce(() => {
|
|
|
226
255
|
const page = pagination.value.pageIndex + 1;
|
|
227
256
|
if (page > 1) query.page = String(page);
|
|
228
257
|
else delete query.page;
|
|
229
|
-
if (pagination.value.pageSize !==
|
|
230
|
-
query.page_size =
|
|
258
|
+
if (pagination.value.pageSize !== defaultPageSize)
|
|
259
|
+
query.page_size = formatPageSize(pagination.value.pageSize);
|
|
231
260
|
else delete query.page_size;
|
|
232
261
|
if (search.value) query.search = search.value;
|
|
233
262
|
else delete query.search;
|
|
@@ -241,6 +270,13 @@ const writeUrlState = debounce(() => {
|
|
|
241
270
|
|
|
242
271
|
watch([pagination, search, sorting], writeUrlState, { deep: true });
|
|
243
272
|
|
|
273
|
+
// A debounced call still pending when the list goes away would act on the next
|
|
274
|
+
// page: the URL write would put this list's query on it.
|
|
275
|
+
onBeforeUnmount(() => {
|
|
276
|
+
onSearchInput.cancel();
|
|
277
|
+
writeUrlState.cancel();
|
|
278
|
+
});
|
|
279
|
+
|
|
244
280
|
// --- Row selection ---
|
|
245
281
|
// Selection is keyed by primary key (lookup), not by row index, so pagination/sort/refresh
|
|
246
282
|
// changes do not affect which rows are marked as selected.
|
|
@@ -266,11 +302,12 @@ watch(selectedRows, (rows) => {
|
|
|
266
302
|
|
|
267
303
|
function buildSelectionQuery(): URLSearchParams {
|
|
268
304
|
const params = new URLSearchParams();
|
|
269
|
-
|
|
305
|
+
if (!showsAllRows.value)
|
|
306
|
+
params.set("page_size", String(pagination.value.pageSize));
|
|
270
307
|
if (search.value) params.set("search", search.value);
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
308
|
+
// The same ordering the list request sends.
|
|
309
|
+
if (sorting.value.length)
|
|
310
|
+
params.set("ordering", orderingParam(sorting.value));
|
|
274
311
|
return params;
|
|
275
312
|
}
|
|
276
313
|
|
|
@@ -476,7 +513,7 @@ function applyOffline(source: T[]) {
|
|
|
476
513
|
const q = search.value.toLowerCase();
|
|
477
514
|
arr = arr.filter((row) =>
|
|
478
515
|
props.columns.some((c) =>
|
|
479
|
-
String(row
|
|
516
|
+
String(atKey(row, c.key) ?? "")
|
|
480
517
|
.toLowerCase()
|
|
481
518
|
.includes(q),
|
|
482
519
|
),
|
|
@@ -589,13 +626,11 @@ async function refresh() {
|
|
|
589
626
|
const params: Record<string, unknown> = {
|
|
590
627
|
...endpointParams,
|
|
591
628
|
...(props.filterParams ?? {}),
|
|
592
|
-
|
|
629
|
+
// "All rows" sends no pagination params: the backend returns the whole collection.
|
|
630
|
+
...(showsAllRows.value ? {} : paginationP),
|
|
593
631
|
};
|
|
594
632
|
if (search.value) params.search = search.value;
|
|
595
|
-
if (sorting.value.length)
|
|
596
|
-
params.ordering = sorting.value
|
|
597
|
-
.map((s) => `${s.desc ? "-" : ""}${s.id}`)
|
|
598
|
-
.join(",");
|
|
633
|
+
if (sorting.value.length) params.ordering = orderingParam(sorting.value);
|
|
599
634
|
|
|
600
635
|
const res = await crud.list(params as Record<string, string>);
|
|
601
636
|
|
|
@@ -657,13 +692,23 @@ watch(
|
|
|
657
692
|
search,
|
|
658
693
|
],
|
|
659
694
|
([newEndpoint, , newFilters], [oldEndpoint, , oldFilters]) => {
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
} else {
|
|
695
|
+
// The immediate first run has no old values: it is the initial load, so it
|
|
696
|
+
// fetches the page restored from the URL.
|
|
697
|
+
const isFirstRun = oldFilters === undefined;
|
|
698
|
+
if (isFirstRun) {
|
|
665
699
|
refresh();
|
|
700
|
+
return;
|
|
666
701
|
}
|
|
702
|
+
const endpointChanged = newEndpoint !== oldEndpoint;
|
|
703
|
+
const filtersChanged = newFilters !== oldFilters;
|
|
704
|
+
const contextChanged = endpointChanged || filtersChanged;
|
|
705
|
+
const isOnFirstPage = pagination.value.pageIndex === 0;
|
|
706
|
+
// Moving to the first page runs this watcher again, and that run fetches.
|
|
707
|
+
if (contextChanged && !isOnFirstPage) {
|
|
708
|
+
pagination.value = { ...pagination.value, pageIndex: 0 };
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
refresh();
|
|
667
712
|
},
|
|
668
713
|
{ immediate: true, deep: true },
|
|
669
714
|
);
|
|
@@ -673,6 +718,35 @@ const UCheckbox = resolveComponent("UCheckbox");
|
|
|
673
718
|
const UButton = resolveComponent("UButton");
|
|
674
719
|
const UIcon = resolveComponent("UIcon");
|
|
675
720
|
|
|
721
|
+
// A sortable header is a button: the icon shows the current direction, the
|
|
722
|
+
// accessible name says what the next click does (UTable sets no `aria-sort`).
|
|
723
|
+
const SORT_ICONS = {
|
|
724
|
+
none: "i-lucide-arrow-up-down",
|
|
725
|
+
asc: "i-lucide-arrow-up-narrow-wide",
|
|
726
|
+
desc: "i-lucide-arrow-down-wide-narrow",
|
|
727
|
+
};
|
|
728
|
+
const SORT_NEXT_ACTION = {
|
|
729
|
+
none: "mapo.listTable.sortAscending",
|
|
730
|
+
asc: "mapo.listTable.sortDescending",
|
|
731
|
+
desc: "mapo.listTable.clearSorting",
|
|
732
|
+
};
|
|
733
|
+
|
|
734
|
+
function sortHeader(col: ListColumn<T>) {
|
|
735
|
+
const sort = sorting.value.find((s) => s.id === col.key);
|
|
736
|
+
const direction = !sort ? "none" : sort.desc ? "desc" : "asc";
|
|
737
|
+
return h(UButton, {
|
|
738
|
+
color: "neutral",
|
|
739
|
+
variant: "ghost",
|
|
740
|
+
label: col.label,
|
|
741
|
+
icon: SORT_ICONS[direction],
|
|
742
|
+
class: "-mx-2.5",
|
|
743
|
+
"aria-label": t(SORT_NEXT_ACTION[direction], { column: col.label }),
|
|
744
|
+
onClick: () => {
|
|
745
|
+
sorting.value = nextSorting(sorting.value, col.key);
|
|
746
|
+
},
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
|
|
676
750
|
const tableColumns = computed<TableColumn<T>[]>(() => {
|
|
677
751
|
const cols: TableColumn<T>[] = [];
|
|
678
752
|
|
|
@@ -731,8 +805,11 @@ const tableColumns = computed<TableColumn<T>[]>(() => {
|
|
|
731
805
|
const col = props.columns[i]!;
|
|
732
806
|
const isFirst = i === 0 && !!props.detailBase;
|
|
733
807
|
cols.push({
|
|
808
|
+
// TanStack would turn a dotted key into `category_name`; the sorting
|
|
809
|
+
// state uses the column key, so the id must be the key itself.
|
|
810
|
+
id: col.key,
|
|
734
811
|
accessorKey: col.key,
|
|
735
|
-
header: col.label,
|
|
812
|
+
header: col.sortable ? () => sortHeader(col) : col.label,
|
|
736
813
|
cell: ({ row }: { row: { original: T } }) => {
|
|
737
814
|
const cellSlot = slots[`cell.${col.key}`];
|
|
738
815
|
if (cellSlot)
|
|
@@ -770,6 +847,7 @@ const tableColumns = computed<TableColumn<T>[]>(() => {
|
|
|
770
847
|
variant: "ghost",
|
|
771
848
|
color: "neutral",
|
|
772
849
|
icon: "i-lucide-pencil",
|
|
850
|
+
"aria-label": t("mapo.edit"),
|
|
773
851
|
onClick: () =>
|
|
774
852
|
openQuickEdit(
|
|
775
853
|
atKey(row.original, props.lookup) as string | number,
|
|
@@ -784,6 +862,7 @@ const tableColumns = computed<TableColumn<T>[]>(() => {
|
|
|
784
862
|
variant: "ghost",
|
|
785
863
|
color: "error",
|
|
786
864
|
icon: "i-lucide-trash-2",
|
|
865
|
+
"aria-label": t("mapo.delete"),
|
|
787
866
|
onClick: () => deleteRow(row.original),
|
|
788
867
|
}),
|
|
789
868
|
);
|
|
@@ -800,6 +879,19 @@ const tableColumns = computed<TableColumn<T>[]>(() => {
|
|
|
800
879
|
return cols;
|
|
801
880
|
});
|
|
802
881
|
|
|
882
|
+
// A search or a filter with no match reads differently from an empty list.
|
|
883
|
+
const emptyText = computed(() => {
|
|
884
|
+
const isSearching = !!search.value;
|
|
885
|
+
const isFiltering = Object.values(props.filterParams ?? {}).some(
|
|
886
|
+
(value) => value != null && value !== "",
|
|
887
|
+
);
|
|
888
|
+
return t(
|
|
889
|
+
isSearching || isFiltering
|
|
890
|
+
? "mapo.listTable.noResults"
|
|
891
|
+
: "mapo.listTable.noItems",
|
|
892
|
+
);
|
|
893
|
+
});
|
|
894
|
+
|
|
803
895
|
// --- Pagination for UTable ---
|
|
804
896
|
const paginationOptions = computed(() => ({
|
|
805
897
|
manualPagination: true,
|
|
@@ -841,7 +933,7 @@ const sortingOptions = computed(() => ({
|
|
|
841
933
|
:pagination-options="paginationOptions"
|
|
842
934
|
:sorting="sorting"
|
|
843
935
|
:sorting-options="sortingOptions"
|
|
844
|
-
:empty="
|
|
936
|
+
:empty="emptyText"
|
|
845
937
|
@update:pagination="pagination = $event ?? pagination"
|
|
846
938
|
@update:sorting="sorting = $event ?? sorting"
|
|
847
939
|
>
|
|
@@ -849,7 +941,7 @@ const sortingOptions = computed(() => ({
|
|
|
849
941
|
<slot name="dtable.empty">
|
|
850
942
|
<div class="flex flex-col items-center gap-2 py-8 text-muted">
|
|
851
943
|
<UIcon name="i-lucide-inbox" class="h-8 w-8" />
|
|
852
|
-
<span class="text-sm">{{
|
|
944
|
+
<span class="text-sm">{{ emptyText }}</span>
|
|
853
945
|
</div>
|
|
854
946
|
</slot>
|
|
855
947
|
</template>
|
|
@@ -870,23 +962,18 @@ const sortingOptions = computed(() => ({
|
|
|
870
962
|
<!-- Pagination controls -->
|
|
871
963
|
<div class="flex items-center justify-between text-sm text-muted">
|
|
872
964
|
<span>{{ t("mapo.listTable.totalItems", { total }) }}</span>
|
|
965
|
+
<!-- Nuxt UI 4's UPagination models `page`: with `modelValue` it runs uncontrolled. -->
|
|
873
966
|
<UPagination
|
|
874
|
-
|
|
967
|
+
v-if="!showsAllRows"
|
|
968
|
+
:page="pagination.pageIndex + 1"
|
|
875
969
|
:total="total"
|
|
876
970
|
:items-per-page="pagination.pageSize"
|
|
877
971
|
size="sm"
|
|
878
|
-
@update:
|
|
879
|
-
pagination = { ...pagination, pageIndex: $event - 1 }
|
|
880
|
-
"
|
|
972
|
+
@update:page="pagination = { ...pagination, pageIndex: $event - 1 }"
|
|
881
973
|
/>
|
|
882
974
|
<USelect
|
|
883
975
|
:model-value="pagination.pageSize"
|
|
884
|
-
:items="
|
|
885
|
-
pageSizeOptions.map((n) => ({
|
|
886
|
-
label: t('mapo.listTable.perPage', { n }),
|
|
887
|
-
value: n,
|
|
888
|
-
}))
|
|
889
|
-
"
|
|
976
|
+
:items="pageSizeItems"
|
|
890
977
|
size="xs"
|
|
891
978
|
class="w-28"
|
|
892
979
|
@update:model-value="
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { ref, watch, computed } from "vue";
|
|
2
|
+
import { ref, watch, computed, onMounted } from "vue";
|
|
3
3
|
import { useI18n } from "vue-i18n";
|
|
4
4
|
import { useRuntimeConfig } from "#app";
|
|
5
5
|
import {
|
|
@@ -12,7 +12,8 @@ import { usePermissions } from "@mapomodule/store/runtime/composables/usePermiss
|
|
|
12
12
|
import { useMediaStore } from "../stores/media.js";
|
|
13
13
|
import type { MediaItem } from "../types/media.js";
|
|
14
14
|
|
|
15
|
-
defineProps<{
|
|
15
|
+
const props = defineProps<{
|
|
16
|
+
/** Overrides the languages read from the endpoint. Rarely needed. */
|
|
16
17
|
languages?: string[];
|
|
17
18
|
defaultLang?: string;
|
|
18
19
|
}>();
|
|
@@ -35,6 +36,18 @@ const saving = ref(false);
|
|
|
35
36
|
const newFile = ref<File | null>(null);
|
|
36
37
|
const maintainUrl = ref(false);
|
|
37
38
|
const currentLang = ref("");
|
|
39
|
+
|
|
40
|
+
// The languages actually offered. An explicit prop wins; otherwise they come
|
|
41
|
+
// from the media endpoint's own OPTIONS metadata, so a host page never has to
|
|
42
|
+
// restate what the backend already knows — and a media model nobody registered
|
|
43
|
+
// for translation shows no switcher rather than tabs whose values it discards.
|
|
44
|
+
const activeLangs = computed(() =>
|
|
45
|
+
props.languages?.length ? props.languages : store.languages,
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
onMounted(() => {
|
|
49
|
+
store.deriveLanguages();
|
|
50
|
+
});
|
|
38
51
|
// Pristine copy taken when entering edit mode, restored on Cancel — the form
|
|
39
52
|
// mutates store.editMedia directly, so without this Cancel would leave the
|
|
40
53
|
// unsaved edits visible in the info panel (legacy used deepClone the same way).
|
|
@@ -254,7 +267,7 @@ function formatDate(dateStr: string): string {
|
|
|
254
267
|
<!-- Edit form (shown when editing) -->
|
|
255
268
|
<div v-if="editing" class="space-y-4 px-4 py-3">
|
|
256
269
|
<!-- Lang switch -->
|
|
257
|
-
<UFieldGroup v-if="
|
|
270
|
+
<UFieldGroup v-if="activeLangs.length > 1" size="xs">
|
|
258
271
|
<UButton
|
|
259
272
|
:variant="currentLang === '' ? 'solid' : 'outline'"
|
|
260
273
|
color="neutral"
|
|
@@ -263,7 +276,7 @@ function formatDate(dateStr: string): string {
|
|
|
263
276
|
{{ t("mapo.mediaEditor.defaultLang") }}
|
|
264
277
|
</UButton>
|
|
265
278
|
<UButton
|
|
266
|
-
v-for="lang in
|
|
279
|
+
v-for="lang in activeLangs"
|
|
267
280
|
:key="lang"
|
|
268
281
|
:variant="currentLang === lang ? 'solid' : 'outline'"
|
|
269
282
|
color="neutral"
|
|
@@ -55,6 +55,15 @@ const pendingCount = computed(
|
|
|
55
55
|
() => entries.value.filter((e) => e.status === "pending").length,
|
|
56
56
|
);
|
|
57
57
|
|
|
58
|
+
// The text metadata of a pending file, labelled like MapoMediaEditor's fields.
|
|
59
|
+
// Labels, not placeholders: title and alt text start from the file name, so a
|
|
60
|
+
// placeholder would never show what they are.
|
|
61
|
+
const textFields = computed(() => [
|
|
62
|
+
{ key: "title" as const, label: t("mapo.title") },
|
|
63
|
+
{ key: "alt_text" as const, label: t("mapo.altTag") },
|
|
64
|
+
{ key: "description" as const, label: t("mapo.description") },
|
|
65
|
+
]);
|
|
66
|
+
|
|
58
67
|
// Destination options: the current folder plus its subfolders (legacy parity).
|
|
59
68
|
const folderOptions = computed(() => [
|
|
60
69
|
{
|
|
@@ -260,32 +269,27 @@ onUnmounted(clearAll);
|
|
|
260
269
|
</span>
|
|
261
270
|
</div>
|
|
262
271
|
|
|
263
|
-
<!-- Metadata inputs (only for pending)
|
|
272
|
+
<!-- Metadata inputs (only for pending). The inputs take their
|
|
273
|
+
size from UFormField. -->
|
|
264
274
|
<div
|
|
265
275
|
v-if="entry.status === 'pending'"
|
|
266
276
|
class="grid grid-cols-2 gap-1.5"
|
|
267
277
|
>
|
|
268
|
-
<
|
|
269
|
-
v-
|
|
270
|
-
|
|
271
|
-
:
|
|
272
|
-
/>
|
|
273
|
-
<UInput
|
|
274
|
-
v-model="entry.alt_text"
|
|
275
|
-
size="xs"
|
|
276
|
-
:placeholder="t('mapo.altTag')"
|
|
277
|
-
/>
|
|
278
|
-
<UInput
|
|
279
|
-
v-model="entry.description"
|
|
280
|
-
size="xs"
|
|
281
|
-
:placeholder="t('mapo.description')"
|
|
282
|
-
/>
|
|
283
|
-
<USelect
|
|
284
|
-
v-model="entry.folder"
|
|
285
|
-
:items="folderOptions"
|
|
278
|
+
<UFormField
|
|
279
|
+
v-for="field in textFields"
|
|
280
|
+
:key="field.key"
|
|
281
|
+
:label="field.label"
|
|
286
282
|
size="xs"
|
|
287
|
-
|
|
288
|
-
|
|
283
|
+
>
|
|
284
|
+
<UInput v-model="entry[field.key]" class="w-full" />
|
|
285
|
+
</UFormField>
|
|
286
|
+
<UFormField :label="t('mapo.folder')" size="xs">
|
|
287
|
+
<USelect
|
|
288
|
+
v-model="entry.folder"
|
|
289
|
+
:items="folderOptions"
|
|
290
|
+
class="w-full"
|
|
291
|
+
/>
|
|
292
|
+
</UFormField>
|
|
289
293
|
</div>
|
|
290
294
|
|
|
291
295
|
<!-- Progress bar -->
|
|
@@ -8,6 +8,7 @@ import { useMapoT } from "@mapomodule/i18n/runtime/composables/useMapoT";
|
|
|
8
8
|
import { applyMultipartPolicy } from "@mapomodule/core/runtime/api/multipart";
|
|
9
9
|
import { useNuxtApp, useRuntimeConfig } from "#app";
|
|
10
10
|
import { defaultMediaAdapter } from "../adapters/defaultMediaAdapter.js";
|
|
11
|
+
import { languagesFromMetadata } from "../utils/langInfo.js";
|
|
11
12
|
import type {
|
|
12
13
|
MediaItem,
|
|
13
14
|
MediaFolder,
|
|
@@ -85,6 +86,14 @@ export const useMediaStore = defineStore("mapo-media", () => {
|
|
|
85
86
|
const _currentAll = ref(false);
|
|
86
87
|
const _currentLang = ref<string | undefined>(undefined);
|
|
87
88
|
|
|
89
|
+
// Language codes the media model is actually registered for, read once from
|
|
90
|
+
// the endpoint's OPTIONS. It lives here rather than in the editor because all
|
|
91
|
+
// three entry points — manager, picker dialog, and the `media` form field —
|
|
92
|
+
// mount their own editor, and each would otherwise need the host page to hand
|
|
93
|
+
// it a hardcoded list.
|
|
94
|
+
const languages = ref<string[]>([]);
|
|
95
|
+
let languagesPromise: Promise<void> | null = null;
|
|
96
|
+
|
|
88
97
|
// ─── Getters ──────────────────────────────────────────────────────────────
|
|
89
98
|
const parentFolder = computed(
|
|
90
99
|
() => parentFolders.value[parentFolders.value.length - 1] ?? null,
|
|
@@ -120,6 +129,27 @@ export const useMediaStore = defineStore("mapo-media", () => {
|
|
|
120
129
|
return useCrud<MediaFolder>(endpoints.folders);
|
|
121
130
|
}
|
|
122
131
|
|
|
132
|
+
/**
|
|
133
|
+
* Ask the media endpoint to describe its language situation, at most once.
|
|
134
|
+
*
|
|
135
|
+
* `lang_info` is served on OPTIONS only: it describes the model, so there is
|
|
136
|
+
* no record to read it from, and a media library nobody registered for
|
|
137
|
+
* translation reports none — which is the point. The in-flight promise is
|
|
138
|
+
* kept so several editors mounting at once share a single request.
|
|
139
|
+
*/
|
|
140
|
+
async function deriveLanguages(): Promise<void> {
|
|
141
|
+
if (languagesPromise) return languagesPromise;
|
|
142
|
+
languagesPromise = (async () => {
|
|
143
|
+
try {
|
|
144
|
+
languages.value = languagesFromMetadata(await mediaCrud().options());
|
|
145
|
+
} catch {
|
|
146
|
+
// A backend without OPTIONS metadata just gets no language switcher.
|
|
147
|
+
languagesPromise = null;
|
|
148
|
+
}
|
|
149
|
+
})();
|
|
150
|
+
return languagesPromise;
|
|
151
|
+
}
|
|
152
|
+
|
|
123
153
|
// ─── Breadcrumb maintenance ─────────────────────────────────────────────
|
|
124
154
|
// Driven by the response's `parent_folder` (matches the legacy contract):
|
|
125
155
|
// push when entering a new folder, slice when navigating back up.
|
|
@@ -445,12 +475,14 @@ export const useMediaStore = defineStore("mapo-media", () => {
|
|
|
445
475
|
selection,
|
|
446
476
|
editList,
|
|
447
477
|
selectMode,
|
|
478
|
+
languages,
|
|
448
479
|
// getters
|
|
449
480
|
parentFolder,
|
|
450
481
|
editListSet,
|
|
451
482
|
editListState,
|
|
452
483
|
// actions
|
|
453
484
|
getRoot,
|
|
485
|
+
deriveLanguages,
|
|
454
486
|
navigateToFolder,
|
|
455
487
|
openEditor,
|
|
456
488
|
closeEditor,
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
/** Defines a single column in the list table. */
|
|
2
2
|
export interface ListColumn<T = Record<string, unknown>> {
|
|
3
|
-
/**
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Property of the row to show, a key of `T`. A dotted path (`category.name`)
|
|
5
|
+
* reads a field of a related object; it starts with a key of `T`.
|
|
6
|
+
*/
|
|
7
|
+
key: (keyof T & string) | `${keyof T & string}.${string}`;
|
|
5
8
|
label: string;
|
|
9
|
+
/**
|
|
10
|
+
* Turns the header into a button that cycles ascending, descending and
|
|
11
|
+
* unsorted. The list sends the order to the backend as `ordering`, or sorts
|
|
12
|
+
* in memory in offline and hybrid mode.
|
|
13
|
+
*/
|
|
6
14
|
sortable?: boolean;
|
|
7
15
|
/** CSS class applied to the `<td>` cell. */
|
|
8
16
|
class?: string;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** One sort key as `UTable` holds it: the column id and the direction. */
|
|
2
|
+
export interface TableSort {
|
|
3
|
+
id: string;
|
|
4
|
+
desc: boolean;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The page size that stands for "all rows". A plain number, so the paging
|
|
9
|
+
* arithmetic and the in-memory slicing keep working unchanged.
|
|
10
|
+
*/
|
|
11
|
+
export const ALL_ROWS = Number.MAX_SAFE_INTEGER;
|
|
12
|
+
|
|
13
|
+
/** A `pageSizeOptions` entry as the table stores it: `"all"` → {@link ALL_ROWS}. */
|
|
14
|
+
export function toPageSize(option: number | "all"): number {
|
|
15
|
+
return option === "all" ? ALL_ROWS : option;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Reads `page_size` from the URL: `all`, or a positive number, else `fallback`. */
|
|
19
|
+
export function parsePageSize(value: unknown, fallback: number): number {
|
|
20
|
+
if (value === "all") return ALL_ROWS;
|
|
21
|
+
const size = Number(value);
|
|
22
|
+
return Number.isFinite(size) && size > 0 ? size : fallback;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Writes a page size to the URL: {@link ALL_ROWS} as `all`. */
|
|
26
|
+
export function formatPageSize(size: number): string {
|
|
27
|
+
return size === ALL_ROWS ? "all" : String(size);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The sorting after a click on a sortable header. The column goes from
|
|
32
|
+
* unsorted to ascending, to descending, and back to unsorted, so the natural
|
|
33
|
+
* order (needed by drag reorder) is one click away. It replaces any other key.
|
|
34
|
+
*/
|
|
35
|
+
export function nextSorting(
|
|
36
|
+
sorting: TableSort[],
|
|
37
|
+
columnId: string,
|
|
38
|
+
): TableSort[] {
|
|
39
|
+
const current = sorting.find((sort) => sort.id === columnId);
|
|
40
|
+
if (!current) return [{ id: columnId, desc: false }];
|
|
41
|
+
if (!current.desc) return [{ id: columnId, desc: true }];
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The `ordering` param for a sorting: comma-separated keys, `-` for descending.
|
|
47
|
+
* A dotted key becomes a Django lookup (`category.name` → `category__name`),
|
|
48
|
+
* the way DRF's OrderingFilter reaches a field of a related object.
|
|
49
|
+
*/
|
|
50
|
+
export function orderingParam(sorting: TableSort[]): string {
|
|
51
|
+
return sorting
|
|
52
|
+
.map((sort) => `${sort.desc ? "-" : ""}${sort.id.split(".").join("__")}`)
|
|
53
|
+
.join(",");
|
|
54
|
+
}
|