2016-06-29 19:26:31 +02:00
|
|
|
import {Component, Input, OnChanges} from "@angular/core";
|
2016-12-27 21:55:51 +02:00
|
|
|
import {DirectoryDTO} from "../../../../common/entities/DirectoryDTO";
|
2016-12-27 00:36:38 +02:00
|
|
|
import {RouterLink} from "@angular/router";
|
2016-06-29 19:26:31 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'gallery-navbar',
|
|
|
|
templateUrl: 'app/gallery/navigator/navigator.gallery.component.html',
|
2016-12-27 00:36:38 +02:00
|
|
|
providers: [RouterLink],
|
2016-06-29 19:26:31 +02:00
|
|
|
})
|
|
|
|
export class GalleryNavigatorComponent implements OnChanges {
|
2016-12-27 21:55:51 +02:00
|
|
|
@Input() directory: DirectoryDTO;
|
2016-06-29 19:26:31 +02:00
|
|
|
|
2016-12-27 00:36:38 +02:00
|
|
|
routes: Array<any> = [];
|
2016-06-29 19:26:31 +02:00
|
|
|
|
|
|
|
constructor() {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ngOnChanges() {
|
|
|
|
this.getPath();
|
|
|
|
}
|
|
|
|
|
2016-12-27 00:36:38 +02:00
|
|
|
getPath(): any {
|
2016-06-29 19:26:31 +02:00
|
|
|
if (!this.directory) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
let path = this.directory.path.replace(new RegExp("\\\\", 'g'), "/");
|
|
|
|
|
|
|
|
let dirs = path.split("/");
|
|
|
|
dirs.push(this.directory.name);
|
|
|
|
|
|
|
|
//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-12-27 00:36:38 +02:00
|
|
|
let arr: any = [];
|
2016-06-29 19:26:31 +02:00
|
|
|
|
|
|
|
//create root link
|
|
|
|
if (dirs.length == 0) {
|
|
|
|
arr.push({name: "Images", route: null});
|
|
|
|
} else {
|
|
|
|
arr.push({name: "Images", route: "/"});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//create rest navigation
|
2016-12-27 00:36:38 +02:00
|
|
|
dirs.forEach((name, index) => {
|
2016-06-29 19:26:31 +02:00
|
|
|
let route = dirs.slice(0, dirs.indexOf(name) + 1).join("/");
|
|
|
|
if (dirs.length - 1 == index) {
|
|
|
|
arr.push({name: name, route: null});
|
|
|
|
} else {
|
|
|
|
arr.push({name: name, route: route});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
this.routes = arr;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|