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';
|
2018-05-27 08:49:55 +08:00
|
|
|
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';
|
2018-11-02 23:24:37 +08:00
|
|
|
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'],
|
2017-06-11 04:32:56 +08:00
|
|
|
templateUrl: './navigator.gallery.component.html',
|
|
|
|
providers: [RouterLink],
|
2016-06-30 01:26:31 +08:00
|
|
|
})
|
|
|
|
export class GalleryNavigatorComponent implements OnChanges {
|
2017-06-11 04:32:56 +08:00
|
|
|
@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 }[] = [];
|
2018-11-02 23:24:37 +08:00
|
|
|
config = Config;
|
2018-12-20 06:14:33 +08:00
|
|
|
DefaultSorting = Config.Client.Other.defaultPhotoSortingMethod;
|
2019-01-07 06:15:52 +08:00
|
|
|
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,
|
2018-05-27 08:49:55 +08:00
|
|
|
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);
|
2019-01-07 06:15:52 +08:00
|
|
|
this.RootFolderName = this.i18n('Images');
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
2016-06-30 01:26:31 +08:00
|
|
|
|
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
ngOnChanges() {
|
|
|
|
this.getPath();
|
|
|
|
}
|
2016-06-30 01:26:31 +08:00
|
|
|
|
2017-06-11 04:32:56 +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('/');
|
2017-06-11 04:32:56 +08:00
|
|
|
dirs.push(this.directory.name);
|
2016-06-30 01:26:31 +08:00
|
|
|
|
2018-05-04 07:17:08 +08:00
|
|
|
// removing empty strings
|
2017-06-11 04:32:56 +08:00
|
|
|
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]) {
|
2017-06-11 04:32:56 +08:00
|
|
|
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) {
|
2019-01-07 06:15:52 +08:00
|
|
|
arr.push({name: this.RootFolderName, route: null});
|
2017-06-11 04:32:56 +08:00
|
|
|
} else {
|
2019-01-07 06:15:52 +08:00
|
|
|
arr.push({name: this.RootFolderName, route: UserDTO.isPathAvailable('/', user.permissions) ? '/' : null});
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
2016-06-30 01:26:31 +08:00
|
|
|
|
2018-05-04 07:17:08 +08:00
|
|
|
// create rest navigation
|
2017-06-11 04:32:56 +08:00
|
|
|
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) {
|
2017-06-11 04:32:56 +08:00
|
|
|
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});
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
|
|
|
});
|
2016-06-30 01:26:31 +08:00
|
|
|
|
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
this.routes = arr;
|
2016-06-30 01:26:31 +08:00
|
|
|
|
|
|
|
|
2017-06-11 04:32:56 +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 {
|
2019-01-07 06:15:52 +08:00
|
|
|
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
|
|
|
|
2019-01-07 06:15:52 +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;
|
|
|
|
}
|
|
|
|
|