1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00

Fix gallery order issue

* Add code to sort the folder in gallery by date
* Add code to sort the media files in a folder using natural-order
This commit is contained in:
Bruce Chen 2021-02-26 23:50:29 +08:00
parent 7f321a3ff5
commit 9711b5956a
2 changed files with 9 additions and 20 deletions

View File

@ -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) => {

View File

@ -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) => {