mirror of
https://github.com/bpatrik/pigallery2.git
synced 2025-01-10 04:07:35 +02:00
Creating def. sorting for search results. fixes #566
This commit is contained in:
parent
5f3ebfc128
commit
9b56331f50
@ -144,13 +144,16 @@ export class ClientOtherConfig {
|
||||
enableCache: boolean = true;
|
||||
@ConfigProperty()
|
||||
enableOnScrollRendering: boolean = true;
|
||||
@ConfigProperty({type: SortingMethods})
|
||||
@ConfigProperty({type: SortingMethods,description:'Default sorting method for directory results'})
|
||||
defaultPhotoSortingMethod: SortingMethods = SortingMethods.ascDate;
|
||||
|
||||
@ConfigProperty({type: SortingMethods,description:'Default sorting method for search results'})
|
||||
defaultSearchSortingMethod: SortingMethods = SortingMethods.descDate;
|
||||
@ConfigProperty({
|
||||
description:
|
||||
'If enabled directories will be sorted by date, like photos, otherwise by name. Directory date is the last modification time of that directory not the creation date of the oldest photo',
|
||||
})
|
||||
enableDirectorySortingByDate: boolean = false;
|
||||
enableDirectorySortingByDate: boolean = false;
|
||||
@ConfigProperty()
|
||||
enableOnScrollThumbnailPrioritising: boolean = true;
|
||||
@ConfigProperty()
|
||||
|
@ -118,7 +118,7 @@ export class GalleryNavigatorComponent {
|
||||
|
||||
get DefaultSorting(): SortingMethods {
|
||||
return this.sortingService.getDefaultSorting(
|
||||
this.galleryService.content.value.directory
|
||||
this.galleryService.content.value
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1,20 +1,21 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { NetworkService } from '../../../model/network/network.service';
|
||||
import { ParentDirectoryDTO } from '../../../../../common/entities/DirectoryDTO';
|
||||
import { GalleryCacheService } from '../cache.gallery.service';
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
import { Config } from '../../../../../common/config/public/Config';
|
||||
import { SortingMethods } from '../../../../../common/entities/SortingMethods';
|
||||
import { PG2ConfMap } from '../../../../../common/PG2ConfMap';
|
||||
import { ContentService, DirectoryContent } from '../content.service';
|
||||
import { PhotoDTO } from '../../../../../common/entities/PhotoDTO';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { SeededRandomService } from '../../../model/seededRandom.service';
|
||||
import {Injectable} from '@angular/core';
|
||||
import {NetworkService} from '../../../model/network/network.service';
|
||||
import {ParentDirectoryDTO} from '../../../../../common/entities/DirectoryDTO';
|
||||
import {GalleryCacheService} from '../cache.gallery.service';
|
||||
import {BehaviorSubject, Observable} from 'rxjs';
|
||||
import {Config} from '../../../../../common/config/public/Config';
|
||||
import {SortingMethods} from '../../../../../common/entities/SortingMethods';
|
||||
import {PG2ConfMap} from '../../../../../common/PG2ConfMap';
|
||||
import {ContentService, ContentWrapperWithError, DirectoryContent} from '../content.service';
|
||||
import {PhotoDTO} from '../../../../../common/entities/PhotoDTO';
|
||||
import {map, switchMap} from 'rxjs/operators';
|
||||
import {SeededRandomService} from '../../../model/seededRandom.service';
|
||||
import {ContentWrapper} from '../../../../../common/entities/ConentWrapper';
|
||||
|
||||
@Injectable()
|
||||
export class GallerySortingService {
|
||||
public sorting: BehaviorSubject<SortingMethods>;
|
||||
private collator = new Intl.Collator(undefined, { numeric: true });
|
||||
private collator = new Intl.Collator(undefined, {numeric: true});
|
||||
|
||||
constructor(
|
||||
private networkService: NetworkService,
|
||||
@ -30,21 +31,24 @@ export class GallerySortingService {
|
||||
const sort = this.galleryCacheService.getSorting(c.directory);
|
||||
if (sort !== null) {
|
||||
this.sorting.next(sort);
|
||||
} else {
|
||||
this.sorting.next(this.getDefaultSorting(c.directory));
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.sorting.next(this.getDefaultSorting(c));
|
||||
});
|
||||
}
|
||||
|
||||
getDefaultSorting(directory: ParentDirectoryDTO): SortingMethods {
|
||||
if (directory && directory.metaFile) {
|
||||
getDefaultSorting(cw: ContentWrapper): SortingMethods {
|
||||
if (cw.directory && cw.directory.metaFile) {
|
||||
for (const file in PG2ConfMap.sorting) {
|
||||
if (directory.metaFile.some((f) => f.name === file)) {
|
||||
if (cw.directory.metaFile.some((f) => f.name === file)) {
|
||||
return (PG2ConfMap.sorting as any)[file];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cw.searchResult) {
|
||||
return Config.Client.Other.defaultSearchSortingMethod;
|
||||
}
|
||||
return Config.Client.Other.defaultPhotoSortingMethod;
|
||||
}
|
||||
|
||||
@ -53,7 +57,7 @@ export class GallerySortingService {
|
||||
if (this.galleryService.content.value.directory) {
|
||||
if (
|
||||
sorting !==
|
||||
this.getDefaultSorting(this.galleryService.content.value.directory)
|
||||
this.getDefaultSorting(this.galleryService.content.value)
|
||||
) {
|
||||
this.galleryCacheService.setSorting(
|
||||
this.galleryService.content.value.directory,
|
||||
|
@ -99,6 +99,17 @@
|
||||
[required]="true">
|
||||
</app-settings-entry>
|
||||
|
||||
<app-settings-entry
|
||||
name="Default photo sorting method for search results"
|
||||
i18n-name
|
||||
[ngModel]="states.Client.defaultSearchSortingMethod"
|
||||
link="https://github.com/bpatrik/pigallery2/issues/566"
|
||||
linkText="See 566."
|
||||
[optionMap]="sortingMap"
|
||||
[simplifiedMode]="simplifiedMode"
|
||||
[required]="true">
|
||||
</app-settings-entry>
|
||||
|
||||
<app-settings-entry
|
||||
name="Sort directories by date"
|
||||
description="If enabled, directories will be sorted by date, like photos, otherwise by name. Directory date is the last modification time of that directory not the creation date of the oldest photo."
|
||||
|
Loading…
Reference in New Issue
Block a user