1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2024-11-30 09:07:06 +02:00

adding sorting for directories

This commit is contained in:
Patrik J. Braun 2018-11-02 16:38:29 +01:00
parent 90c04b7f6b
commit a9f5e612e2

View File

@ -14,6 +14,8 @@ import {UserRoles} from '../../../common/entities/UserDTO';
import {interval} from 'rxjs';
import {ContentWrapper} from '../../../common/entities/ConentWrapper';
import {PageHelper} from '../model/page.helper';
import {SortingMethods} from '../../../common/entities/SortingMethods';
import {PhotoDTO} from '../../../common/entities/PhotoDTO';
@Component({
selector: 'app-gallery',
@ -35,7 +37,8 @@ export class GalleryComponent implements OnInit, OnDestroy {
private subscription = {
content: null,
route: null,
timer: null
timer: null,
sorting: null
};
public countDown = null;
public mapEnabled = true;
@ -107,10 +110,13 @@ export class GalleryComponent implements OnInit, OnDestroy {
if (this.subscription.timer !== null) {
this.subscription.timer.unsubscribe();
}
if (this.subscription.sorting !== null) {
this.subscription.sorting.unsubscribe();
}
}
private onContentChange = (content: ContentWrapper) => {
const dirSorter = (a: DirectoryDTO, b: DirectoryDTO) => {
const ascdirSorter = (a: DirectoryDTO, b: DirectoryDTO) => {
return a.name.localeCompare(b.name);
};
@ -118,7 +124,8 @@ export class GalleryComponent implements OnInit, OnDestroy {
directories: [],
photos: []
});
this.directories = tmp.directories.sort(dirSorter);
this.directories = tmp.directories;
this.sortDirectories();
this.isPhotoWithLocation = false;
for (let i = 0; i < tmp.photos.length; i++) {
if (tmp.photos[i].metadata &&
@ -132,6 +139,36 @@ export class GalleryComponent implements OnInit, OnDestroy {
}
};
private sortDirectories() {
switch (this._galleryService.sorting.value) {
case SortingMethods.ascName:
case SortingMethods.ascDate:
this.directories.sort((a: DirectoryDTO, b: DirectoryDTO) => {
if (a.name.toLowerCase() < b.name.toLowerCase()) {
return -1;
}
if (a.name.toLowerCase() > b.name.toLowerCase()) {
return 1;
}
return 0;
});
break;
case SortingMethods.descName:
case SortingMethods.descDate:
this.directories.sort((a: DirectoryDTO, b: DirectoryDTO) => {
if (a.name.toLowerCase() < b.name.toLowerCase()) {
return 1;
}
if (a.name.toLowerCase() > b.name.toLowerCase()) {
return -1;
}
return 0;
});
break;
}
}
async ngOnInit() {
await this.shareService.wait();
if (!this._authService.isAuthenticated() &&
@ -151,6 +188,10 @@ export class GalleryComponent implements OnInit, OnDestroy {
this.subscription.timer = this.$counter.subscribe((x) => this.updateTimer(x));
}
this.subscription.sorting = this._galleryService.sorting.subscribe(() => {
this.sortDirectories();
});
}
}