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