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 {ShareService} from '../share.service';
|
|
|
|
import {I18n} from '@ngx-translate/i18n-polyfill';
|
2018-05-27 08:49:55 +08:00
|
|
|
import {QueryService} from '../../model/query.service';
|
2016-06-30 01:26:31 +08:00
|
|
|
|
|
|
|
@Component({
|
2018-05-04 07:17:08 +08:00
|
|
|
selector: 'app-gallery-navbar',
|
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;
|
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,
|
2018-05-27 08:49:55 +08:00
|
|
|
public queryService: QueryService,
|
2018-03-30 08:30:23 +08:00
|
|
|
private i18n: I18n) {
|
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) {
|
2018-03-31 03:30:30 +08:00
|
|
|
arr.push({name: this.i18n('Images'), route: null});
|
2017-06-11 04:32:56 +08:00
|
|
|
} else {
|
2018-03-31 03:30:30 +08:00
|
|
|
arr.push({name: this.i18n('Images'), 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
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-07-04 01:17:49 +08:00
|
|
|
interface NavigatorPath {
|
|
|
|
name: string;
|
|
|
|
route: string;
|
|
|
|
}
|
|
|
|
|