Skip to content

Commit 8705964

Browse files
committed
Display thumbnail size by file processor
1 parent 70871a7 commit 8705964

File tree

5 files changed

+64
-21
lines changed

5 files changed

+64
-21
lines changed

com.woltlab.wcf/templates/shared_fileProcessorFormField.tpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
{if $field->isBigPreview()}true{else}false{/if},
2727
{if $field->isSimpleReplace()}true{else}false{/if},
2828
{if $field->isHideDeleteButton()}true{else}false{/if},
29+
{if $field->getThumbnailSize() === null}undefined{else}'{$field->getThumbnailSize()|encodeJS}'{/if},
2930
[{implode from=$actionButtons item=actionButton}{
3031
title: '{unsafe:$actionButton['title']|encodeJS}',
3132
icon: {if $actionButton['icon'] === null}undefined{else}'{unsafe:$actionButton['icon']->toHtml()|encodeJS}'{/if},

ts/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @since 6.1
66
*/
77

8-
import WoltlabCoreFileElement from "WoltLabSuite/Core/Component/File/woltlab-core-file";
8+
import WoltlabCoreFileElement, { Thumbnail } from "WoltLabSuite/Core/Component/File/woltlab-core-file";
99
import { getPhrase } from "WoltLabSuite/Core/Language";
1010
import { deleteFile } from "WoltLabSuite/Core/Api/Files/DeleteFile";
1111
import DomChangeListener from "WoltLabSuite/Core/Dom/Change/Listener";
@@ -37,6 +37,7 @@ export class FileProcessor {
3737
readonly #singleFileUpload: boolean;
3838
readonly #simpleReplace: boolean;
3939
readonly #hideDeleteButton: boolean;
40+
readonly #thumbnailSize?: string;
4041
readonly #extraButtons: ExtraButton[];
4142
#uploadResolve: undefined | (() => void);
4243

@@ -46,6 +47,7 @@ export class FileProcessor {
4647
useBigPreview: boolean = false,
4748
simpleReplace: boolean = false,
4849
hideDeleteButton: boolean = false,
50+
thumbnailSize?: string,
4951
extraButtons: ExtraButton[] = [],
5052
) {
5153
this.#fieldId = fieldId;
@@ -54,6 +56,7 @@ export class FileProcessor {
5456
this.#simpleReplace = simpleReplace;
5557
this.#hideDeleteButton = hideDeleteButton;
5658
this.#extraButtons = extraButtons;
59+
this.#thumbnailSize = thumbnailSize;
5760

5861
this.#container = document.getElementById(fieldId + "Container")!;
5962
if (this.#container === null) {
@@ -306,17 +309,17 @@ export class FileProcessor {
306309

307310
#fileInitializationCompleted(element: WoltlabCoreFileElement, container: HTMLElement): void {
308311
if (this.#useBigPreview) {
309-
element.dataset.previewUrl = element.link!;
310-
element.unbounded = true;
312+
setThumbnail(
313+
element,
314+
element.thumbnails.find((thumbnail) => thumbnail.identifier === this.#thumbnailSize),
315+
true,
316+
);
311317
} else {
312318
if (element.isImage()) {
313-
const thumbnail = element.thumbnails.find((thumbnail) => thumbnail.identifier === "tiny");
314-
if (thumbnail !== undefined) {
315-
element.thumbnail = thumbnail;
316-
} else {
317-
element.dataset.previewUrl = element.link!;
318-
element.unbounded = false;
319-
}
319+
const thumbnailSize = this.#thumbnailSize ?? "tiny";
320+
321+
const thumbnail = element.thumbnails.find((thumbnail) => thumbnail.identifier === thumbnailSize);
322+
setThumbnail(element, thumbnail);
320323

321324
if (element.link !== undefined && element.filename !== undefined) {
322325
const filenameLink = document.createElement("a");
@@ -371,6 +374,16 @@ export class FileProcessor {
371374
}
372375
}
373376

377+
function setThumbnail(element: WoltlabCoreFileElement, thumbnail?: Thumbnail, unbounded: boolean = false) {
378+
if (unbounded) {
379+
element.dataset.previewUrl = thumbnail !== undefined ? thumbnail.link : element.link;
380+
} else if (thumbnail !== undefined) {
381+
element.thumbnail = thumbnail;
382+
}
383+
384+
element.unbounded = unbounded;
385+
}
386+
374387
export function getValues(fieldId: string): undefined | number | Set<number> {
375388
const field = fileProcessors.get(fieldId);
376389
if (field === undefined) {

wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.js

Lines changed: 16 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wcfsetup/install/files/lib/action/UserAvatarAction.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ private function getForm(UserProfile $user): Psr15DialogForm
112112
->bigPreview()
113113
->simpleReplace()
114114
->hideDeleteButton()
115+
->thumbnailSize('128')
115116
->addDependency(
116117
ValueFormFieldDependency::create('avatarType')
117118
->fieldId('avatarType')

wcfsetup/install/files/lib/system/form/builder/field/FileProcessorFormField.class.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ final class FileProcessorFormField extends AbstractFormField
4747
private bool $bigPreview = false;
4848
private bool $simpleReplace = false;
4949
private bool $hideDeleteButton = false;
50+
private ?string $thumbnailSize = null;
5051
private array $actionButtons = [];
5152

5253
#[\Override]
@@ -355,4 +356,26 @@ public function isHideDeleteButton(): bool
355356
{
356357
return $this->hideDeleteButton;
357358
}
359+
360+
/**
361+
* Sets the thumbnail size for the preview.
362+
*
363+
* If no size is set:
364+
* - And the big preview is enabled, the full size is used
365+
* - Otherwise, the thumbnail size `tiny` is used
366+
*/
367+
public function thumbnailSize(?string $thumbnailSize): self
368+
{
369+
$this->thumbnailSize = $thumbnailSize;
370+
371+
return $this;
372+
}
373+
374+
/**
375+
* Returns the thumbnail size for the preview.
376+
*/
377+
public function getThumbnailSize(): ?string
378+
{
379+
return $this->thumbnailSize;
380+
}
358381
}

0 commit comments

Comments
 (0)