1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00
pigallery2/src/frontend/app/model/navigation.service.ts

67 lines
2.2 KiB
TypeScript
Raw Normal View History

import {Injectable} from '@angular/core';
2017-07-09 12:03:17 +02: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 {
constructor(private router: Router, private shareService: ShareService) {
}
2017-07-09 12:03:17 +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
}
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'], {
queryParams: {sk: this.shareService.getSharingKey()},
2022-04-04 19:37:31 +02:00
});
2017-07-09 12:03:17 +02:00
} else {
return this.router.navigate(['login']);
2017-07-09 12:03:17 +02: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) {
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)]);
}
}
return this.router.navigate(['gallery', '']);
}
}
public async toGallery(): Promise<boolean> {
console.log('toGallery');
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 {
return this.router.navigate(['gallery', '']);
2017-07-09 12:03:17 +02:00
}
}
public async search(searchText: string): Promise<boolean> {
return this.router.navigate(['search', searchText]);
}
2017-07-09 12:03:17 +02:00
}