mirror of
https://github.com/xuthus83/pigallery2.git
synced 2025-01-14 14:43:17 +08:00
Adding sort by file size. Fixes #222
This commit is contained in:
parent
442a9ab690
commit
70f4b02659
@ -375,6 +375,9 @@ export class SearchManager {
|
||||
case SortByTypes.PersonCount:
|
||||
query.addOrderBy('media.metadata.personsLength', sort.ascending ? 'ASC' : 'DESC');
|
||||
break;
|
||||
case SortByTypes.FileSize:
|
||||
query.addOrderBy('media.metadata.fileSize', sort.ascending ? 'ASC' : 'DESC');
|
||||
break;
|
||||
case SortByTypes.Random:
|
||||
if (Config.Database.type === DatabaseType.mysql) {
|
||||
query.groupBy('RAND(), media.id');
|
||||
|
@ -7,6 +7,7 @@ export enum SortByDirectionalTypes {
|
||||
Date = 20,
|
||||
Rating = 30,
|
||||
PersonCount = 40,
|
||||
FileSize = 50,
|
||||
}
|
||||
|
||||
// These cant be set asc or desc
|
||||
|
@ -49,6 +49,7 @@ EnumTranslations[SortByTypes[SortByTypes.Name]] = $localize`name`;
|
||||
EnumTranslations[SortByTypes[SortByTypes.Rating]] = $localize`rating`;
|
||||
EnumTranslations[SortByTypes[SortByTypes.Random]] = $localize`random`;
|
||||
EnumTranslations[SortByTypes[SortByTypes.PersonCount]] = $localize`persons`;
|
||||
EnumTranslations[SortByTypes[SortByTypes.FileSize]] = $localize`file size`;
|
||||
|
||||
EnumTranslations[GroupByTypes[GroupByTypes.NoGrouping]] = $localize`don't group`;
|
||||
|
||||
|
@ -148,6 +148,12 @@ export class GallerySortingService {
|
||||
(a.metadata?.faces?.length || 0) - (b.metadata?.faces?.length || 0)
|
||||
);
|
||||
break;
|
||||
case SortByTypes.FileSize:
|
||||
media.sort(
|
||||
(a: PhotoDTO, b: PhotoDTO) =>
|
||||
(a.metadata?.fileSize || 0) - (b.metadata?.fileSize || 0)
|
||||
);
|
||||
break;
|
||||
case SortByTypes.Random:
|
||||
this.rndService.setSeed(media.length);
|
||||
media.sort((a: PhotoDTO, b: PhotoDTO): number => {
|
||||
@ -189,6 +195,8 @@ export class GallerySortingService {
|
||||
};
|
||||
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) =>
|
||||
@ -246,6 +254,20 @@ export class GallerySortingService {
|
||||
case SortByTypes.Rating:
|
||||
groupFN = (m: MediaDTO) => ((m as PhotoDTO).metadata.rating || 0).toString();
|
||||
break;
|
||||
case SortByTypes.FileSize: {
|
||||
const groups = [0.5, 1, 2, 5, 10, 15, 20, 30, 50]; // MBs
|
||||
groupFN = (m: MediaDTO) => {
|
||||
const mbites = ((m as PhotoDTO).metadata.fileSize || 0) / 1024 / 1024;
|
||||
const i = groups.findIndex((s) => s > mbites);
|
||||
if (i == -1) {
|
||||
return '>' + groups[groups.length - 1] + ' MB';
|
||||
} else if (i == 0) {
|
||||
return '<' + groups[0] + ' MB';
|
||||
}
|
||||
return groups[i - 1] + ' - ' + groups[i] + ' MB';
|
||||
};
|
||||
}
|
||||
break;
|
||||
case SortByTypes.PersonCount:
|
||||
groupFN = (m: MediaDTO) => ((m as PhotoDTO).metadata.faces || []).length.toString();
|
||||
break;
|
||||
|
@ -14,6 +14,9 @@
|
||||
<ng-container *ngSwitchCase="GroupSortByTypes.Random">
|
||||
<ng-icon name="ionShuffleOutline"></ng-icon>
|
||||
</ng-container>
|
||||
<ng-container *ngSwitchCase="GroupSortByTypes.FileSize">
|
||||
<ng-icon name="ionDocumentOutline"></ng-icon>
|
||||
</ng-container>
|
||||
<ng-container *ngSwitchCase="GroupSortByTypes.NoGrouping">
|
||||
<ng-icon name="ionCloseOutline"></ng-icon>
|
||||
</ng-container>
|
||||
|
Loading…
x
Reference in New Issue
Block a user