diff --git a/src/module/alertModal.js b/src/module/alertModal.js index 3a0db33..647a3d6 100644 --- a/src/module/alertModal.js +++ b/src/module/alertModal.js @@ -171,7 +171,7 @@ export async function leaveConformance(next, addConformanceCreateCheckId, toPath * @param { string } failureType * @param { string } failureMsg */ -export async function uploadFailedFirst(failureType, failureMsg) { +export async function uploadFailedFirst(failureType, failureMsg, failureLoc) { // msg: 'not in UTF-8' | 'insufficient columns' | 'the csv file is empty' | 'the filename does not ends with .csv' // type: 'encoding' | 'insufficient_columns' | 'empty' | 'name_suffix' let value = ''; @@ -180,16 +180,16 @@ export async function uploadFailedFirst(failureType, failureMsg) { value = 'File size exceeds 90MB.'; break; case 'encoding': - value = 'not in UTF-8'; + value = `Please use [UFT-8] for character encoding: (Row #${failureLoc})`; break; case 'insufficient_columns': - value = 'insufficient columns'; + value = 'Need at least five columns of data.'; break; case 'empty': - value = 'the csv file is empty'; + value = 'Need at least one record of data.'; break; case 'name_suffix': - value = 'the filename does not ends with .csv'; + value = 'File is not in [csv] format.'; break; default: value = failureMsg; @@ -207,31 +207,41 @@ export async function uploadFailedFirst(failureType, failureMsg) { }; /** * Upload failde Second - * @param { string } failureType - * @param { string } failureMsg + * @param { array } detail */ -export async function uploadFailedSecond(failureType, failureMsg) { - let value = ''; - switch (failureType) { - case 'malformed': - value = failureMsg; +export async function uploadFailedSecond(detail) { + let srt = ''; + let manySrt = ''; + + detail.forEach(i => { + let content = ''; + + switch (i.type) { + case 'too_many': + manySrt = 'There are more errors.'; + break; + case 'unrecognized': + content = `
  • Data unregnizable in [Status] Column: (Row #${i.loc[1]}, "${i.input}")
  • `; + break; + case 'malformed': + content = `
  • Data malformed in [Timestamp] Column: (Row #${i.loc[1]}, "${i.input}")
  • `; + break; + case 'missing': + content = `
  • Data missing in [${i.loc[2]}] Column: (Row #${i.loc[1]})
  • `; break; - case 'missing': - value = failureMsg; - break; - default: - value = failureMsg; - break; - } + } + srt += content; + }); await Swal.fire({ title: 'UPLOAD FAILED', - html: value, + html: `

    The following errors have been detected:

    ${manySrt} Please check.

    `, timer: 5000, // 停留5秒後自動關閉 showConfirmButton: false, icon: 'error', iconColor: '#FF3366', customClass: customClass - }) + }); + srt = ''; }; /** * Upload Success @@ -277,7 +287,6 @@ export async function uploadConfirm(fetchData) { export async function uploadloader() { await Swal.fire({ html: '', - // timer: 5000, // 停留5秒後自動關閉 showConfirmButton: false, allowOutsideClick: false, customClass: customClass, @@ -322,7 +331,7 @@ export async function renameModal(rename, type, id) { */ export async function deleteFileModal(files, type, id) { const filesStore = FilesStore(); - let htmlText = files.length === 0 ? '' : `

    All related files will be deleted.

    List of file(s) to delete:

    `; + let htmlText = files.length === 0 ? '' : `

    All related files will be deleted.

    List of file(s) to delete:

    `; const result = await Swal.fire({ title: 'ARE YOU SURE?', html: htmlText, diff --git a/src/stores/files.js b/src/stores/files.js index f2782ba..e19d1ac 100644 --- a/src/stores/files.js +++ b/src/stores/files.js @@ -123,16 +123,17 @@ export default defineStore('filesStore', { uploadloader(); // 進度條 try { const response = await axios.post(api, fromData, config); - console.log('第一階段 response:', response); + this.uploadId = response.data.id; this.$router.push({name: 'Upload'}); Swal.close(); // 關閉進度條 } catch(error) { - console.log('第一階段 error:', error); if(error.response.status === 422) { // msg: 'not in UTF-8' | 'insufficient columns' | 'the csv file is empty' | 'the filename does not ends with .csv' // type: 'encoding' | 'insufficient_columns' | 'empty' | 'name_suffix' - uploadFailedFirst(error.response.data.detail[0].type, error.response.data.detail[0].msg); + let detail = error.response.data.detail; + + uploadFailedFirst(detail[0].type, detail[0].msg, detail[0].loc[2]); } else { Swal.close(); // 關閉進度條 apiError(error, 'Failed to upload the files.'); @@ -164,7 +165,6 @@ export default defineStore('filesStore', { uploadloader(); // 進度條 try { const response = await axios.post(api, data); - console.log('第二階段 response:', response); this.uploadLogId = await response.data.id; await Swal.close(); // 關閉進度條 @@ -172,10 +172,10 @@ export default defineStore('filesStore', { await uploadSuccess(); this.$router.push({name: 'Files'}); } catch(error) { - console.log('第二階段 error:', error); - if(error.response.status === 422) { - uploadFailedSecond(error.response.data.detail[0].type, error.response.data.detail[0].msg); + let detail = [...error.response.data.detail]; + + uploadFailedSecond(detail); } else { Swal.close(); // 關閉進度條 apiError(error, 'Failed to upload the log files.');