2017-07-08 12:43:42 +02:00
|
|
|
import {Component, OnInit, ViewContainerRef} from "@angular/core";
|
2016-12-27 00:36:38 +02:00
|
|
|
import {AuthenticationService} from "./model/network/authentication.service";
|
2016-12-27 17:09:47 +02:00
|
|
|
import {UserDTO} from "../../common/entities/UserDTO";
|
2016-12-27 00:36:38 +02:00
|
|
|
import {Router} from "@angular/router";
|
2017-07-08 00:18:24 +02:00
|
|
|
import {Config} from "../../common/config/public/Config";
|
|
|
|
import {Title} from "@angular/platform-browser";
|
2017-07-08 12:43:42 +02:00
|
|
|
import {NotificationService} from "./model/notification.service";
|
2017-07-09 12:03:17 +02:00
|
|
|
import {ShareService} from "./gallery/share.service";
|
2016-03-12 15:57:22 +02:00
|
|
|
|
2017-06-21 21:16:04 +02:00
|
|
|
|
2016-03-12 15:57:22 +02:00
|
|
|
@Component({
|
2017-06-10 22:32:56 +02:00
|
|
|
selector: 'pi-gallery2-app',
|
|
|
|
template: `<router-outlet></router-outlet>`,
|
2016-12-27 00:36:38 +02:00
|
|
|
|
2016-03-12 15:57:22 +02:00
|
|
|
})
|
2016-05-09 17:04:56 +02:00
|
|
|
export class AppComponent implements OnInit {
|
2016-03-13 12:28:29 +02:00
|
|
|
|
2017-07-08 12:43:42 +02:00
|
|
|
constructor(private _router: Router,
|
|
|
|
private _authenticationService: AuthenticationService,
|
2017-07-09 12:03:17 +02:00
|
|
|
private _shareService: ShareService,
|
2017-07-08 12:43:42 +02:00
|
|
|
private _title: Title, vcr: ViewContainerRef,
|
|
|
|
notificatin: NotificationService) {
|
|
|
|
notificatin.setRootViewContainerRef(vcr);
|
2017-06-10 22:32:56 +02:00
|
|
|
}
|
2016-03-12 19:11:19 +02:00
|
|
|
|
2017-07-09 12:03:17 +02:00
|
|
|
async ngOnInit() {
|
2017-07-08 00:18:24 +02:00
|
|
|
this._title.setTitle(Config.Client.applicationTitle);
|
2017-07-09 12:03:17 +02:00
|
|
|
await this._shareService.wait();
|
2017-07-03 19:17:49 +02:00
|
|
|
this._authenticationService.user.subscribe((user: UserDTO) => {
|
2017-07-09 12:03:17 +02:00
|
|
|
if (this._authenticationService.isAuthenticated()) {
|
|
|
|
if (this.isLoginPage()) {
|
|
|
|
return this.toGallery();
|
2017-06-10 22:32:56 +02:00
|
|
|
}
|
|
|
|
} else {
|
2017-07-09 12:03:17 +02:00
|
|
|
if (!this.isLoginPage()) {
|
|
|
|
return this.toLogin();
|
2017-06-10 22:32:56 +02:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 23:15:03 +02:00
|
|
|
|
2017-06-10 22:32:56 +02:00
|
|
|
});
|
2016-05-09 17:04:56 +02:00
|
|
|
|
2016-03-19 10:58:27 +02:00
|
|
|
|
2017-06-10 22:32:56 +02:00
|
|
|
}
|
2017-06-21 21:16:04 +02:00
|
|
|
|
2017-07-09 12:03:17 +02:00
|
|
|
private isLoginPage() {
|
|
|
|
return this._router.isActive('login', true) || this._router.isActive('shareLogin', false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private toLogin() {
|
|
|
|
if (this._shareService.isSharing()) {
|
|
|
|
return this._router.navigate(["shareLogin"], {queryParams: {sk: this._shareService.getSharingKey()}});
|
|
|
|
} else {
|
|
|
|
return this._router.navigate(["login"]);
|
|
|
|
}
|
|
|
|
}
|
2017-06-21 21:16:04 +02:00
|
|
|
|
2017-07-09 12:03:17 +02:00
|
|
|
private toGallery() {
|
|
|
|
if (this._shareService.isSharing()) {
|
|
|
|
return this._router.navigate(["share", this._shareService.getSharingKey()]);
|
|
|
|
} else {
|
|
|
|
return this._router.navigate(["gallery", ""]);
|
|
|
|
}
|
|
|
|
}
|
2017-06-10 22:32:56 +02:00
|
|
|
}
|