From 6bcd8ff33c85becc09b3ff8b754d858a4ba44f5f Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Thu, 24 Jun 2021 23:00:41 +0200 Subject: [PATCH] Add sorting by rating #80 --- src/common/PG2ConfMap.ts | 2 ++ src/common/entities/SortingMethods.ts | 2 +- src/frontend/app/pipes/IconizeSortingMethod.ts | 4 ++++ src/frontend/app/pipes/StringifySortingMethod.ts | 4 ++++ src/frontend/app/ui/gallery/gallery.component.ts | 3 +++ src/frontend/app/ui/gallery/grid/grid.gallery.component.ts | 6 ++++++ .../ui/gallery/navigator/navigator.gallery.component.css | 6 +++++- .../ui/gallery/navigator/navigator.gallery.component.html | 4 +++- 8 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/common/PG2ConfMap.ts b/src/common/PG2ConfMap.ts index d25ab0f0..4c05432a 100644 --- a/src/common/PG2ConfMap.ts +++ b/src/common/PG2ConfMap.ts @@ -11,6 +11,8 @@ export const PG2ConfMap = { '.order_ascending_name.pg2conf': SortingMethods.ascName, '.order_descending_date.pg2conf': SortingMethods.descDate, '.order_ascending_date.pg2conf': SortingMethods.ascDate, + '.order_descending_rating.pg2conf': SortingMethods.descRating, + '.order_ascending_rating.pg2conf': SortingMethods.ascRating, '.order_random.pg2conf': SortingMethods.random } }; diff --git a/src/common/entities/SortingMethods.ts b/src/common/entities/SortingMethods.ts index dab4c965..aba385e1 100644 --- a/src/common/entities/SortingMethods.ts +++ b/src/common/entities/SortingMethods.ts @@ -1,3 +1,3 @@ export enum SortingMethods { - ascName = 1, descName = 2, ascDate = 3, descDate = 4, random = 5 + ascName = 1, descName, ascDate, descDate, ascRating, descRating, random } diff --git a/src/frontend/app/pipes/IconizeSortingMethod.ts b/src/frontend/app/pipes/IconizeSortingMethod.ts index 9f2a2494..99c1bcb2 100644 --- a/src/frontend/app/pipes/IconizeSortingMethod.ts +++ b/src/frontend/app/pipes/IconizeSortingMethod.ts @@ -6,6 +6,10 @@ import {SortingMethods} from '../../../common/entities/SortingMethods'; export class IconizeSortingMethod implements PipeTransform { transform(method: SortingMethods): string { switch (method) { + case SortingMethods.ascRating: + return ''; + case SortingMethods.descRating: + return ''; case SortingMethods.ascName: return 'A'; case SortingMethods.descName: diff --git a/src/frontend/app/pipes/StringifySortingMethod.ts b/src/frontend/app/pipes/StringifySortingMethod.ts index 57866967..c7c56ab6 100644 --- a/src/frontend/app/pipes/StringifySortingMethod.ts +++ b/src/frontend/app/pipes/StringifySortingMethod.ts @@ -9,6 +9,10 @@ export class StringifySortingMethod implements PipeTransform { transform(method: SortingMethods): string { switch (method) { + case SortingMethods.ascRating: + return $localize`ascending rating`; + case SortingMethods.descRating: + return $localize`descending rating`; case SortingMethods.ascName: return $localize`ascending name`; case SortingMethods.descName: diff --git a/src/frontend/app/ui/gallery/gallery.component.ts b/src/frontend/app/ui/gallery/gallery.component.ts index e01c29fa..65496a26 100644 --- a/src/frontend/app/ui/gallery/gallery.component.ts +++ b/src/frontend/app/ui/gallery/gallery.component.ts @@ -165,6 +165,7 @@ export class GalleryComponent implements OnInit, OnDestroy { return; } switch (this.galleryService.sorting.value) { + case SortingMethods.ascRating: // directories does not have rating case SortingMethods.ascName: this.directories.sort((a: DirectoryDTO, b: DirectoryDTO) => compare()(a.name, b.name)); break; @@ -175,6 +176,8 @@ export class GalleryComponent implements OnInit, OnDestroy { } this.directories.sort((a: DirectoryDTO, b: DirectoryDTO) => compare()(a.name, b.name)); break; + + case SortingMethods.descRating: // directories does not have rating case SortingMethods.descName: this.directories.sort((a: DirectoryDTO, b: DirectoryDTO) => compare({order: 'desc'})(a.name, b.name)); break; diff --git a/src/frontend/app/ui/gallery/grid/grid.gallery.component.ts b/src/frontend/app/ui/gallery/grid/grid.gallery.component.ts index 83a03cf7..d7c8ac94 100644 --- a/src/frontend/app/ui/gallery/grid/grid.gallery.component.ts +++ b/src/frontend/app/ui/gallery/grid/grid.gallery.component.ts @@ -257,6 +257,12 @@ export class GalleryGridComponent implements OnChanges, OnInit, AfterViewInit, O return b.metadata.creationDate - a.metadata.creationDate; }); break; + case SortingMethods.ascRating: + this.media.sort((a: PhotoDTO, b: PhotoDTO) => (a.metadata.rating || 0) - (b.metadata.rating || 0)); + break; + case SortingMethods.descRating: + this.media.sort((a: PhotoDTO, b: PhotoDTO) => (b.metadata.rating || 0) - (a.metadata.rating || 0)); + break; case SortingMethods.random: this.rndService.setSeed(this.media.length); this.media.sort((a: PhotoDTO, b: PhotoDTO): number => { diff --git a/src/frontend/app/ui/gallery/navigator/navigator.gallery.component.css b/src/frontend/app/ui/gallery/navigator/navigator.gallery.component.css index 5c33782c..2cd9df30 100644 --- a/src/frontend/app/ui/gallery/navigator/navigator.gallery.component.css +++ b/src/frontend/app/ui/gallery/navigator/navigator.gallery.component.css @@ -30,7 +30,11 @@ ol { } .dropdown-menu { - min-width: 10rem; + min-width: 13rem; +} + +.dropdown-item{ + padding: 0.25rem 0.5rem; } .row { diff --git a/src/frontend/app/ui/gallery/navigator/navigator.gallery.component.html b/src/frontend/app/ui/gallery/navigator/navigator.gallery.component.html index 6d8dcda7..db19a4bb 100644 --- a/src/frontend/app/ui/gallery/navigator/navigator.gallery.component.html +++ b/src/frontend/app/ui/gallery/navigator/navigator.gallery.component.html @@ -43,7 +43,9 @@