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

Using natural-orderby for sorting

This commit is contained in:
erri120 2021-02-02 22:29:43 +01:00
parent db1fea37fa
commit c0a0ac15b3
No known key found for this signature in database
GPG Key ID: 7FA9556C936B847C
3 changed files with 11 additions and 20 deletions

5
package-lock.json generated
View File

@ -13493,6 +13493,11 @@
"resolved": "https://registry.npmjs.org/napi-build-utils/-/napi-build-utils-1.0.2.tgz", "resolved": "https://registry.npmjs.org/napi-build-utils/-/napi-build-utils-1.0.2.tgz",
"integrity": "sha512-ONmRUqK7zj7DWX0D9ADe03wbwOBZxNAfF20PlGfCWQcD3+/MakShIHrMqx9YwPTfxDdF1zLeL+RGZiR9kGMLdg==" "integrity": "sha512-ONmRUqK7zj7DWX0D9ADe03wbwOBZxNAfF20PlGfCWQcD3+/MakShIHrMqx9YwPTfxDdF1zLeL+RGZiR9kGMLdg=="
}, },
"natural-orderby": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/natural-orderby/-/natural-orderby-2.0.3.tgz",
"integrity": "sha512-p7KTHxU0CUrcOXe62Zfrb5Z13nLvPhSWR/so3kFulUQU0sgUll2Z0LwpsLN351eOOD+hRGu/F1g+6xDfPeD++Q=="
},
"needle": { "needle": {
"version": "2.5.2", "version": "2.5.2",
"resolved": "https://registry.npmjs.org/needle/-/needle-2.5.2.tgz", "resolved": "https://registry.npmjs.org/needle/-/needle-2.5.2.tgz",

View File

@ -30,13 +30,12 @@
"url": "https://github.com/bpatrik/PiGallery2/issues" "url": "https://github.com/bpatrik/PiGallery2/issues"
}, },
"dependencies": { "dependencies": {
"bcrypt": "5.0.0",
"body-parser": "1.19.0", "body-parser": "1.19.0",
"cookie-parser": "1.4.5", "cookie-parser": "1.4.5",
"cookie-session": "2.0.0-rc.1", "cookie-session": "2.0.0-rc.1",
"csurf": "1.11.0", "csurf": "1.11.0",
"ejs": "3.1.5", "ejs": "3.1.5",
"bcrypt": "5.0.0",
"sharp": "0.23.4",
"exifreader": "3.13.0", "exifreader": "3.13.0",
"express": "4.17.1", "express": "4.17.1",
"express-unless": "0.5.0", "express-unless": "0.5.0",
@ -44,7 +43,9 @@
"image-size": "0.9.3", "image-size": "0.9.3",
"jimp": "0.16.1", "jimp": "0.16.1",
"locale": "0.1.0", "locale": "0.1.0",
"natural-orderby": "^2.0.3",
"reflect-metadata": "0.1.13", "reflect-metadata": "0.1.13",
"sharp": "0.23.4",
"sqlite3": "5.0.0", "sqlite3": "5.0.0",
"ts-exif-parser": "0.2.1", "ts-exif-parser": "0.2.1",
"ts-node-iptc": "1.0.11", "ts-node-iptc": "1.0.11",

View File

@ -19,6 +19,7 @@ import {QueryParams} from '../../../../common/QueryParams';
import {SeededRandomService} from '../../model/seededRandom.service'; import {SeededRandomService} from '../../model/seededRandom.service';
import {take} from 'rxjs/operators'; import {take} from 'rxjs/operators';
import {FileDTO} from '../../../../common/entities/FileDTO'; import {FileDTO} from '../../../../common/entities/FileDTO';
import { compare } from 'natural-orderby';
@Component({ @Component({
selector: 'app-gallery', selector: 'app-gallery',
@ -172,27 +173,11 @@ export class GalleryComponent implements OnInit, OnDestroy {
switch (this._galleryService.sorting.value) { switch (this._galleryService.sorting.value) {
case SortingMethods.ascName: case SortingMethods.ascName:
case SortingMethods.ascDate: case SortingMethods.ascDate:
this.directories.sort((a: DirectoryDTO, b: DirectoryDTO) => { this.directories.sort((a: DirectoryDTO, b: DirectoryDTO) => compare()(a.name, b.name));
if (a.name.toLowerCase() < b.name.toLowerCase()) {
return -1;
}
if (a.name.toLowerCase() > b.name.toLowerCase()) {
return 1;
}
return 0;
});
break; break;
case SortingMethods.descName: case SortingMethods.descName:
case SortingMethods.descDate: case SortingMethods.descDate:
this.directories.sort((a: DirectoryDTO, b: DirectoryDTO) => { this.directories.sort((a: DirectoryDTO, b: DirectoryDTO) => compare({ order: 'desc' })(a.name, b.name));
if (a.name.toLowerCase() < b.name.toLowerCase()) {
return 1;
}
if (a.name.toLowerCase() > b.name.toLowerCase()) {
return -1;
}
return 0;
});
break; break;
case SortingMethods.random: case SortingMethods.random:
this.rndService.setSeed(this.directories.length); this.rndService.setSeed(this.directories.length);