adminforth 1.1.65 → 1.1.67

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 (62) hide show
  1. package/auth.ts +19 -4
  2. package/dataConnectors/mongo.ts +7 -13
  3. package/dataConnectors/postgres.ts +2 -2
  4. package/dataConnectors/sqlite.ts +2 -2
  5. package/dist/auth.js +14 -4
  6. package/dist/dataConnectors/mongo.js +1 -9
  7. package/dist/index.js +4 -9
  8. package/dist/plugins/AuditLogPlugin/custom/AuditLogView.vue +7 -6
  9. package/dist/plugins/AuditLogPlugin/index.js +17 -13
  10. package/dist/servers/express.js +1 -1
  11. package/dist/spa/index.html +2 -2
  12. package/dist/spa/package-lock.json +17 -4
  13. package/dist/spa/package.json +2 -1
  14. package/dist/spa/spa/src/App.vue +24 -12
  15. package/dist/spa/spa/src/composables/useStores.ts +16 -4
  16. package/dist/spa/spa/src/main.ts +1 -1
  17. package/dist/spa/src/App.vue +125 -45
  18. package/dist/spa/src/assets/logo.svg +19 -1
  19. package/dist/spa/src/components/AcceptModal.vue +2 -9
  20. package/dist/spa/src/components/BreadcrumbsWithButtons.vue +1 -1
  21. package/dist/spa/src/components/CustomDatePicker.vue +16 -3
  22. package/dist/spa/src/components/CustomDateRangePicker.vue +11 -2
  23. package/dist/spa/src/components/Dropdown.vue +6 -1
  24. package/dist/spa/src/components/Filters.vue +40 -19
  25. package/dist/spa/src/components/ResourceForm.vue +26 -24
  26. package/dist/spa/src/components/ResourceListTable.vue +419 -0
  27. package/dist/spa/src/components/Toast.vue +66 -0
  28. package/dist/spa/src/components/ValueRenderer.vue +14 -8
  29. package/dist/spa/src/composables/useFrontendApi.ts +26 -0
  30. package/dist/spa/src/composables/useStores.ts +113 -0
  31. package/dist/spa/src/main.ts +1 -1
  32. package/dist/spa/src/router/index.ts +30 -20
  33. package/dist/spa/src/spa_types/core.ts +51 -0
  34. package/dist/spa/src/stores/core.ts +48 -31
  35. package/dist/spa/src/stores/filters.ts +22 -0
  36. package/dist/spa/src/stores/modal.ts +13 -3
  37. package/dist/spa/src/stores/toast.ts +15 -0
  38. package/dist/spa/src/stores/user.ts +54 -0
  39. package/dist/spa/src/utils.ts +62 -7
  40. package/dist/spa/src/views/CreateView.vue +67 -15
  41. package/dist/spa/src/views/EditView.vue +45 -11
  42. package/dist/spa/src/views/ListView.vue +82 -366
  43. package/dist/spa/src/views/LoginView.vue +16 -4
  44. package/dist/spa/src/views/ShowView.vue +105 -21
  45. package/dist/spa/tailwind.config.js +1 -1
  46. package/dist/spa/vite.config.ts +6 -0
  47. package/index.ts +7 -12
  48. package/package.json +1 -1
  49. package/plugins/AuditLogPlugin/custom/AuditLogView.vue +7 -6
  50. package/plugins/AuditLogPlugin/index.ts +22 -15
  51. package/servers/express.ts +1 -1
  52. package/spa/src/App.vue +24 -12
  53. package/spa/src/composables/useStores.ts +16 -4
  54. package/spa/src/main.ts +1 -1
  55. package/types/AdminForthConfig.ts +18 -4
  56. package/types/FrontendAPI.ts +1 -15
  57. package/dist/plugins/AccessControl/index.js +0 -66
  58. package/dist/plugins/AccessControl/types.js +0 -1
  59. package/dist/spa/public/favicon.ico +0 -0
  60. package/dist/spa/spa/public/favicon.ico +0 -0
  61. package/dist/types.js +0 -30
  62. /package/dist/spa/{spa/public → public/assets}/favicon.png +0 -0
@@ -1,11 +1,11 @@
1
1
  <template>
2
- <div>
2
+ <div class="rounded-default">
3
3
 
4
4
  <div
5
- class="relative shadow-resourse-form-shadow sm:rounded-lg dark:shadow-2xl dark:shadow-black"
5
+ class="relative shadow-resourse-form-shadow sm:rounded-lg dark:shadow-2xl dark:shadow-black rounded-default"
6
6
  >
7
7
  <form autocomplete="off" @submit.prevent>
8
- <table class="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400">
8
+ <table class="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400 ">
9
9
  <thead class="text-xs text-gray-700 uppercase bg-form-view-heading dark:bg-gray-700 dark:text-gray-400">
10
10
  <tr>
11
11
  <th scope="col" class="px-6 py-3">
@@ -30,28 +30,28 @@
30
30
  />
31
31
  </template>
32
32
  <template v-else>
33
- <td class="px-6 py-4 whitespace-nowrap">
34
- {{ column.label }}
35
- <span :data-tooltip-target="`tooltip-show-${i}`" class="relative inline-block">
36
- <IconExclamationCircleSolid v-if="column.required[mode]" class="w-4 h-4"
37
- :class="(columnError(column) && validating) ? 'text-red-500 dark:text-red-400' : 'text-gray-400 dark:text-gray-500'"
38
- />
39
- </span>
40
- <div :id="`tooltip-show-${i}`"
41
- role="tooltip" class="absolute z-10 invisible inline-block px-3 py-2 text-sm font-medium text-white transition-opacity duration-300 bg-gray-900 rounded-lg shadow-sm opacity-0 tooltip dark:bg-gray-700">
42
- Required field
43
- <div class="tooltip-arrow" data-popper-arrow></div>
44
- </div>
33
+ <td class="px-6 py-4 whitespace-nowrap "> <!--align-top-->
34
+ {{ column.label }}
35
+ <span :data-tooltip-target="`tooltip-show-${i}`" class="relative inline-block">
36
+ <IconExclamationCircleSolid v-if="column.required[mode]" class="w-4 h-4"
37
+ :class="(columnError(column) && validating) ? 'text-red-500 dark:text-red-400' : 'text-gray-400 dark:text-gray-500'"
38
+ />
39
+ </span>
40
+ <div :id="`tooltip-show-${i}`"
41
+ role="tooltip" class="absolute z-10 invisible inline-block px-3 py-2 text-sm font-medium text-white transition-opacity duration-300 bg-gray-900 rounded-lg shadow-sm opacity-0 tooltip dark:bg-gray-700">
42
+ Required field
43
+ <div class="tooltip-arrow" data-popper-arrow></div>
44
+ </div>
45
45
  </td>
46
46
  <td class="px-6 py-4 whitespace-nowrap whitespace-pre-wrap relative">
47
-
48
47
  <Dropdown
49
48
  single
50
49
  v-if="column.foreignResource"
51
50
  :options="columnOptions[column.name] || []"
51
+ :placeholder = "columnOptions[column.name]?.length || 'There are no options available'"
52
52
  :modelValue="currentValues[column.name]"
53
53
  @update:modelValue="setCurrentValue(column.name, $event)"
54
- />
54
+ ></Dropdown>
55
55
  <Dropdown
56
56
  single
57
57
  v-else-if="column.enum"
@@ -79,6 +79,7 @@
79
79
  v-else-if="['datetime'].includes(column.type)"
80
80
  :column="column"
81
81
  :valueStart="currentValues[column.name]"
82
+ auto-hide
82
83
  @update:valueStart="setCurrentValue(column.name, $event)"
83
84
  />
84
85
  <input
@@ -120,9 +121,6 @@
120
121
  <IconEyeSolid class="w-6 h-6 text-gray-400" v-if="!unmasked[column.name]" />
121
122
  <IconEyeSlashSolid class="w-6 h-6 text-gray-400" v-else />
122
123
  </button>
123
-
124
-
125
-
126
124
  <div v-if="columnError(column) && validating" class="mt-1 text-xs text-red-500 dark:text-red-400">{{ columnError(column) }}</div>
127
125
 
128
126
  <div v-if="column.editingNote && column.editingNote[mode]" class="mt-1 text-xs text-gray-400 dark:text-gray-500">{{ column.editingNote[mode] }}</div>
@@ -154,7 +152,7 @@ const router = useRouter();
154
152
 
155
153
  const props = defineProps({
156
154
  loading: Boolean,
157
- resourceColumns: Object,
155
+ resource: Object,
158
156
  record: Object,
159
157
  validating: Boolean,
160
158
  customComponentsPerColumn: Object,
@@ -196,7 +194,11 @@ const columnError = (column) => {
196
194
  for (let i = 0; i < validationArray.length; i++) {
197
195
  if (validationArray[i].regExp) {
198
196
  const regExp = new RegExp(validationArray[i].regExp);
199
- if (!regExp.test(currentValues.value[column.name])) {
197
+ let value = currentValues.value[column.name];
198
+ if (value === undefined || value === null) {
199
+ value = '';
200
+ }
201
+ if (!regExp.test(value)) {
200
202
  return validationArray[i].message;
201
203
  }
202
204
  }
@@ -226,7 +228,7 @@ onMounted(() => {
226
228
 
227
229
  const columnOptions = computedAsync(async () => {
228
230
  return (await Promise.all(
229
- Object.values(props.resourceColumns).map(async (column) => {
231
+ Object.values(props.resource.columns).map(async (column) => {
230
232
  if (column.foreignResource) {
231
233
  const list = await callAdminForthApi({
232
234
  method: 'POST',
@@ -249,7 +251,7 @@ const coreStore = useCoreStore();
249
251
 
250
252
  const editableColumns = computed(() => {
251
253
  const mode = props.record ? 'edit' : 'create';
252
- return props.resourceColumns?.filter(column => column.showIn.includes(mode));
254
+ return props.resource?.columns?.filter(column => column.showIn.includes(mode));
253
255
  });
254
256
 
255
257
  const isValid = computed(() => {
@@ -0,0 +1,419 @@
1
+ <template>
2
+ <!-- table -->
3
+ <div class="relative overflow-x-auto shadow-list-table-shadow dark:shadow-black overflow-y-hidden rounded-default">
4
+
5
+ <!-- skelet loader -->
6
+ <div role="status" v-if="!resource || !resource.columns"
7
+ 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">
8
+ <div class="flex items-center justify-between h-16">
9
+ <div>
10
+ <div class="h-2.5 bg-gray-300 rounded-full dark:bg-gray-600 w-24 mb-2.5"></div>
11
+ <div class="w-32 h-2 bg-gray-200 rounded-full dark:bg-gray-700"></div>
12
+ </div>
13
+ <div class="h-2.5 bg-gray-300 rounded-full dark:bg-gray-700 w-12"></div>
14
+ </div>
15
+
16
+ <div class="flex items-center justify-between h-16 pt-4" v-for="i in new Array(10)">
17
+ <div>
18
+ <div class="h-2.5 bg-gray-300 rounded-full dark:bg-gray-600 w-24 mb-2.5"></div>
19
+ <div class="w-32 h-2 bg-gray-200 rounded-full dark:bg-gray-700"></div>
20
+ </div>
21
+ <div class="h-2.5 bg-gray-300 rounded-full dark:bg-gray-700 w-12"></div>
22
+ </div>
23
+ <span class="sr-only">Loading...</span>
24
+ </div>
25
+
26
+ <table v-else class="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400 rounded-default">
27
+ <thead class="text-xs text-view-table-heading-text bg-list-view-table-heading dark:bg-gray-700 dark:text-gray-400">
28
+ <tr>
29
+ <th scope="col" class="p-4">
30
+ <div v-if="rows && rows.length" class="flex items-center">
31
+ <input id="checkbox-all-search" type="checkbox" :checked="allFromThisPageChecked" @change="selectAll()"
32
+ class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 dark:focus:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
33
+ <label for="checkbox-all-search" class="sr-only">checkbox</label>
34
+ </div>
35
+ </th>
36
+
37
+ <th v-for="c in columnsListed" scope="col" class="px-6 py-3">
38
+ <div @click="() => c.sortable && onSortButtonClick(c.name)" class="flex items-center " :class="{'cursor-pointer':c.sortable}">
39
+ {{ c.label }}
40
+
41
+ <div v-if="c.sortable"
42
+ :style="{ 'color':ascArr.includes(c.name)?'green':descArr.includes(c.name)?'red':'currentColor'}">
43
+ <svg v-if="ascArr.includes(c.name) || descArr.includes(c.name)" class="w-3 h-3 ms-1.5"
44
+ :class="{'rotate-180':descArr.includes(c.name)}" viewBox="0 0 24 24">
45
+ <path
46
+ 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"/>
47
+ </svg>
48
+ <svg v-else class="w-3 h-3 ms-1.5 opacity-30" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"
49
+ fill='currentColor'
50
+ viewBox="0 0 24 24">
51
+ <path
52
+ 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"/>
53
+ </svg>
54
+ </div>
55
+ </div>
56
+ </th>
57
+
58
+ <th scope="col" class="px-6 py-3">
59
+ Actions
60
+ </th>
61
+ </tr>
62
+ </thead>
63
+ <tbody>
64
+ <tr v-if="!rows" class="bg-list-view-table-bg border-b dark:bg-gray-800 dark:border-gray-700">
65
+ <td :colspan="resource?.columns.length + 2">
66
+
67
+ <div role="status"
68
+ class="max-w p-4 space-y-4 divide-y divide-gray-200 rounded animate-pulse dark:divide-gray-700 md:p-6 dark:border-gray-700">
69
+ <div class="flex items-center justify-between">
70
+ <div>
71
+ <div class="h-2.5 bg-gray-300 rounded-full dark:bg-gray-600 w-24 mb-2.5"></div>
72
+ <div class="w-32 h-2 bg-gray-200 rounded-full dark:bg-gray-700"></div>
73
+ </div>
74
+ <div class="h-2.5 bg-gray-300 rounded-full dark:bg-gray-700 w-12"></div>
75
+ </div>
76
+ <div class="flex items-center justify-between pt-4">
77
+ <div>
78
+ <div class="h-2.5 bg-gray-300 rounded-full dark:bg-gray-600 w-24 mb-2.5"></div>
79
+ <div class="w-32 h-2 bg-gray-200 rounded-full dark:bg-gray-700"></div>
80
+ </div>
81
+ <div class="h-2.5 bg-gray-300 rounded-full dark:bg-gray-700 w-12"></div>
82
+ </div>
83
+ <div class="flex items-center justify-between pt-4">
84
+ <div>
85
+ <div class="h-2.5 bg-gray-300 rounded-full dark:bg-gray-600 w-24 mb-2.5"></div>
86
+ <div class="w-32 h-2 bg-gray-200 rounded-full dark:bg-gray-700"></div>
87
+ </div>
88
+ <div class="h-2.5 bg-gray-300 rounded-full dark:bg-gray-700 w-12"></div>
89
+ </div>
90
+ <div class="flex items-center justify-between pt-4">
91
+ <div>
92
+ <div class="h-2.5 bg-gray-300 rounded-full dark:bg-gray-600 w-24 mb-2.5"></div>
93
+ <div class="w-32 h-2 bg-gray-200 rounded-full dark:bg-gray-700"></div>
94
+ </div>
95
+ <div class="h-2.5 bg-gray-300 rounded-full dark:bg-gray-700 w-12"></div>
96
+ </div>
97
+ <div class="flex items-center justify-between pt-4">
98
+ <div>
99
+ <div class="h-2.5 bg-gray-300 rounded-full dark:bg-gray-600 w-24 mb-2.5"></div>
100
+ <div class="w-32 h-2 bg-gray-200 rounded-full dark:bg-gray-700"></div>
101
+ </div>
102
+ <div class="h-2.5 bg-gray-300 rounded-full dark:bg-gray-700 w-12"></div>
103
+ </div>
104
+ <span class="sr-only">Loading...</span>
105
+ </div>
106
+ </td>
107
+ </tr>
108
+ <tr v-else-if="rows.length === 0" class="bg-list-view-table-bg border-b dark:bg-gray-800 dark:border-gray-700">
109
+ <td :colspan="resource?.columns.length + 2">
110
+
111
+ <div id="toast-simple"
112
+ 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"
113
+ role="alert">
114
+ <IconInboxOutline class="w-6 h-6 text-gray-500 dark:text-gray-400"/>
115
+ <div class="ps-4 text-sm font-normal">No items here yet</div>
116
+ </div>
117
+
118
+ </td>
119
+ </tr>
120
+
121
+ <tr v-else v-for="(row, rowI) in rows" :key="row.id"
122
+ class="bg-list-view-table-bg border-b dark:bg-gray-800 border-list-view-border-color dark:border-gray-700 hover:bg-list-view-table-row-hover dark:hover:bg-gray-600">
123
+ <td class="w-4 p-4">
124
+ <div class="flex items center">
125
+ <input
126
+ id="checkbox-table-search-1"
127
+ type="checkbox"
128
+ :checked="checkboxesInternal.includes(row.id)"
129
+ @change="(e)=>{addToCheckedValues(row.id)}"
130
+ class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 dark:focus:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
131
+ <label for="checkbox-table-search-1" class="sr-only">checkbox</label>
132
+ </div>
133
+ </td>
134
+ <td v-for="c in columnsListed" class="px-6 py-4">
135
+ <!-- if c.name in listComponentsPerColumn, render it. If not, render ValueRenderer -->
136
+ <component
137
+ :is="c?.components?.list ? getCustomComponent(c.components.list) : ValueRenderer"
138
+ :meta="c?.components?.list.meta"
139
+ :column="c"
140
+ :record="row"
141
+ :adminUser="coreStore.adminUser"
142
+ :resource="resource"
143
+ />
144
+ </td>
145
+ <td class=" items-center px-6 py-4">
146
+ <div class="flex">
147
+ <RouterLink
148
+ v-if="resource.options?.allowedActions.show"
149
+ :to="{
150
+ name: 'resource-show',
151
+ params: {
152
+ resourceId: resource.resourceId,
153
+ primaryKey: row._primaryKeyValue,
154
+ }
155
+ }"
156
+ class="font-medium text-blue-600 dark:text-blue-500 hover:underline"
157
+ :data-tooltip-target="`tooltip-show-${rowI}`"
158
+ >
159
+ <IconEyeSolid class="w-5 h-5 me-2"/>
160
+ </RouterLink>
161
+
162
+ <div :id="`tooltip-show-${rowI}`"
163
+ role="tooltip"
164
+ class="absolute z-10 invisible inline-block px-3 py-2 text-sm font-medium text-white transition-opacity duration-300 bg-gray-900 rounded-lg shadow-sm opacity-0 tooltip dark:bg-gray-700">
165
+ Show item
166
+ <div class="tooltip-arrow" data-popper-arrow></div>
167
+ </div>
168
+
169
+ <RouterLink v-if="resource.options?.allowedActions.edit"
170
+ :to="{
171
+ name: 'resource-edit',
172
+ params: {
173
+ resourceId: resource.resourceId,
174
+ primaryKey: row._primaryKeyValue
175
+ }
176
+ }"
177
+ class="font-medium text-blue-600 dark:text-blue-500 hover:underline ms-3"
178
+ :data-tooltip-target="`tooltip-edit-${rowI}`"
179
+ >
180
+ <IconPenSolid class="w-5 h-5 me-2"/>
181
+ </RouterLink>
182
+
183
+ <div :id="`tooltip-edit-${rowI}`"
184
+ role="tooltip"
185
+ class="absolute z-10 invisible inline-block px-3 py-2 text-sm font-medium text-white transition-opacity duration-300 bg-gray-900 rounded-lg shadow-sm opacity-0 tooltip dark:bg-gray-700">
186
+ Edit
187
+ <div class="tooltip-arrow" data-popper-arrow></div>
188
+ </div>
189
+
190
+ <button v-if="resource.options?.allowedActions.delete"
191
+ class="font-medium text-red-600 dark:text-red-500 hover:underline ms-3"
192
+ :data-tooltip-target="`tooltip-delete-${rowI}`"
193
+ @click="deleteRecord(row)"
194
+ >
195
+ <IconTrashBinSolid class="w-5 h-5 me-2"/>
196
+ </button>
197
+
198
+ <div :id="`tooltip-delete-${rowI}`"
199
+ role="tooltip"
200
+ class="absolute z-10 invisible inline-block px-3 py-2 text-sm font-medium text-white transition-opacity duration-300 bg-gray-900 rounded-lg shadow-sm opacity-0 tooltip dark:bg-gray-700">
201
+ Delete
202
+ <div class="tooltip-arrow" data-popper-arrow></div>
203
+ </div>
204
+ </div>
205
+ </td>
206
+ </tr>
207
+ </tbody>
208
+ </table>
209
+ </div>
210
+ <!-- pagination -->
211
+ <div class="flex flex-col items-center mt-4 mb-4 xs:flex-row xs:justify-between xs:items-center"
212
+ v-if="rows && totalRows >= pageSize && totalRows > 0"
213
+ >
214
+ <!-- Help text -->
215
+ <span class="text-sm text-gray-700 dark:text-gray-400">
216
+ Showing <span class="font-semibold text-gray-900 dark:text-white">
217
+ {{ (page - 1) * pageSize + 1 }}
218
+ </span> to <span class="font-semibold text-gray-900 dark:text-white">
219
+ {{ Math.min(page * pageSize, totalRows) }}
220
+ </span> of <span class="font-semibold text-gray-900 dark:text-white">{{
221
+ totalRows
222
+ }}</span> Entries
223
+ </span>
224
+ <div class="inline-flex mt-2 xs:mt-0">
225
+ <!-- Buttons -->
226
+ <button
227
+ class="flex items-center py-1 px-3 text-sm font-medium text-gray-900 focus:outline-none bg-white border-r-0 rounded-s border border-gray-300 hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-4 focus:ring-gray-100 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700 disabled:opacity-50"
228
+ @click="page--" :disabled="page <= 1">
229
+ <svg class="w-3.5 h-3.5 me-2 rtl:rotate-180" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none"
230
+ viewBox="0 0 14 10">
231
+ <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
232
+ d="M13 5H1m0 0 4 4M1 5l4-4"/>
233
+ </svg>
234
+ Prev
235
+ </button>
236
+ <button
237
+ class="flex items-center py-1 px-3 text-sm font-medium text-gray-900 focus:outline-none bg-white border-r-0 border border-gray-300 hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-4 focus:ring-gray-100 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700 disabled:opacity-50"
238
+ @click="page = 1" :disabled="page <= 1">
239
+ <!-- <IconChevronDoubleLeftOutline class="w-4 h-4" /> -->
240
+ 1
241
+ </button>
242
+ <input type="text"
243
+ class="w-10 py-1.5 px-3 text-sm text-center text-gray-700 border border-gray-300 dark:border-gray-700 dark:text-gray-400 dark:bg-gray-800 z-10"
244
+ v-model="page"/>
245
+
246
+ <button
247
+ class="flex items-center py-1 px-3 text-sm font-medium text-gray-900 focus:outline-none bg-white border-l-0 border border-gray-300 hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-4 focus:ring-gray-100 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700 disabled:opacity-50"
248
+ @click="page = totalPages" :disabled="page >= totalPages">
249
+ {{ totalPages }}
250
+
251
+ <!-- <IconChevronDoubleRightOutline class="w-4 h-4" /> -->
252
+ </button>
253
+ <button
254
+ class="flex items-center py-1 px-3 text-sm font-medium text-gray-900 focus:outline-none bg-white border-l-0 rounded-e border border-gray-300 hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-4 focus:ring-gray-100 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700 disabled:opacity-50"
255
+
256
+ @click="page++" :disabled="page >= totalPages">
257
+ Next
258
+ <svg class="w-3.5 h-3.5 ms-2 rtl:rotate-180" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none"
259
+ viewBox="0 0 14 10">
260
+ <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
261
+ d="M1 5h12m0 0L9 1m4 4L9 9"/>
262
+ </svg>
263
+ </button>
264
+ </div>
265
+
266
+ </div>
267
+ </template>
268
+
269
+ <script setup>
270
+
271
+
272
+ import { initFlowbite } from 'flowbite';
273
+ import { computed, onMounted, ref, watch } from 'vue';
274
+ import { useRoute } from 'vue-router';
275
+ import { callAdminForthApi, getIcon } from '@/utils';
276
+
277
+ import ValueRenderer from '@/components/ValueRenderer.vue';
278
+ import { getCustomComponent } from '@/utils';
279
+ import { useCoreStore } from '@/stores/core';
280
+ import { showSuccesTost } from '@/composables/useFrontendApi';
281
+
282
+ import {
283
+ IconInboxOutline,
284
+ IconPlusOutline
285
+ } from '@iconify-prerendered/vue-flowbite';
286
+
287
+ import {
288
+ IconBanOutline,
289
+ IconEyeSolid,
290
+ IconFilterOutline,
291
+ IconPenSolid,
292
+ IconTrashBinSolid
293
+ } from '@iconify-prerendered/vue-flowbite';
294
+
295
+ const coreStore = useCoreStore();
296
+
297
+ const props = defineProps([
298
+ 'resource',
299
+ 'rows',
300
+ 'totalRows',
301
+ 'pageSize',
302
+ 'checkboxes'
303
+ ])
304
+
305
+ // emits, update page
306
+ const emits = defineEmits([
307
+ 'update:page',
308
+ 'update:sort',
309
+ 'update:checkboxes',
310
+ 'update:records'
311
+
312
+ ]);
313
+
314
+ const checkboxesInternal = ref([]);
315
+ const page = ref(1);
316
+ const sort = ref([]);
317
+
318
+
319
+ watch(() => page.value, (newPage) => {
320
+ emits('update:page', newPage);
321
+ });
322
+
323
+ watch(() => sort.value, (newSort) => {
324
+ emits('update:sort', newSort);
325
+ });
326
+
327
+ watch(() => checkboxesInternal.value, (newCheckboxes) => {
328
+ console.log('checkboxesInternal ch changed, emiting', newCheckboxes)
329
+
330
+ emits('update:checkboxes', newCheckboxes);
331
+ });
332
+
333
+ watch(() => props.checkboxes, (newCheckboxes) => {
334
+ console.log('Props ch changed', newCheckboxes)
335
+ checkboxesInternal.value = newCheckboxes;
336
+ });
337
+
338
+ function addToCheckedValues(id) {
339
+ if (checkboxesInternal.value.includes(id)) {
340
+ checkboxesInternal.value = checkboxesInternal.value.filter((item) => item !== id);
341
+ } else {
342
+ checkboxesInternal.value.push(id);
343
+ }
344
+ checkboxesInternal.value = [ ...checkboxesInternal.value ]
345
+ }
346
+
347
+ const columnsListed = computed(() => props.resource?.columns?.filter(c => c.showIn.includes('list')));
348
+
349
+ async function selectAll(value) {
350
+ props.rows.forEach((r) => {
351
+ if (!checkboxesInternal.value.includes(r.id)) {
352
+ checkboxesInternal.value.push(r.id)
353
+ } else {
354
+ checkboxesInternal.value = checkboxesInternal.value.filter((item) => item !== r.id)
355
+ }
356
+ });
357
+ checkboxesInternal.value = [ ...checkboxesInternal.value ]
358
+ // checkboxes.value = rows.value.map((v) => v.id);
359
+ }
360
+
361
+ const totalPages = computed(() => Math.ceil(props.totalRows / props.pageSize));
362
+
363
+
364
+
365
+
366
+ const allFromThisPageChecked = computed(() => {
367
+ if (!props.rows) return false;
368
+ return props.rows.every((r) => props.checkboxes.includes(r.id));
369
+ });
370
+ const ascArr = computed(() => sort.value.filter((s) => s.direction === 'asc').map((s) => s.field));
371
+ const descArr = computed(() => sort.value.filter((s) => s.direction === 'desc').map((s) => s.field));
372
+
373
+
374
+ function onSortButtonClick(field) {
375
+ const sortIndex = sort.value.findIndex((s) => s.field === field);
376
+ if (sortIndex === -1) {
377
+ sort.value = [{field, direction: 'asc'}, ...sort.value];
378
+ } else {
379
+ const sortField = sort.value[sortIndex];
380
+ if (sortField.direction === 'asc') {
381
+ sort.value[sortIndex].direction = 'desc';
382
+ } else {
383
+ sort.value.splice(sortIndex, 1);
384
+ }
385
+ }
386
+ }
387
+
388
+ async function deleteRecord(row) {
389
+ const data = await window.adminforth.confirm({
390
+ message: 'Are you sure you want to delete this item?',
391
+ yes: 'Delete',
392
+ no: 'Cancel',
393
+ });
394
+ if (data) {
395
+ try {
396
+ const res = await callAdminForthApi({
397
+ path: '/delete_record',
398
+ method: 'POST',
399
+ body: {
400
+ resourceId: props.resource.resourceId,
401
+ primaryKey: row._primaryKeyValue,
402
+ }});
403
+ if (!res.error){
404
+ emits('update:records', true)
405
+ showSuccesTost('Record deleted successfully')
406
+ } else {
407
+ console.error(res.error)
408
+ }
409
+
410
+ } catch (e) {
411
+ console.error(e);
412
+ };
413
+ }
414
+
415
+
416
+ }
417
+
418
+
419
+ </script>
@@ -0,0 +1,66 @@
1
+ <template>
2
+
3
+
4
+ <div id="toast-default" class="flex items-center w-full max-w-xs p-4 text-gray-500 bg-white rounded-lg shadow dark:text-gray-400 dark:bg-gray-800" role="alert">
5
+ <div v-if="toast.variant == 'info'" class="inline-flex items-center justify-center flex-shrink-0 w-8 h-8 text-blue-500 bg-blue-100 rounded-lg dark:bg-blue-800 dark:text-blue-200">
6
+ <svg class="w-4 h-4" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 20">
7
+ <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.147 15.085a7.159 7.159 0 0 1-6.189 3.307A6.713 6.713 0 0 1 3.1 15.444c-2.679-4.513.287-8.737.888-9.548A4.373 4.373 0 0 0 5 1.608c1.287.953 6.445 3.218 5.537 10.5 1.5-1.122 2.706-3.01 2.853-6.14 1.433 1.049 3.993 5.395 1.757 9.117Z"/>
8
+ </svg>
9
+ <span class="sr-only">Fire icon</span>
10
+ </div>
11
+ <div v-else-if="toast.variant == 'danger'" class="inline-flex items-center justify-center flex-shrink-0 w-8 h-8 text-red-500 bg-red-100 rounded-lg dark:bg-red-800 dark:text-red-200">
12
+ <svg class="w-5 h-5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
13
+ <path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5Zm3.707 11.793a1 1 0 1 1-1.414 1.414L10 11.414l-2.293 2.293a1 1 0 0 1-1.414-1.414L8.586 10 6.293 7.707a1 1 0 0 1 1.414-1.414L10 8.586l2.293-2.293a1 1 0 0 1 1.414 1.414L11.414 10l2.293 2.293Z"/>
14
+ </svg>
15
+ <span class="sr-only">Error icon</span>
16
+ </div>
17
+ <div v-else-if="toast.variant == 'warning'"class="inline-flex items-center justify-center flex-shrink-0 w-8 h-8 text-orange-500 bg-orange-100 rounded-lg dark:bg-orange-700 dark:text-orange-200">
18
+ <svg class="w-5 h-5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
19
+ <path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5ZM10 15a1 1 0 1 1 0-2 1 1 0 0 1 0 2Zm1-4a1 1 0 0 1-2 0V6a1 1 0 0 1 2 0v5Z"/>
20
+ </svg>
21
+ <span class="sr-only">Warning icon</span>
22
+ </div>
23
+ <div v-else class="inline-flex items-center justify-center flex-shrink-0 w-8 h-8 text-green-500 bg-green-100 rounded-lg dark:bg-green-800 dark:text-green-200">
24
+ <svg class="w-5 h-5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
25
+ <path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5Zm3.707 8.207-4 4a1 1 0 0 1-1.414 0l-2-2a1 1 0 0 1 1.414-1.414L9 10.586l3.293-3.293a1 1 0 0 1 1.414 1.414Z"/>
26
+ </svg>
27
+ <span class="sr-only">Check icon</span>
28
+ </div>
29
+ <div class="ms-3 text-sm font-normal">{{toast.message}}</div>
30
+ <button @click="closeToast" type="button" class="ms-auto -mx-1.5 -my-1.5 bg-white text-gray-400 hover:text-gray-900 rounded-lg focus:ring-2 focus:ring-gray-300 p-1.5 hover:bg-gray-100 inline-flex items-center justify-center h-8 w-8 dark:text-gray-500 dark:hover:text-white dark:bg-gray-800 dark:hover:bg-gray-700" >
31
+ <svg class="w-3 h-3" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 14">
32
+ <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6"/>
33
+ </svg>
34
+ </button>
35
+ </div>
36
+
37
+
38
+ </template>
39
+
40
+ <script setup lang="ts">
41
+ import { onMounted } from 'vue';
42
+ import { useToastStore } from '@/stores/toast';
43
+ const toastStore = useToastStore();
44
+ const emit = defineEmits(['close']);
45
+ const props = defineProps<{
46
+ toast:{message: string;
47
+ variant: string;
48
+ id: string;
49
+ timeout?: number|'unlimited';}
50
+ }>();
51
+ function closeToast() {
52
+ emit('close');
53
+ }
54
+
55
+ onMounted(() => {
56
+ if (props.toast.timeout === 'unlimited') return;
57
+ else {
58
+ setTimeout(() => {emit('close');}, props.toast.timeout || 10000 );
59
+ }
60
+ });
61
+
62
+ </script>
63
+
64
+ <style lang="scss" scoped>
65
+
66
+ </style>
@@ -1,9 +1,10 @@
1
1
  <template>
2
2
  <div>
3
+
3
4
  <span v-if="column.foreignResource">
4
- <RouterLink v-if="row[column.name]" class="font-medium text-blue-600 dark:text-blue-500 hover:brightness-110"
5
- :to="{ name: 'resource-show', params: { resourceId: column.foreignResource.resourceId, primaryKey: row[column.name].pk } }">
6
- {{ row[column.name].label }}
5
+ <RouterLink v-if="record[column.name]" class="font-medium text-blue-600 dark:text-blue-500 hover:brightness-110"
6
+ :to="{ name: 'resource-show', params: { resourceId: column.foreignResource.resourceId, primaryKey: record[column.name].pk } }">
7
+ {{ record[column.name].label }}
7
8
  </RouterLink>
8
9
  <div v-else>
9
10
  <span class="text-gray-400">-</span>
@@ -11,18 +12,18 @@
11
12
  </span>
12
13
 
13
14
  <span v-else-if="column.type === 'boolean'">
14
- <span v-if="row[column.name]" class="bg-green-100 text-green-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded dark:bg-gray-700 dark:text-green-400 border border-green-400">Yes</span>
15
+ <span v-if="record[column.name]" class="bg-green-100 text-green-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded dark:bg-gray-700 dark:text-green-400 border border-green-400">Yes</span>
15
16
  <span v-else class="bg-red-100 text-red-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded dark:bg-gray-700 dark:text-red-400 border border-red-400">No</span>
16
17
  </span>
17
18
  <span v-else-if="column.enum">
18
- {{ column.enum.find(e => e.value === row[column.name])?.label }}
19
+ {{ checkEmptyValues(column.enum.find(e => e.value === record[column.name])?.label,route.meta.type) }}
19
20
  </span>
20
21
  <span v-else-if="column.type === 'datetime'">
21
- {{ formatDate(row[column.name]) }}
22
+ {{ checkEmptyValues(formatDate(record[column.name]),route.meta.type) }}
22
23
 
23
24
  </span>
24
25
  <span v-else>
25
- {{ row[column.name] }}
26
+ {{ checkEmptyValues(record[column.name],route.meta.type) }}
26
27
  </span>
27
28
  </div>
28
29
  </template>
@@ -33,17 +34,22 @@
33
34
  import dayjs from 'dayjs';
34
35
  import utc from 'dayjs/plugin/utc';
35
36
  import timezone from 'dayjs/plugin/timezone';
37
+ import {checkEmptyValues} from '@/utils';
38
+ import { useRoute, useRouter } from 'vue-router';
39
+
36
40
 
37
41
  import { useCoreStore } from '@/stores/core';
38
42
 
39
43
  const coreStore = useCoreStore();
44
+ const route = useRoute();
45
+
40
46
 
41
47
  dayjs.extend(utc);
42
48
  dayjs.extend(timezone);
43
49
 
44
50
  const props = defineProps({
45
51
  column: Object,
46
- row: Object
52
+ record: Object
47
53
  });
48
54
 
49
55