diff --git a/src/frontend/app/ui/gallery/gallery.component.ts b/src/frontend/app/ui/gallery/gallery.component.ts index 598aa54e..b2d72cb0 100644 --- a/src/frontend/app/ui/gallery/gallery.component.ts +++ b/src/frontend/app/ui/gallery/gallery.component.ts @@ -172,13 +172,17 @@ export class GalleryComponent implements OnInit, OnDestroy { } switch (this._galleryService.sorting.value) { case SortingMethods.ascName: - case SortingMethods.ascDate: this.directories.sort((a: DirectoryDTO, b: DirectoryDTO) => compare()(a.name, b.name)); break; + case SortingMethods.ascDate: + this.directories.sort((a: DirectoryDTO, b: DirectoryDTO) => compare()(a.lastModified, b.lastModified)); + break; case SortingMethods.descName: - case SortingMethods.descDate: this.directories.sort((a: DirectoryDTO, b: DirectoryDTO) => compare({ order: 'desc' })(a.name, b.name)); break; + case SortingMethods.descDate: + this.directories.sort((a: DirectoryDTO, b: DirectoryDTO) => compare({ order: 'desc' })(a.lastModified, b.lastModified)); + break; case SortingMethods.random: this.rndService.setSeed(this.directories.length); this.directories.sort((a: DirectoryDTO, b: DirectoryDTO) => { 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 a3c5a4cd..92830d3d 100644 --- a/src/frontend/app/ui/gallery/grid/grid.gallery.component.ts +++ b/src/frontend/app/ui/gallery/grid/grid.gallery.component.ts @@ -28,6 +28,7 @@ import {SortingMethods} from '../../../../../common/entities/SortingMethods'; import {MediaDTO} from '../../../../../common/entities/MediaDTO'; import {QueryParams} from '../../../../../common/QueryParams'; import {SeededRandomService} from '../../../model/seededRandom.service'; +import { compare } from 'natural-orderby'; @Component({ selector: 'app-gallery-grid', @@ -230,26 +231,10 @@ export class GalleryGridComponent implements OnChanges, OnInit, AfterViewInit, O private sortPhotos() { switch (this.galleryService.sorting.value) { case SortingMethods.ascName: - this.media.sort((a: PhotoDTO, b: PhotoDTO) => { - if (a.name.toLowerCase() < b.name.toLowerCase()) { - return -1; - } - if (a.name.toLowerCase() > b.name.toLowerCase()) { - return 1; - } - return 0; - }); + this.media.sort((a: PhotoDTO, b: PhotoDTO) => compare()(a.name, b.name)); break; case SortingMethods.descName: - this.media.sort((a: PhotoDTO, b: PhotoDTO) => { - if (a.name.toLowerCase() < b.name.toLowerCase()) { - return 1; - } - if (a.name.toLowerCase() > b.name.toLowerCase()) { - return -1; - } - return 0; - }); + this.media.sort((a: PhotoDTO, b: PhotoDTO) => compare({order: 'desc' })(a.name, b.name)); break; case SortingMethods.ascDate: this.media.sort((a: PhotoDTO, b: PhotoDTO) => {