@adminforth/import-export 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build.log +2 -2
- package/custom/ImportCsv.vue +34 -16
- package/dist/custom/ImportCsv.vue +34 -16
- package/dist/index.js +12 -8
- package/index.ts +14 -11
- package/package.json +1 -1
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
|
-
total size is
|
|
13
|
+
sent 16,715 bytes received 115 bytes 33,660.00 bytes/sec
|
|
14
|
+
total size is 16,295 speedup is 0.97
|
package/custom/ImportCsv.vue
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div @click="
|
|
2
|
+
<div @click="handleImportClick"
|
|
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
|
-
|
|
6
|
-
|
|
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,11 +36,17 @@
|
|
|
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';
|
|
@@ -42,7 +55,8 @@ import { useI18n } from 'vue-i18n';
|
|
|
42
55
|
|
|
43
56
|
const { t } = useI18n();
|
|
44
57
|
|
|
45
|
-
const
|
|
58
|
+
const importProgress: Ref<boolean> = ref(false);
|
|
59
|
+
const checkProgress: Ref<boolean> = ref(false);
|
|
46
60
|
const confirmDialog = ref(null);
|
|
47
61
|
const importStats = ref(null);
|
|
48
62
|
const pendingData = ref(null);
|
|
@@ -64,33 +78,35 @@ const computedButtons = computed(() => {
|
|
|
64
78
|
return buttons.filter(button => button.visible !== false);
|
|
65
79
|
});
|
|
66
80
|
async function confirmImport(dialog) {
|
|
67
|
-
dialog.hide();
|
|
68
81
|
await postData(pendingData.value);
|
|
82
|
+
dialog.hide();
|
|
69
83
|
}
|
|
70
84
|
|
|
71
85
|
async function checkRecords(data: Record<string, string[]>) {
|
|
86
|
+
checkProgress.value = true;
|
|
72
87
|
const resp = await callAdminForthApi({
|
|
73
88
|
path: `/plugin/${props.meta.pluginInstanceId}/check-records`,
|
|
74
89
|
method: 'POST',
|
|
75
90
|
body: { data }
|
|
76
91
|
});
|
|
77
|
-
|
|
92
|
+
checkProgress.value = false;
|
|
78
93
|
return resp;
|
|
79
94
|
}
|
|
80
95
|
|
|
81
96
|
async function confirmImportNewOnly(dialog) {
|
|
82
|
-
dialog.hide();
|
|
83
97
|
await postDataNewOnly(pendingData.value);
|
|
98
|
+
dialog.hide();
|
|
84
99
|
}
|
|
85
100
|
|
|
86
101
|
async function postData(data: Record<string, string[]>, skipDuplicates: boolean = false) {
|
|
102
|
+
importProgress.value = true;
|
|
87
103
|
const resp = await callAdminForthApi({
|
|
88
104
|
path: `/plugin/${props.meta.pluginInstanceId}/import-csv`,
|
|
89
105
|
method: 'POST',
|
|
90
106
|
body: { data }
|
|
91
107
|
});
|
|
92
108
|
|
|
93
|
-
|
|
109
|
+
importProgress.value = false;
|
|
94
110
|
|
|
95
111
|
if (resp.importedCount > 0 || resp.updatedCount > 0) {
|
|
96
112
|
adminforth.list.refresh();
|
|
@@ -106,13 +122,14 @@ async function postData(data: Record<string, string[]>, skipDuplicates: boolean
|
|
|
106
122
|
}
|
|
107
123
|
|
|
108
124
|
async function postDataNewOnly(data: Record<string, string[]>) {
|
|
125
|
+
importProgress.value = true;
|
|
109
126
|
const resp = await callAdminForthApi({
|
|
110
127
|
path: `/plugin/${props.meta.pluginInstanceId}/import-csv-new-only`,
|
|
111
128
|
method: 'POST',
|
|
112
129
|
body: { data }
|
|
113
130
|
});
|
|
114
131
|
|
|
115
|
-
|
|
132
|
+
importProgress.value = false;
|
|
116
133
|
if (resp.importedCount > 0) {
|
|
117
134
|
adminforth.list.refresh();
|
|
118
135
|
}
|
|
@@ -125,18 +142,15 @@ async function postDataNewOnly(data: Record<string, string[]>) {
|
|
|
125
142
|
}
|
|
126
143
|
|
|
127
144
|
async function importCsv() {
|
|
128
|
-
inProgress.value = false;
|
|
129
145
|
const fileInput = document.createElement('input');
|
|
130
146
|
|
|
131
147
|
fileInput.type = 'file';
|
|
132
148
|
fileInput.accept = '.csv';
|
|
133
149
|
fileInput.click();
|
|
134
150
|
fileInput.onchange = async (e) => {
|
|
135
|
-
inProgress.value = true;
|
|
136
151
|
|
|
137
152
|
const file = (e.target as HTMLInputElement).files?.[0];
|
|
138
153
|
if (!file) {
|
|
139
|
-
inProgress.value = false;
|
|
140
154
|
return;
|
|
141
155
|
}
|
|
142
156
|
const reader = new FileReader();
|
|
@@ -177,7 +191,6 @@ async function importCsv() {
|
|
|
177
191
|
const stats = await checkRecords(data);
|
|
178
192
|
importStats.value = stats;
|
|
179
193
|
confirmDialog.value?.open();
|
|
180
|
-
inProgress.value = false;
|
|
181
194
|
},
|
|
182
195
|
error: (error) => {
|
|
183
196
|
adminforth.alert({
|
|
@@ -188,7 +201,6 @@ async function importCsv() {
|
|
|
188
201
|
}
|
|
189
202
|
});
|
|
190
203
|
} catch (error) {
|
|
191
|
-
inProgress.value = false;
|
|
192
204
|
adminforth.alert({
|
|
193
205
|
message: `Error processing CSV: ${error.message}`,
|
|
194
206
|
variant: 'danger'
|
|
@@ -198,4 +210,10 @@ async function importCsv() {
|
|
|
198
210
|
reader.readAsText(file);
|
|
199
211
|
};
|
|
200
212
|
}
|
|
213
|
+
function handleImportClick() {
|
|
214
|
+
console.log('handleImportClick', checkProgress.value);
|
|
215
|
+
if (!checkProgress.value) {
|
|
216
|
+
importCsv();
|
|
217
|
+
}
|
|
218
|
+
}
|
|
201
219
|
</script>
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div @click="
|
|
2
|
+
<div @click="handleImportClick"
|
|
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
|
-
|
|
6
|
-
|
|
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,11 +36,17 @@
|
|
|
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';
|
|
@@ -42,7 +55,8 @@ import { useI18n } from 'vue-i18n';
|
|
|
42
55
|
|
|
43
56
|
const { t } = useI18n();
|
|
44
57
|
|
|
45
|
-
const
|
|
58
|
+
const importProgress: Ref<boolean> = ref(false);
|
|
59
|
+
const checkProgress: Ref<boolean> = ref(false);
|
|
46
60
|
const confirmDialog = ref(null);
|
|
47
61
|
const importStats = ref(null);
|
|
48
62
|
const pendingData = ref(null);
|
|
@@ -64,33 +78,35 @@ const computedButtons = computed(() => {
|
|
|
64
78
|
return buttons.filter(button => button.visible !== false);
|
|
65
79
|
});
|
|
66
80
|
async function confirmImport(dialog) {
|
|
67
|
-
dialog.hide();
|
|
68
81
|
await postData(pendingData.value);
|
|
82
|
+
dialog.hide();
|
|
69
83
|
}
|
|
70
84
|
|
|
71
85
|
async function checkRecords(data: Record<string, string[]>) {
|
|
86
|
+
checkProgress.value = true;
|
|
72
87
|
const resp = await callAdminForthApi({
|
|
73
88
|
path: `/plugin/${props.meta.pluginInstanceId}/check-records`,
|
|
74
89
|
method: 'POST',
|
|
75
90
|
body: { data }
|
|
76
91
|
});
|
|
77
|
-
|
|
92
|
+
checkProgress.value = false;
|
|
78
93
|
return resp;
|
|
79
94
|
}
|
|
80
95
|
|
|
81
96
|
async function confirmImportNewOnly(dialog) {
|
|
82
|
-
dialog.hide();
|
|
83
97
|
await postDataNewOnly(pendingData.value);
|
|
98
|
+
dialog.hide();
|
|
84
99
|
}
|
|
85
100
|
|
|
86
101
|
async function postData(data: Record<string, string[]>, skipDuplicates: boolean = false) {
|
|
102
|
+
importProgress.value = true;
|
|
87
103
|
const resp = await callAdminForthApi({
|
|
88
104
|
path: `/plugin/${props.meta.pluginInstanceId}/import-csv`,
|
|
89
105
|
method: 'POST',
|
|
90
106
|
body: { data }
|
|
91
107
|
});
|
|
92
108
|
|
|
93
|
-
|
|
109
|
+
importProgress.value = false;
|
|
94
110
|
|
|
95
111
|
if (resp.importedCount > 0 || resp.updatedCount > 0) {
|
|
96
112
|
adminforth.list.refresh();
|
|
@@ -106,13 +122,14 @@ async function postData(data: Record<string, string[]>, skipDuplicates: boolean
|
|
|
106
122
|
}
|
|
107
123
|
|
|
108
124
|
async function postDataNewOnly(data: Record<string, string[]>) {
|
|
125
|
+
importProgress.value = true;
|
|
109
126
|
const resp = await callAdminForthApi({
|
|
110
127
|
path: `/plugin/${props.meta.pluginInstanceId}/import-csv-new-only`,
|
|
111
128
|
method: 'POST',
|
|
112
129
|
body: { data }
|
|
113
130
|
});
|
|
114
131
|
|
|
115
|
-
|
|
132
|
+
importProgress.value = false;
|
|
116
133
|
if (resp.importedCount > 0) {
|
|
117
134
|
adminforth.list.refresh();
|
|
118
135
|
}
|
|
@@ -125,18 +142,15 @@ async function postDataNewOnly(data: Record<string, string[]>) {
|
|
|
125
142
|
}
|
|
126
143
|
|
|
127
144
|
async function importCsv() {
|
|
128
|
-
inProgress.value = false;
|
|
129
145
|
const fileInput = document.createElement('input');
|
|
130
146
|
|
|
131
147
|
fileInput.type = 'file';
|
|
132
148
|
fileInput.accept = '.csv';
|
|
133
149
|
fileInput.click();
|
|
134
150
|
fileInput.onchange = async (e) => {
|
|
135
|
-
inProgress.value = true;
|
|
136
151
|
|
|
137
152
|
const file = (e.target as HTMLInputElement).files?.[0];
|
|
138
153
|
if (!file) {
|
|
139
|
-
inProgress.value = false;
|
|
140
154
|
return;
|
|
141
155
|
}
|
|
142
156
|
const reader = new FileReader();
|
|
@@ -177,7 +191,6 @@ async function importCsv() {
|
|
|
177
191
|
const stats = await checkRecords(data);
|
|
178
192
|
importStats.value = stats;
|
|
179
193
|
confirmDialog.value?.open();
|
|
180
|
-
inProgress.value = false;
|
|
181
194
|
},
|
|
182
195
|
error: (error) => {
|
|
183
196
|
adminforth.alert({
|
|
@@ -188,7 +201,6 @@ async function importCsv() {
|
|
|
188
201
|
}
|
|
189
202
|
});
|
|
190
203
|
} catch (error) {
|
|
191
|
-
inProgress.value = false;
|
|
192
204
|
adminforth.alert({
|
|
193
205
|
message: `Error processing CSV: ${error.message}`,
|
|
194
206
|
variant: 'danger'
|
|
@@ -198,4 +210,10 @@ async function importCsv() {
|
|
|
198
210
|
reader.readAsText(file);
|
|
199
211
|
};
|
|
200
212
|
}
|
|
213
|
+
function handleImportClick() {
|
|
214
|
+
console.log('handleImportClick', checkProgress.value);
|
|
215
|
+
if (!checkProgress.value) {
|
|
216
|
+
importCsv();
|
|
217
|
+
}
|
|
218
|
+
}
|
|
201
219
|
</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
|
-
|
|
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
|
-
|
|
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
|
|
208
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
235
|
-
|
|
236
|
-
|
|
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
|
}
|