This commit is contained in:
2022-03-24 19:44:12 +00:00
parent 51eeaf9739
commit 7a3c7946ef

View File

@@ -26,17 +26,17 @@
color="primary" color="primary"
text text
@click="process" @click="process"
>{{ $ay.t("Import") }}</v-btn >{{ $ay.t("Open") }}</v-btn
> >
</v-col> </v-col>
<v-col cols="12"> <v-col v-if="outputText != null" cols="12">
<v-textarea <v-textarea
v-model="importResult" v-model="outputText"
full-width full-width
readonly readonly
auto-grow auto-grow
data-cy="importResult" data-cy="outputText"
></v-textarea> ></v-textarea>
</v-col> </v-col>
</v-row> </v-row>
@@ -53,7 +53,7 @@ export default {
}, },
uploadFile: [], uploadFile: [],
ayaType: 8, //<<<<<<<<<<<<<-----------------------------CHANGE THIS TO ZERO WHEN DONE TESTING ayaType: 8, //<<<<<<<<<<<<<-----------------------------CHANGE THIS TO ZERO WHEN DONE TESTING
importResult: "", outputText: null,
rights: window.$gz.role.defaultRightsObject(), rights: window.$gz.role.defaultRightsObject(),
uploading: false uploading: false
}; };
@@ -74,7 +74,7 @@ export default {
if (!this.uploadFile) { if (!this.uploadFile) {
return; return;
} }
this.importResult = ""; this.outputText = null;
try { try {
let fileType = this.uploadFile.type.toLowerCase(); let fileType = this.uploadFile.type.toLowerCase();
if (!fileType.includes("csv") && !fileType.includes("json")) { if (!fileType.includes("csv") && !fileType.includes("json")) {
@@ -85,8 +85,9 @@ export default {
if (isCSV) { if (isCSV) {
let res = await parseCSVFile(this.uploadFile); let res = await parseCSVFile(this.uploadFile);
if (res.errors) { if (res.errors) {
this.importResult = JSON.stringify(res.errors); this.outputText =
throw new Error("Errors in CSV file import can not proceed"); "LT:CSV parsing errors:\n" + JSON.stringify(res.errors);
throw new Error("LT:Errors in CSV file import can not proceed");
} }
if (res.data) { if (res.data) {
dat = res.data; dat = res.data;
@@ -98,57 +99,31 @@ export default {
} }
console.log("The final data is ", dat); console.log("The final data is ", dat);
//upload the data
await this.upload(dat);
} catch (error) { } catch (error) {
window.$gz.errorHandler.handleFormError(error); window.$gz.errorHandler.handleFormError(error);
} finally {
this.uploading = false;
} }
}, },
async upload() { async upload(dat) {
if (!this.uploadFile) {
return;
}
try { try {
// console.log("Upload file is:", this.uploadFile); this.uploading = true;
// let fileType = this.uploadFile.type.toLowerCase(); const res = await window.$gz.api.post("import", {
// if (!fileType.includes("csv") && !fileType.includes("json")) { data: dat,
// throw new Error("Not supported file type, must be .csv or .json"); atype: this.ayaType
// } });
// const isCSV = fileType.includes("csv"); if (res.error) {
// let dat = null; window.$gz.errorHandler.handleFormError(res.error);
// if (isCSV) { } else {
// dat = await parse(this.uploadFile); //result is an array of strings
// } else { let outText = "";
// dat = JSON.parse(this.uploadFile); res.data.forEach(function appendImportResultItem(value) {
// } outText += value + "\n";
// console.log("The final data is ", dat); });
//similar code in wiki-control this.outputText = await window.$gz.translation.translateStringWithMultipleKeysAsync(
// const vm = this; outText
// const fileData = []; );
// for (let i = 0; i < vm.uploadFile.length; i++) { }
// const f = vm.uploadFile[i];
// fileData.push({ name: f.name, lastModified: f.lastModified });
// }
// const at = {
// ayaType: vm.ayaType,
// files: vm.uploadFile,
// fileData: JSON.stringify(fileData)
// };
// vm.uploading = true;
// const res = await window.$gz.api.upload("import/upload", at);
// if (res.error) {
// window.$gz.errorHandler.handleFormError(res.error);
// } else {
// vm.uploadFile = [];
// //result is an array of strings
// let outText = "";
// res.data.forEach(function appendImportResultItem(value) {
// outText += value + "\n";
// });
// vm.importResult = await window.$gz.translation.translateStringWithMultipleKeysAsync(
// outText
// );
// }
} catch (error) { } catch (error) {
window.$gz.errorHandler.handleFormError(error); window.$gz.errorHandler.handleFormError(error);
} finally { } finally {