mirror of
https://github.com/xuthus83/pigallery2.git
synced 2024-11-03 21:04:03 +08:00
adding sorting for directories
This commit is contained in:
parent
90c04b7f6b
commit
a9f5e612e2
@ -14,6 +14,8 @@ import {UserRoles} from '../../../common/entities/UserDTO';
|
|||||||
import {interval} from 'rxjs';
|
import {interval} from 'rxjs';
|
||||||
import {ContentWrapper} from '../../../common/entities/ConentWrapper';
|
import {ContentWrapper} from '../../../common/entities/ConentWrapper';
|
||||||
import {PageHelper} from '../model/page.helper';
|
import {PageHelper} from '../model/page.helper';
|
||||||
|
import {SortingMethods} from '../../../common/entities/SortingMethods';
|
||||||
|
import {PhotoDTO} from '../../../common/entities/PhotoDTO';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-gallery',
|
selector: 'app-gallery',
|
||||||
@ -35,7 +37,8 @@ export class GalleryComponent implements OnInit, OnDestroy {
|
|||||||
private subscription = {
|
private subscription = {
|
||||||
content: null,
|
content: null,
|
||||||
route: null,
|
route: null,
|
||||||
timer: null
|
timer: null,
|
||||||
|
sorting: null
|
||||||
};
|
};
|
||||||
public countDown = null;
|
public countDown = null;
|
||||||
public mapEnabled = true;
|
public mapEnabled = true;
|
||||||
@ -107,10 +110,13 @@ export class GalleryComponent implements OnInit, OnDestroy {
|
|||||||
if (this.subscription.timer !== null) {
|
if (this.subscription.timer !== null) {
|
||||||
this.subscription.timer.unsubscribe();
|
this.subscription.timer.unsubscribe();
|
||||||
}
|
}
|
||||||
|
if (this.subscription.sorting !== null) {
|
||||||
|
this.subscription.sorting.unsubscribe();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private onContentChange = (content: ContentWrapper) => {
|
private onContentChange = (content: ContentWrapper) => {
|
||||||
const dirSorter = (a: DirectoryDTO, b: DirectoryDTO) => {
|
const ascdirSorter = (a: DirectoryDTO, b: DirectoryDTO) => {
|
||||||
return a.name.localeCompare(b.name);
|
return a.name.localeCompare(b.name);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -118,7 +124,8 @@ export class GalleryComponent implements OnInit, OnDestroy {
|
|||||||
directories: [],
|
directories: [],
|
||||||
photos: []
|
photos: []
|
||||||
});
|
});
|
||||||
this.directories = tmp.directories.sort(dirSorter);
|
this.directories = tmp.directories;
|
||||||
|
this.sortDirectories();
|
||||||
this.isPhotoWithLocation = false;
|
this.isPhotoWithLocation = false;
|
||||||
for (let i = 0; i < tmp.photos.length; i++) {
|
for (let i = 0; i < tmp.photos.length; i++) {
|
||||||
if (tmp.photos[i].metadata &&
|
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() {
|
async ngOnInit() {
|
||||||
await this.shareService.wait();
|
await this.shareService.wait();
|
||||||
if (!this._authService.isAuthenticated() &&
|
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.timer = this.$counter.subscribe((x) => this.updateTimer(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.subscription.sorting = this._galleryService.sorting.subscribe(() => {
|
||||||
|
this.sortDirectories();
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user