karso/front/src/app-root/app.component.ts

180 lines
4.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 { EventOnMenu, MenuItem, MenuPosition, SSOService, SessionService, UserRoles222, UserService } from '@kangaroo-and-rabbit/kar-cw';
import { environmentKarso } from 'environments/environment';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.less'],
})
export class AppComponent implements OnInit {
title: string = environmentKarso.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}`);
});
}
eventOnMenu(data: EventOnMenu): void { }
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: 'Change the Password of your account',
icon: 'key',
title: 'Change Password',
navigateTo: 'password',
},
/*{
position: MenuPosition.LEFT,
hover: "Change your Avatar",
icon: "account_box",
title: "Change Avatar",
navigateTo: "avatar",
}, */ {
position: MenuPosition.LEFT,
hover: 'Admin configuration karso management',
icon: 'settings',
title: 'Admin Settings',
navigateTo: 'settings',
enable: this.sessionService.hasRight(UserRoles222.admin),
}, { // TODO move this in the setting environment system ?
position: MenuPosition.LEFT,
hover: 'Admin of users',
icon: 'manage_accounts',
title: 'Manage Accounts',
navigateTo: 'manage_accounts',
enable: this.sessionService.hasRight(UserRoles222.admin),
}, {
position: MenuPosition.LEFT,
hover: 'Admin of all the applications',
icon: 'app_registration',
title: 'Manage Applications',
navigateTo: 'applications',
enable: this.sessionService.hasRight(UserRoles222.admin),
},
],
},
{
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,
icon: "settings",
title: "Settings",
navigateTo: "settings",
}, */{
position: MenuPosition.LEFT,
icon: 'help',
title: 'Help',
navigateTo: 'help',
}, {
position: MenuPosition.LEFT,
hover: 'Exit connection',
icon: 'exit_to_app',
title: 'Sign out',
navigateTo: 'signout',
},
],
},
];
} 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: 'add_circle_outline',
title: 'Sign-up',
model: this.signUpEnable ? undefined : 'disable',
navigateTo: 'signup',
},
{
position: MenuPosition.RIGHT,
hover: 'Login page',
icon: 'account_circle',
title: 'Sign-in',
navigateTo: 'signin',
},
];
}
console.log(' ==> DONE');
}
}