adminforth 2.26.0-test.4 → 2.26.0

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.
Files changed (44) hide show
  1. package/dist/dataConnectors/baseConnector.d.ts.map +1 -1
  2. package/dist/dataConnectors/baseConnector.js +4 -8
  3. package/dist/dataConnectors/baseConnector.js.map +1 -1
  4. package/dist/dataConnectors/clickhouse.js +1 -1
  5. package/dist/dataConnectors/clickhouse.js.map +1 -1
  6. package/dist/dataConnectors/mysql.js +1 -1
  7. package/dist/dataConnectors/mysql.js.map +1 -1
  8. package/dist/dataConnectors/qdrant.d.ts +57 -0
  9. package/dist/dataConnectors/qdrant.d.ts.map +1 -0
  10. package/dist/dataConnectors/qdrant.js +469 -0
  11. package/dist/dataConnectors/qdrant.js.map +1 -0
  12. package/dist/dataConnectors/sqlite.d.ts.map +1 -1
  13. package/dist/dataConnectors/sqlite.js +0 -2
  14. package/dist/dataConnectors/sqlite.js.map +1 -1
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +22 -33
  17. package/dist/index.js.map +1 -1
  18. package/dist/modules/configValidator.d.ts.map +1 -1
  19. package/dist/modules/configValidator.js +3 -2
  20. package/dist/modules/configValidator.js.map +1 -1
  21. package/dist/modules/restApi.d.ts.map +1 -1
  22. package/dist/modules/restApi.js +8 -15
  23. package/dist/modules/restApi.js.map +1 -1
  24. package/dist/modules/utils.d.ts +6 -0
  25. package/dist/modules/utils.d.ts.map +1 -1
  26. package/dist/modules/utils.js +13 -0
  27. package/dist/modules/utils.js.map +1 -1
  28. package/dist/spa/src/components/BreadcrumbsWithButtons.vue +4 -5
  29. package/dist/spa/src/components/ListActionsThreeDots.vue +1 -1
  30. package/dist/spa/src/components/ResourceListTable.vue +271 -124
  31. package/dist/spa/src/components/Sidebar.vue +5 -1
  32. package/dist/spa/src/components/ThreeDotsMenu.vue +2 -2
  33. package/dist/spa/src/renderers/CountryFlag.vue +2 -2
  34. package/dist/spa/src/types/Back.ts +17 -3
  35. package/dist/spa/src/types/Common.ts +12 -0
  36. package/dist/spa/src/views/ListView.vue +4 -38
  37. package/dist/spa/src/views/PageNotFound.vue +5 -1
  38. package/dist/types/Back.d.ts +19 -2
  39. package/dist/types/Back.d.ts.map +1 -1
  40. package/dist/types/Back.js.map +1 -1
  41. package/dist/types/Common.d.ts.map +1 -1
  42. package/dist/types/Common.js.map +1 -1
  43. package/package.json +2 -1
  44. package/dist/spa/src/components/ResourceListTableVirtual.vue +0 -789
@@ -1,789 +0,0 @@
1
- <template>
2
- <!-- table -->
3
- <div class="relative shadow-listTableShadow dark:shadow-darkListTableShadow overflow-auto "
4
- :class="{'rounded-default': !noRoundings}"
5
- :style="{ maxHeight: `${containerHeight}px` }"
6
- @scroll="handleScroll"
7
- ref="containerRef"
8
- >
9
- <!-- skelet loader -->
10
- <div role="status" v-if="!resource || !resource.columns"
11
- class="max-w p-4 space-y-4 divide-y divide-gray-200 rounded shadow animate-pulse dark:divide-gray-700 md:p-6 dark:border-gray-700">
12
-
13
- <div role="status" class="max-w-sm animate-pulse">
14
- <div class="h-2 bg-lightListSkeletLoader rounded-full dark:bg-darkListSkeletLoader max-w-[360px]"></div>
15
- </div>
16
- </div>
17
- <table v-else class="w-full text-sm text-left rtl:text-right text-lightListTableText dark:text-darkListTableText rounded-default">
18
-
19
- <tbody>
20
- <!-- table header -->
21
- <tr class="t-header sticky z-20 top-0 text-xs text-lightListTableHeadingText bg-lightListTableHeading dark:bg-darkListTableHeading dark:text-darkListTableHeadingText">
22
- <td scope="col" class="list-table-header-cell p-4 sticky-column bg-lightListTableHeading dark:bg-darkListTableHeading">
23
- <Checkbox
24
- :modelValue="allFromThisPageChecked"
25
- :disabled="!rows || !rows.length"
26
- @update:modelValue="selectAll"
27
- >
28
- <span class="sr-only">{{ $t('checkbox') }}</span>
29
- </Checkbox>
30
- </td>
31
-
32
- <td v-for="c in columnsListed" ref="headerRefs" scope="col" class="list-table-header-cell px-2 md:px-3 lg:px-6 py-3" :class="{'sticky-column bg-lightListTableHeading dark:bg-darkListTableHeading': c.listSticky}">
33
-
34
- <div @click="(evt) => c.sortable && onSortButtonClick(evt, c.name)"
35
- class="flex items-center " :class="{'cursor-pointer':c.sortable}">
36
- {{ c.label }}
37
-
38
- <div v-if="c.sortable">
39
- <svg v-if="ascArr.includes(c.name) || descArr.includes(c.name)" class="w-3 h-3 ms-1.5"
40
- fill='currentColor'
41
- :class="{'rotate-180':descArr.includes(c.name)}" viewBox="0 0 24 24">
42
- <path
43
- d="M8.574 11.024h6.852a2.075 2.075 0 0 0 1.847-1.086 1.9 1.9 0 0 0-.11-1.986L13.736 2.9a2.122 2.122 0 0 0-3.472 0L6.837 7.952a1.9 1.9 0 0 0-.11 1.986 2.074 2.074 0 0 0 1.847 0z"/>
44
- </svg>
45
- <svg v-else class="w-3 h-3 ms-1.5 opacity-30" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"
46
- fill='currentColor'
47
- viewBox="0 0 24 24">
48
- <path
49
- d="M8.574 11.024h6.852a2.075 2.075 0 0 0 1.847-1.086 1.9 1.9 0 0 0-.11-1.986L13.736 2.9a2.122 2.122 0 0 0-3.472 0L6.837 7.952a1.9 1.9 0 0 0-.11 1.986 2.074 2.074 0 0 0 1.847 1.086Zm6.852 1.952H8.574a2.072 2.072 0 0 0-1.847 1.087 1.9 1.9 0 0 0 .11 1.985l3.426 5.05a2.123 2.123 0 0 0 3.472 0l3.427-5.05a1.9 1.9 0 0 0 .11-1.985 2.074 2.074 0 0 0-1.846-1.087Z"/>
50
- </svg>
51
- </div>
52
- <span
53
- class="bg-red-100 text-red-800 text-xs font-medium me-1 px-1 py-0.5 rounded dark:bg-gray-700 dark:text-red-400 border border-red-400"
54
- v-if="sort.findIndex((s: any) => s.field === c.name) !== -1 && sort?.length > 1">
55
- {{ sort.findIndex((s: any) => s.field === c.name) + 1 }}
56
- </span>
57
-
58
- </div>
59
- </td>
60
-
61
- <td scope="col" class="px-6 py-3">
62
- {{ $t('Actions') }}
63
- </td>
64
- </tr>
65
- <tr v-for="c in tableBodyStartInjection" :key="c.id" class="align-top border-b border-lightListBorder dark:border-darkListBorder dark:bg-darkListTable">
66
- <component :is="getCustomComponent(c)" :meta="c.meta" :resource="resource" :adminUser="coreStore.adminUser" />
67
- </tr>
68
- <!-- table header end -->
69
- <SkeleteLoader
70
- v-if="!rows"
71
- :columns="resource?.columns.filter((c: AdminForthResourceColumnCommon) => c.showIn?.list).length + 2"
72
- :rows="rowHeights.length || 3"
73
- :row-heights="rowHeights"
74
- :column-widths="columnWidths"
75
- />
76
-
77
- <tr v-else-if="rows.length === 0" class="bg-lightListTable dark:bg-darkListTable dark:border-darkListTableBorder">
78
- <td :colspan="resource?.columns.length + 2">
79
-
80
- <div id="toast-simple"
81
- class=" mx-auto my-5 flex items-center w-full max-w-xs p-4 space-x-4 rtl:space-x-reverse text-gray-500 divide-x rtl:divide-x-reverse divide-gray-200 dark:text-gray-400 dark:divide-gray-700 space-x dark:bg-gray-800"
82
- role="alert">
83
- <IconInboxOutline class="w-6 h-6 text-gray-500 dark:text-gray-400"/>
84
- <div class="ps-4 text-sm font-normal">{{ $t('No items here yet') }}</div>
85
- </div>
86
-
87
- </td>
88
- </tr>
89
-
90
- <!-- Virtual scroll spacer -->
91
- <tr v-if="spacerHeight > 0">
92
- <td :colspan="resource?.columns.length + 2" :style="{ height: `${spacerHeight}px` }"></td>
93
- </tr>
94
-
95
- <!-- Visible rows -->
96
- <component
97
- v-for="(row, rowI) in visibleRows"
98
- :is="tableRowReplaceInjection ? getCustomComponent(tableRowReplaceInjection) : 'tr'"
99
- :key="`row_${row._primaryKeyValue}`"
100
- :record="row"
101
- :resource="resource"
102
- :adminUser="coreStore.adminUser"
103
- :meta="tableRowReplaceInjection ? tableRowReplaceInjection.meta : undefined"
104
- @click="onClick($event, row)"
105
- ref="rowRefs"
106
- class="list-table-body-row bg-lightListTable dark:bg-darkListTable border-lightListBorder dark:border-gray-700 hover:bg-lightListTableRowHover dark:hover:bg-darkListTableRowHover"
107
- :class="{'border-b': rowI !== visibleRows.length - 1, 'cursor-pointer': row._clickUrl !== null}"
108
- @mounted="(el: any) => updateRowHeight(`row_${row._primaryKeyValue}`, el.offsetHeight)"
109
- >
110
- <td class="w-4 p-4 cursor-default sticky-column bg-lightListTable dark:bg-darkListTable" @click="(e)=>e.stopPropagation()">
111
- <Checkbox
112
- :model-value="checkboxesInternal.includes(row._primaryKeyValue)"
113
- @change="(e: any)=>{addToCheckedValues(row._primaryKeyValue)}"
114
- @click="(e: any)=>e.stopPropagation()"
115
- >
116
- <span class="sr-only">{{ $t('checkbox') }}</span>
117
- </Checkbox>
118
- </td>
119
- <td v-for="c in columnsListed" class="px-2 md:px-3 lg:px-6 py-4" :class="{'sticky-column bg-lightListTable dark:bg-darkListTable': c.listSticky}">
120
- <!-- if c.name in listComponentsPerColumn, render it. If not, render ValueRenderer -->
121
- <component
122
- :is="c?.components?.list ? getCustomComponent(typeof c.components.list === 'string' ? { file: c.components.list } : c.components.list) : ValueRenderer"
123
- :meta="typeof c?.components?.list === 'object' ? c.components.list.meta : undefined"
124
- :column="c"
125
- :record="row"
126
- :adminUser="coreStore.adminUser"
127
- :resource="resource"
128
- />
129
- </td>
130
- <td class=" items-center px-2 md:px-3 lg:px-6 py-4 cursor-default" @click="(e)=>{e.stopPropagation()}">
131
- <div class="flex text-lightPrimary dark:text-darkPrimary items-center gap-2">
132
- <Tooltip v-if="resource.options?.baseActionsAsQuickIcons && resource.options?.baseActionsAsQuickIcons.includes('show')">
133
- <RouterLink
134
- v-if="resource.options?.allowedActions?.show"
135
- :to="{
136
- name: 'resource-show',
137
- params: {
138
- resourceId: resource.resourceId,
139
- primaryKey: row._primaryKeyValue,
140
- }
141
- }"
142
-
143
- >
144
- <IconEyeSolid class="af-show-icon w-5 h-5 me-2"/>
145
- </RouterLink>
146
-
147
- <template v-slot:tooltip>
148
- {{ $t('Show item') }}
149
- </template>
150
- </Tooltip>
151
- <Tooltip v-if="resource.options?.baseActionsAsQuickIcons && resource.options?.baseActionsAsQuickIcons.includes('edit')" >
152
- <RouterLink
153
- v-if="resource.options?.allowedActions?.edit"
154
- :to="{
155
- name: 'resource-edit',
156
- params: {
157
- resourceId: resource.resourceId,
158
- primaryKey: row._primaryKeyValue,
159
- }
160
- }"
161
- >
162
- <IconPenSolid class="af-edit-icon w-5 h-5 me-2"/>
163
- </RouterLink>
164
- <template v-slot:tooltip>
165
- {{ $t('Edit item') }}
166
- </template>
167
- </Tooltip>
168
- <Tooltip v-if="resource.options?.baseActionsAsQuickIcons && resource.options?.baseActionsAsQuickIcons.includes('delete')">
169
- <button
170
- v-if="resource.options?.allowedActions?.delete"
171
- @click="deleteRecord(row)"
172
- >
173
- <IconTrashBinSolid class="af-delete-icon w-5 h-5 me-2"/>
174
- </button>
175
-
176
- <template v-slot:tooltip>
177
- {{ $t('Delete item') }}
178
- </template>
179
- </Tooltip>
180
- <template v-if="customActionsInjection">
181
- <component
182
- v-for="c in customActionsInjection"
183
- :is="getCustomComponent(c)"
184
- :meta="c.meta"
185
- :resource="coreStore.resource"
186
- :adminUser="coreStore.adminUser"
187
- :record="row"
188
- :updateRecords="()=>emits('update:records', true)"
189
- />
190
- </template>
191
- <template v-if="resource.options?.actions">
192
- <Tooltip
193
- v-for="action in resource.options.actions.filter(a => a.showIn?.list)"
194
- :key="action.id"
195
- >
196
- <CallActionWrapper
197
- :disabled="rowActionLoadingStates?.[action.id]"
198
- @callAction="startCustomAction(action.id, row)"
199
- >
200
- <component
201
- :is="action.customComponent ? getCustomComponent(action.customComponent) : 'span'"
202
- :meta="action.customComponent?.meta"
203
- :row="row"
204
- :resource="resource"
205
- :adminUser="adminUser"
206
- @callAction="(payload? : Object) => startCustomAction(action.id, row, payload )"
207
- >
208
- <button
209
- type="button"
210
- class="border border-gray-300 dark:border-gray-700 dark:border-opacity-0 border-opacity-0 hover:border-opacity-100 dark:hover:border-opacity-100 rounded-md hover:bg-gray-100 dark:hover:bg-gray-800 cursor-pointer"
211
- :disabled="rowActionLoadingStates?.[action.id]"
212
- >
213
- <component
214
- v-if="action.icon"
215
- :is="getIcon(action.icon)"
216
- class="w-6 h-6 text-lightPrimary dark:text-darkPrimary"
217
- />
218
- </button>
219
- </component>
220
- </CallActionWrapper>
221
-
222
- <template #tooltip>
223
- {{ action.name }}
224
- </template>
225
- </Tooltip>
226
- </template>
227
- <ListActionsThreeDots
228
- v-if="showListActionsThreeDots"
229
- :resourceOptions="resource?.options"
230
- :record="row"
231
- :updateRecords="()=>emits('update:records', true)"
232
- :deleteRecord="deleteRecord"
233
- :resourceId="resource.resourceId"
234
- :startCustomAction="startCustomAction"
235
- :customActionIconsThreeDotsMenuItems="customActionIconsThreeDotsMenuItems"
236
- />
237
- </div>
238
- </td>
239
- </component>
240
-
241
- <!-- Bottom spacer -->
242
- <tr v-if="totalHeight > 0">
243
- <td :colspan="resource?.columns.length + 2"
244
- :style="{ height: `${Math.max(0, totalHeight - (endIndex + 1) * (props.itemHeight || 52.5))}px` }">
245
- </td>
246
- </tr>
247
- </tbody>
248
- </table>
249
- </div>
250
- <!-- pagination
251
- totalRows in v-if is used to not hide page input during loading when user puts cursor into it and edit directly (rows gets null there during edit)
252
- -->
253
- <div class="af-pagination-container flex flex-row items-center mt-4 xs:flex-row xs:justify-between xs:items-center gap-3">
254
-
255
- <div class="af-pagination-buttons-container inline-flex "
256
- v-if="(rows || totalRows) && totalRows >= pageSize && totalRows > 0"
257
- >
258
- <!-- Buttons -->
259
- <button
260
- class="af-pagination-prev-button flex items-center py-1 px-3 gap-1 text-sm font-medium text-lightListTablePaginationText focus:outline-none bg-lightListTablePaginationBackgoround border-r-0 rounded-s border border-lightListTablePaginationBorder hover:bg-lightListTablePaginationBackgoroundHover hover:text-lightListTablePaginationTextHover focus:z-10 focus:ring-4 focus:ring-lightListTablePaginationFocusRing dark:focus:ring-darkListTablePaginationFocusRing dark:bg-darkListTablePaginationBackgoround dark:text-darkListTablePaginationText dark:border-darkListTablePaginationBorder dark:hover:text-darkListTablePaginationTextHover dark:hover:bg-darkListTablePaginationBackgoroundHover disabled:opacity-50"
261
- @click="page--; pageInput = page.toString();" :disabled="page <= 1">
262
- <svg class="w-3.5 h-3.5 rtl:rotate-180" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none"
263
- viewBox="0 0 14 10">
264
- <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
265
- d="M13 5H1m0 0 4 4M1 5l4-4"/>
266
- </svg>
267
- <span class="hidden sm:inline">
268
- {{ $t('Prev') }}
269
- </span>
270
- </button>
271
- <button
272
- class="af-pagination-first-page-button flex items-center py-1 px-3 text-sm font-medium text-lightListTablePaginationText focus:outline-none bg-lightListTablePaginationBackgoround border-r-0 border border-lightListTablePaginationBorder hover:bg-lightListTablePaginationBackgoroundHover hover:text-lightListTablePaginationTextHover focus:z-10 focus:ring-4 focus:ring-lightListTablePaginationFocusRing dark:focus:ring-darkListTablePaginationFocusRing dark:bg-darkListTablePaginationBackgoround dark:text-darkListTablePaginationText dark:border-darkListTablePaginationBorder dark:hover:text-darkListTablePaginationTextHover dark:hover:bg-darkListTablePaginationBackgoroundHover disabled:opacity-50"
273
- @click="page = 1; pageInput = page.toString();" :disabled="page <= 1">
274
- <!-- <IconChevronDoubleLeftOutline class="w-4 h-4" /> -->
275
- 1
276
- </button>
277
- <input
278
- type="text"
279
- v-model="pageInput"
280
- :style="{ width: `${Math.max(1, pageInput.length+4)}ch` }"
281
- class="af-pagination-input min-w-10 outline-none inline-block py-1.5 px-3 text-sm text-center text-lightListTablePaginationCurrentPageText border border-lightListTablePaginationBorder dark:border-darkListTablePaginationBorder dark:text-darkListTablePaginationCurrentPageText dark:bg-darkListTablePaginationBackgoround z-10"
282
- @keydown="onPageKeydown($event)"
283
- @blur="validatePageInput()"
284
- />
285
-
286
- <button
287
- class="af-pagination-last-page-button flex items-center py-1 px-3 text-sm font-medium text-lightListTablePaginationText focus:outline-none bg-lightListTablePaginationBackgoround border-l-0 border border-lightListTablePaginationBorder hover:bg-lightListTablePaginationBackgoroundHover hover:text-lightListTablePaginationTextHover focus:z-10 focus:ring-4 focus:ring-lightListTablePaginationFocusRing dark:focus:ring-darkListTablePaginationFocusRing dark:bg-darkListTablePaginationBackgoround dark:text-darkListTablePaginationText dark:border-darkListTablePaginationBorder dark:hover:text-white dark:hover:bg-darkListTablePaginationBackgoroundHover disabled:opacity-50"
288
- @click="page = totalPages; pageInput = page.toString();" :disabled="page >= totalPages">
289
- {{ totalPages }}
290
-
291
- <!-- <IconChevronDoubleRightOutline class="w-4 h-4" /> -->
292
- </button>
293
- <button
294
- class="af-pagination-next-button flex items-center py-1 px-3 gap-1 text-sm font-medium text-lightListTablePaginationText focus:outline-none bg-lightListTablePaginationBackgoround border-l-0 rounded-e border border-lightListTablePaginationBorder hover:bg-lightListTablePaginationBackgoroundHover hover:text-lightListTablePaginationTextHover focus:z-10 focus:ring-4 focus:ring-lightListTablePaginationFocusRing dark:focus:ring-darkListTablePaginationFocusRing dark:bg-darkListTablePaginationBackgoround dark:text-darkListTablePaginationText dark:border-darkListTablePaginationBorder dark:hover:text-white dark:hover:bg-darkListTablePaginationBackgoroundHover disabled:opacity-50"
295
- @click="page++; pageInput = page.toString();" :disabled="page >= totalPages">
296
- <span class="hidden sm:inline">{{ $t('Next') }}</span>
297
- <svg class="w-3.5 h-3.5 rtl:rotate-180" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none"
298
- viewBox="0 0 14 10">
299
- <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
300
- d="M1 5h12m0 0L9 1m4 4L9 9"/>
301
- </svg>
302
- </button>
303
- </div>
304
-
305
- <!-- Help text -->
306
- <span class="ml-4 text-sm text-lightListTablePaginationHelpText dark:text-darkListTablePaginationHelpText">
307
- <span v-if="((((page || 1) - 1) * pageSize + 1 > totalRows) && totalRows > 0)">{{ $t('Wrong Page') }} </span>
308
- <template v-else-if="resource && totalRows > 0">
309
-
310
- <span class="af-pagination-info hidden sm:inline">
311
- <i18n-t keypath="Showing {from} to {to} of {total} Entries" tag="p" >
312
- <template v-slot:from>
313
- <strong>{{ from }}</strong>
314
- </template>
315
- <template v-slot:to>
316
- <strong>{{ to }}</strong>
317
- </template>
318
- <template v-slot:total>
319
- <strong>{{ totalRows }}</strong>
320
- </template>
321
- </i18n-t>
322
- </span>
323
- <span class="sm:hidden">
324
- <i18n-t keypath="{from} - {to} of {total}" tag="p" >
325
- <template v-slot:from>
326
- <strong>{{ from }}</strong>
327
- </template>
328
- <template v-slot:to>
329
- <strong>{{ to }}</strong>
330
- </template>
331
- <template v-slot:total>
332
- <strong>{{ totalRows }}</strong>
333
- </template>
334
- </i18n-t>
335
- </span>
336
- </template>
337
- </span>
338
- </div>
339
- </template>
340
-
341
- <script setup lang="ts">
342
-
343
-
344
- import { computed, onMounted, ref, watch, useTemplateRef, nextTick, type Ref } from 'vue';
345
- import { callAdminForthApi } from '@/utils';
346
- import { useI18n } from 'vue-i18n';
347
- import ValueRenderer from '@/components/ValueRenderer.vue';
348
- import { getCustomComponent } from '@/utils';
349
- import { useCoreStore } from '@/stores/core';
350
- import { showSuccesTost, showErrorTost } from '@/composables/useFrontendApi';
351
- import SkeleteLoader from '@/components/SkeleteLoader.vue';
352
- import { getIcon } from '@/utils';
353
- import {
354
- IconEyeSolid,
355
- IconPenSolid,
356
- IconTrashBinSolid,
357
- IconInboxOutline
358
- } from '@iconify-prerendered/vue-flowbite';
359
- import router from '@/router';
360
- import { Tooltip } from '@/afcl';
361
- import type { AdminForthResourceCommon, AdminForthResourceColumnCommon, AdminForthComponentDeclarationFull } from '@/types/Common';
362
- import { useAdminforth } from '@/adminforth';
363
- import Checkbox from '@/afcl/Checkbox.vue';
364
- import ListActionsThreeDots from '@/components/ListActionsThreeDots.vue';
365
- import CallActionWrapper from '@/components/CallActionWrapper.vue'
366
-
367
- const coreStore = useCoreStore();
368
- const { t } = useI18n();
369
- const { alert, confirm } = useAdminforth();
370
- const props = defineProps<{
371
- page: number,
372
- resource: AdminForthResourceCommon | null,
373
- rows: any[] | null,
374
- totalRows: number,
375
- pageSize: number,
376
- checkboxes: any[],
377
- sort: any[],
378
- noRoundings?: boolean,
379
- customActionsInjection?: any[],
380
- tableBodyStartInjection?: any[],
381
- containerHeight?: number,
382
- itemHeight?: number,
383
- bufferSize?: number,
384
- customActionIconsThreeDotsMenuItems?: any[]
385
- tableRowReplaceInjection?: AdminForthComponentDeclarationFull
386
- }>();
387
-
388
- // emits, update page
389
- const emits = defineEmits([
390
- 'update:page',
391
- 'update:sort',
392
- 'update:checkboxes',
393
- 'update:records'
394
-
395
- ]);
396
-
397
- const checkboxesInternal: Ref<any[]> = ref([]);
398
- const pageInput = ref('1');
399
- const page = ref(1);
400
- const sort: Ref<Array<{field: string, direction: string}>> = ref([]);
401
-
402
- const showListActionsThreeDots = computed(() => {
403
- return props.resource?.options?.actions?.some(a => a.showIn?.listThreeDotsMenu) // show if any action is set to show in three dots menu
404
- || (props.customActionIconsThreeDotsMenuItems && props.customActionIconsThreeDotsMenuItems.length > 0) // or if there are custom action icons for three dots menu
405
- || !props.resource?.options.baseActionsAsQuickIcons // or if there is no baseActionsAsQuickIcons
406
- || (props.resource?.options.baseActionsAsQuickIcons && props.resource?.options.baseActionsAsQuickIcons.length < 3) // if there all 3 base actions are shown as quick icons - hide three dots icon
407
- })
408
-
409
- const from = computed(() => ((page.value || 1) - 1) * props.pageSize + 1);
410
- const to = computed(() => Math.min((page.value || 1) * props.pageSize, props.totalRows));
411
-
412
- watch(() => page.value, (newPage) => {
413
- emits('update:page', newPage);
414
- });
415
- async function onPageKeydown(event: any) {
416
- // page input should accept only numbers, arrow keys and backspace
417
- if (['Enter', 'Space'].includes(event.code) ||
418
- (!['Backspace', 'ArrowRight', 'ArrowLeft'].includes(event.code)
419
- && isNaN(Number(String.fromCharCode(event.keyCode || 0))))) {
420
- event.preventDefault();
421
- if (event.code === 'Enter') {
422
- validatePageInput();
423
- event.target.blur();
424
- }
425
- }
426
- }
427
-
428
- watch(() => sort.value, (newSort) => {
429
- emits('update:sort', newSort);
430
- });
431
-
432
- watch(() => checkboxesInternal.value, (newCheckboxes) => {
433
- emits('update:checkboxes', newCheckboxes);
434
- });
435
-
436
- watch(() => props.checkboxes, (newCheckboxes) => {
437
- checkboxesInternal.value = newCheckboxes;
438
- });
439
-
440
- watch(() => props.sort, (newSort: any) => {
441
- sort.value = newSort;
442
- });
443
-
444
- watch(() => props.page, (newPage) => {
445
- // page.value and newPage will not be equal only on page load
446
- // this check prevents cursor jumping on manual input
447
- if (page.value !== newPage) pageInput.value = newPage.toString();
448
- page.value = newPage;
449
- });
450
-
451
- const rowRefs = useTemplateRef<HTMLElement[]>('rowRefs');
452
- const headerRefs = useTemplateRef<HTMLElement[]>('headerRefs');
453
- const rowHeights = ref<number[]>([]);
454
- const columnWidths = ref<number[]>([]);
455
- watch(() => props.rows, (newRows) => {
456
- // rows are set to null when new records are loading
457
- rowHeights.value = newRows || !rowRefs.value ? [] : rowRefs.value.map((el: HTMLElement) => el.offsetHeight);
458
- columnWidths.value = newRows || !headerRefs.value ? [] : [48, ...headerRefs.value.map((el: HTMLElement) => el.offsetWidth)];
459
- });
460
-
461
- function addToCheckedValues(id: string | number) {
462
- if (checkboxesInternal.value.includes(id)) {
463
- checkboxesInternal.value = checkboxesInternal.value.filter((item) => item !== id);
464
- } else {
465
- checkboxesInternal.value.push(id);
466
- }
467
- checkboxesInternal.value = [ ...checkboxesInternal.value ]
468
- }
469
-
470
- const columnsListed = computed(() => props.resource?.columns?.filter((c: AdminForthResourceColumnCommon) => c.showIn?.list));
471
-
472
- async function selectAll() {
473
- if (!allFromThisPageChecked.value) {
474
- props.rows?.forEach((r) => {
475
- if (!checkboxesInternal.value.includes(r._primaryKeyValue)) {
476
- checkboxesInternal.value.push(r._primaryKeyValue)
477
- }
478
- });
479
- } else {
480
- props.rows?.forEach((r) => {
481
- checkboxesInternal.value = checkboxesInternal.value.filter((item) => item !== r._primaryKeyValue);
482
- });
483
- }
484
- checkboxesInternal.value = [ ...checkboxesInternal.value ];
485
- }
486
-
487
- const totalPages = computed(() => Math.ceil(props.totalRows / props.pageSize));
488
-
489
- const allFromThisPageChecked = computed(() => {
490
- if (!props.rows || !props.rows.length) return false;
491
- return props.rows.every((r) => checkboxesInternal.value.includes(r._primaryKeyValue));
492
- });
493
- const ascArr = computed(() => sort.value.filter((s: any) => s.direction === 'asc').map((s: any) => s.field));
494
- const descArr = computed(() => sort.value.filter((s: any) => s.direction === 'desc').map((s: any) => s.field));
495
-
496
-
497
- function onSortButtonClick(event: any, field: string) {
498
- // if ctrl key is pressed, add to sort otherwise sort by this field
499
- // in any case if field is already in sort, toggle direction
500
-
501
- const sortIndex = sort.value.findIndex((s: any) => s.field === field);
502
- if (sortIndex === -1) {
503
- // field is not in sort, add it
504
- if (event.ctrlKey) {
505
- sort.value = [...sort.value,{field, direction: 'asc'}];
506
- } else {
507
- sort.value = [{field, direction: 'asc'}];
508
- }
509
- } else {
510
- const sortField = sort.value[sortIndex];
511
- if (sortField.direction === 'asc') {
512
- sort.value = sort.value.map((s) => s.field === field ? {field, direction: 'desc'} : s);
513
- } else {
514
- sort.value = sort.value.filter((s) => s.field !== field);
515
- }
516
- }
517
- }
518
-
519
-
520
- const clickTarget = ref(null);
521
-
522
- async function onClick(e: any, row: any) {
523
- if(clickTarget.value === e.target) return;
524
- clickTarget.value = e.target;
525
- await new Promise((resolve) => setTimeout(resolve, 100));
526
- if (window.getSelection()?.toString()) return;
527
- else {
528
- if (row._clickUrl === null) {
529
- // user asked to nothing on click
530
- return;
531
- }
532
- if (e.ctrlKey || e.metaKey || row._clickUrl?.includes('target=_blank')) {
533
-
534
- if (row._clickUrl) {
535
- window.open(row._clickUrl, '_blank');
536
- } else {
537
- window.open(
538
- router.resolve({
539
- name: 'resource-show',
540
- params: {
541
- resourceId: props.resource?.resourceId,
542
- primaryKey: row._primaryKeyValue,
543
- },
544
- }).href,
545
- '_blank'
546
- );
547
- }
548
- } else {
549
- if (row._clickUrl) {
550
- if (row._clickUrl.startsWith('http')) {
551
- document.location.href = row._clickUrl;
552
- } else {
553
- router.push(row._clickUrl);
554
- }
555
- } else {
556
- router.push({
557
- name: 'resource-show',
558
- params: {
559
- resourceId: props.resource?.resourceId,
560
- primaryKey: row._primaryKeyValue,
561
- },
562
- });
563
- }
564
- }
565
- }
566
- }
567
-
568
- async function deleteRecord(row: any) {
569
- const data = await confirm({
570
- message: t('Are you sure you want to delete this item?'),
571
- yes: t('Delete'),
572
- no: t('Cancel'),
573
- });
574
- if (data) {
575
- try {
576
- const res = await callAdminForthApi({
577
- path: '/delete_record',
578
- method: 'POST',
579
- body: {
580
- resourceId: props.resource?.resourceId,
581
- primaryKey: row._primaryKeyValue,
582
- }
583
- });
584
- if (!res.error){
585
- emits('update:records', true)
586
- showSuccesTost(t('Record deleted successfully'))
587
- } else {
588
- showErrorTost(res.error)
589
- }
590
-
591
- } catch (e) {
592
- showErrorTost(t('Something went wrong, please try again later'));
593
- console.error(e);
594
- };
595
- }
596
- }
597
-
598
- const actionLoadingStates = ref<Record<string | number, boolean>>({});
599
-
600
- async function startCustomAction(actionId: string, row: any, extraData: Record<string, any> = {}) {
601
- actionLoadingStates.value[actionId] = true;
602
-
603
- const data = await callAdminForthApi({
604
- path: '/start_custom_action',
605
- method: 'POST',
606
- body: {
607
- resourceId: props.resource?.resourceId,
608
- actionId: actionId,
609
- recordId: row._primaryKeyValue,
610
- extra: extraData
611
- }
612
- });
613
-
614
- actionLoadingStates.value[actionId] = false;
615
-
616
- if (data?.redirectUrl) {
617
- // Check if the URL should open in a new tab
618
- if (data.redirectUrl.includes('target=_blank')) {
619
- window.open(data.redirectUrl.replace('&target=_blank', '').replace('?target=_blank', ''), '_blank');
620
- } else {
621
- // Navigate within the app
622
- if (data.redirectUrl.startsWith('http')) {
623
- window.location.href = data.redirectUrl;
624
- } else {
625
- router.push(data.redirectUrl);
626
- }
627
- }
628
- return;
629
- }
630
- if (data?.ok) {
631
- emits('update:records', true);
632
-
633
- if (data.successMessage) {
634
- alert({
635
- message: data.successMessage,
636
- variant: 'success'
637
- });
638
- }
639
- }
640
-
641
- if (data?.error) {
642
- showErrorTost(data.error);
643
- }
644
- }
645
-
646
-
647
- function validatePageInput() {
648
- const newPage = parseInt(pageInput.value) || 1;
649
- const validPage = Math.max(1, Math.min(newPage, totalPages.value));
650
- page.value = validPage;
651
- pageInput.value = validPage.toString();
652
- }
653
-
654
- // Add throttle utility
655
- const throttle = (fn: Function, delay: number) => {
656
- let lastCall = 0;
657
- return (...args: any[]) => {
658
- const now = Date.now();
659
- if (now - lastCall >= delay) {
660
- lastCall = now;
661
- fn(...args);
662
- }
663
- };
664
- };
665
-
666
- // Virtual scroll state
667
- const containerRef = ref<HTMLElement | null>(null);
668
- const scrollTop = ref(0);
669
- const visibleRows = ref<any[]>([]);
670
- const startIndex = ref(0);
671
- const endIndex = ref(0);
672
- const totalHeight = ref(0);
673
- const spacerHeight = ref(0);
674
- const rowHeightsMap = ref<{[key: string]: number}>({});
675
- const rowPositions = ref<number[]>([]);
676
-
677
- // Calculate row positions based on heights
678
- const calculateRowPositions = () => {
679
- if (!props.rows) return;
680
-
681
- let currentPosition = 0;
682
- rowPositions.value = props.rows.map((row) => {
683
- const height = rowHeightsMap.value[`row_${row._primaryKeyValue}`] || props.itemHeight || 52.5;
684
- const position = currentPosition;
685
- currentPosition += height;
686
- return position;
687
- });
688
- totalHeight.value = currentPosition;
689
- };
690
-
691
- // Calculate visible rows based on scroll position
692
- const calculateVisibleRows = () => {
693
- if (!props.rows?.length) {
694
- visibleRows.value = props.rows || [];
695
- return;
696
- }
697
-
698
- const buffer = props.bufferSize || 5;
699
- const containerHeight = props.containerHeight || 900;
700
-
701
- // For single item or small datasets, show all rows
702
- if (props.rows.length <= buffer * 2 + 1) {
703
- startIndex.value = 0;
704
- endIndex.value = props.rows.length - 1;
705
- visibleRows.value = props.rows;
706
- spacerHeight.value = 0;
707
- return;
708
- }
709
-
710
- // Binary search for start index
711
- let low = 0;
712
- let high = rowPositions.value.length - 1;
713
- const targetPosition = scrollTop.value;
714
-
715
- while (low <= high) {
716
- const mid = Math.floor((low + high) / 2);
717
- if (rowPositions.value[mid] <= targetPosition) {
718
- low = mid + 1;
719
- } else {
720
- high = mid - 1;
721
- }
722
- }
723
-
724
- const newStartIndex = Math.max(0, low - 1 - buffer);
725
- const newEndIndex = Math.min(
726
- props.rows.length - 1,
727
- newStartIndex + Math.ceil(containerHeight / (props.itemHeight || 52.5)) + buffer * 2
728
- );
729
-
730
- // Ensure at least one row is visible
731
- if (newEndIndex < newStartIndex) {
732
- startIndex.value = 0;
733
- endIndex.value = Math.min(props.rows.length - 1, Math.ceil(containerHeight / (props.itemHeight || 52.5)));
734
- } else {
735
- startIndex.value = newStartIndex;
736
- endIndex.value = newEndIndex;
737
- }
738
-
739
- visibleRows.value = props.rows.slice(startIndex.value, endIndex.value + 1);
740
- spacerHeight.value = startIndex.value > 0 ? rowPositions.value[startIndex.value - 1] : 0;
741
- };
742
-
743
- // Throttled scroll handler
744
- const handleScroll = throttle((e: Event) => {
745
- const target = e.target as HTMLElement;
746
- scrollTop.value = target.scrollTop;
747
- calculateVisibleRows();
748
- }, 16);
749
-
750
- // Update row height when it changes
751
- const updateRowHeight = (rowId: string, height: number) => {
752
- if (rowHeightsMap.value[rowId] !== height) {
753
- rowHeightsMap.value[rowId] = height;
754
- calculateRowPositions();
755
- calculateVisibleRows();
756
- }
757
- };
758
-
759
- // Watch for changes in rows
760
- watch(() => props.rows, () => {
761
- if (props.rows) {
762
- calculateRowPositions();
763
- calculateVisibleRows();
764
- }
765
- }, { immediate: true });
766
-
767
-
768
-
769
- </script>
770
-
771
- <style lang="scss" scoped>
772
- input[type="checkbox"][disabled] {
773
- @apply opacity-50;
774
- }
775
- input[type="checkbox"]:not([disabled]) {
776
- @apply cursor-pointer;
777
- }
778
- td.sticky-column {
779
- @apply sticky left-0 z-10;
780
- &:not(:first-child) {
781
- @apply left-[56px];
782
- }
783
- }
784
- tr.list-table-body-row:not(:first-child):hover {
785
- td.sticky-column:not(.list-table-header-cell) {
786
- @apply bg-lightListTableRowHover dark:bg-darkListTableRowHover;
787
- }
788
- }
789
- </style>