1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/frontend/app/gallery/navigator/navigator.gallery.component.ts

121 lines
3.7 KiB
TypeScript
Raw Normal View History

2018-12-23 23:18:44 +08:00
import {Component, HostListener, Input, OnChanges} from '@angular/core';
2018-03-31 03:30:30 +08:00
import {DirectoryDTO} from '../../../../common/entities/DirectoryDTO';
2018-12-23 23:18:44 +08:00
import {Router, RouterLink} from '@angular/router';
2018-03-31 03:30:30 +08:00
import {UserDTO} from '../../../../common/entities/UserDTO';
import {AuthenticationService} from '../../model/network/authentication.service';
import {I18n} from '@ngx-translate/i18n-polyfill';
import {QueryService} from '../../model/query.service';
2018-05-29 02:03:12 +08:00
import {GalleryService} from '../gallery.service';
import {Utils} from '../../../../common/Utils';
import {SortingMethods} from '../../../../common/entities/SortingMethods';
import {Config} from '../../../../common/config/public/Config';
2018-12-02 19:22:20 +08:00
import {SearchResultDTO} from '../../../../common/entities/SearchResultDTO';
import {SearchTypes} from '../../../../common/entities/AutoCompleteItem';
2016-06-30 01:26:31 +08:00
@Component({
2018-05-04 07:17:08 +08:00
selector: 'app-gallery-navbar',
2018-05-29 02:03:12 +08:00
styleUrls: ['./navigator.gallery.component.css'],
templateUrl: './navigator.gallery.component.html',
providers: [RouterLink],
2016-06-30 01:26:31 +08:00
})
export class GalleryNavigatorComponent implements OnChanges {
@Input() directory: DirectoryDTO;
2018-12-02 19:22:20 +08:00
@Input() searchResult: SearchResultDTO;
2016-06-30 01:26:31 +08:00
2018-12-20 06:14:33 +08:00
routes: NavigatorPath[] = [];
2018-05-29 02:03:12 +08:00
SortingMethods = SortingMethods;
sortingMethodsType: { key: number; value: string }[] = [];
config = Config;
2018-12-20 06:14:33 +08:00
DefaultSorting = Config.Client.Other.defaultPhotoSortingMethod;
private readonly RootFolderName: string;
2016-06-30 01:26:31 +08:00
2018-12-02 19:22:20 +08:00
readonly SearchTypes = SearchTypes;
2017-07-04 01:17:49 +08:00
constructor(private _authService: AuthenticationService,
public queryService: QueryService,
2018-05-29 02:03:12 +08:00
public galleryService: GalleryService,
2018-12-23 23:18:44 +08:00
private router: Router,
2018-03-30 08:30:23 +08:00
private i18n: I18n) {
2018-05-29 02:03:12 +08:00
this.sortingMethodsType = Utils.enumToArray(SortingMethods);
this.RootFolderName = this.i18n('Images');
}
2016-06-30 01:26:31 +08:00
ngOnChanges() {
this.getPath();
}
2016-06-30 01:26:31 +08:00
getPath(): any {
if (!this.directory) {
return [];
}
2016-06-30 01:26:31 +08:00
2018-05-04 07:17:08 +08:00
const path = this.directory.path.replace(new RegExp('\\\\', 'g'), '/');
2016-06-30 01:26:31 +08:00
2018-05-04 07:17:08 +08:00
const dirs = path.split('/');
dirs.push(this.directory.name);
2016-06-30 01:26:31 +08:00
2018-05-04 07:17:08 +08:00
// removing empty strings
for (let i = 0; i < dirs.length; i++) {
2018-03-31 03:30:30 +08:00
if (!dirs[i] || 0 === dirs[i].length || '.' === dirs[i]) {
dirs.splice(i, 1);
i--;
}
}
2016-06-30 01:26:31 +08:00
2017-07-04 01:17:49 +08:00
const user = this._authService.user.value;
2018-05-04 07:17:08 +08:00
const arr: NavigatorPath[] = [];
2016-06-30 01:26:31 +08:00
2018-05-04 07:17:08 +08:00
// create root link
if (dirs.length === 0) {
arr.push({name: this.RootFolderName, route: null});
} else {
arr.push({name: this.RootFolderName, route: UserDTO.isPathAvailable('/', user.permissions) ? '/' : null});
}
2016-06-30 01:26:31 +08:00
2018-05-04 07:17:08 +08:00
// create rest navigation
dirs.forEach((name, index) => {
2018-03-31 03:30:30 +08:00
const route = dirs.slice(0, dirs.indexOf(name) + 1).join('/');
2018-05-04 07:17:08 +08:00
if (dirs.length - 1 === index) {
arr.push({name: name, route: null});
} else {
2017-07-09 18:03:17 +08:00
arr.push({name: name, route: UserDTO.isPathAvailable(route, user.permissions) ? route : null});
}
});
2016-06-30 01:26:31 +08:00
this.routes = arr;
2016-06-30 01:26:31 +08:00
}
2016-06-30 01:26:31 +08:00
2018-05-29 02:03:12 +08:00
setSorting(sorting: SortingMethods) {
this.galleryService.setSorting(sorting);
}
2018-12-02 19:22:20 +08:00
get ItemCount(): number {
return this.directory ? this.directory.mediaCount : this.searchResult.media.length;
2018-12-02 19:22:20 +08:00
}
2016-06-30 01:26:31 +08:00
/*
@HostListener('window:keydown', ['$event'])
onKeyPress(e: KeyboardEvent) {
if (this.routes.length < 2) {
return;
}
const event: KeyboardEvent = window.event ? <any>window.event : e;
if (event.altKey === true && event.key === 'ArrowUp') {
const path = this.routes[this.routes.length - 2];
this.router.navigate(['/gallery', path.route],
{queryParams: this.queryService.getParams()}).catch(console.error);
}
}*/
2016-06-30 01:26:31 +08:00
}
2017-07-04 01:17:49 +08:00
interface NavigatorPath {
name: string;
route: string;
}