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