From 73a8c4202a9d4fd7746e080a339c0fa644d4b32f Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Sun, 6 Sep 2020 17:07:40 +0200 Subject: [PATCH] Implementing custom folder sorting, by adding support for pg2conf metafiles. Fixes: #177 --- README.md | 3 +++ src/common/PG2ConfMap.ts | 16 ++++++++++++++++ src/common/SupportedFormats.ts | 2 +- src/frontend/app/app.module.ts | 4 +++- src/frontend/app/pipes/GPXFilesFilterPipe.ts | 10 ++++++++++ .../app/ui/gallery/gallery.component.html | 4 ++-- .../app/ui/gallery/gallery.component.ts | 3 ++- src/frontend/app/ui/gallery/gallery.service.ts | 17 ++++++++++++++--- .../ui/gallery/map/map.gallery.component.html | 2 +- .../app/ui/gallery/map/map.gallery.component.ts | 2 +- .../navigator/navigator.gallery.component.ts | 1 + 11 files changed, 54 insertions(+), 10 deletions(-) create mode 100644 src/common/PG2ConfMap.ts create mode 100644 src/frontend/app/pipes/GPXFilesFilterPipe.ts diff --git a/README.md b/README.md index afe8fc70..70615613 100644 --- a/README.md +++ b/README.md @@ -201,6 +201,9 @@ apt-get install build-essential libkrb5-dev gcc g++ * cleaning up temp folder * indexing db * folder ignoring [#87](https://github.com/bpatrik/pigallery2/issues/87) + * `.pg2conf` UI modifying files. [#177](https://github.com/bpatrik/pigallery2/issues/177). + * List of these files are passed down to the UI modify its behaviour. + * Currently, supported custom, per folder sorting. * Dockerized * **Markdown based blogging support** - `future plan` * you can write some note in the blog.md for every directory diff --git a/src/common/PG2ConfMap.ts b/src/common/PG2ConfMap.ts new file mode 100644 index 00000000..a1dde1da --- /dev/null +++ b/src/common/PG2ConfMap.ts @@ -0,0 +1,16 @@ +import {SortingMethods} from './entities/SortingMethods'; + + +/** + * This contains the action of the supported list of *.pg2conf files. + * These files are passed down to the client as metaFiles (like photos and directories) + */ +export const PG2ConfMap = { + sorting: { + '.order_descending_name.pg2conf': SortingMethods.descName, + '.order_ascending_name.pg2conf': SortingMethods.ascName, + '.order_descending_date.pg2conf': SortingMethods.descDate, + '.order_ascending_date.pg2conf': SortingMethods.ascDate, + '.order_random.pg2conf': SortingMethods.random + } +}; diff --git a/src/common/SupportedFormats.ts b/src/common/SupportedFormats.ts index d61b54eb..41e78f84 100644 --- a/src/common/SupportedFormats.ts +++ b/src/common/SupportedFormats.ts @@ -15,7 +15,7 @@ export const SupportedFormats = { 'ogg' ], MetaFiles: [ - 'gpx' + 'gpx', 'pg2conf' ], // These formats need to be transcoded (with the build-in ffmpeg support) TranscodeNeed: { diff --git a/src/frontend/app/app.module.ts b/src/frontend/app/app.module.ts index d318b90e..5685d09b 100644 --- a/src/frontend/app/app.module.ts +++ b/src/frontend/app/app.module.ts @@ -24,6 +24,7 @@ import {LoginComponent} from './ui/login/login.component'; import {AdminComponent} from './ui/admin/admin.component'; import {GalleryComponent} from './ui/gallery/gallery.component'; import {StringifyRole} from './pipes/StringifyRolePipe'; +import {GPXFilesFilterPipe} from './pipes/GPXFilesFilterPipe'; import {GalleryMapComponent} from './ui/gallery/map/map.gallery.component'; import {GalleryMapLightboxComponent} from './ui/gallery/map/lightbox/lightbox.map.gallery.component'; import {ThumbnailManagerService} from './ui/gallery/thumbnailManager.service'; @@ -211,7 +212,8 @@ export function translationsFactory(locale: string) { IconizeSortingMethod, StringifySortingMethod, DurationPipe, - FileSizePipe + FileSizePipe, + GPXFilesFilterPipe ], providers: [ {provide: HTTP_INTERCEPTORS, useClass: CSRFInterceptor, multi: true}, diff --git a/src/frontend/app/pipes/GPXFilesFilterPipe.ts b/src/frontend/app/pipes/GPXFilesFilterPipe.ts new file mode 100644 index 00000000..fc150f31 --- /dev/null +++ b/src/frontend/app/pipes/GPXFilesFilterPipe.ts @@ -0,0 +1,10 @@ +import {Pipe, PipeTransform} from '@angular/core'; +import {FileDTO} from '../../../common/entities/FileDTO'; + + +@Pipe({name: 'gpxFiles'}) +export class GPXFilesFilterPipe implements PipeTransform { + transform(metaFiles: FileDTO[]) { + return metaFiles.filter((f: FileDTO) => f.name.toLocaleLowerCase().endsWith('.gpx')); + } +} diff --git a/src/frontend/app/ui/gallery/gallery.component.html b/src/frontend/app/ui/gallery/gallery.component.html index a971f0d4..17357c02 100644 --- a/src/frontend/app/ui/gallery/gallery.component.html +++ b/src/frontend/app/ui/gallery/gallery.component.html @@ -34,7 +34,7 @@ + [gpxFiles]="_galleryService.content.value.directory.metaFile | gpxFiles"> @@ -48,7 +48,7 @@ + [gpxFiles]="_galleryService.content.value.searchResult.metaFile | gpxFiles"> diff --git a/src/frontend/app/ui/gallery/gallery.component.ts b/src/frontend/app/ui/gallery/gallery.component.ts index c9cc646c..03321946 100644 --- a/src/frontend/app/ui/gallery/gallery.component.ts +++ b/src/frontend/app/ui/gallery/gallery.component.ts @@ -18,6 +18,7 @@ import {PhotoDTO} from '../../../../common/entities/PhotoDTO'; import {QueryParams} from '../../../../common/QueryParams'; import {SeededRandomService} from '../../model/seededRandom.service'; import {take} from 'rxjs/operators'; +import {FileDTO} from '../../../../common/entities/FileDTO'; @Component({ selector: 'app-gallery', @@ -57,6 +58,7 @@ export class GalleryComponent implements OnInit, OnDestroy { PageHelper.showScrollY(); } + updateTimer(t: number) { if (this.shareService.sharingSubject.value == null) { return; @@ -210,6 +212,5 @@ export class GalleryComponent implements OnInit, OnDestroy { } } - } diff --git a/src/frontend/app/ui/gallery/gallery.service.ts b/src/frontend/app/ui/gallery/gallery.service.ts index 562010a5..b73197b9 100644 --- a/src/frontend/app/ui/gallery/gallery.service.ts +++ b/src/frontend/app/ui/gallery/gallery.service.ts @@ -10,6 +10,7 @@ import {ShareService} from './share.service'; import {NavigationService} from '../../model/navigation.service'; import {SortingMethods} from '../../../../common/entities/SortingMethods'; import {QueryParams} from '../../../../common/QueryParams'; +import {PG2ConfMap} from '../../../../common/PG2ConfMap'; @Injectable() @@ -40,10 +41,21 @@ export class GalleryService { this.sorting = new BehaviorSubject(Config.Client.Other.defaultPhotoSortingMethod); } + getDefaultSorting(directory: DirectoryDTO): SortingMethods { + if (directory && directory.metaFile) { + for (const file in PG2ConfMap.sorting) { + if (directory.metaFile.some(f => f.name === file)) { + return (PG2ConfMap.sorting)[file]; + } + } + } + return Config.Client.Other.defaultPhotoSortingMethod; + } + setSorting(sorting: SortingMethods): void { this.sorting.next(sorting); if (this.content.value.directory) { - if (sorting !== Config.Client.Other.defaultPhotoSortingMethod) { + if (sorting !== this.getDefaultSorting(this.content.value.directory)) { this.galleryCacheService.setSorting(this.content.value.directory, sorting); } else { this.galleryCacheService.removeSorting(this.content.value.directory); @@ -59,7 +71,7 @@ export class GalleryService { if (sort !== null) { this.sorting.next(sort); } else { - this.sorting.next(Config.Client.Other.defaultPhotoSortingMethod); + this.sorting.next(this.getDefaultSorting(content.directory)); } } } @@ -199,7 +211,6 @@ export class GalleryService { } - isSearchResult(): boolean { return !!this.content.value.searchResult; } diff --git a/src/frontend/app/ui/gallery/map/map.gallery.component.html b/src/frontend/app/ui/gallery/map/map.gallery.component.html index 0b1937a2..54af89b6 100644 --- a/src/frontend/app/ui/gallery/map/map.gallery.component.html +++ b/src/frontend/app/ui/gallery/map/map.gallery.component.html @@ -1,5 +1,5 @@ - +
= []; diff --git a/src/frontend/app/ui/gallery/navigator/navigator.gallery.component.ts b/src/frontend/app/ui/gallery/navigator/navigator.gallery.component.ts index 979d07f9..e0633e59 100644 --- a/src/frontend/app/ui/gallery/navigator/navigator.gallery.component.ts +++ b/src/frontend/app/ui/gallery/navigator/navigator.gallery.component.ts @@ -45,6 +45,7 @@ export class GalleryNavigatorComponent implements OnChanges { ngOnChanges() { this.getPath(); + this.DefaultSorting = this.galleryService.getDefaultSorting(this.directory); } getPath(): any {