Skip to content
Snippets Groups Projects
Commit 99cce644 authored by Ron Lucke's avatar Ron Lucke Committed by David Siegfried
Browse files

fix #465

Closes #465

Merge request studip/studip!1107
parent eae2953d
No related branches found
No related tags found
No related merge requests found
......@@ -29,6 +29,62 @@ class Gallery extends BlockType
return _('Bilder aus einem Ordner im Dateibereich zeigen.');
}
/**
* 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();
if ($typedFolder->folder_type === 'HiddenFolder' && !$typedFolder->download_allowed) {
return $payload;
}
$payload['folder-type'] = $typedFolder->folder_type;
foreach ($typedFolder->getFiles() as $folderFile) {
$fileRef = $folderFile->getFileRef();
$file = [];
$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' => $fileRef->getAuthorName()]
]
];
$file['meta'] = [
'download-url' => $folderFile->getDownloadURL(),
];
if ($this->filePermission($typedFolder, $file, $user) && $fileRef->isImage()) {
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);
}
public function initialPayload(): array
{
return [
......
......@@ -5,9 +5,9 @@
:canEdit="canEdit"
:isTeacher="isTeacher"
:preview="true"
@showEdit="initCurrentData"
@showEdit="showEdit"
@storeEdit="storeBlock"
@closeEdit="initCurrentData"
@closeEdit="closeEdit"
>
<template #content>
<div v-if="files.length !== 0" class="cw-block-gallery-content" :style="{ 'max-height': currentHeight + 'px' }">
......@@ -19,7 +19,7 @@
>
<div class="cw-block-gallery-number-text">{{ index + 1 }} / {{ files.length }}</div>
<img
:src="image.download_url"
:src="image.meta['download-url']"
:style="{ 'max-height': currentHeight + 'px' }"
@load="
if (files.length - 1 === index) {
......@@ -28,7 +28,7 @@
"
/>
<div v-if="currentShowFileNames === 'true'" class="cw-block-gallery-file-name">
<span>{{ image.name }}</span>
<span>{{ image.attributes.name }}</span>
</div>
</div>
<div v-if="currentNav === 'true'">
......@@ -107,8 +107,9 @@ export default {
currentHeight: '',
currentShowFileNames: '',
currentAutoplayTimer: '',
files: [],
editModeFiles: [],
slideIndex: 0,
editMode: false,
};
},
computed: {
......@@ -135,6 +136,12 @@ export default {
showFileNames() {
return this.block?.attributes?.payload?.show_filenames;
},
files() {
if (!this.editMode) {
return this.block?.attributes?.payload?.files;
}
return this.editModeFiles;
}
},
mounted() {
this.initCurrentData();
......@@ -169,7 +176,7 @@ export default {
this.processFiles(files);
},
processFiles(files) {
this.files = files
this.editModeFiles = files
.filter((file) => {
if (this.relatedTermOfUse({parent: file, relationship: 'terms-of-use'}).attributes['download-condition'] !== 0) {
return false;
......@@ -182,14 +189,26 @@ export default {
})
.map((file) => ({
id: file.id,
name: file.attributes.name,
download_url: this.urlHelper.getURL(
'sendfile.php',
{ type: 0, file_id: file.id, file_name: file.attributes.name },
true
),
attributes: {
name: file.attributes.name
},
meta: {
'download-url': this.urlHelper.getURL(
'sendfile.php',
{ type: 0, file_id: file.id, file_name: file.attributes.name },
true
),
},
}));
},
showEdit() {
this.editMode = true;
this.initCurrentData();
},
closeEdit() {
this.editMode = false;
this.initCurrentData();
},
storeBlock() {
let attributes = {};
attributes.payload = {};
......@@ -206,10 +225,10 @@ export default {
containerId: this.block.relationships.container.data.id,
});
},
plusSlides: function (n) {
plusSlides(n) {
this.showSlides((this.slideIndex += n));
},
showSlides: function (n) {
showSlides(n) {
let slides = this.$refs.images;
if (slides === undefined) {
return false;
......@@ -225,7 +244,7 @@ export default {
});
slides[this.slideIndex].style.display = 'block';
},
playSlides: function () {
playSlides() {
let slides = this.$refs.images;
slides.forEach((slide) => {
slide.style.display = 'none';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment