adminforth 2.26.0-next.3 → 2.26.0-next.30

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