This commit is contained in:
Matej Glasnák committed 2023-02-01 14:58:17 +01:00
1 parent 0cf30d75e3
commit 3902cbd601
5 files changed
+97 -6

No files matched your search

+81
View File
@@ -0,0 +1,81 @@
<template>
<input type="file" name="file" id="fileInput" class="hidden-input" accept="*"
@change="onChange" ref="fileUpload"
/>
<br>
<br>
<v-btn @click="createWithoutFile()">CREATE without file</v-btn>
<br>
<br>
<v-btn @click="createWithFile()">CREATE with file</v-btn>
</template>
<script>
import moment from 'moment'
import axios from 'axios'
export default {
data() {
return {
files: null
}
},
methods: {
async createWithoutFile() {
const masterTask = this._getMastertaskObject()
await axios.post('https://taskmanager.internal.studiotem.com/api/v1/mastertasks', this._objectToFormData(masterTask))
console.log(await this.$axios.get_data('v1/mastertasks'))
},
async createWithFile() {
if (!this.files) return alert('No files uploaded')
const masterTask = this._getMastertaskObject()
masterTask.data.files = this.files
await axios.post('https://taskmanager.internal.studiotem.com/api/v1/mastertasks', this._objectToFormData(masterTask))
console.log(await this.$axios.get_data('v1/mastertasks'))
},
_getMastertaskObject() {
const employees = [{
id: 1,
duration: 1000
}]
return {
data: {
name: `name-${3}`,
description: `description`,
duration: 1231,
deadline: moment().format('YYYY-MM-DD HH:MM:SS'),
project_id: 1,
team_id: 1,
employees: employees
}
}
},
onChange($event) {
this.files = $event.target.files
},
_buildFormData(formData, data, parentKey) {
if (data && typeof data === 'object' && !(data instanceof Date) && !(data instanceof File))
Object.keys(data).forEach(key => this._buildFormData(formData, data[key], parentKey ? `${parentKey}[${key}]` : key));
else
formData.append(parentKey, data == null ? '' : data);
},
_objectToFormData(data) {
const formData = new FormData()
this._buildFormData(formData, data)
return formData
}
}
}
</script>