2016-06-30 01:26:31 +08:00
|
|
|
import {Component, Input, OnChanges} from "@angular/core";
|
2016-12-28 03:55:51 +08:00
|
|
|
import {DirectoryDTO} from "../../../../common/entities/DirectoryDTO";
|
2016-12-27 06:36:38 +08:00
|
|
|
import {RouterLink} from "@angular/router";
|
2017-07-09 18:03:17 +08:00
|
|
|
import {UserDTO} from "../../../../common/entities/UserDTO";
|
2017-07-04 01:17:49 +08:00
|
|
|
import {AuthenticationService} from "../../model/network/authentication.service";
|
|
|
|
import {ShareService} from "../share.service";
|
2016-06-30 01:26:31 +08:00
|
|
|
|
|
|
|
@Component({
|
2017-06-11 04:32:56 +08:00
|
|
|
selector: 'gallery-navbar',
|
|
|
|
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;
|
2016-06-30 01:26:31 +08:00
|
|
|
|
2017-07-04 01:17:49 +08:00
|
|
|
routes: Array<NavigatorPath> = [];
|
2016-06-30 01:26:31 +08:00
|
|
|
|
2017-07-04 01:17:49 +08:00
|
|
|
constructor(private _authService: AuthenticationService,
|
|
|
|
public _shareService: ShareService) {
|
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
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
let path = this.directory.path.replace(new RegExp("\\\\", 'g'), "/");
|
2016-06-30 01:26:31 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
let dirs = path.split("/");
|
|
|
|
dirs.push(this.directory.name);
|
2016-06-30 01:26:31 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
//removing empty strings
|
|
|
|
for (let i = 0; i < dirs.length; i++) {
|
|
|
|
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;
|
|
|
|
let arr: NavigatorPath[] = [];
|
2016-06-30 01:26:31 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
//create root link
|
|
|
|
if (dirs.length == 0) {
|
|
|
|
arr.push({name: "Images", route: null});
|
|
|
|
} else {
|
2017-07-09 18:03:17 +08:00
|
|
|
arr.push({name: "Images", route: UserDTO.isPathAvailable("/", user.permissions) ? "/" : null});
|
2016-06-30 01:26:31 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
2016-06-30 01:26:31 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
//create rest navigation
|
|
|
|
dirs.forEach((name, index) => {
|
2017-07-04 01:17:49 +08:00
|
|
|
const route = dirs.slice(0, dirs.indexOf(name) + 1).join("/");
|
2017-06-11 04:32:56 +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});
|
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
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-07-04 01:17:49 +08:00
|
|
|
interface NavigatorPath {
|
|
|
|
name: string;
|
|
|
|
route: string;
|
|
|
|
}
|
|
|
|
|