Skip to content

Commit d2d1472

Browse files
authored
Merge pull request #342 from antegs/fix-gallery-sorting
Fix gallery sorting #341
2 parents bae5559 + d8f0a7f commit d2d1472

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@
125125
"leaflet": "1.7.1",
126126
"leaflet.markercluster": "1.5.0",
127127
"mocha": "8.4.0",
128-
"natural-orderby": "2.0.3",
129128
"ngx-bootstrap": "6.2.0",
130129
"ngx-clipboard": "14.0.1",
131130
"ngx-cookie-service": "11.0.2",

src/frontend/app/ui/gallery/gallery.component.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {PhotoDTO} from '../../../../common/entities/PhotoDTO';
1717
import {QueryParams} from '../../../../common/QueryParams';
1818
import {SeededRandomService} from '../../model/seededRandom.service';
1919
import {take} from 'rxjs/operators';
20-
import {compare} from 'natural-orderby';
2120

2221
@Component({
2322
selector: 'app-gallery',
@@ -160,33 +159,34 @@ export class GalleryComponent implements OnInit, OnDestroy {
160159
}
161160
};
162161

162+
private collator = new Intl.Collator(undefined, {numeric: true});
163+
163164
private sortDirectories(): void {
164165
if (!this.directories) {
165166
return;
166167
}
167168
switch (this.galleryService.sorting.value) {
168169
case SortingMethods.ascRating: // directories does not have rating
169170
case SortingMethods.ascName:
170-
this.directories.sort((a, b) => compare()(a.name, b.name));
171+
this.directories.sort((a, b) => this.collator.compare(a.name, b.name));
171172
break;
172173
case SortingMethods.ascDate:
173174
if (Config.Client.Other.enableDirectorySortingByDate === true) {
174-
this.directories.sort((a, b) => compare()(a.lastModified, b.lastModified));
175+
this.directories.sort((a, b) => a.lastModified - b.lastModified);
175176
break;
176177
}
177-
this.directories.sort((a, b) => compare()(a.name, b.name));
178+
this.directories.sort((a, b) => this.collator.compare(a.name, b.name));
178179
break;
179-
180180
case SortingMethods.descRating: // directories does not have rating
181181
case SortingMethods.descName:
182-
this.directories.sort((a, b) => compare({order: 'desc'})(a.name, b.name));
182+
this.directories.sort((a, b) => this.collator.compare(b.name, a.name));
183183
break;
184184
case SortingMethods.descDate:
185185
if (Config.Client.Other.enableDirectorySortingByDate === true) {
186-
this.directories.sort((a, b) => compare({order: 'desc'})(a.lastModified, b.lastModified));
186+
this.directories.sort((a, b) => b.lastModified - a.lastModified);
187187
break;
188188
}
189-
this.directories.sort((a, b) => compare({order: 'desc'})(a.name, b.name));
189+
this.directories.sort((a, b) => this.collator.compare(b.name, a.name));
190190
break;
191191
case SortingMethods.random:
192192
this.rndService.setSeed(this.directories.length);
@@ -207,4 +207,3 @@ export class GalleryComponent implements OnInit, OnDestroy {
207207

208208
}
209209
}
210-

src/frontend/app/ui/gallery/grid/grid.gallery.component.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import {SortingMethods} from '../../../../../common/entities/SortingMethods';
2828
import {MediaDTO, MediaDTOUtils} from '../../../../../common/entities/MediaDTO';
2929
import {QueryParams} from '../../../../../common/QueryParams';
3030
import {SeededRandomService} from '../../../model/seededRandom.service';
31-
import {compare} from 'natural-orderby';
3231

3332
@Component({
3433
selector: 'app-gallery-grid',
@@ -239,13 +238,15 @@ export class GalleryGridComponent implements OnChanges, OnInit, AfterViewInit, O
239238
this.changeDetector.detectChanges();
240239
}
241240

241+
private collator = new Intl.Collator(undefined, {numeric: true});
242+
242243
private sortPhotos(): void {
243244
switch (this.galleryService.sorting.value) {
244245
case SortingMethods.ascName:
245-
this.media.sort((a: PhotoDTO, b: PhotoDTO) => compare()(a.name, b.name));
246+
this.media.sort((a: PhotoDTO, b: PhotoDTO) => this.collator.compare(a.name, b.name));
246247
break;
247248
case SortingMethods.descName:
248-
this.media.sort((a: PhotoDTO, b: PhotoDTO) => compare({order: 'desc'})(a.name, b.name));
249+
this.media.sort((a: PhotoDTO, b: PhotoDTO) => this.collator.compare(b.name, a.name));
249250
break;
250251
case SortingMethods.ascDate:
251252
this.media.sort((a: PhotoDTO, b: PhotoDTO): number => {
@@ -378,6 +379,3 @@ export class GalleryGridComponent implements OnChanges, OnInit, AfterViewInit, O
378379

379380

380381
}
381-
382-
383-

0 commit comments

Comments
 (0)