@adminforth/import-export 1.3.1 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,8 +15,6 @@ steps:
15
15
  from_secret: VAULT_TOKEN
16
16
  commands:
17
17
  - infisical export --domain https://vault.devforth.io/api --format=dotenv-export --env="prod" > /woodpecker/deploy.vault.env
18
- secrets:
19
- - VAULT_TOKEN
20
18
 
21
19
  release:
22
20
  image: node:20
package/build.log CHANGED
@@ -10,5 +10,5 @@ custom/package-lock.json
10
10
  custom/package.json
11
11
  custom/tsconfig.json
12
12
 
13
- sent 14,627 bytes received 115 bytes 29,484.00 bytes/sec
14
- total size is 14,207 speedup is 0.96
13
+ sent 16,789 bytes received 115 bytes 33,808.00 bytes/sec
14
+ total size is 16,369 speedup is 0.97
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div @click="exportCsv" class="cursor-pointer flex gap-2 items-center">
2
+ <div class="cursor-pointer flex gap-2 items-center">
3
3
  {{$t("Export")}} {{ meta.select === 'all' ? $t('All'): $t('Filtered') }} {{$t('to CSV')}}
4
4
 
5
5
  <svg v-if="inProgress"
@@ -19,6 +19,10 @@ const filtersStore = useFiltersStore();
19
19
  const coreStore = useCoreStore();
20
20
  const inProgress = ref(false);
21
21
 
22
+ defineExpose({
23
+ click,
24
+ });
25
+
22
26
  const props = defineProps({
23
27
  meta: Object,
24
28
  record: Object,
@@ -77,4 +81,8 @@ async function exportCsv() {
77
81
  adminforth.list.closeThreeDotsDropdown();
78
82
  }
79
83
  }
84
+
85
+ function click() {
86
+ exportCsv();
87
+ }
80
88
  </script>
@@ -1,9 +1,16 @@
1
1
  <template>
2
- <div @click="importCsv" class="cursor-pointer flex gap-2 items-center">
2
+ <div
3
+ :class="[
4
+ 'cursor-pointer flex gap-2 items-center',
5
+ checkProgress ? 'opacity-50 pointer-events-none' : ''
6
+ ]">
3
7
  {{$t('Import from CSV')}}
4
-
5
- <svg v-if="inProgress"
6
- aria-hidden="true" class="w-4 h-4 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/><path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/></svg>
8
+ </div>
9
+ <div v-if="checkProgress" class="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-20">
10
+ <div class="flex flex-col items-center bg-white dark:bg-gray-800 p-6 rounded-lg shadow-lg">
11
+ <p class="text-gray-700 dark:text-gray-300 text-sm">{{ $t('Checking data...') }}</p>
12
+ <svg aria-hidden="true" class="w-4 h-4 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/><path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/></svg>
13
+ </div>
7
14
  </div>
8
15
  <Dialog ref="confirmDialog" :header="t('Import Confirmation')" :buttons="computedButtons">
9
16
  <div v-if="importStats">
@@ -29,20 +36,31 @@
29
36
  <p>{{ $t('Would you like to proceed?') }}</p>
30
37
  </template>
31
38
  </div>
39
+ <div v-if="importProgress" class="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-20">
40
+ <div class="flex flex-col items-center bg-white dark:bg-gray-800 p-6 rounded-lg shadow-lg">
41
+ <p class="text-gray-700 dark:text-gray-300 text-sm">{{ $t('Importing...') }}</p>
42
+ <svg aria-hidden="true" class="w-4 h-4 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/><path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/></svg>
43
+ </div>
44
+ </div>
32
45
  </Dialog>
33
46
  </template>
34
47
 
35
48
  <script setup lang="ts">
36
- import { ref, Ref, computed } from 'vue';
49
+ import { ref, Ref, computed, watch } from 'vue';
37
50
  import { callAdminForthApi } from '@/utils';
38
51
  import adminforth from '@/adminforth';
39
52
  import Papa from 'papaparse';
40
53
  import { Dialog } from '@/afcl';
41
54
  import { useI18n } from 'vue-i18n';
42
55
 
56
+
43
57
  const { t } = useI18n();
58
+ defineExpose({
59
+ click,
60
+ });
44
61
 
45
- const inProgress: Ref<boolean> = ref(false);
62
+ const importProgress: Ref<boolean> = ref(false);
63
+ const checkProgress: Ref<boolean> = ref(false);
46
64
  const confirmDialog = ref(null);
47
65
  const importStats = ref(null);
48
66
  const pendingData = ref(null);
@@ -56,41 +74,43 @@ const computedButtons = computed(() => {
56
74
  const buttons = [
57
75
  { label: t('⚠️ Import All — Replace & Overwrite'), onclick: (dialog) => { confirmImport(dialog) }, visible: importStats.value.existingCount > 0 && importStats.value.newCount > 0 },
58
76
  { label: t('⚠️ Replace Existing Records'), onclick: (dialog) => { confirmImport(dialog) }, visible: importStats.value.existingCount > 0 && importStats.value.newCount === 0 },
59
- { label: t('Import New Only'), onclick: (dialog) => { confirmImportNewOnly(dialog) }, visible: importStats.value.existingCount > 0 && importStats.value.newCount > 0 },
60
- { label: t('Import Records'), onclick: (dialog) => { confirmImportNewOnly(dialog) }, visible: importStats.value.existingCount === 0 && importStats.value.newCount > 0 },
61
- { label: t('Cancel'), onclick: (dialog) => dialog.hide() }
77
+ { label: t('Import New Only'), onclick: (dialog) => { confirmImportNewOnly(dialog) }, visible: importStats.value.existingCount > 0 && importStats.value.newCount > 0 },
78
+ { label: t('Import Records'), onclick: (dialog) => { confirmImportNewOnly(dialog) }, visible: importStats.value.existingCount === 0 && importStats.value.newCount > 0 },
79
+ { label: t('Cancel'), onclick: (dialog) => dialog.hide() }
62
80
  ];
63
81
 
64
82
  return buttons.filter(button => button.visible !== false);
65
83
  });
66
84
  async function confirmImport(dialog) {
67
- dialog.hide();
68
85
  await postData(pendingData.value);
86
+ dialog.hide();
69
87
  }
70
88
 
71
89
  async function checkRecords(data: Record<string, string[]>) {
90
+ checkProgress.value = true;
72
91
  const resp = await callAdminForthApi({
73
92
  path: `/plugin/${props.meta.pluginInstanceId}/check-records`,
74
93
  method: 'POST',
75
94
  body: { data }
76
95
  });
77
-
96
+ checkProgress.value = false;
78
97
  return resp;
79
98
  }
80
99
 
81
100
  async function confirmImportNewOnly(dialog) {
82
- dialog.hide();
83
101
  await postDataNewOnly(pendingData.value);
102
+ dialog.hide();
84
103
  }
85
104
 
86
105
  async function postData(data: Record<string, string[]>, skipDuplicates: boolean = false) {
106
+ importProgress.value = true;
87
107
  const resp = await callAdminForthApi({
88
108
  path: `/plugin/${props.meta.pluginInstanceId}/import-csv`,
89
109
  method: 'POST',
90
110
  body: { data }
91
111
  });
92
112
 
93
- inProgress.value = false;
113
+ importProgress.value = false;
94
114
 
95
115
  if (resp.importedCount > 0 || resp.updatedCount > 0) {
96
116
  adminforth.list.refresh();
@@ -106,13 +126,14 @@ async function postData(data: Record<string, string[]>, skipDuplicates: boolean
106
126
  }
107
127
 
108
128
  async function postDataNewOnly(data: Record<string, string[]>) {
129
+ importProgress.value = true;
109
130
  const resp = await callAdminForthApi({
110
131
  path: `/plugin/${props.meta.pluginInstanceId}/import-csv-new-only`,
111
132
  method: 'POST',
112
133
  body: { data }
113
134
  });
114
135
 
115
- inProgress.value = false;
136
+ importProgress.value = false;
116
137
  if (resp.importedCount > 0) {
117
138
  adminforth.list.refresh();
118
139
  }
@@ -125,18 +146,15 @@ async function postDataNewOnly(data: Record<string, string[]>) {
125
146
  }
126
147
 
127
148
  async function importCsv() {
128
- inProgress.value = false;
129
149
  const fileInput = document.createElement('input');
130
150
 
131
151
  fileInput.type = 'file';
132
152
  fileInput.accept = '.csv';
133
153
  fileInput.click();
134
154
  fileInput.onchange = async (e) => {
135
- inProgress.value = true;
136
155
 
137
156
  const file = (e.target as HTMLInputElement).files?.[0];
138
157
  if (!file) {
139
- inProgress.value = false;
140
158
  return;
141
159
  }
142
160
  const reader = new FileReader();
@@ -177,7 +195,6 @@ async function importCsv() {
177
195
  const stats = await checkRecords(data);
178
196
  importStats.value = stats;
179
197
  confirmDialog.value?.open();
180
- inProgress.value = false;
181
198
  },
182
199
  error: (error) => {
183
200
  adminforth.alert({
@@ -188,7 +205,6 @@ async function importCsv() {
188
205
  }
189
206
  });
190
207
  } catch (error) {
191
- inProgress.value = false;
192
208
  adminforth.alert({
193
209
  message: `Error processing CSV: ${error.message}`,
194
210
  variant: 'danger'
@@ -198,4 +214,14 @@ async function importCsv() {
198
214
  reader.readAsText(file);
199
215
  };
200
216
  }
217
+ function handleImportClick() {
218
+ console.log('handleImportClick', checkProgress.value);
219
+ if (!checkProgress.value) {
220
+ importCsv();
221
+ }
222
+ }
223
+
224
+ function click() {
225
+ importCsv();
226
+ }
201
227
  </script>
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div @click="exportCsv" class="cursor-pointer flex gap-2 items-center">
2
+ <div class="cursor-pointer flex gap-2 items-center">
3
3
  {{$t("Export")}} {{ meta.select === 'all' ? $t('All'): $t('Filtered') }} {{$t('to CSV')}}
4
4
 
5
5
  <svg v-if="inProgress"
@@ -19,6 +19,10 @@ const filtersStore = useFiltersStore();
19
19
  const coreStore = useCoreStore();
20
20
  const inProgress = ref(false);
21
21
 
22
+ defineExpose({
23
+ click,
24
+ });
25
+
22
26
  const props = defineProps({
23
27
  meta: Object,
24
28
  record: Object,
@@ -77,4 +81,8 @@ async function exportCsv() {
77
81
  adminforth.list.closeThreeDotsDropdown();
78
82
  }
79
83
  }
84
+
85
+ function click() {
86
+ exportCsv();
87
+ }
80
88
  </script>
@@ -1,9 +1,16 @@
1
1
  <template>
2
- <div @click="importCsv" class="cursor-pointer flex gap-2 items-center">
2
+ <div
3
+ :class="[
4
+ 'cursor-pointer flex gap-2 items-center',
5
+ checkProgress ? 'opacity-50 pointer-events-none' : ''
6
+ ]">
3
7
  {{$t('Import from CSV')}}
4
-
5
- <svg v-if="inProgress"
6
- aria-hidden="true" class="w-4 h-4 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/><path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/></svg>
8
+ </div>
9
+ <div v-if="checkProgress" class="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-20">
10
+ <div class="flex flex-col items-center bg-white dark:bg-gray-800 p-6 rounded-lg shadow-lg">
11
+ <p class="text-gray-700 dark:text-gray-300 text-sm">{{ $t('Checking data...') }}</p>
12
+ <svg aria-hidden="true" class="w-4 h-4 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/><path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/></svg>
13
+ </div>
7
14
  </div>
8
15
  <Dialog ref="confirmDialog" :header="t('Import Confirmation')" :buttons="computedButtons">
9
16
  <div v-if="importStats">
@@ -29,20 +36,31 @@
29
36
  <p>{{ $t('Would you like to proceed?') }}</p>
30
37
  </template>
31
38
  </div>
39
+ <div v-if="importProgress" class="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-20">
40
+ <div class="flex flex-col items-center bg-white dark:bg-gray-800 p-6 rounded-lg shadow-lg">
41
+ <p class="text-gray-700 dark:text-gray-300 text-sm">{{ $t('Importing...') }}</p>
42
+ <svg aria-hidden="true" class="w-4 h-4 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/><path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/></svg>
43
+ </div>
44
+ </div>
32
45
  </Dialog>
33
46
  </template>
34
47
 
35
48
  <script setup lang="ts">
36
- import { ref, Ref, computed } from 'vue';
49
+ import { ref, Ref, computed, watch } from 'vue';
37
50
  import { callAdminForthApi } from '@/utils';
38
51
  import adminforth from '@/adminforth';
39
52
  import Papa from 'papaparse';
40
53
  import { Dialog } from '@/afcl';
41
54
  import { useI18n } from 'vue-i18n';
42
55
 
56
+
43
57
  const { t } = useI18n();
58
+ defineExpose({
59
+ click,
60
+ });
44
61
 
45
- const inProgress: Ref<boolean> = ref(false);
62
+ const importProgress: Ref<boolean> = ref(false);
63
+ const checkProgress: Ref<boolean> = ref(false);
46
64
  const confirmDialog = ref(null);
47
65
  const importStats = ref(null);
48
66
  const pendingData = ref(null);
@@ -56,41 +74,43 @@ const computedButtons = computed(() => {
56
74
  const buttons = [
57
75
  { label: t('⚠️ Import All — Replace & Overwrite'), onclick: (dialog) => { confirmImport(dialog) }, visible: importStats.value.existingCount > 0 && importStats.value.newCount > 0 },
58
76
  { label: t('⚠️ Replace Existing Records'), onclick: (dialog) => { confirmImport(dialog) }, visible: importStats.value.existingCount > 0 && importStats.value.newCount === 0 },
59
- { label: t('Import New Only'), onclick: (dialog) => { confirmImportNewOnly(dialog) }, visible: importStats.value.existingCount > 0 && importStats.value.newCount > 0 },
60
- { label: t('Import Records'), onclick: (dialog) => { confirmImportNewOnly(dialog) }, visible: importStats.value.existingCount === 0 && importStats.value.newCount > 0 },
61
- { label: t('Cancel'), onclick: (dialog) => dialog.hide() }
77
+ { label: t('Import New Only'), onclick: (dialog) => { confirmImportNewOnly(dialog) }, visible: importStats.value.existingCount > 0 && importStats.value.newCount > 0 },
78
+ { label: t('Import Records'), onclick: (dialog) => { confirmImportNewOnly(dialog) }, visible: importStats.value.existingCount === 0 && importStats.value.newCount > 0 },
79
+ { label: t('Cancel'), onclick: (dialog) => dialog.hide() }
62
80
  ];
63
81
 
64
82
  return buttons.filter(button => button.visible !== false);
65
83
  });
66
84
  async function confirmImport(dialog) {
67
- dialog.hide();
68
85
  await postData(pendingData.value);
86
+ dialog.hide();
69
87
  }
70
88
 
71
89
  async function checkRecords(data: Record<string, string[]>) {
90
+ checkProgress.value = true;
72
91
  const resp = await callAdminForthApi({
73
92
  path: `/plugin/${props.meta.pluginInstanceId}/check-records`,
74
93
  method: 'POST',
75
94
  body: { data }
76
95
  });
77
-
96
+ checkProgress.value = false;
78
97
  return resp;
79
98
  }
80
99
 
81
100
  async function confirmImportNewOnly(dialog) {
82
- dialog.hide();
83
101
  await postDataNewOnly(pendingData.value);
102
+ dialog.hide();
84
103
  }
85
104
 
86
105
  async function postData(data: Record<string, string[]>, skipDuplicates: boolean = false) {
106
+ importProgress.value = true;
87
107
  const resp = await callAdminForthApi({
88
108
  path: `/plugin/${props.meta.pluginInstanceId}/import-csv`,
89
109
  method: 'POST',
90
110
  body: { data }
91
111
  });
92
112
 
93
- inProgress.value = false;
113
+ importProgress.value = false;
94
114
 
95
115
  if (resp.importedCount > 0 || resp.updatedCount > 0) {
96
116
  adminforth.list.refresh();
@@ -106,13 +126,14 @@ async function postData(data: Record<string, string[]>, skipDuplicates: boolean
106
126
  }
107
127
 
108
128
  async function postDataNewOnly(data: Record<string, string[]>) {
129
+ importProgress.value = true;
109
130
  const resp = await callAdminForthApi({
110
131
  path: `/plugin/${props.meta.pluginInstanceId}/import-csv-new-only`,
111
132
  method: 'POST',
112
133
  body: { data }
113
134
  });
114
135
 
115
- inProgress.value = false;
136
+ importProgress.value = false;
116
137
  if (resp.importedCount > 0) {
117
138
  adminforth.list.refresh();
118
139
  }
@@ -125,18 +146,15 @@ async function postDataNewOnly(data: Record<string, string[]>) {
125
146
  }
126
147
 
127
148
  async function importCsv() {
128
- inProgress.value = false;
129
149
  const fileInput = document.createElement('input');
130
150
 
131
151
  fileInput.type = 'file';
132
152
  fileInput.accept = '.csv';
133
153
  fileInput.click();
134
154
  fileInput.onchange = async (e) => {
135
- inProgress.value = true;
136
155
 
137
156
  const file = (e.target as HTMLInputElement).files?.[0];
138
157
  if (!file) {
139
- inProgress.value = false;
140
158
  return;
141
159
  }
142
160
  const reader = new FileReader();
@@ -177,7 +195,6 @@ async function importCsv() {
177
195
  const stats = await checkRecords(data);
178
196
  importStats.value = stats;
179
197
  confirmDialog.value?.open();
180
- inProgress.value = false;
181
198
  },
182
199
  error: (error) => {
183
200
  adminforth.alert({
@@ -188,7 +205,6 @@ async function importCsv() {
188
205
  }
189
206
  });
190
207
  } catch (error) {
191
- inProgress.value = false;
192
208
  adminforth.alert({
193
209
  message: `Error processing CSV: ${error.message}`,
194
210
  variant: 'danger'
@@ -198,4 +214,14 @@ async function importCsv() {
198
214
  reader.readAsText(file);
199
215
  };
200
216
  }
217
+ function handleImportClick() {
218
+ console.log('handleImportClick', checkProgress.value);
219
+ if (!checkProgress.value) {
220
+ importCsv();
221
+ }
222
+ }
223
+
224
+ function click() {
225
+ importCsv();
226
+ }
201
227
  </script>
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { AdminForthPlugin, suggestIfTypo, Filters } from "adminforth";
10
+ import { AdminForthPlugin, suggestIfTypo, AdminForthFilterOperators, Filters } from "adminforth";
11
11
  export default class ImportExport extends AdminForthPlugin {
12
12
  constructor(options) {
13
13
  super(options, import.meta.url);
@@ -191,26 +191,30 @@ export default class ImportExport extends AdminForthPlugin {
191
191
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body }) {
192
192
  const { data } = body;
193
193
  const primaryKeyColumn = this.resourceConfig.columns.find(col => col.primaryKey);
194
- const rows = [];
195
194
  const columns = Object.keys(data);
196
195
  const columnValues = Object.values(data);
197
- for (let i = 0; i < columnValues[0].length; i++) {
196
+ const rows = Array.from({ length: columnValues[0].length }, (_, i) => {
198
197
  const row = {};
199
198
  for (let j = 0; j < columns.length; j++) {
200
199
  row[columns[j]] = columnValues[j][i];
201
200
  }
202
- rows.push(row);
203
- }
201
+ return row;
202
+ });
204
203
  const primaryKeys = rows
205
204
  .map(row => row[primaryKeyColumn.name])
206
205
  .filter(key => key !== undefined && key !== null && key !== '');
207
- const records = yield this.adminforth.resource(this.resourceConfig.resourceId).list([]);
208
- const existingRecords = records.filter((record) => primaryKeys.includes(record[primaryKeyColumn.name]));
206
+ const existingRecords = yield this.adminforth
207
+ .resource(this.resourceConfig.resourceId)
208
+ .list([{
209
+ field: primaryKeyColumn.name,
210
+ operator: AdminForthFilterOperators.IN,
211
+ value: primaryKeys,
212
+ }]);
209
213
  return {
210
214
  ok: true,
211
215
  total: rows.length,
212
216
  existingCount: existingRecords.length,
213
- newCount: rows.length - existingRecords.length
217
+ newCount: rows.length - existingRecords.length,
214
218
  };
215
219
  })
216
220
  });
package/index.ts CHANGED
@@ -212,35 +212,38 @@ export default class ImportExport extends AdminForthPlugin {
212
212
  path: `/plugin/${this.pluginInstanceId}/check-records`,
213
213
  noAuth: true,
214
214
  handler: async ({ body }) => {
215
- const { data } = body;
216
-
215
+ const { data } = body as { data: Record<string, unknown[]> };
217
216
  const primaryKeyColumn = this.resourceConfig.columns.find(col => col.primaryKey);
218
-
219
- const rows = [];
220
217
  const columns = Object.keys(data);
221
218
  const columnValues = Object.values(data);
222
- for (let i = 0; i < (columnValues[0] as any[]).length; i++) {
219
+
220
+ const rows = Array.from({ length: columnValues[0].length }, (_, i) => {
223
221
  const row = {};
224
222
  for (let j = 0; j < columns.length; j++) {
225
223
  row[columns[j]] = columnValues[j][i];
226
224
  }
227
- rows.push(row);
228
- }
225
+ return row;
226
+ });
229
227
 
230
228
  const primaryKeys = rows
231
229
  .map(row => row[primaryKeyColumn.name])
232
230
  .filter(key => key !== undefined && key !== null && key !== '');
233
231
 
234
- const records = await this.adminforth.resource(this.resourceConfig.resourceId).list([])
235
-
236
- const existingRecords = records.filter((record) => primaryKeys.includes(record[primaryKeyColumn.name]));
232
+ const existingRecords = await this.adminforth
233
+ .resource(this.resourceConfig.resourceId)
234
+ .list([{
235
+ field: primaryKeyColumn.name,
236
+ operator: AdminForthFilterOperators.IN,
237
+ value: primaryKeys,
238
+ }]);
237
239
 
238
240
  return {
239
241
  ok: true,
240
242
  total: rows.length,
241
243
  existingCount: existingRecords.length,
242
- newCount: rows.length - existingRecords.length
244
+ newCount: rows.length - existingRecords.length,
243
245
  };
246
+
244
247
  }
245
248
  });
246
249
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/import-export",
3
- "version": "1.3.1",
3
+ "version": "1.4.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",