@adminforth/import-export 1.0.0 → 1.0.2
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/custom/ExportCsv.vue +2 -1
- package/custom/ImportCsv.vue +8 -4
- package/dist/custom/ExportCsv.vue +72 -0
- package/dist/custom/ImportCsv.vue +93 -0
- package/dist/index.js +140 -0
- package/dist/types.js +1 -0
- package/index.ts +16 -2
- package/package.json +4 -9
package/custom/ExportCsv.vue
CHANGED
|
@@ -61,9 +61,10 @@ async function exportCsv() {
|
|
|
61
61
|
} else {
|
|
62
62
|
loadFile(resp.data, `export-${coreStore.resource.resourceId}-${new Date().toISOString()}.csv`);
|
|
63
63
|
window.adminforth.alert({
|
|
64
|
-
message:
|
|
64
|
+
message: `Exported ${resp.exportedCount} item${resp.exportedCount > 1 ? 's' : ''} successfully. Check your downloads folder`,
|
|
65
65
|
})
|
|
66
66
|
}
|
|
67
|
+
window.adminforth.list.closeThreeDotsDropdown();
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
|
package/custom/ImportCsv.vue
CHANGED
|
@@ -31,13 +31,18 @@ async function postData(data: Record<string, string[]>) {
|
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
inProgress.value = false;
|
|
34
|
-
|
|
34
|
+
|
|
35
|
+
if (resp.importedCount > 0) {
|
|
36
|
+
window.adminforth.list.refresh();
|
|
37
|
+
}
|
|
35
38
|
window.adminforth.alert({
|
|
36
|
-
message: `Imported count ${resp.importedCount} records. ${resp.errors
|
|
37
|
-
variant: resp.errors
|
|
39
|
+
message: `Imported count ${resp.importedCount || 0} records. ${resp.errors?.length ? `Errors: ${resp.errors.join(', ')}` : ''}`,
|
|
40
|
+
variant: resp.errors?.length ? (
|
|
38
41
|
resp.importedCount ? 'warning' : 'danger'
|
|
39
42
|
) : 'success'
|
|
40
43
|
});
|
|
44
|
+
|
|
45
|
+
window.adminforth.list.closeThreeDotsDropdown();
|
|
41
46
|
}
|
|
42
47
|
|
|
43
48
|
async function importCsv() {
|
|
@@ -63,7 +68,6 @@ async function importCsv() {
|
|
|
63
68
|
const reader = new FileReader();
|
|
64
69
|
reader.onload = async (e) => {
|
|
65
70
|
const text = e.target.result as string;
|
|
66
|
-
console.log('fileInput.onchange 3 ', text);
|
|
67
71
|
|
|
68
72
|
const lines = text.split('\n');
|
|
69
73
|
const columns = lines[0].split(',');
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div @click="exportCsv" class="cursor-pointer flex gap-2 items-center">
|
|
3
|
+
Export {{ meta.select === 'all' ? 'All': 'Filtered' }} to 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>
|
|
7
|
+
|
|
8
|
+
</div>
|
|
9
|
+
</template>
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
<script setup lang="ts">
|
|
13
|
+
|
|
14
|
+
import { onMounted, ref } from 'vue';
|
|
15
|
+
import { useCoreStore } from '@/stores/core';
|
|
16
|
+
import { callAdminForthApi, loadFile } from '@/utils';
|
|
17
|
+
import { useFiltersStore } from '@/stores/filters';
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
const filtersStore = useFiltersStore();
|
|
21
|
+
|
|
22
|
+
const props = defineProps({
|
|
23
|
+
meta: Object,
|
|
24
|
+
record: Object,
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
const inProgress = ref(false);
|
|
28
|
+
|
|
29
|
+
const coreStore = useCoreStore();
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
onMounted(async () => {
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
function loadFile(data, filename) {
|
|
36
|
+
const blob = new Blob([data], { type: 'text/csv' });
|
|
37
|
+
const url = window.URL.createObjectURL(blob);
|
|
38
|
+
const a = document.createElement('a');
|
|
39
|
+
a.href = url;
|
|
40
|
+
a.download = filename;
|
|
41
|
+
a.click();
|
|
42
|
+
window.URL.revokeObjectURL(url);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function exportCsv() {
|
|
46
|
+
|
|
47
|
+
inProgress.value = true;
|
|
48
|
+
const resp = await callAdminForthApi({
|
|
49
|
+
path: `/plugin/${props.meta.pluginInstanceId}/export-csv`,
|
|
50
|
+
method: 'POST',
|
|
51
|
+
body: {
|
|
52
|
+
filters: props.meta.select === 'all' ? [] : filtersStore.getFilters(),
|
|
53
|
+
sort: filtersStore.getSort(),
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
inProgress.value = false;
|
|
57
|
+
if (resp.error) {
|
|
58
|
+
window.adminforth.alert({
|
|
59
|
+
message: resp.error,
|
|
60
|
+
})
|
|
61
|
+
} else {
|
|
62
|
+
loadFile(resp.data, `export-${coreStore.resource.resourceId}-${new Date().toISOString()}.csv`);
|
|
63
|
+
window.adminforth.alert({
|
|
64
|
+
message: `Exported ${resp.exportedCount} item${resp.exportedCount > 1 ? 's' : ''} successfully. Check your downloads folder`,
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
window.adminforth.list.closeThreeDotsDropdown();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
</script>
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div @click="importCsv" class="cursor-pointer flex gap-2 items-center">
|
|
3
|
+
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>
|
|
7
|
+
|
|
8
|
+
</div>
|
|
9
|
+
</template>
|
|
10
|
+
|
|
11
|
+
<script setup lang="ts">
|
|
12
|
+
import { ref, Ref } from 'vue';
|
|
13
|
+
import { callAdminForthApi } from '@/utils';
|
|
14
|
+
|
|
15
|
+
const inProgress: Ref<boolean> = ref(false);
|
|
16
|
+
|
|
17
|
+
const props = defineProps({
|
|
18
|
+
meta: Object,
|
|
19
|
+
record: Object,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
async function postData(data: Record<string, string[]>) {
|
|
23
|
+
console.log('postData 1 ', data);
|
|
24
|
+
|
|
25
|
+
const resp = await callAdminForthApi({
|
|
26
|
+
path: `/plugin/${props.meta.pluginInstanceId}/import-csv`,
|
|
27
|
+
method: 'POST',
|
|
28
|
+
body: {
|
|
29
|
+
data
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
inProgress.value = false;
|
|
34
|
+
|
|
35
|
+
if (resp.importedCount > 0) {
|
|
36
|
+
window.adminforth.list.refresh();
|
|
37
|
+
}
|
|
38
|
+
window.adminforth.alert({
|
|
39
|
+
message: `Imported count ${resp.importedCount || 0} records. ${resp.errors?.length ? `Errors: ${resp.errors.join(', ')}` : ''}`,
|
|
40
|
+
variant: resp.errors?.length ? (
|
|
41
|
+
resp.importedCount ? 'warning' : 'danger'
|
|
42
|
+
) : 'success'
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
window.adminforth.list.closeThreeDotsDropdown();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function importCsv() {
|
|
49
|
+
// create file input and open it (with csv type)
|
|
50
|
+
inProgress.value = false;
|
|
51
|
+
const fileInput = document.createElement('input');
|
|
52
|
+
|
|
53
|
+
fileInput.type = 'file';
|
|
54
|
+
fileInput.accept = '.csv';
|
|
55
|
+
fileInput.click();
|
|
56
|
+
fileInput.onchange = async (e) => {
|
|
57
|
+
inProgress.value = true;
|
|
58
|
+
|
|
59
|
+
const file = (e.target as HTMLInputElement).files?.[0];
|
|
60
|
+
if (!file) {
|
|
61
|
+
inProgress.value = false;
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// post data in format, plain json
|
|
66
|
+
// data is in format {[columnName]: [value1, value2, value3...], [columnName2]: [value1, value2, value3...]}
|
|
67
|
+
const data = {};
|
|
68
|
+
const reader = new FileReader();
|
|
69
|
+
reader.onload = async (e) => {
|
|
70
|
+
const text = e.target.result as string;
|
|
71
|
+
|
|
72
|
+
const lines = text.split('\n');
|
|
73
|
+
const columns = lines[0].split(',');
|
|
74
|
+
for (let i = 1; i < lines.length; i++) {
|
|
75
|
+
const values = lines[i].split(',');
|
|
76
|
+
for (let j = 0; j < columns.length; j++) {
|
|
77
|
+
if (!data[columns[j]]) {
|
|
78
|
+
data[columns[j]] = [];
|
|
79
|
+
}
|
|
80
|
+
data[columns[j]].push(values[j]);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
await postData(data);
|
|
84
|
+
};
|
|
85
|
+
reader.readAsText(file);
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
</script>
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { AdminForthPlugin, suggestIfTypo, AdminForthFilterOperators } from "adminforth";
|
|
11
|
+
export default class ImportExport extends AdminForthPlugin {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
super(options, import.meta.url);
|
|
14
|
+
this.options = options;
|
|
15
|
+
}
|
|
16
|
+
modifyResourceConfig(adminforth, resourceConfig) {
|
|
17
|
+
const _super = Object.create(null, {
|
|
18
|
+
modifyResourceConfig: { get: () => super.modifyResourceConfig }
|
|
19
|
+
});
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
_super.modifyResourceConfig.call(this, adminforth, resourceConfig);
|
|
22
|
+
if (!resourceConfig.options.pageInjections) {
|
|
23
|
+
resourceConfig.options.pageInjections = {};
|
|
24
|
+
}
|
|
25
|
+
if (!resourceConfig.options.pageInjections.list) {
|
|
26
|
+
resourceConfig.options.pageInjections.list = {};
|
|
27
|
+
}
|
|
28
|
+
if (!resourceConfig.options.pageInjections.list.threeDotsDropdownItems) {
|
|
29
|
+
resourceConfig.options.pageInjections.list.threeDotsDropdownItems = [];
|
|
30
|
+
}
|
|
31
|
+
resourceConfig.options.pageInjections.list.threeDotsDropdownItems.push({
|
|
32
|
+
file: this.componentPath('ExportCsv.vue'),
|
|
33
|
+
meta: { pluginInstanceId: this.pluginInstanceId, select: 'all' }
|
|
34
|
+
}, {
|
|
35
|
+
file: this.componentPath('ExportCsv.vue'),
|
|
36
|
+
meta: { pluginInstanceId: this.pluginInstanceId, select: 'filtered' }
|
|
37
|
+
}, {
|
|
38
|
+
file: this.componentPath('ImportCsv.vue'),
|
|
39
|
+
meta: { pluginInstanceId: this.pluginInstanceId }
|
|
40
|
+
});
|
|
41
|
+
// simply modify resourceConfig or adminforth.config. You can get access to plugin options via this.options;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
validateConfigAfterDiscover(adminforth, resourceConfig) {
|
|
45
|
+
// optional method where you can safely check field types after database discovery was performed
|
|
46
|
+
}
|
|
47
|
+
instanceUniqueRepresentation(pluginOptions) {
|
|
48
|
+
// optional method to return unique string representation of plugin instance.
|
|
49
|
+
// Needed if plugin can have multiple instances on one resource
|
|
50
|
+
return `${this.pluginInstanceId}`;
|
|
51
|
+
}
|
|
52
|
+
setupEndpoints(server) {
|
|
53
|
+
server.endpoint({
|
|
54
|
+
method: 'POST',
|
|
55
|
+
path: `/plugin/${this.pluginInstanceId}/export-csv`,
|
|
56
|
+
noAuth: true,
|
|
57
|
+
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body }) {
|
|
58
|
+
const { filters, sort } = body;
|
|
59
|
+
for (const filter of (filters || [])) {
|
|
60
|
+
if (!Object.values(AdminForthFilterOperators).includes(filter.operator)) {
|
|
61
|
+
throw new Error(`Operator '${filter.operator}' is not allowed`);
|
|
62
|
+
}
|
|
63
|
+
if (!this.resourceConfig.columns.some((col) => col.name === filter.field)) {
|
|
64
|
+
throw new Error(`Field '${filter.field}' is not in resource '${this.resourceConfig.resourceId}'. Available fields: ${this.resourceConfig.columns.map((col) => col.name).join(', ')}`);
|
|
65
|
+
}
|
|
66
|
+
if (filter.operator === AdminForthFilterOperators.IN || filter.operator === AdminForthFilterOperators.NIN) {
|
|
67
|
+
if (!Array.isArray(filter.value)) {
|
|
68
|
+
throw new Error(`Value for operator '${filter.operator}' should be an array`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (filter.operator === AdminForthFilterOperators.IN && filter.value.length === 0) {
|
|
72
|
+
// nonsense
|
|
73
|
+
return { data: [], total: 0 };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const data = yield this.adminforth.connectors[this.resourceConfig.dataSource].getData({
|
|
77
|
+
resource: this.resourceConfig,
|
|
78
|
+
limit: 1e6,
|
|
79
|
+
offset: 0,
|
|
80
|
+
filters,
|
|
81
|
+
sort,
|
|
82
|
+
getTotals: true,
|
|
83
|
+
});
|
|
84
|
+
// csv export
|
|
85
|
+
const columns = this.resourceConfig.columns.filter((col) => !col.virtual);
|
|
86
|
+
let csv = data.data.map((row) => {
|
|
87
|
+
return columns.map((col) => {
|
|
88
|
+
return row[col.name];
|
|
89
|
+
}).join(',');
|
|
90
|
+
}).join('\n');
|
|
91
|
+
// add headers
|
|
92
|
+
const headers = columns.map((col) => col.name).join(',');
|
|
93
|
+
csv = `${headers}\n${csv}`;
|
|
94
|
+
return { data: csv, exportedCount: data.total, ok: true };
|
|
95
|
+
})
|
|
96
|
+
});
|
|
97
|
+
server.endpoint({
|
|
98
|
+
method: 'POST',
|
|
99
|
+
path: `/plugin/${this.pluginInstanceId}/import-csv`,
|
|
100
|
+
noAuth: true,
|
|
101
|
+
handler: (_b) => __awaiter(this, [_b], void 0, function* ({ body }) {
|
|
102
|
+
const { data } = body;
|
|
103
|
+
// data is in format {[columnName]: [value1, value2, value3...], [columnName2]: [value1, value2, value3...]}
|
|
104
|
+
// we need to convert it to [{columnName: value1, columnName2: value1}, {columnName: value2, columnName2: value2}...]
|
|
105
|
+
const rows = [];
|
|
106
|
+
const columns = Object.keys(data);
|
|
107
|
+
// check column names are valid
|
|
108
|
+
const errors = [];
|
|
109
|
+
columns.forEach((col) => {
|
|
110
|
+
if (!this.resourceConfig.columns.some((c) => c.name === col)) {
|
|
111
|
+
const similar = suggestIfTypo(this.resourceConfig.columns.map((c) => c.name), col);
|
|
112
|
+
errors.push(`Column '${col}' defined in CSV not found in resource '${this.resourceConfig.resourceId}'. ${similar ? `If you mean '${similar}', rename it in CSV` : 'If column is in database but not in resource configuration, add it with showIn:[]'}`);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
if (errors.length > 0) {
|
|
116
|
+
return { ok: false, errors };
|
|
117
|
+
}
|
|
118
|
+
const columnValues = Object.values(data);
|
|
119
|
+
for (let i = 0; i < columnValues[0].length; i++) {
|
|
120
|
+
const row = {};
|
|
121
|
+
for (let j = 0; j < columns.length; j++) {
|
|
122
|
+
row[columns[j]] = columnValues[j][i];
|
|
123
|
+
}
|
|
124
|
+
rows.push(row);
|
|
125
|
+
}
|
|
126
|
+
let importedCount = 0;
|
|
127
|
+
yield Promise.all(rows.map((row) => __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
try {
|
|
129
|
+
yield this.adminforth.resource(this.resourceConfig.resourceId).create(row);
|
|
130
|
+
importedCount++;
|
|
131
|
+
}
|
|
132
|
+
catch (e) {
|
|
133
|
+
errors.push(e.message);
|
|
134
|
+
}
|
|
135
|
+
})));
|
|
136
|
+
return { ok: true, importedCount, errors };
|
|
137
|
+
})
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/index.ts
CHANGED
|
@@ -97,7 +97,7 @@ export default class ImportExport extends AdminForthPlugin {
|
|
|
97
97
|
const headers = columns.map((col) => col.name).join(',');
|
|
98
98
|
csv = `${headers}\n${csv}`;
|
|
99
99
|
|
|
100
|
-
return { data: csv,
|
|
100
|
+
return { data: csv, exportedCount: data.total, ok: true };
|
|
101
101
|
|
|
102
102
|
}
|
|
103
103
|
});
|
|
@@ -112,6 +112,21 @@ export default class ImportExport extends AdminForthPlugin {
|
|
|
112
112
|
// we need to convert it to [{columnName: value1, columnName2: value1}, {columnName: value2, columnName2: value2}...]
|
|
113
113
|
const rows = [];
|
|
114
114
|
const columns = Object.keys(data);
|
|
115
|
+
|
|
116
|
+
// check column names are valid
|
|
117
|
+
const errors: string[] = [];
|
|
118
|
+
columns.forEach((col) => {
|
|
119
|
+
if (!this.resourceConfig.columns.some((c) => c.name === col)) {
|
|
120
|
+
const similar = suggestIfTypo(this.resourceConfig.columns.map((c) => c.name), col);
|
|
121
|
+
errors.push(`Column '${col}' defined in CSV not found in resource '${this.resourceConfig.resourceId}'. ${
|
|
122
|
+
similar ? `If you mean '${similar}', rename it in CSV` : 'If column is in database but not in resource configuration, add it with showIn:[]'}`
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
if (errors.length > 0) {
|
|
127
|
+
return { ok: false, errors };
|
|
128
|
+
}
|
|
129
|
+
|
|
115
130
|
const columnValues: any[] = Object.values(data);
|
|
116
131
|
for (let i = 0; i < columnValues[0].length; i++) {
|
|
117
132
|
const row = {};
|
|
@@ -121,7 +136,6 @@ export default class ImportExport extends AdminForthPlugin {
|
|
|
121
136
|
rows.push(row);
|
|
122
137
|
}
|
|
123
138
|
|
|
124
|
-
const errors: string[] = [];
|
|
125
139
|
let importedCount = 0;
|
|
126
140
|
await Promise.all(rows.map(async (row) => {
|
|
127
141
|
try {
|
package/package.json
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adminforth/import-export",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc && rsync -av --exclude 'node_modules' custom dist/ && npm version patch",
|
|
9
|
-
"rollout": "npm publish --access public"
|
|
9
|
+
"rollout": "npm run build && npm version patch && npm publish --access public",
|
|
10
|
+
"prepare": "npm link adminforth"
|
|
10
11
|
},
|
|
11
12
|
"keywords": [],
|
|
12
13
|
"author": "",
|
|
13
14
|
"license": "ISC",
|
|
14
15
|
"description": "",
|
|
15
|
-
"
|
|
16
|
-
"@types/node": "^22.6.1",
|
|
17
|
-
"adminforth": "file:../..",
|
|
18
|
-
"typescript": "^5.6.2"
|
|
19
|
-
},
|
|
20
|
-
"dependencies": {
|
|
21
|
-
}
|
|
16
|
+
"dependencies": {}
|
|
22
17
|
}
|