2022-12-11 00:24:20 +01:00
|
|
|
import {Injectable} from '@angular/core';
|
2017-07-09 12:03:17 +02:00
|
|
|
|
2022-12-11 00:24:20 +01:00
|
|
|
import {Router} from '@angular/router';
|
|
|
|
import {ShareService} from '../ui/gallery/share.service';
|
|
|
|
import {Config} from '../../../common/config/public/Config';
|
|
|
|
import {NavigationLinkTypes} from '../../../common/config/public/ClientConfig';
|
2017-07-09 12:03:17 +02:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class NavigationService {
|
2022-12-11 00:24:20 +01:00
|
|
|
constructor(private router: Router, private shareService: ShareService) {
|
|
|
|
}
|
2017-07-09 12:03:17 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
public isLoginPage(): boolean {
|
2022-04-04 19:37:31 +02:00
|
|
|
return (
|
|
|
|
this.router.isActive('login', true) ||
|
|
|
|
this.router.isActive('shareLogin', true)
|
|
|
|
);
|
2017-07-09 12:03:17 +02:00
|
|
|
}
|
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
public async toLogin(): Promise<boolean> {
|
|
|
|
await this.shareService.wait();
|
|
|
|
if (this.shareService.isSharing()) {
|
2022-04-04 19:37:31 +02:00
|
|
|
return this.router.navigate(['shareLogin'], {
|
2022-12-11 00:24:20 +01:00
|
|
|
queryParams: {sk: this.shareService.getSharingKey()},
|
2022-04-04 19:37:31 +02:00
|
|
|
});
|
2017-07-09 12:03:17 +02:00
|
|
|
} else {
|
2021-04-18 15:48:35 +02:00
|
|
|
return this.router.navigate(['login']);
|
2017-07-09 12:03:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-11 00:24:20 +01:00
|
|
|
public async toDefault(): Promise<boolean> {
|
|
|
|
await this.shareService.wait();
|
|
|
|
if (this.shareService.isSharing()) {
|
|
|
|
return this.router.navigate(['share', this.shareService.getSharingKey()]);
|
|
|
|
} else {
|
2022-12-28 19:12:18 +01:00
|
|
|
if (Config.Gallery.NavBar.links && Config.Gallery.NavBar.links.length > 0) {
|
|
|
|
switch (Config.Gallery.NavBar.links[0].type) {
|
2022-12-11 00:24:20 +01:00
|
|
|
case NavigationLinkTypes.gallery:
|
|
|
|
return this.router.navigate(['gallery', '']);
|
|
|
|
case NavigationLinkTypes.albums:
|
|
|
|
return this.router.navigate(['albums', '']);
|
|
|
|
case NavigationLinkTypes.faces:
|
|
|
|
return this.router.navigate(['faces', '']);
|
|
|
|
case NavigationLinkTypes.search:
|
2022-12-28 19:12:18 +01:00
|
|
|
return this.router.navigate(['search', JSON.stringify(Config.Gallery.NavBar.links[0].SearchQuery)]);
|
2022-12-11 00:24:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.router.navigate(['gallery', '']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
public async toGallery(): Promise<boolean> {
|
2022-12-11 00:24:20 +01:00
|
|
|
console.log('toGallery');
|
2021-04-18 15:48:35 +02:00
|
|
|
await this.shareService.wait();
|
|
|
|
if (this.shareService.isSharing()) {
|
|
|
|
return this.router.navigate(['share', this.shareService.getSharingKey()]);
|
2017-07-09 12:03:17 +02:00
|
|
|
} else {
|
2021-04-18 15:48:35 +02:00
|
|
|
return this.router.navigate(['gallery', '']);
|
2017-07-09 12:03:17 +02:00
|
|
|
}
|
|
|
|
}
|
2018-12-04 21:43:07 +01:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
public async search(searchText: string): Promise<boolean> {
|
|
|
|
return this.router.navigate(['search', searchText]);
|
2018-12-04 21:43:07 +01:00
|
|
|
}
|
2017-07-09 12:03:17 +02:00
|
|
|
}
|