158 lines
3.9 KiB
TypeScript
158 lines
3.9 KiB
TypeScript
/** @file
|
|
* @author Edouard DUPIN
|
|
* @copyright 2018, Edouard DUPIN, all right reserved
|
|
* @license PROPRIETARY (see license file)
|
|
*/
|
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
import { MenuItem, UserService, SessionService, SSOService, MenuPosition, EventOnMenu } from '@kangaroo-and-rabbit/kar-cw';
|
|
import { environment } from 'environments/environment';
|
|
|
|
enum MenuEventType {
|
|
SSO_SITE = 'SSO_SITE',
|
|
}
|
|
|
|
@Component({
|
|
selector: 'app-root',
|
|
templateUrl: './app.component.html',
|
|
styleUrls: ['./app.component.less'],
|
|
})
|
|
export class AppComponent implements OnInit {
|
|
title: string = environment.edgeMode ? 'Karso-edge' : 'Karso';
|
|
autoConnectedDone: boolean = false;
|
|
isConnected: boolean = false;
|
|
signUpEnable: boolean = true;
|
|
currentMenu: MenuItem[] = [];
|
|
|
|
constructor(
|
|
private userService: UserService,
|
|
private sessionService: SessionService,
|
|
private ssoService: SSOService
|
|
) { }
|
|
|
|
ngOnInit() {
|
|
console.log(`call with: ${window.location.href}`);
|
|
this.autoConnectedDone = false;
|
|
this.isConnected = false;
|
|
this.updateMainMenu();
|
|
const self = this;
|
|
this.sessionService.change.subscribe(isConnected => {
|
|
console.log(`receive event from session ...${isConnected}`);
|
|
self.isConnected = isConnected;
|
|
self.updateMainMenu();
|
|
});
|
|
this.userService
|
|
.checkAutoConnect()
|
|
.then(() => {
|
|
console.log(` ==>>>>> Auto-connect THEN !!!`);
|
|
self.autoConnectedDone = true;
|
|
})
|
|
.catch(error => {
|
|
console.log(` ==>>>>> Auto-connect CATCH !!! ${error}`);
|
|
self.autoConnectedDone = true;
|
|
})
|
|
.finally(() => {
|
|
console.log(` ==>>>>> Auto-connect FINALLY !!!`);
|
|
self.autoConnectedDone = true;
|
|
});
|
|
this.ssoService
|
|
.checkSignUpEnable()
|
|
.then((value: boolean) => {
|
|
console.log(`Get value signUp = ${value}`);
|
|
self.signUpEnable = value;
|
|
self.updateMainMenu();
|
|
})
|
|
.catch((error: any) => {
|
|
console.log(`Can not call the sso to check the sign-up_interface: ${error}`);
|
|
});
|
|
}
|
|
|
|
updateMainMenu(): void {
|
|
console.log('update main menu :');
|
|
if (this.isConnected) {
|
|
console.log(' ==> is connected');
|
|
this.currentMenu = [
|
|
{
|
|
position: MenuPosition.LEFT,
|
|
hover: `You are logged as: ${this.sessionService.getLogin()}`,
|
|
icon: 'menu',
|
|
title: 'Menu',
|
|
subMenu: [
|
|
{
|
|
position: MenuPosition.LEFT,
|
|
hover: 'Go to Home page',
|
|
icon: 'home',
|
|
title: 'Home',
|
|
navigateTo: 'home',
|
|
}, {
|
|
position: MenuPosition.LEFT,
|
|
hover: 'Exit connection',
|
|
icon: 'exit_to_app',
|
|
title: 'Sign out',
|
|
navigateTo: 'signout',
|
|
}
|
|
],
|
|
},
|
|
{
|
|
position: MenuPosition.RIGHT,
|
|
image: 'assets/images/avatar_generic.svg',
|
|
title: '',
|
|
subMenu: [
|
|
{
|
|
position: MenuPosition.LEFT,
|
|
hover: `You are logged as: <b>${this.sessionService.getLogin()}</b>`,
|
|
title: `Sign in as ${this.sessionService.getLogin()}`,
|
|
}, {
|
|
position: MenuPosition.LEFT,
|
|
hover: 'Exit connection',
|
|
icon: 'exit_to_app',
|
|
title: 'Sign out',
|
|
navigateTo: 'signout',
|
|
}, {
|
|
position: MenuPosition.RIGHT,
|
|
hover: 'Create a new account',
|
|
icon: 'eject',
|
|
title: 'Parent',
|
|
navigateTo: 'signup',
|
|
},
|
|
],
|
|
},
|
|
];
|
|
} else {
|
|
this.currentMenu = [
|
|
{
|
|
position: MenuPosition.LEFT,
|
|
hover: 'Go to Home page',
|
|
icon: 'home',
|
|
title: 'Home',
|
|
navigateTo: 'home',
|
|
},
|
|
{
|
|
position: MenuPosition.RIGHT,
|
|
hover: 'Create a new account',
|
|
icon: 'eject',
|
|
title: 'Parent',
|
|
callback: true,
|
|
otherData: MenuEventType.SSO_SITE,
|
|
},
|
|
{
|
|
position: MenuPosition.RIGHT,
|
|
hover: 'Login page',
|
|
icon: 'account_circle',
|
|
title: 'Sign-in',
|
|
navigateTo: 'signin',
|
|
},
|
|
];
|
|
}
|
|
console.log(' ==> DONE');
|
|
}
|
|
|
|
eventOnMenu(data: EventOnMenu): void {
|
|
switch (data.menu.otherData) {
|
|
case MenuEventType.SSO_SITE:
|
|
this.ssoService.requestOpenSite();
|
|
break;
|
|
}
|
|
}
|
|
}
|