Skip to content

Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.

feat(frontend:files): image viewer slideshow

718549bbd4e2ea32
diff --git a/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.html b/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.html
index 361421fb..161470e1 100644
--- a/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.html
+++ b/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.html
@@ -16,7 +16,7 @@
<div class="modal-body">
@switch (shortMime) {
@case ('image') {
- <app-files-viewer-image [currentHeight]="currentHeight" [file]="currentFile"></app-files-viewer-image>
+ <app-files-viewer-image [currentHeight]="currentHeight" [(file)]="currentFile" [directoryImages]="directoryImages()"></app-files-viewer-image>
}
@case ('pdf') {
<app-files-viewer-pdf [currentHeight]="currentHeight" [fileUrl]="currentFile.dataUrl"></app-files-viewer-pdf>
diff --git a/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.ts b/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.ts
index 1bde98fb..af96774c 100644
--- a/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.ts
+++ b/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.ts
@@ -4,7 +4,7 @@
* See the LICENSE file for licensing details
*/
-import { Component, inject, Input, OnDestroy, OnInit } from '@angular/core'
+import { Component, computed, inject, Input, OnDestroy, OnInit } from '@angular/core'
import { Subscription } from 'rxjs'
import { LayoutService } from '../../../../layout/layout.service'
import { FileModel } from '../../models/file.model'
@@ -25,6 +25,7 @@ export class FilesViewerDialogComponent implements OnInit, OnDestroy {
@Input({ required: true }) mode: 'view' | 'edit'
@Input({ required: true }) shortMime: string
protected currentHeight: number
+ protected directoryImages = computed(() => this.directoryFiles.filter((file) => file.isImage))
private readonly layout = inject(LayoutService)
private readonly subscription: Subscription = this.layout.resizeEvent.subscribe(() => this.onResize())
private readonly offsetTop = 42
diff --git a/frontend/src/app/applications/files/components/viewers/files-viewer-image.component.html b/frontend/src/app/applications/files/components/viewers/files-viewer-image.component.html
new file mode 100644
index 00000000..2c036772
--- /dev/null
+++ b/frontend/src/app/applications/files/components/viewers/files-viewer-image.component.html
@@ -0,0 +1,66 @@
+<!--
+ ~ Copyright (C) 2012-2025 Johan Legrand <[email protected]>
+ ~ This file is part of Sync-in | The open source file sync and share solution
+ ~ See the LICENSE file for licensing details
+ -->
+
+<div [style.height.px]="currentHeight()">
+ <div class="app-top-menu d-flex justify-content-between">
+ <div class="d-flex">
+ <button
+ (click)="previousImage()"
+ [tooltip]="'Previous' | translate:locale.language"
+ [adaptivePosition]="true"
+ container="body"
+ class="d-none d-sm-block btn btn-sm btn-custom me-1"
+ type="button">
+ <fa-icon [icon]="icons.faAngleLeft"></fa-icon>
+ </button>
+ <button
+ (click)="nextImage()"
+ [tooltip]="'Next' | translate:locale.language"
+ container="body"
+ class="d-none d-sm-block btn btn-sm btn-custom me-1"
+ type="button">
+ <fa-icon [icon]="icons.faAngleRight"></fa-icon>
+ </button>
+ @if (!isSlideshowActive()) {
+ <button
+ (click)="startSlideshow()"
+ [tooltip]="'Start slideshow' | translate:locale.language"
+ container="body"
+ class="d-none d-sm-block btn btn-sm btn-custom me-1"
+ type="button">
+ <fa-icon [icon]="icons.faPlay"></fa-icon>
+ </button>
+ } @else {
+ <button
+ (click)="stopSlideshow()"
+ [tooltip]="'Stop slideshow' | translate:locale.language"
+ container="body"
+ class="d-none d-sm-block btn btn-sm btn-custom me-1"
+ type="button">
+ <fa-icon [icon]="icons.faStop"></fa-icon>
+ </button>
+ }
+ </div>
+ <div>{{ imageIndex() + 1 }} of {{ imageCount() }}</div>
+ <button
+ btnCheckbox
+ [(ngModel)]="isInfoboxOpen"
+ [tooltip]="'Info' | translate:locale.language"
+ container="body"
+ class="d-none d-sm-block btn btn-sm btn-custom me-1"
+ type="button">
+ <fa-icon [icon]="icons.faInfo"></fa-icon>
+ </button>
+ </div>
+ <div class="d-flex justify-content-center" [style.height]="`calc(${currentHeight()}px - 40px)`">
+ <img #image (load)="onImageLoad()" [src]="file().dataUrl" [style.max-height]="`calc(${currentHeight()}px - 40px)`" alt="" class="img-fluid align-self-center" />
+ <div class="info-box position-absolute end-0 bottom-0" [class.d-none]="!isInfoboxOpen()">
+ {{ file().mime }}
+ {{ imageResolution() }}
+ {{ file().hSize }}
+ </div>
+ </div>
+</div>
diff --git a/frontend/src/app/applications/files/components/viewers/files-viewer-image.component.ts b/frontend/src/app/applications/files/components/viewers/files-viewer-image.component.ts
index 66776ae3..12bd640d 100755
--- a/frontend/src/app/applications/files/components/viewers/files-viewer-image.component.ts
+++ b/frontend/src/app/applications/files/components/viewers/files-viewer-image.component.ts
@@ -4,23 +4,71 @@
* See the LICENSE file for licensing details
*/
-import { Component, input, OnInit } from '@angular/core'
+import { ChangeDetectionStrategy, Component, computed, DestroyRef, ElementRef, inject, input, model, signal, viewChild } from '@angular/core'
+import { FormsModule } from '@angular/forms'
+import { takeUntilDestroyed } from '@angular/core/rxjs-interop'
+import { FaIconComponent } from '@fortawesome/angular-fontawesome'
+import { faAngleLeft, faAngleRight, faInfo, faPlay, faStop } from '@fortawesome/free-solid-svg-icons'
+import { ButtonCheckboxDirective } from 'ngx-bootstrap/buttons'
+import { TooltipModule } from 'ngx-bootstrap/tooltip'
+import { L10N_LOCALE, L10nLocale, L10nTranslatePipe } from 'angular-l10n'
+import { Subscription, timer } from 'rxjs'
import { FileModel } from '../../models/file.model'
+const slideDelay = 5000
+
@Component({
selector: 'app-files-viewer-image',
- template: `<div class="d-flex justify-content-center" [style.height.px]="currentHeight()">
- <img [src]="currentFile.dataUrl" [style.max-height.px]="currentHeight()" alt="" class="img-fluid align-self-center" />
- </div>`
+ imports: [FormsModule, TooltipModule, FaIconComponent, ButtonCheckboxDirective, L10nTranslatePipe],
+ styles: [
+ `
+ .info-box {
+ text-shadow:
+ 1px 1px 2px #000,
+ 0 0 1em #fff,
+ 0 0 0.2em #fff;
+ }
+ `
+ ],
+ templateUrl: 'files-viewer-image.component.html',
+ changeDetection: ChangeDetectionStrategy.OnPush
})
-export class FilesViewerImageComponent implements OnInit {
- file = input<FileModel>()
- directoryFiles = input<FileModel[]>()
+export class FilesViewerImageComponent {
+ file = model<FileModel>()
+ directoryImages = input<FileModel[]>()
currentHeight = input<number>()
- protected currentFile: FileModel
+ protected isInfoboxOpen = signal(false)
+ protected isSlideshowActive = signal(false)
+ protected imageCount = computed(() => this.directoryImages().length)
+ protected imageIndex = computed(() => this.directoryImages().indexOf(this.file()))
+ protected imageResolution = signal<string>('')
+ protected readonly icons = { faAngleLeft, faAngleRight, faInfo, faPlay, faStop }
+ protected readonly locale = inject<L10nLocale>(L10N_LOCALE)
+ private destroyRef = inject(DestroyRef)
+ private imageRef = viewChild.required<ElementRef>('image')
+ private slideshowSub: Subscription
+
+ protected onImageLoad() {
+ const img = this.imageRef().nativeElement
+ this.imageResolution.set(`${img.naturalWidth}x${img.naturalHeight}`)
+ }
+
+ protected nextImage() {
+ this.file.set(this.directoryImages()[(this.imageIndex() + 1) % this.imageCount()])
+ }
+
+ protected previousImage() {
+ this.file.set(this.directoryImages()[(this.imageCount() + this.imageIndex() - 1) % this.imageCount()])
+ }
- ngOnInit() {
- console.log('init')
- this.currentFile = this.file()
+ protected startSlideshow() {
+ this.isSlideshowActive.set(true)
+ this.slideshowSub = timer(slideDelay, slideDelay)
+ .pipe(takeUntilDestroyed(this.destroyRef))
+ .subscribe(() => this.nextImage())
+ }
+ protected stopSlideshow() {
+ this.slideshowSub?.unsubscribe()
+ this.isSlideshowActive.set(false)
}
}
diff --git a/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.html b/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.html
index 615c3ae7..91c65e81 100644
--- a/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.html
+++ b/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.html
@@ -41,7 +41,7 @@
</button>
<button
btnCheckbox
- [ngModel]="this.isSearchPanelOpen()"
+ [ngModel]="isSearchPanelOpen"
(ngModelChange)="toggleSearch()"
[tooltip]="'Search' | translate:locale.language"
container="body"
@@ -61,4 +61,4 @@
[theme]="currentTheme"
[readonly]="isReadonly()"
[lineWrapping]="lineWrapping()" />
-</div>
\ No newline at end of file
+</div>
diff --git a/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.ts b/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.ts
index 567b5d20..09e3c7ce 100644
--- a/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.ts
+++ b/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.ts
@@ -6,7 +6,7 @@
import { CodeEditor } from '@acrodata/code-editor'
import { HttpClient, HttpErrorResponse } from '@angular/common/http'
-import { Component, HostListener, inject, input, linkedSignal, OnDestroy, OnInit, signal, ViewChild, ViewEncapsulation } from '@angular/core'
+import { Component, HostListener, inject, input, linkedSignal, OnDestroy, OnInit, signal, viewChild, ViewEncapsulation } from '@angular/core'
import { FormsModule } from '@angular/forms'
import { LanguageDescription } from '@codemirror/language'
import { languages } from '@codemirror/language-data'
@@ -55,7 +55,7 @@ import { FilesUploadService } from '../../services/files-upload.service'
templateUrl: 'files-viewer-text.component.html'
})
export class FilesViewerTextComponent implements OnInit, OnDestroy {
- @ViewChild('editor') editor: CodeEditor
+ editor = viewChild<CodeEditor>('editor')
currentHeight = input<number>()
file = input<FileModel>()
mode = input<'view' | 'edit'>('view')
@@ -146,11 +146,11 @@ export class FilesViewerTextComponent implements OnInit, OnDestroy {
}
toggleSearch() {
- this.isSearchPanelOpen.set(!this.isSearchPanelOpen())
+ this.isSearchPanelOpen.update((value) => !value)
if (this.isSearchPanelOpen()) {
- openSearchPanel(this.editor.view)
+ openSearchPanel(this.editor().view)
} else {
- closeSearchPanel(this.editor.view)
+ closeSearchPanel(this.editor().view)
}
}