Skip to content
Snippets Groups Projects
Commit affb5d54 authored by Edward Alexander Jaya's avatar Edward Alexander Jaya
Browse files

Add error message

parent b56b1b99
1 merge request!42Dev
Pipeline #27731 canceled with stage
in 36 minutes and 57 seconds
...@@ -140,7 +140,7 @@ export default { ...@@ -140,7 +140,7 @@ export default {
this.filesCount = 0 this.filesCount = 0
} }
}, },
invalidUpload(){ invalidUpload() {
this.$swal.fire({ this.$swal.fire({
title: "No Image Selected", title: "No Image Selected",
icon: "error", icon: "error",
...@@ -167,14 +167,14 @@ export default { ...@@ -167,14 +167,14 @@ export default {
} }
}) })
}, },
showErrorUploadPopUp () { showErrorUploadPopUp (errorText) {
return this.$swal.fire({ return this.$swal.fire({
title: 'Error!', title: 'Error!',
text: 'Cannot Upload File.', text: errorText,
icon: 'error' icon: 'error'
}) })
}, },
validUpload(){ validUpload() {
this.files = this.$refs.myDropzone.getAcceptedFiles() this.files = this.$refs.myDropzone.getAcceptedFiles()
// var total = this.files.length // var total = this.files.length
var count = 0 var count = 0
...@@ -186,31 +186,23 @@ export default { ...@@ -186,31 +186,23 @@ export default {
allowEscapeKey: false, allowEscapeKey: false,
onOpen: async () => { onOpen: async () => {
this.$swal.showLoading() this.$swal.showLoading()
var isUploadedAll = true
for (var idxFile = 0; idxFile < this.files.length; idxFile++) { for (var idxFile = 0; idxFile < this.files.length; idxFile++) {
var file = this.files[idxFile] var file = this.files[idxFile]
if (await this.upload(file, file.name)) { if (await this.upload(file, file.name)) {
count += 1;size += file.size count += 1; size += file.size
this.$refs.myDropzone.removeFile(file) this.$refs.myDropzone.removeFile(file)
this.filesCount-- this.filesCount--
} else { } else {
isUploadedAll = false
break break
} }
} }
if (!isUploadedAll) {
await this.showErrorUploadPopUp()
}
if (count !== 0) { if (count !== 0) {
this.showSuccessUploadPopUp(count, size) this.showSuccessUploadPopUp(count, size)
} }
} }
}) })
}, },
async upload(f, name){ async upload(f, name) {
var url = "/api/image/upload" var url = "/api/image/upload"
var formData = new FormData() var formData = new FormData()
formData.append("image", f, name) formData.append("image", f, name)
...@@ -218,8 +210,13 @@ export default { ...@@ -218,8 +210,13 @@ export default {
const config = { const config = {
headers: {'Content-Type':'multipart/form-data'} headers: {'Content-Type':'multipart/form-data'}
} }
var response = await this.$axios.post(url, formData, config).catch(error => console.error(error)) var response = await this.$axios.post(url, formData, config).catch(async (error) => {
return(response && response.status === 200) console.log('data: ', error)
console.error(error.response)
await this.showErrorUploadPopUp(error.response.data.error)
})
console.log('response: ', response)
return (response && response.status === 200)
}, },
invalidFolder(){ invalidFolder(){
this.$swal.fire({ this.$swal.fire({
...@@ -232,17 +229,16 @@ export default { ...@@ -232,17 +229,16 @@ export default {
async handleUpload(){ async handleUpload(){
this.files = await this.$refs.myDropzone.getAcceptedFiles() this.files = await this.$refs.myDropzone.getAcceptedFiles()
console.log("Files: ", this.files) console.log("Files: ", this.files)
if (!this.dataset || this.dataset === "Choose Folder") { if (!this.dataset || this.dataset === 'Choose Folder') {
this.invalidFolder() this.invalidFolder()
} else { } else {
if(this.files.length === 0){ if (this.files.length === 0){
this.invalidUpload() this.invalidUpload()
} else { } else {
this.files = [] this.files = []
await this.validUpload() await this.validUpload()
} }
} }
} }
} }
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment