mirror of
https://github.com/xuthus83/pigallery2.git
synced 2025-01-14 14:43:17 +08:00
Refactor the config a bit to make it easier to understand: #587
This commit is contained in:
parent
26d94e0482
commit
02daa25bc1
@ -84,7 +84,7 @@ export class GalleryMWs {
|
|||||||
res: Response,
|
res: Response,
|
||||||
next: NextFunction
|
next: NextFunction
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (Config.Gallery.enableDownloadZip === false) {
|
if (Config.Gallery.NavBar.enableDownloadZip === false) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
const directoryName = req.params['directory'] || '/';
|
const directoryName = req.params['directory'] || '/';
|
||||||
|
File diff suppressed because one or more lines are too long
@ -26,7 +26,7 @@
|
|||||||
<div class="divider"> </div>
|
<div class="divider"> </div>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<ng-container *ngIf="config.Gallery.enableDownloadZip && isDirectory && ItemCount > 0">
|
<ng-container *ngIf="config.Gallery.NavBar.enableDownloadZip && isDirectory && ItemCount > 0">
|
||||||
<a [href]="getDownloadZipLink()"
|
<a [href]="getDownloadZipLink()"
|
||||||
class="btn btn-outline-secondary btn-navigator">
|
class="btn btn-outline-secondary btn-navigator">
|
||||||
<ng-icon name="ionDownloadOutline" title="Download" i18n-title></ng-icon>
|
<ng-icon name="ionDownloadOutline" title="Download" i18n-title></ng-icon>
|
||||||
@ -34,7 +34,7 @@
|
|||||||
<div class="divider"> </div>
|
<div class="divider"> </div>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<ng-container *ngIf="config.Gallery.enableDirectoryFlattening && isDirectory && authService.canSearch()">
|
<ng-container *ngIf="config.Gallery.NavBar.enableDirectoryFlattening && isDirectory && authService.canSearch()">
|
||||||
<a
|
<a
|
||||||
[routerLink]="['/search', getDirectoryFlattenSearchQuery()]"
|
[routerLink]="['/search', getDirectoryFlattenSearchQuery()]"
|
||||||
class="btn btn-outline-secondary btn-navigator">
|
class="btn btn-outline-secondary btn-navigator">
|
||||||
|
@ -55,7 +55,7 @@ export class GalleryNavigatorService {
|
|||||||
|
|
||||||
|
|
||||||
getDefaultGridSize(): GridSizes {
|
getDefaultGridSize(): GridSizes {
|
||||||
return Config.Gallery.defaultGidSize;
|
return Config.Gallery.NavBar.defaultGidSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,16 +22,22 @@ export class GallerySortingService {
|
|||||||
private collator = new Intl.Collator(undefined, {numeric: true});
|
private collator = new Intl.Collator(undefined, {numeric: true});
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private galleryCacheService: GalleryCacheService,
|
private galleryCacheService: GalleryCacheService,
|
||||||
private galleryService: ContentLoaderService,
|
private galleryService: ContentLoaderService,
|
||||||
private rndService: SeededRandomService,
|
private rndService: SeededRandomService,
|
||||||
private datePipe: DatePipe
|
private datePipe: DatePipe
|
||||||
) {
|
) {
|
||||||
this.sorting = new BehaviorSubject(
|
this.sorting = new BehaviorSubject(
|
||||||
{method: Config.Gallery.defaultPhotoSortingMethod.method, ascending: Config.Gallery.defaultPhotoSortingMethod.ascending}
|
{
|
||||||
|
method: Config.Gallery.NavBar.SortingGrouping.defaultPhotoSortingMethod.method,
|
||||||
|
ascending: Config.Gallery.NavBar.SortingGrouping.defaultPhotoSortingMethod.ascending
|
||||||
|
}
|
||||||
);
|
);
|
||||||
this.grouping = new BehaviorSubject(
|
this.grouping = new BehaviorSubject(
|
||||||
{method: Config.Gallery.defaultPhotoGroupingMethod.method, ascending: Config.Gallery.defaultPhotoGroupingMethod.ascending}
|
{
|
||||||
|
method: Config.Gallery.NavBar.SortingGrouping.defaultPhotoGroupingMethod.method,
|
||||||
|
ascending: Config.Gallery.NavBar.SortingGrouping.defaultPhotoGroupingMethod.ascending
|
||||||
|
}
|
||||||
);
|
);
|
||||||
this.galleryService.content.subscribe((c) => {
|
this.galleryService.content.subscribe((c) => {
|
||||||
if (c) {
|
if (c) {
|
||||||
@ -57,7 +63,7 @@ export class GallerySortingService {
|
|||||||
const s = this.sorting.value;
|
const s = this.sorting.value;
|
||||||
const g = this.grouping.value;
|
const g = this.grouping.value;
|
||||||
return s.method === defS.method && s.ascending === defS.ascending &&
|
return s.method === defS.method && s.ascending === defS.ascending &&
|
||||||
g.method === defG.method && g.ascending === defG.ascending;
|
g.method === defG.method && g.ascending === defG.ascending;
|
||||||
}
|
}
|
||||||
|
|
||||||
getDefaultSorting(cw: ContentWrapper): SortingMethod {
|
getDefaultSorting(cw: ContentWrapper): SortingMethod {
|
||||||
@ -69,33 +75,33 @@ export class GallerySortingService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cw.searchResult) {
|
if (cw.searchResult) {
|
||||||
return Config.Gallery.defaultSearchSortingMethod;
|
return Config.Gallery.NavBar.SortingGrouping.defaultSearchSortingMethod;
|
||||||
}
|
}
|
||||||
return Config.Gallery.defaultPhotoSortingMethod;
|
return Config.Gallery.NavBar.SortingGrouping.defaultPhotoSortingMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
getDefaultGrouping(cw: ContentWrapper): GroupingMethod {
|
getDefaultGrouping(cw: ContentWrapper): GroupingMethod {
|
||||||
if (cw.searchResult) {
|
if (cw.searchResult) {
|
||||||
return Config.Gallery.defaultSearchGroupingMethod;
|
return Config.Gallery.NavBar.SortingGrouping.defaultSearchGroupingMethod;
|
||||||
}
|
}
|
||||||
return Config.Gallery.defaultPhotoGroupingMethod;
|
return Config.Gallery.NavBar.SortingGrouping.defaultPhotoGroupingMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
setSorting(sorting: SortingMethod): void {
|
setSorting(sorting: SortingMethod): void {
|
||||||
this.sorting.next(sorting);
|
this.sorting.next(sorting);
|
||||||
if (this.galleryService.content.value) {
|
if (this.galleryService.content.value) {
|
||||||
if (
|
if (
|
||||||
sorting !==
|
sorting !==
|
||||||
this.getDefaultSorting(this.galleryService.content.value)
|
this.getDefaultSorting(this.galleryService.content.value)
|
||||||
) {
|
) {
|
||||||
this.galleryCacheService.setSorting(
|
this.galleryCacheService.setSorting(
|
||||||
this.galleryService.content.value,
|
this.galleryService.content.value,
|
||||||
sorting
|
sorting
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
this.galleryCacheService.removeSorting(
|
this.galleryCacheService.removeSorting(
|
||||||
this.galleryService.content.value
|
this.galleryService.content.value
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -105,16 +111,16 @@ export class GallerySortingService {
|
|||||||
this.grouping.next(grouping);
|
this.grouping.next(grouping);
|
||||||
if (this.galleryService.content.value) {
|
if (this.galleryService.content.value) {
|
||||||
if (
|
if (
|
||||||
grouping !==
|
grouping !==
|
||||||
this.getDefaultGrouping(this.galleryService.content.value)
|
this.getDefaultGrouping(this.galleryService.content.value)
|
||||||
) {
|
) {
|
||||||
this.galleryCacheService.setGrouping(
|
this.galleryCacheService.setGrouping(
|
||||||
this.galleryService.content.value,
|
this.galleryService.content.value,
|
||||||
grouping
|
grouping
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
this.galleryCacheService.removeGrouping(
|
this.galleryCacheService.removeGrouping(
|
||||||
this.galleryService.content.value
|
this.galleryService.content.value
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -127,7 +133,7 @@ export class GallerySortingService {
|
|||||||
switch (sorting.method) {
|
switch (sorting.method) {
|
||||||
case SortByTypes.Name:
|
case SortByTypes.Name:
|
||||||
media.sort((a: PhotoDTO, b: PhotoDTO) =>
|
media.sort((a: PhotoDTO, b: PhotoDTO) =>
|
||||||
this.collator.compare(a.name, b.name)
|
this.collator.compare(a.name, b.name)
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case SortByTypes.Date:
|
case SortByTypes.Date:
|
||||||
@ -137,20 +143,20 @@ export class GallerySortingService {
|
|||||||
break;
|
break;
|
||||||
case SortByTypes.Rating:
|
case SortByTypes.Rating:
|
||||||
media.sort(
|
media.sort(
|
||||||
(a: PhotoDTO, b: PhotoDTO) =>
|
(a: PhotoDTO, b: PhotoDTO) =>
|
||||||
(a.metadata.rating || 0) - (b.metadata.rating || 0)
|
(a.metadata.rating || 0) - (b.metadata.rating || 0)
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case SortByTypes.PersonCount:
|
case SortByTypes.PersonCount:
|
||||||
media.sort(
|
media.sort(
|
||||||
(a: PhotoDTO, b: PhotoDTO) =>
|
(a: PhotoDTO, b: PhotoDTO) =>
|
||||||
(a.metadata?.faces?.length || 0) - (b.metadata?.faces?.length || 0)
|
(a.metadata?.faces?.length || 0) - (b.metadata?.faces?.length || 0)
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case SortByTypes.FileSize:
|
case SortByTypes.FileSize:
|
||||||
media.sort(
|
media.sort(
|
||||||
(a: PhotoDTO, b: PhotoDTO) =>
|
(a: PhotoDTO, b: PhotoDTO) =>
|
||||||
(a.metadata?.fileSize || 0) - (b.metadata?.fileSize || 0)
|
(a.metadata?.fileSize || 0) - (b.metadata?.fileSize || 0)
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case SortByTypes.Random:
|
case SortByTypes.Random:
|
||||||
@ -164,9 +170,9 @@ export class GallerySortingService {
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
})
|
})
|
||||||
.sort((): number => {
|
.sort((): number => {
|
||||||
return this.rndService.get() - 0.5;
|
return this.rndService.get() - 0.5;
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!sorting.ascending) {
|
if (!sorting.ascending) {
|
||||||
@ -208,103 +214,103 @@ export class GallerySortingService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public applySorting(
|
public applySorting(
|
||||||
directoryContent: Observable<DirectoryContent>
|
directoryContent: Observable<DirectoryContent>
|
||||||
): Observable<GroupedDirectoryContent> {
|
): Observable<GroupedDirectoryContent> {
|
||||||
return directoryContent.pipe(
|
return directoryContent.pipe(
|
||||||
switchMap((dirContent) => {
|
switchMap((dirContent) => {
|
||||||
return this.grouping.pipe(
|
return this.grouping.pipe(
|
||||||
switchMap((grouping) => {
|
switchMap((grouping) => {
|
||||||
return this.sorting.pipe(
|
return this.sorting.pipe(
|
||||||
map((sorting) => {
|
map((sorting) => {
|
||||||
if (!dirContent) {
|
if (!dirContent) {
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
const c: GroupedDirectoryContent = {
|
|
||||||
mediaGroups: [],
|
|
||||||
directories: dirContent.directories,
|
|
||||||
metaFile: dirContent.metaFile,
|
|
||||||
};
|
|
||||||
if (c.directories) {
|
|
||||||
switch (sorting.method) {
|
|
||||||
case SortByTypes.FileSize:
|
|
||||||
case SortByTypes.PersonCount:
|
|
||||||
case SortByTypes.Rating: // directories do not have rating
|
|
||||||
case SortByTypes.Name:
|
|
||||||
c.directories.sort((a, b) =>
|
|
||||||
this.collator.compare(a.name, b.name)
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
case SortByTypes.Date:
|
|
||||||
if (
|
|
||||||
Config.Gallery.enableDirectorySortingByDate === true
|
|
||||||
) {
|
|
||||||
c.directories.sort(
|
|
||||||
(a, b) => (a.oldestMedia || a.lastModified) - (b.oldestMedia || b.lastModified)
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
c.directories.sort((a, b) =>
|
const c: GroupedDirectoryContent = {
|
||||||
this.collator.compare(a.name, b.name)
|
mediaGroups: [],
|
||||||
);
|
directories: dirContent.directories,
|
||||||
break;
|
metaFile: dirContent.metaFile,
|
||||||
case SortByTypes.Random:
|
};
|
||||||
this.rndService.setSeed(c.directories.length);
|
if (c.directories) {
|
||||||
c.directories
|
switch (sorting.method) {
|
||||||
.sort((a, b): number => {
|
case SortByTypes.FileSize:
|
||||||
if (a.name.toLowerCase() < b.name.toLowerCase()) {
|
case SortByTypes.PersonCount:
|
||||||
return 1;
|
case SortByTypes.Rating: // directories do not have rating
|
||||||
|
case SortByTypes.Name:
|
||||||
|
c.directories.sort((a, b) =>
|
||||||
|
this.collator.compare(a.name, b.name)
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case SortByTypes.Date:
|
||||||
|
if (
|
||||||
|
Config.Gallery.enableDirectorySortingByDate === true
|
||||||
|
) {
|
||||||
|
c.directories.sort(
|
||||||
|
(a, b) => (a.oldestMedia || a.lastModified) - (b.oldestMedia || b.lastModified)
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
c.directories.sort((a, b) =>
|
||||||
|
this.collator.compare(a.name, b.name)
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case SortByTypes.Random:
|
||||||
|
this.rndService.setSeed(c.directories.length);
|
||||||
|
c.directories
|
||||||
|
.sort((a, b): number => {
|
||||||
|
if (a.name.toLowerCase() < b.name.toLowerCase()) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (a.name.toLowerCase() > b.name.toLowerCase()) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
})
|
||||||
|
.sort((): number => {
|
||||||
|
return this.rndService.get() - 0.5;
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sorting.ascending) {
|
||||||
|
c.directories.reverse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// group
|
||||||
|
if (dirContent.media) {
|
||||||
|
const mCopy = dirContent.media;
|
||||||
|
this.sortMedia(grouping, mCopy);
|
||||||
|
const groupFN = this.getGroupByNameFn(grouping);
|
||||||
|
|
||||||
|
c.mediaGroups = [];
|
||||||
|
|
||||||
|
for (const m of mCopy) {
|
||||||
|
const k = groupFN(m);
|
||||||
|
if (c.mediaGroups.length == 0 || c.mediaGroups[c.mediaGroups.length - 1].name != k) {
|
||||||
|
c.mediaGroups.push({name: k, media: []});
|
||||||
}
|
}
|
||||||
if (a.name.toLowerCase() > b.name.toLowerCase()) {
|
c.mediaGroups[c.mediaGroups.length - 1].media.push(m);
|
||||||
return -1;
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
})
|
if (grouping.method === GroupByTypes.Date) {
|
||||||
.sort((): number => {
|
// We do not need the youngest as we group by day. All photos are from the same day
|
||||||
return this.rndService.get() - 0.5;
|
c.mediaGroups.forEach(g => {
|
||||||
|
g.date = Utils.makeUTCMidnight(new Date(g.media?.[0]?.metadata?.creationDate));
|
||||||
});
|
});
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!sorting.ascending) {
|
// sort groups
|
||||||
c.directories.reverse();
|
for (let i = 0; i < c.mediaGroups.length; ++i) {
|
||||||
}
|
this.sortMedia(sorting, c.mediaGroups[i].media);
|
||||||
}
|
}
|
||||||
|
|
||||||
// group
|
return c;
|
||||||
if (dirContent.media) {
|
})
|
||||||
const mCopy = dirContent.media;
|
);
|
||||||
this.sortMedia(grouping, mCopy);
|
|
||||||
const groupFN = this.getGroupByNameFn(grouping);
|
|
||||||
|
|
||||||
c.mediaGroups = [];
|
|
||||||
|
|
||||||
for (const m of mCopy) {
|
|
||||||
const k = groupFN(m);
|
|
||||||
if (c.mediaGroups.length == 0 || c.mediaGroups[c.mediaGroups.length - 1].name != k) {
|
|
||||||
c.mediaGroups.push({name: k, media: []});
|
|
||||||
}
|
|
||||||
c.mediaGroups[c.mediaGroups.length - 1].media.push(m);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (grouping.method === GroupByTypes.Date) {
|
|
||||||
// We do not need the youngest as we group by day. All photos are from the same day
|
|
||||||
c.mediaGroups.forEach(g => {
|
|
||||||
g.date = Utils.makeUTCMidnight(new Date(g.media?.[0]?.metadata?.creationDate));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// sort groups
|
|
||||||
for (let i = 0; i < c.mediaGroups.length; ++i) {
|
|
||||||
this.sortMedia(sorting, c.mediaGroups[i].media);
|
|
||||||
}
|
|
||||||
|
|
||||||
return c;
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
);
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user