@motor-cms/ui-media 3.0.2 → 4.0.1

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.
@@ -8,6 +8,12 @@ import type {
8
8
  } from '@motor-cms/ui-core/app/types/grid'
9
9
  import type { FileResource } from '../../types/media'
10
10
 
11
+ export interface GallerySortOption {
12
+ label: string
13
+ field: string
14
+ direction: 'asc' | 'desc'
15
+ }
16
+
11
17
  const props = withDefaults(defineProps<{
12
18
  id: string
13
19
  fetch: (params: GridParams) => Promise<PaginatedResponse<FileResource>>
@@ -15,9 +21,11 @@ const props = withDefaults(defineProps<{
15
21
  bulkActions?: BulkActionDef[]
16
22
  searchable?: boolean
17
23
  perPage?: number
24
+ sortOptions?: GallerySortOption[]
18
25
  }>(), {
19
26
  searchable: true,
20
- perPage: 25
27
+ perPage: 25,
28
+ sortOptions: () => []
21
29
  })
22
30
 
23
31
  const emit = defineEmits<{
@@ -36,6 +44,26 @@ if (props.filters) {
36
44
  gridState.initFilters(props.filters.map(f => f.key))
37
45
  }
38
46
 
47
+ // Sort dropdown — option key is `${field}:${direction}`
48
+ function sortKey(opt: GallerySortOption): string {
49
+ return `${opt.field}:${opt.direction}`
50
+ }
51
+ const sortSelectItems = computed(() =>
52
+ props.sortOptions.map(opt => ({ label: opt.label, value: sortKey(opt) }))
53
+ )
54
+ const activeSortKey = computed(() => {
55
+ const field = gridState.state.sort
56
+ if (!field) {
57
+ // Pick the first option as the visible default so the dropdown isn't empty
58
+ return props.sortOptions[0] ? sortKey(props.sortOptions[0]) : ''
59
+ }
60
+ return `${field}:${gridState.state.direction}`
61
+ })
62
+ function onSortChange(value: string): void {
63
+ const opt = props.sortOptions.find(o => sortKey(o) === value)
64
+ if (opt) gridState.setSort(opt.field, opt.direction)
65
+ }
66
+
39
67
  // Accumulated items + internal pagination
40
68
  const items = ref<FileResource[]>([])
41
69
  const currentPage = ref(0)
@@ -189,6 +217,16 @@ useIntersectionObserver(
189
217
  @reset-filters="gridState.resetFilters()"
190
218
  >
191
219
  <template #toolbar-extra>
220
+ <USelect
221
+ v-if="sortOptions.length > 0"
222
+ :model-value="activeSortKey"
223
+ :items="sortSelectItems"
224
+ value-key="value"
225
+ label-key="label"
226
+ :aria-label="t('motor-core.grid.sort')"
227
+ class="w-44"
228
+ @update:model-value="onSortChange"
229
+ />
192
230
  <span
193
231
  v-if="totalItems > 0"
194
232
  class="text-sm text-muted whitespace-nowrap"
@@ -3,7 +3,7 @@
3
3
  "file": "Datei",
4
4
  "title": "Dateien",
5
5
  "subtitle": "Dateien verwalten",
6
- "add": "Datei hinzufuegen",
6
+ "add": "Datei hinzufügen",
7
7
  "create_title": "Dateien hochladen",
8
8
  "edit_title": "Datei bearbeiten",
9
9
  "view_title": "Datei ansehen",
@@ -19,22 +19,22 @@
19
19
  "categories": "Kategorien",
20
20
  "client_id": "Mandant",
21
21
  "is_global": "Global",
22
- "is_excluded_from_search_index": "Vom Suchindex ausschliessen",
22
+ "is_excluded_from_search_index": "Vom Suchindex ausschließen",
23
23
  "group_basic": "Allgemein",
24
24
  "group_categories": "Kategorien",
25
25
  "group_settings": "Einstellungen",
26
- "drop_files": "Dateien hierher ziehen oder klicken zum Auswaehlen",
26
+ "drop_files": "Dateien hierher ziehen oder klicken zum Auswählen",
27
27
  "browse": "Durchsuchen",
28
- "pending_files": "Ausgewaehlte Dateien",
29
- "no_files_selected": "Keine Dateien ausgewaehlt",
28
+ "pending_files": "Ausgewählte Dateien",
29
+ "no_files_selected": "Keine Dateien ausgewählt",
30
30
  "current_file": "Aktuelle Datei",
31
31
  "replace_file": "Datei ersetzen",
32
32
  "url_copied": "URL in die Zwischenablage kopiert",
33
33
  "copy_url": "URL kopieren",
34
34
  "preview": "Vorschau",
35
35
  "upload_progress": "Lade Datei {current} von {total} hoch...",
36
- "categories_required": "Bitte mindestens eine Kategorie auswaehlen",
37
- "files_required": "Bitte mindestens eine Datei auswaehlen",
36
+ "categories_required": "Bitte mindestens eine Kategorie auswählen",
37
+ "files_required": "Bitte mindestens eine Datei auswählen",
38
38
  "view_gallery": "Galerie-Ansicht",
39
39
  "view_table": "Tabellen-Ansicht",
40
40
  "all_loaded": "Alle Dateien geladen",
@@ -76,6 +76,11 @@ const bulkActions: BulkActionDef[] = [
76
76
  ]
77
77
 
78
78
  const fetchFiles = useGridFetch<File>('/api/v2/files')
79
+
80
+ const gallerySortOptions = computed(() => [
81
+ { label: t('motor-core.grid.sort_newest_first'), field: 'created_at', direction: 'desc' as const },
82
+ { label: t('motor-core.grid.sort_oldest_first'), field: 'created_at', direction: 'asc' as const }
83
+ ])
79
84
  </script>
80
85
 
81
86
  <template>
@@ -125,6 +130,7 @@ const fetchFiles = useGridFetch<File>('/api/v2/files')
125
130
  :filters="filters"
126
131
  :bulk-actions="bulkActions"
127
132
  :per-page="25"
133
+ :sort-options="gallerySortOptions"
128
134
  @show-usage="openUsageModal"
129
135
  >
130
136
  <template #empty-action>
@@ -7,12 +7,12 @@ export const fileMeta = {
7
7
  schemaName: 'FileResource',
8
8
  fields: {
9
9
  id: { type: 'integer', renderer: 'number', hideable: false },
10
- client_id: { type: 'string' },
10
+ client_id: { type: 'integer', renderer: 'number' },
11
11
  client: { type: 'ref', renderer: 'text', ref: 'ClientResource', labelKey: 'name' },
12
12
  description: { type: 'string' },
13
13
  author: { type: 'string' },
14
14
  source: { type: 'string' },
15
- is_global: { type: 'boolean', renderer: 'boolean' },
15
+ is_global: { type: 'integer', renderer: 'number' },
16
16
  alt_text: { type: 'string' },
17
17
  file: { type: 'unknown' },
18
18
  categories: { type: 'ref[]', renderer: 'list', ref: 'CategoryResource', labelKey: 'name' },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@motor-cms/ui-media",
3
- "version": "3.0.2",
3
+ "version": "4.0.1",
4
4
  "type": "module",
5
5
  "main": "./nuxt.config.ts",
6
6
  "files": [
@@ -13,7 +13,7 @@
13
13
  "@vueuse/core": "^14.0.0"
14
14
  },
15
15
  "peerDependencies": {
16
- "@motor-cms/ui-core": ">=3.0.2",
16
+ "@motor-cms/ui-core": ">=4.0.0",
17
17
  "nuxt": "^4.0.0",
18
18
  "vue": "^3.5.0"
19
19
  }