docstore: use API entrypoint for storing storedObject in AddAsyncUpload.vue

This commit is contained in:
nobohan 2022-02-24 12:11:34 +01:00
parent b1390f4e9b
commit 3f43574371
3 changed files with 54 additions and 11 deletions

View File

@ -34,19 +34,19 @@ class StoredObject implements AsyncFileInterface, Document
{ {
/** /**
* @ORM\Column(type="datetime", name="creation_date") * @ORM\Column(type="datetime", name="creation_date")
* @Serializer\Groups({"read"}) * @Serializer\Groups({"read", "write"})
*/ */
private DateTimeInterface $creationDate; private DateTimeInterface $creationDate;
/** /**
* @ORM\Column(type="json", name="datas") * @ORM\Column(type="json", name="datas")
* @Serializer\Groups({"read"}) * @Serializer\Groups({"read", "write"})
*/ */
private array $datas = []; private array $datas = [];
/** /**
* @ORM\Column(type="text") * @ORM\Column(type="text")
* @Serializer\Groups({"read"}) * @Serializer\Groups({"read", "write"})
*/ */
private $filename; private $filename;
@ -54,30 +54,32 @@ class StoredObject implements AsyncFileInterface, Document
* @ORM\Id * @ORM\Id
* @ORM\GeneratedValue * @ORM\GeneratedValue
* @ORM\Column(type="integer") * @ORM\Column(type="integer")
* @Serializer\Groups({"read"}) * @Serializer\Groups({"read", "write"})
*/ */
private $id; private $id;
/** /**
* @var int[] * @var int[]
* @ORM\Column(type="json", name="iv") * @ORM\Column(type="json", name="iv")
* @Serializer\Groups({"write"})
*/ */
private array $iv = []; private array $iv = [];
/** /**
* @ORM\Column(type="json", name="key") * @ORM\Column(type="json", name="key")
* @Serializer\Groups({"write"})
*/ */
private array $keyInfos = []; private array $keyInfos = [];
/** /**
* @ORM\Column(type="text", name="type") * @ORM\Column(type="text", name="type")
* @Serializer\Groups({"read"}) * @Serializer\Groups({"read", "write"})
*/ */
private string $type = ''; private string $type = '';
/** /**
* @ORM\Column(type="uuid", unique=true) * @ORM\Column(type="uuid", unique=true)
* @Serializer\Groups({"read"}) * @Serializer\Groups({"read", "write"})
*/ */
private UuidInterface $uuid; private UuidInterface $uuid;

View File

@ -36,6 +36,7 @@
data-temp-url-get="/asyncupload/temp_url/generate/GET" data-temp-url-get="/asyncupload/temp_url/generate/GET"
:data-max-files="options.maxFiles" :data-max-files="options.maxFiles"
:data-max-post-size="options.maxPostSize" :data-max-post-size="options.maxPostSize"
:v-model="dataAsyncFileUpload"
> >
<input <input
type="hidden" type="hidden"
@ -55,7 +56,7 @@
<template v-slot:footer> <template v-slot:footer>
<button class="btn btn-create" <button class="btn btn-create"
@click.prevent="$emit('addDocument', { })"> @click.prevent="saveDocument">
{{ $t('action.add')}} {{ $t('action.add')}}
</button> </button>
</template> </template>
@ -68,6 +69,7 @@
<script> <script>
import Modal from 'ChillMainAssets/vuejs/_components/Modal'; import Modal from 'ChillMainAssets/vuejs/_components/Modal';
import { searchForZones } from '../../module/async_upload/uploader'; import { searchForZones } from '../../module/async_upload/uploader';
import { makeFetch } from "ChillMainAssets/lib/api/apiMethods";
const i18n = { const i18n = {
messages: { messages: {
@ -116,6 +118,40 @@ export default {
openModal() { openModal() {
this.modal.showModal = true; this.modal.showModal = true;
}, },
saveDocument() {
const dropzone = this.$refs.dropZoneWrapper;
if (dropzone) {
const inputKey = dropzone.querySelector('input[data-stored-object-key]');
const inputIv = dropzone.querySelector('input[data-stored-object-iv]');
const inputObject = dropzone.querySelector('input[data-async-file-upload]');
const inputType = dropzone.querySelector('input[data-async-file-type]');
const url = '/api/1.0/docstore/stored-object.json';
const body = {
filename: inputObject.value,
keyInfos: JSON.parse(inputKey.value),
iv: JSON.parse(inputIv.value),
type: inputType.value,
};
makeFetch('POST', url, body)
.then(r => {
this.$emit("addDocument", r);
this.modal.showModal = false;
})
.catch((error) => {
console.log(error); //TODO error handling
if (error.name === 'ValidationException') {
for (let v of error.violations) {
this.$toast.open({message: v });
}
} else {
this.$toast.open({message: 'An error occurred'});
}
});
} else {
this.$toast.open({message: 'An error occurred - drop zone not found'});
}
}
} }
} }
</script> </script>

View File

@ -107,6 +107,7 @@
<add-async-upload <add-async-upload
:buttonTitle="$t('browse')" :buttonTitle="$t('browse')"
:options="asyncUploadOptions" :options="asyncUploadOptions"
@addDocument="addDocument"
> >
</add-async-upload> </add-async-upload>
</li> </li>
@ -229,11 +230,11 @@ export default {
}) })
; ;
}, },
buildEditLink(storedObject) { buildEditLink(storedObject) {
return `/wopi/edit/${storedObject.uuid}?returnPath=` + encodeURIComponent( return `/wopi/edit/${storedObject.uuid}?returnPath=` + encodeURIComponent(
window.location.pathname + window.location.search + window.location.hash); window.location.pathname + window.location.search + window.location.hash);
}, },
submitBeforeGenerate({template}) { submitBeforeGenerate({template}) {
const callback = (data) => { const callback = (data) => {
let evaluationId = data.accompanyingPeriodWorkEvaluations.find(e => e.key === this.evaluation.key).id; let evaluationId = data.accompanyingPeriodWorkEvaluations.find(e => e.key === this.evaluation.key).id;
@ -241,6 +242,10 @@ export default {
}; };
return this.$store.dispatch('submit', callback).catch(e => { console.log(e); throw e; }); return this.$store.dispatch('submit', callback).catch(e => { console.log(e); throw e; });
},
addDocument(storedObject) {
console.log(storedObject);
console.log('Add document');
} }
}, },
} }