adminforth 1.0.11 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/auth.js CHANGED
@@ -28,7 +28,7 @@ class AdminForthAuth {
28
28
  }
29
29
 
30
30
  // issue JWT token
31
- const expiresIn = process.env.ADMINFORTH_AUTH_EXPIRESIN || '1h';
31
+ const expiresIn = process.env.ADMINFORTH_AUTH_EXPIRESIN || '24h';
32
32
  return jwt.sign(payload, secret, { expiresIn });
33
33
  }
34
34
 
package/index.js CHANGED
@@ -526,6 +526,20 @@ class AdminForth {
526
526
  if (!resource) {
527
527
  return { error: `Resource '${body['resourceId']}' not found` };
528
528
  }
529
+
530
+ const record = body['record'];
531
+ // execute hook if needed
532
+ if (resource.hooks?.create?.beforeSave) {
533
+ const resp = await resource.hooks?.create?.beforeSave({ resource, record, adminUser });
534
+ if (!resp || (!resp.ok && !resp.error)) {
535
+ throw new Error(`Hook beforeSave must return object with {ok: true} or { error: 'Error' } `);
536
+ }
537
+
538
+ if (resp.error) {
539
+ return { error: resp.error };
540
+ }
541
+ }
542
+
529
543
  for (const column of resource.columns) {
530
544
  if (column.fillOnCreate) {
531
545
  if (body['record'][column.name] === undefined) {
@@ -551,31 +565,15 @@ class AdminForth {
551
565
  }
552
566
  }
553
567
  }
554
- const connector = this.connectors[resource.dataSource];
555
-
556
- const record = body['record'];
557
-
558
- // execute hook if needed
559
- if (resource.hooks?.create?.beforeSave) {
560
- const resp = await resource.hooks?.create?.beforeSave({ resource, record, adminUser });
561
- if (!resp || (!resp.ok && !resp.error)) {
562
- throw new Error(`Hook beforeSave must return object with {ok: true} or { error: 'Error' } `);
563
- }
564
-
565
- if (resp.error) {
566
- return { error: resp.error };
567
- }
568
- }
569
568
 
570
569
  // remove virtual columns from record
571
570
  for (const column of resource.columns.filter((col) => col.virtual)) {
572
- if (record[column.name]) {
573
- delete record[column.name];
574
- }
571
+ if (record[column.name]) {
572
+ delete record[column.name];
573
+ }
575
574
  }
576
-
575
+ const connector = this.connectors[resource.dataSource];
577
576
  await connector.createRecord({ resource, record });
578
-
579
577
  // execute hook if needed
580
578
  if (resource.hooks?.create?.afterSave) {
581
579
  const resp = await resource.hooks?.create?.afterSave({ resource, record, adminUser });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adminforth",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "description": "OpenSource Vue3 powered forth-generation admin panel",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,33 +1,24 @@
1
1
  <template>
2
2
  <div>
3
3
  <div class="mx-auto grid grid-cols-2 gap-4 mb-2">
4
- <div>
5
- <label for="start-time" class="block mb-2 text-sm font-medium text-gray-900 dark:text-gray-400">Start
6
- date:</label>
7
-
8
- <div class="relative">
9
- <div class="absolute inset-y-0 end-0 top-0 flex items-center pe-3.5">
10
- <IconCalendar class="w-4 h-4 text-gray-500 dark:text-gray-400"/>
11
- </div>
12
-
13
- <input ref="datepickerStartEl" type="text"
14
- class="bg-gray-50 border leading-none border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
15
- placeholder="Start date">
4
+ <div class="relative">
5
+ <div class="absolute inset-y-0 end-0 top-0 flex items-center pe-3.5 pointer-events-none">
6
+ <IconCalendar class="w-4 h-4 text-gray-500 dark:text-gray-400"/>
16
7
  </div>
17
- </div>
18
-
19
- <div>
20
- <label for="start-time" class="block mb-2 text-sm font-medium text-gray-900 dark:text-gray-400">End date:</label>
21
8
 
22
- <div class="relative">
23
- <div class="absolute inset-y-0 end-0 top-0 flex items-center pe-3.5">
24
- <IconCalendar class="w-4 h-4 text-gray-500 dark:text-gray-400"/>
25
- </div>
9
+ <input ref="datepickerStartEl" type="text"
10
+ class="bg-gray-50 border leading-none border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
11
+ placeholder="From">
12
+ </div>
26
13
 
27
- <input ref="datepickerEndEl" type="text"
28
- class="bg-gray-50 border leading-none border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
29
- placeholder="End date">
14
+ <div class="relative">
15
+ <div class="absolute inset-y-0 end-0 top-0 flex items-center pe-3.5 pointer-events-none">
16
+ <IconCalendar class="w-4 h-4 text-gray-500 dark:text-gray-400"/>
30
17
  </div>
18
+
19
+ <input ref="datepickerEndEl" type="text"
20
+ class="bg-gray-50 border leading-none border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
21
+ placeholder="To">
31
22
  </div>
32
23
  </div>
33
24
 
@@ -35,7 +26,7 @@
35
26
  <div class="mx-auto grid grid-cols-2 gap-4 mb-2" :class="{hidden: !showTimeInputs}">
36
27
  <div>
37
28
  <div class="relative">
38
- <div class="absolute inset-y-0 end-0 top-0 flex items-center pe-3.5 pointer-events-none">
29
+ <div class="absolute inset-y-0 end-0 top-0 flex items-center pe-3.5">
39
30
  <IconTime class="w-4 h-4 text-gray-500 dark:text-gray-400 bg-white dark:bg-gray-700"/>
40
31
  </div>
41
32
 
@@ -61,7 +52,7 @@
61
52
  <button type="button"
62
53
  class="text-blue-700 dark:text-blue-500 text-base font-medium hover:underline p-0 inline-flex items-center mb-2"
63
54
  @click="toggleTimeInputs">{{ showTimeInputs ? 'Hide time' : 'Show time' }}
64
- <svg class="w-8 h-8 ms-0.5" :class="{'rotate-180': showTimeInputs}" aria-hidden="true"
55
+ <svg class="w-8 h-8 ms-0.5 relative top-px" :class="{'rotate-180': showTimeInputs}" aria-hidden="true"
65
56
  xmlns="http://www.w3.org/2000/svg" width="24" height="24"
66
57
  fill="none" viewBox="0 0 24 24">
67
58
  <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
@@ -105,7 +105,7 @@ import CustomDateRangePicker from '@/components/CustomDateRangePicker.vue';
105
105
 
106
106
  // props: columns
107
107
  // add support for v-model:filers
108
- const props = defineProps(['columns', 'filters', 'show']);
108
+ const props = defineProps(['columns', 'filters', 'show', 'columnsMinMax']);
109
109
  const emits = defineEmits(['update:filters', 'hide']);
110
110
 
111
111
  const columnsWithFilter = computed(
@@ -79,6 +79,13 @@ onMounted(async () => {
79
79
  });
80
80
 
81
81
  async function saveRecord() {
82
+ if (!isValid.value) {
83
+ validating.value = true;
84
+ return;
85
+ } else {
86
+ validating.value = false;
87
+ }
88
+
82
89
  saving.value = true;
83
90
  await callAdminForthApi({
84
91
  method: 'POST',
@@ -227,7 +227,7 @@
227
227
  </div>
228
228
  <!-- pagination -->
229
229
  <div class="flex flex-col items-center mt-4 xs:flex-row xs:justify-between xs:items-center"
230
- v-if="rows && totalRows > 0"
230
+ v-if="rows && totalRows >= pageSize && totalRows > 0"
231
231
  >
232
232
  <!-- Help text -->
233
233
  <span class="text-sm text-gray-700 dark:text-gray-400">
@@ -379,7 +379,6 @@ async function getList() {
379
379
  sort: sort.value,
380
380
  }
381
381
  });
382
- console.log('coreStore.resourceColumns', coreStore.resourceColumns);
383
382
  rows.value = data.data?.map(row => {
384
383
  row._primaryKeyValue = row[coreStore.resourceColumns.find(c => c.primaryKey).name];
385
384
  return row;