Skip to content
Snippets Groups Projects
Commit 4a8b9934 authored by Ron Lucke's avatar Ron Lucke Committed by Marcus Eibrink-Lunzenauer
Browse files

fix #874

Closes #874

Merge request studip/studip!992
parent 587224fa
No related branches found
No related tags found
No related merge requests found
...@@ -22,8 +22,15 @@ class FileRefsCreateByUpload extends NonJsonApiController ...@@ -22,8 +22,15 @@ class FileRefsCreateByUpload extends NonJsonApiController
throw new AuthorizationFailedException(); throw new AuthorizationFailedException();
} }
$term_id = $request->getParsedBody()['term-id'];
$fileRef = $this->handleUpload($request, $folder); $fileRef = $this->handleUpload($request, $folder);
if ($term_id) {
$fileRef->content_terms_of_use_id = $term_id;
$fileRef->store();
}
return $this->redirectToFileRef($response, $fileRef); return $this->redirectToFileRef($response, $fileRef);
} }
} }
...@@ -19,6 +19,7 @@ class ContentTermsOfUse extends SchemaProvider ...@@ -19,6 +19,7 @@ class ContentTermsOfUse extends SchemaProvider
'name' => (string) $resource['name'], 'name' => (string) $resource['name'],
'description' => mb_strlen($resource['description']) ? (string) $resource['description'] : null, 'description' => mb_strlen($resource['description']) ? (string) $resource['description'] : null,
'icon' => $resource['icon'], 'icon' => $resource['icon'],
'is-default' => (bool) $resource['is_default'],
'download-condition' => (int) $resource['download_condition'], 'download-condition' => (int) $resource['download_condition'],
'mkdate' => date('c', $resource['mkdate']), 'mkdate' => date('c', $resource['mkdate']),
'chdate' => date('c', $resource['chdate']), 'chdate' => date('c', $resource['chdate']),
......
...@@ -38,9 +38,59 @@ class Folder extends BlockType ...@@ -38,9 +38,59 @@ class Folder extends BlockType
]; ];
} }
/**
* Returns the decoded payload of the block associated with this instance.
*
* @return mixed the decoded payload
*/
public function getPayload()
{
$user = \User::findCurrent();
$payload = $this->decodePayloadString($this->block['payload']);
$folder = \Folder::find($payload['folder_id']);
$payload['folder-type'] = null;
$payload['files'] = [];
if ($folder) {
$typedFolder = $folder->getTypedFolder();
$payload['folder-type'] = $typedFolder->folder_type;
foreach ($typedFolder->getFiles() as $folderFile) {
$file['id'] = $folderFile->id;
$file['attributes'] = [
'name' => $folderFile->name,
'mime-type' => $folderFile->mime_type,
'filesize' => (int) $folderFile->size,
'mkdate' => date('c', $folderFile->mkdate),
];
$file['relationships'] = [
'owner' => [
'data' => ['type' => 'users', 'id' => $folderFile->user_id],
'meta' => ['name' => $folderFile->getFileRef()->getAuthorName()]
]
];
$file['meta'] = [
'download-url' => $folderFile->getDownloadURL(),
];
if ($this->filePermission($typedFolder, $file, $user)) {
array_push($payload['files'], $file);
}
}
}
return $payload;
}
private function filePermission($typedFolder, $file, $user): bool
{
return $typedFolder->folder_type !== 'HomeworkFolder' || $user->id === $file['relationships']['owner']['data']['id'] || $typedFolder->isReadable($user->id);
}
/** /**
* get all files related to this bloc. * get all files related to this block.
* *
* @return \FileRef[] list of file references realted to this block * @return \FileRef[] list of file references realted to this block
*/ */
......
...@@ -3668,16 +3668,22 @@ i f r a m e b l o c k e n d ...@@ -3668,16 +3668,22 @@ i f r a m e b l o c k e n d
/* * * * * * * * * * * * /* * * * * * * * * * * *
f o l d e r b l o c k f o l d e r b l o c k
* * * * * * * * * * * */ * * * * * * * * * * * */
.cw-block-folder-info {
border: solid thin $content-color-40;
padding: 10px 10px 0 10px;
overflow: hidden;
border-bottom: none;
}
.cw-block-folder-list { .cw-block-folder-list {
border: solid thin #ccc; border: solid thin $content-color-40;
padding: 4px; padding: 0;
list-style: none; list-style: none;
.cw-block-folder-file-item { .cw-block-folder-file-item {
list-style: none; list-style: none;
&:not(:last-child) { &:not(:last-child) {
border-bottom: solid thin #ccc; border-bottom: solid thin $content-color-40;
} }
a { a {
display: block; display: block;
...@@ -3696,16 +3702,27 @@ f o l d e r b l o c k ...@@ -3696,16 +3702,27 @@ f o l d e r b l o c k
margin: 1em; margin: 1em;
} }
} }
.cw-block-folder-upload {
border: solid thin $content-color-40;
padding: 1em 10px;
border-top: none;
.cw-file-input {
width: calc(100% - 148px);
vertical-align: middle;
}
}
// for folder and download block // for folder and download block
.cw-block-file-info { .cw-block-file-info {
@include background-icon(file, clickable, 24); @include background-icon(file, clickable, 24);
background-repeat: no-repeat; background-repeat: no-repeat;
display: inline-block; display: block;
padding-left: 26px; padding: 16px 16px 16px 40px;
margin: 1em; background-position: 10px 16px;
line-height: 24px; width: calc(100% - 56px);
color: $base-color; overflow: hidden;
text-overflow: ellipsis;
&.cw-block-file-icon-empty { &.cw-block-file-icon-empty {
color: $black; color: $black;
...@@ -3717,34 +3734,77 @@ f o l d e r b l o c k ...@@ -3717,34 +3734,77 @@ f o l d e r b l o c k
} }
&.cw-block-file-icon-audio { &.cw-block-file-icon-audio {
@include background-icon(file-audio, clickable, 24); @include background-icon(file-audio, clickable, 24);
&.download-disabled {
@include background-icon(file-audio, info, 24);
}
} }
&.cw-block-file-icon-pic { &.cw-block-file-icon-pic {
@include background-icon(file-pic, clickable, 24); @include background-icon(file-pic, clickable, 24);
&.download-disabled {
@include background-icon(file-pic, info, 24);
}
} }
&.cw-block-file-icon-video { &.cw-block-file-icon-video {
@include background-icon(file-video, clickable, 24); @include background-icon(file-video, clickable, 24);
&.download-disabled {
@include background-icon(file-video, info, 24);
}
} }
&.cw-block-file-icon-pdf { &.cw-block-file-icon-pdf {
@include background-icon(file-pdf, clickable, 24); @include background-icon(file-pdf, clickable, 24);
&.download-disabled {
@include background-icon(file-pdf, info, 24);
}
} }
&.cw-block-file-icon-word { &.cw-block-file-icon-word {
@include background-icon(file-word, clickable, 24); @include background-icon(file-word, clickable, 24);
&.download-disabled {
@include background-icon(file-word, info, 24);
}
} }
&.cw-block-file-icon-spreadsheet { &.cw-block-file-icon-spreadsheet {
@include background-icon(file-excel, clickable, 24); @include background-icon(file-excel, clickable, 24);
&.download-disabled {
@include background-icon(file-excel, info, 24);
}
} }
&.cw-block-file-icon-text { &.cw-block-file-icon-text {
@include background-icon(file-text, clickable, 24); @include background-icon(file-text, clickable, 24);
&.download-disabled {
@include background-icon(file-text, info, 24);
}
} }
&.cw-block-file-icon-ppt { &.cw-block-file-icon-ppt {
@include background-icon(file-ppt, clickable, 24); @include background-icon(file-ppt, clickable, 24);
&.download-disabled {
@include background-icon(file-ppt, info, 24);
}
} }
&.cw-block-file-icon-archive { &.cw-block-file-icon-archive {
@include background-icon(file-archive, clickable, 24); @include background-icon(file-archive, clickable, 24);
&.download-disabled {
@include background-icon(file-archive, info, 24);
}
} }
&.cw-block-file-icon-file { &.cw-block-file-icon-file {
@include background-icon(file, clickable, 24); @include background-icon(file, clickable, 24);
&.download-disabled {
@include background-icon(file, info, 24);
}
}
}
.cw-block-file-details {
margin-top: -16px;
padding-left: 40px;
padding-bottom: 16px;
color: $dark-gray-color;
} }
.cw-block-file-owner,
.cw-block-file-mkdate {
display: block;
width: calc(100% - 56px);
overflow: hidden;
text-overflow: ellipsis;
} }
/* * * * * * * * * * * * * * * /* * * * * * * * * * * * * * *
f o l d e r b l o c k e n d f o l d e r b l o c k e n d
...@@ -3757,7 +3817,6 @@ d o w n l o a d b l o c k ...@@ -3757,7 +3817,6 @@ d o w n l o a d b l o c k
.cw-block-download { .cw-block-download {
.cw-block-download-content { .cw-block-download-content {
border: solid thin $content-color-40; border: solid thin $content-color-40;
padding: 4px;
.cw-block-download-file-item { .cw-block-download-file-item {
a { a {
display: block; display: block;
...@@ -4760,7 +4819,7 @@ cw tiles end ...@@ -4760,7 +4819,7 @@ cw tiles end
.cw-file-input { .cw-file-input {
width: stretch; width: stretch;
border: solid thin $base-color; border: solid thin $base-color;
font-size: 14px; font-size: 13px;
cursor: pointer; cursor: pointer;
&::file-selector-button { &::file-selector-button {
......
...@@ -587,28 +587,32 @@ export default { ...@@ -587,28 +587,32 @@ export default {
async storeRecording() { async storeRecording() {
let view = this; let view = this;
let user = this.usersById({id: this.userId}); let user = this.usersById({id: this.userId});
let file = {};
let blob = new Blob(view.chunks, {type: 'audio/webm; codecs:vp9' }); let blob = new Blob(view.chunks, {type: 'audio/webm; codecs:vp9' });
file.attributes = {}; let file = {
file.attributes.name = (user.attributes["formatted-name"]).replace(/\s+/g, '_') + '.webm'; attributes: {
let fileObj = false; name: (user.attributes["formatted-name"]).replace(/\s+/g, '_') + '.webm'
try { },
fileObj = await this.createFile({ relationships: {
'terms-of-use': {
data: {
id: 'SELFMADE_NONPUB'
}
}
}
};
let fileObj = await this.createFile({
file: file, file: file,
filedata: blob, filedata: blob,
folder: {id: this.currentFolderId} folder: {id: this.currentFolderId}
}); });
}
catch(e) {
this.companionError({
info: this.$gettext('Es ist ein Fehler aufgetreten! Die Aufnahme konnte nicht gespeichert werden.')
});
console.debug(e);
}
if(fileObj && fileObj.type === 'file-refs') { if(fileObj && fileObj.type === 'file-refs') {
this.companionSuccess({ this.companionSuccess({
info: this.$gettext('Die Aufnahme wurde erfolgreich im Dateibereich abgelegt.') info: this.$gettext('Die Aufnahme wurde erfolgreich im Dateibereich abgelegt.')
}); });
} else {
this.companionError({
info: this.$gettext('Es ist ein Fehler aufgetreten! Die Aufnahme konnte nicht gespeichert werden.')
});
} }
this.newRecording = false; this.newRecording = false;
this.getFolderFiles(); this.getFolderFiles();
......
...@@ -574,24 +574,20 @@ export default { ...@@ -574,24 +574,20 @@ export default {
file.attributes.name = (user.attributes["formatted-name"]).replace(/\s+/g, '_') + '_' + this.block.attributes.title + '_' + this.block.id; file.attributes.name = (user.attributes["formatted-name"]).replace(/\s+/g, '_') + '_' + this.block.attributes.title + '_' + this.block.id;
} }
let img = false; let img = await this.createFile({
try {
img = await this.createFile({
file: file, file: file,
filedata: imageBlob, filedata: imageBlob,
folder: {id: this.currentUploadFolderId} folder: {id: this.currentUploadFolderId}
}); });
}
catch(e) {
this.companionError({
info: this.$gettext('Es ist ein Fehler aufgetretten! Das Bild konnte nicht gespeichert werden.')
});
console.log(e);
}
if(img && img.type === 'file-refs') { if(img && img.type === 'file-refs') {
this.companionSuccess({ this.companionSuccess({
info: this.$gettext('Das Bild wurde erfolgreich im Dateibereich abgelegt.') info: this.$gettext('Das Bild wurde erfolgreich im Dateibereich abgelegt.')
}); });
} else {
this.companionError({
info: this.$gettext('Es ist ein Fehler aufgetretten! Das Bild konnte nicht gespeichert werden.')
});
} }
}, },
}, },
......
...@@ -19,11 +19,16 @@ ...@@ -19,11 +19,16 @@
{{ currentSuccess }} {{ currentSuccess }}
</div> </div>
<div class="cw-block-download-file-item"> <div class="cw-block-download-file-item">
<a target="_blank" :download="currentFile.name" :href="currentFile.download_url" @click="handleDownload"> <a
target="_blank"
:download="currentFile.name"
:title="$gettext('Datei herunterladen')"
:href="currentFile.download_url"
@click="handleDownload"
>
<span class="cw-block-file-info" :class="['cw-block-file-icon-' + currentFile.icon]"> <span class="cw-block-file-info" :class="['cw-block-file-icon-' + currentFile.icon]">
{{ currentFile.name }} {{ currentFile.name }}
</span> </span>
<span class="cw-block-download-download-icon"></span>
</a> </a>
</div> </div>
</div> </div>
......
...@@ -10,36 +10,127 @@ ...@@ -10,36 +10,127 @@
> >
<template #content> <template #content>
<div v-if="currentTitle !== ''" class="cw-block-title">{{ currentTitle }}</div> <div v-if="currentTitle !== ''" class="cw-block-title">{{ currentTitle }}</div>
<div v-if="isHomework" class="cw-block-folder-info">
<p>
{{ $gettext('Dieser Ordner ist ein Hausaufgabenordner. Es können nur Dateien eingestellt werden.') }}
</p>
<p v-if="!isTeacher">
{{ $gettext('Sie selbst haben folgende Dateien in diesen Ordner eingestellt') }}:
</p>
</div>
<ul class="cw-block-folder-list"> <ul class="cw-block-folder-list">
<li v-for="file in files" :key="file.id" class="cw-block-folder-file-item"> <li v-for="file in files" :key="file.id" class="cw-block-folder-file-item">
<a target="_blank" :download="file.name" :href="file.download_url"> <a
<span class="cw-block-file-info" :class="['cw-block-file-icon-' + file.icon]"> v-if="downloadEnabled"
{{ file.name }} target="_blank"
:download="file.attributes.name"
:title="$gettext('Datei herunterladen')"
:href="file.meta['download-url']"
>
<span class="cw-block-file-info" :class="['cw-block-file-icon-' + getIcon(file.attributes['mime-type'])]">
{{ file.attributes.name }}
</span>
<div v-if="isTeacher && isHomework" class="cw-block-file-details">
<span class="cw-block-file-owner">
{{ file.relationships.owner.meta.name }}
</span>
<span class="cw-block-file-mkdate">
{{ getFormattedDate(file.attributes.mkdate) }}
</span> </span>
<span class="cw-block-folder-download-icon"></span> </div>
</a> </a>
<template v-else>
<span class="cw-block-file-info download-disabled" :class="['cw-block-file-icon-' + getIcon(file.attributes['mime-type'])]">
{{ file.attributes.name }}
</span>
<div class="cw-block-file-details">
<span class="cw-block-file-mkdate">
{{ getFormattedDate(file.attributes.mkdate) }}
</span>
</div>
</template>
</li> </li>
<li v-if="files.length === 0"> <li v-if="files.length === 0">
<span class="cw-block-file-info cw-block-file-icon-empty"> <span class="cw-block-file-info cw-block-file-icon-empty">
<translate>Dieser Ordner ist leer</translate> {{ $gettext('Dieser Ordner ist leer') }}
</span> </span>
</li> </li>
</ul> </ul>
<div v-if="uploadEnabled" class="cw-block-folder-upload">
<form class="default" @submit.prevent="">
<label>
{{ $gettext('Dateien zum Hochladen auswählen') }}
<input class="cw-file-input" ref="uploadFile" type="file" @change="displayTermSelector"/>
<button class="button" @click="uploadFile">
{{ $gettext('Datei hochladen') }}
</button>
</label>
</form>
<studip-dialog
v-if="showTermSelector"
width="780"
height="510"
:title="$gettext('Lizenz auswählen')"
:confirmText="$gettext('Speichern')"
confirmClass="accept"
:closeText="$gettext('Lizenzauswahl abbrechen')"
closeClass="cancel"
@close="showTermSelector = false"
@confirm="selectTerm"
>
<template v-slot:dialogContent>
<form class="default" @submit.prevent="">
<div style="margin-bottom: 1ex;">
{{ $gettext('Bereitgestellte Dateien können heruntergeladen und ggf. weiterverbreitet werden. Dabei ist das Urheberrecht sowohl beim Hochladen der Datei als auch bei der Nutzung zu beachten. Bitte geben Sie daher an, um welche Art von Bereitstellung es sich handelt. Diese Angabe dient mehreren Zwecken: Beim Herunterladen wird ein Hinweis angezeigt, welche Nutzung der Datei zulässig ist. Beim Hochladen stellt die Angabe eine Entscheidungshilfe dar, damit Sie sichergehen können, dass die Datei tatsächlich bereitgestellt werden darf.') }}
</div>
<fieldset class="select_terms_of_use">
<template v-for="term in termsOfUse">
<input
type="radio"
name="content_terms_of_use_id"
:value="term.id"
v-model="selectedTerm"
:id="'content_terms_of_use-' + term.id"
:checked="selectedTerm === term.id"
:aria-description="term.description"
:key="term.id + '_input'"
/>
<label @click="selectedTerm = term.id" :key="term.id + 'label'">
<div class="icon">
<studip-icon :shape="term.attributes.icon" size="32"/>
</div>
<div class="text">
{{ term.attributes.name }}
</div>
<studip-icon shape="arr_1down" size="24" class="arrow" />
<studip-icon shape="check-circle" size="24" class="check" />
</label>
<div class="terms_of_use_description" :key="term.id + '_description'">
<div class="description">
{{ term.attributes.description }}
</div>
</div>
</template>
</fieldset>
</form>
</template>
</studip-dialog>
</div>
</template> </template>
<template v-if="canEdit" #edit> <template v-if="canEdit" #edit>
<form class="default" @submit.prevent=""> <form class="default" @submit.prevent="">
<label> <label>
<translate>Überschrift</translate> {{ $gettext('Überschrift') }}
<input type="text" v-model="currentTitle" /> <input type="text" v-model="currentTitle" />
</label> </label>
<label> <label>
<translate>Ordner</translate> {{ $gettext('Ordner') }}
<courseware-folder-chooser v-model="currentFolderId" allowUserFolders /> <courseware-folder-chooser v-model="currentFolderId" allowUserFolders allowHomeworkFolders />
</label> </label>
</form> </form>
</template> </template>
<template #info> <template #info>
<p><translate>Informationen zum Dateiordner-Block</translate></p> <p>{{ $gettext('Informationen zum Dateiordner-Block') }}</p>
</template> </template>
</courseware-default-block> </courseware-default-block>
</div> </div>
...@@ -48,6 +139,7 @@ ...@@ -48,6 +139,7 @@
<script> <script>
import CoursewareDefaultBlock from './CoursewareDefaultBlock.vue'; import CoursewareDefaultBlock from './CoursewareDefaultBlock.vue';
import CoursewareFolderChooser from './CoursewareFolderChooser.vue'; import CoursewareFolderChooser from './CoursewareFolderChooser.vue';
import StudipDialog from '../StudipDialog.vue';
import { mapActions, mapGetters } from 'vuex'; import { mapActions, mapGetters } from 'vuex';
...@@ -56,6 +148,7 @@ export default { ...@@ -56,6 +148,7 @@ export default {
components: { components: {
CoursewareDefaultBlock, CoursewareDefaultBlock,
CoursewareFolderChooser, CoursewareFolderChooser,
StudipDialog
}, },
props: { props: {
block: Object, block: Object,
...@@ -66,66 +159,71 @@ export default { ...@@ -66,66 +159,71 @@ export default {
return { return {
currentTitle: '', currentTitle: '',
currentFolderId: '', currentFolderId: '',
currentFileType: '', currentFolderType: '',
files: [], showTermSelector: false,
selectedTerm: null,
}; };
}, },
computed: { computed: {
...mapGetters({ ...mapGetters({
relatedFileRefs: 'file-refs/related', folderById: 'folders/byId',
urlHelper: 'urlHelper', termsOfUse: 'terms-of-use/all'
relatedTermOfUse: 'terms-of-use/related',
}), }),
folderType() { folderType() {
return this.block?.attributes?.payload?.type; return this.block?.attributes?.payload?.type;
}, },
storedFolderType() {
return this.block?.attributes?.payload?.folder_type;
},
folderTypeHasChanged() {
return this.folderType === this.storedFolderType;
},
folderId() { folderId() {
return this.block?.attributes?.payload?.folder_id; return this.block?.attributes?.payload?.folder_id;
}, },
title() { title() {
return this.block?.attributes?.payload?.title; return this.block?.attributes?.payload?.title;
}, },
files() {
return this.block?.attributes?.payload?.files;
}, },
mounted() { isHomework() {
return this.folderType === 'HomeworkFolder';
},
uploadEnabled() {
return !this.isTeacher && this.isHomework;
},
downloadEnabled() {
return this.isTeacher || !this.isHomework;
}
},
async mounted() {
await this.loadTermsOfUse();
this.initCurrentData(); this.initCurrentData();
}, },
methods: { methods: {
...mapActions({ ...mapActions({
loadRelatedFileRefs: 'file-refs/loadRelated', loadFolder: 'folders/loadById',
loadBlock: 'courseware-blocks/loadById',
updateBlock: 'updateBlockInContainer', updateBlock: 'updateBlockInContainer',
createFile: 'createFile',
companionWarning: 'companionWarning',
companionSuccess: 'companionSuccess',
companionError: 'companionError',
loadTermsOfUse: 'terms-of-use/loadAll'
}), }),
initCurrentData() { async initCurrentData() {
this.currentTitle = this.title; this.currentTitle = this.title;
this.currentFolderId = this.folderId; this.currentFolderId = this.folderId;
this.currentFolderType = this.folderType; if (this.$refs?.uploadFile) {
}, this.$refs.uploadFile.value = null;
async getFolderFiles() { }
const parent = { type: 'folders', id: `${this.currentFolderId}` }; this.selectedTerm = this.getDefaultTerm();
const relationship = 'file-refs'; },
const options = { include: 'terms-of-use' }; async setCurrentFolderType() {
await this.loadRelatedFileRefs({ parent, relationship, options }); await this.loadFolder({ id: this.currentFolderId });
const fileRefs = this.relatedFileRefs({ parent, relationship }) ?? []; const folder = this.folderById({ id: this.currentFolderId });
this.processFiles(fileRefs); this.currentFolderType = folder?.attributes['folder-type'];
},
processFiles(files) {
this.files = files
.filter((file) => {
if (this.relatedTermOfUse({parent: file, relationship: 'terms-of-use'}).attributes['download-condition'] !== 0) {
return false;
} else {
return true;
}
})
.map(({ id, attributes }) => ({
id,
name: attributes.name,
icon: this.getIcon(attributes['mime-type']),
download_url: this.urlHelper.getURL(
`sendfile.php/`,
{ type: 0, file_id: id, file_name: attributes.name },
true
),
}));
}, },
getIcon(mimeType) { getIcon(mimeType) {
let icon = 'file'; let icon = 'file';
...@@ -171,12 +269,22 @@ export default { ...@@ -171,12 +269,22 @@ export default {
return icon; return icon;
}, },
getFormattedDate(unformattedDate) {
const date = new Date(unformattedDate);
const localeDate = date.toLocaleDateString("de-DE", {
year: "numeric",
month: "2-digit",
day: "2-digit",
});
return `${localeDate} ${date.getHours()}:${(date.getMinutes() < 10 ? '0' : '') + date.getMinutes()}:${(date.getSeconds() < 10 ? '0' : '') + date.getSeconds()}`;
},
storeBlock() { storeBlock() {
let attributes = {}; let attributes = {};
attributes.payload = {}; attributes.payload = {};
attributes.payload.title = this.currentTitle; attributes.payload.title = this.currentTitle;
attributes.payload.folder_id = this.currentFolderId; attributes.payload.folder_id = this.currentFolderId;
attributes.payload.type = this.currentFileType; attributes.payload.type = this.currentFolderType;
this.updateBlock({ this.updateBlock({
attributes: attributes, attributes: attributes,
...@@ -184,10 +292,69 @@ export default { ...@@ -184,10 +292,69 @@ export default {
containerId: this.block.relationships.container.data.id, containerId: this.block.relationships.container.data.id,
}); });
}, },
displayTermSelector() {
this.showTermSelector = true;
},
selectTerm() {
this.showTermSelector = false;
this.uploadFile();
},
async uploadFile() {
const userFile = this.$refs?.uploadFile?.files[0];
if (!userFile) {
this.companionWarning({
info: this.$gettext('Bitte wählen Sie eine Datei aus.')
});
return;
}
let file = {
attributes: {
name: userFile.name.replace(/\s/g, '_')
},
relationships: {
'terms-of-use': {
data: {
id: this.selectedTerm
}
}
}
};
let fileObj = await this.createFile({
file: file,
filedata: userFile,
folder: { id: this.currentFolderId }
});
if (fileObj && fileObj.type === 'file-refs') {
this.companionSuccess({
info: this.$gettext('Die Datei wurde erfolgreich im Dateibereich abgelegt.')
});
} else {
if (this.folderType !== 'HomeworkFolder') {
this.companionError({
info: this.$gettext('Es ist ein Fehler aufgetretten.')
});
}
}
this.reload();
},
async reload() {
await this.loadBlock({ id: this.block.id });
this.initCurrentData();
},
getDefaultTerm() {
const defaultTerm = this.termsOfUse.filter(term => term.attributes['is-default'])[0];
if (defaultTerm) {
return defaultTerm.id;
}
return null;
}
}, },
watch: { watch: {
currentFolderId() { currentFolderId() {
this.getFolderFiles(); if (this.canEdit) {
this.setCurrentFolderType();
}
}, },
}, },
}; };
......
...@@ -290,8 +290,12 @@ export const actions = { ...@@ -290,8 +290,12 @@ export const actions = {
}, },
async createFile(context, { file, filedata, folder }) { async createFile(context, { file, filedata, folder }) {
const termId = file.relationships['terms-of-use'].data.id;
const formData = new FormData(); const formData = new FormData();
formData.append('file', filedata, file.attributes.name); formData.append('file', filedata, file.attributes.name);
if (termId) {
formData.append('term-id', termId);
}
const url = `folders/${folder.id}/file-refs`; const url = `folders/${folder.id}/file-refs`;
let request = await state.httpClient.post(url, formData, { let request = await state.httpClient.post(url, formData, {
...@@ -299,10 +303,16 @@ export const actions = { ...@@ -299,10 +303,16 @@ export const actions = {
'Content-Type': 'multipart/form-data', 'Content-Type': 'multipart/form-data',
}, },
}); });
let response = null;
try {
response = await state.httpClient.get(request.headers.location);
}
catch(e) {
console.debug(e);
response = null;
}
return state.httpClient.get(request.headers.location).then((response) => { return response ? response.data.data : response;
return response.data.data;
});
}, },
async createRootFolder({ dispatch, rootGetters }, { context, folder }) { async createRootFolder({ dispatch, rootGetters }, { context, folder }) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment