# HG changeset patch # User Thomas Junk # Date 1542731850 -3600 # Node ID 9b0a7b3ea2970397114c44e1a28ef100c613ca64 # Parent d842d9d10872cd9078985e69abc96b9926b9daea inport sounding results diff -r d842d9d10872 -r 9b0a7b3ea297 client/src/imports/Imports.vue --- a/client/src/imports/Imports.vue Tue Nov 20 17:04:06 2018 +0100 +++ b/client/src/imports/Imports.vue Tue Nov 20 17:37:30 2018 +0100 @@ -2,9 +2,9 @@

Import soundingresults


-
+
-
+
-
+
-
+
-
+
{{uploadLabel}}
-
+
Generate Meta.json + class="btn btn-outline-info pull-left" + >Download Meta.json + + >{{uploadState?"Upload":"Confirm"}}
@@ -90,20 +96,81 @@ importDate: "", uploadLabel: defaultLabel, uploadFile: null, - disableUpload: false + disableUpload: false, + token: null }; }, methods: { + initialState() { + this.importState = IMPORTSTATE.UPLOAD; + this.depthReference = ""; + this.bottleneck = ""; + this.importDate = ""; + this.uploadLabel = defaultLabel; + this.uploadFile = null; + this.disableUpload = false; + this.token = null; + }, fileSelected(e) { const files = e.target.files || e.dataTransfer.files; if (!files) return; this.uploadLabel = files[0].name; this.uploadFile = files[0]; }, - submitUpload() { + deleteTempData() { + HTTP.delete("/imports/soundingresult-upload/" + this.token, { + headers: { + "X-Gemma-Auth": localStorage.getItem("token") + } + }) + .then(() => { + this.initialState(); + }) + .catch(error => { + const { status, data } = error.response; + displayError({ + title: "Backend Error", + message: `${status}: ${data.message || data}` + }); + }); + }, + submit() { if (!this.uploadFile || this.disableUpload) return; + if (this.importState === IMPORTSTATE.UPLOAD) { + this.upload(); + } else { + this.confirm(); + } + }, + upload() { let formData = new FormData(); formData.append("soundingresult", this.uploadFile); + HTTP.post("/imports/soundingresult-upload", formData, { + headers: { + "X-Gemma-Auth": localStorage.getItem("token"), + "Content-Type": "multipart/form-data" + } + }) + .then(response => { + const { bottleneck, date } = response.data.meta; + const depthReference = response.data.meta["depth-reference"]; + this.importState = IMPORTSTATE.EDIT; + this.bottleneck = bottleneck; + this.depthReference = depthReference; + this.importDate = date; + this.token = response.data.token; + }) + .catch(error => { + const { status, data } = error.response; + displayError({ + title: "Backend Error", + message: `${status}: ${data.message || data}` + }); + }); + }, + confirm() { + let formData = new FormData(); + formData.append("token", this.token); HTTP.post("/imports/soundingresult", formData, { headers: { "X-Gemma-Auth": localStorage.getItem("token"), @@ -112,8 +179,10 @@ }) .then(() => { displayInfo({ - title: "Import success" + title: "Import", + message: "Successfully imported " + this.bottleneck }); + this.initialState(); }) .catch(error => { const { status, data } = error.response; @@ -171,8 +240,11 @@