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

93 lines
2.5 KiB
TypeScript
Raw Normal View History

2018-03-31 03:30:30 +08:00
import {Component, Input, OnChanges} from '@angular/core';
import {DirectoryDTO} from '../../../../common/entities/DirectoryDTO';
import {RouterLink} from '@angular/router';
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';
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;
2016-06-30 01:26:31 +08:00
2017-07-04 01:17:49 +08:00
routes: Array<NavigatorPath> = [];
2018-05-29 02:03:12 +08:00
SortingMethods = SortingMethods;
sortingMethodsType: { key: number; value: string }[] = [];
2016-06-30 01:26:31 +08:00
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-03-30 08:30:23 +08:00
private i18n: I18n) {
2018-05-29 02:03:12 +08:00
this.sortingMethodsType = Utils.enumToArray(SortingMethods);
}
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) {
2018-03-31 03:30:30 +08:00
arr.push({name: this.i18n('Images'), route: null});
} else {
2018-03-31 03:30:30 +08:00
arr.push({name: this.i18n('Images'), 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);
}
2016-06-30 01:26:31 +08:00
}
2017-07-04 01:17:49 +08:00
interface NavigatorPath {
name: string;
route: string;
}