import { Component, OnInit, ViewEncapsulation, Input, ChangeDetectionStrategy } from '@angular/core'; import { BaseService } from '../services/base.service'; import { CbmsService } from '../cbms.services'; //import { ColdObservable } from 'rxjs/testing/ColdObservable'; //import { environment } from '../environments/environment'; import { Location, LocationStrategy, PathLocationStrategy } from '@angular/common'; //import { RMComponent } from '../../../../rm.component'; export interface Menu { Displaytext: string; Displayorder: number; MenuId: number; Menulevel: number; ParentMenuId: number; TargetAction: string; TargetServer: string; } @Component({ selector: 'cbms-menu-lib', templateUrl: './menu.component.html', styleUrls: ['./menu.component.scss'], encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.Eager, standalone: false }) export class MenuComponent implements OnInit { public MenuData: Menu[] = []; public data1; public ngMenu: Menu[] = []; wantedData: any = {}; collapse: boolean = false; id: any; private blnIsUid:boolean=false; constructor( private cbmsApi: CbmsService,private location: Location) { if (this.location.path() != "" && this.location.path().indexOf("uid") !== -1) { this.id = this.location.path().split('?')[1].split("uid=")[1].split("&")[0]; this.blnIsUid=true; } else if(this.location.path() != "" && this.location.path().indexOf("xid") !== -1) { this.id = this.location.path().split('?')[1].split("xid=")[1].split("&")[0]; this.blnIsUid=false; } } ngOnInit() { this.GetCBMenu(); } public GetCBMenu() { if (this.id == undefined) { if (localStorage.getItem('UserID') !== null && localStorage.getItem('UserID') !== "") { let userInfo = localStorage.getItem('UserID') let UserIDObj = JSON.parse(userInfo); if (UserIDObj !== null && UserIDObj !== undefined) { if (UserIDObj.type == "uid") { this.id = UserIDObj.id; this.blnIsUid = true; } else { this.id = UserIDObj.id; this.blnIsUid = false; } } } } var req={objUserValidate:{UserId:this.id,IsUid:this.blnIsUid}} this.cbmsApi.GetMenuWithUidOrXid(req).subscribe(data => { this.MenuData = data.MenulistWithUidOrXidResult; // let menutDetails: any = { // Displaytext: 'RM Micro app', // Displayorder: 15, // MenuId: 200, // Menulevel: 1, // ParentMenuId: 152, // TargetAction: environment.appBaseUrl+'search-clients', // TargetServer: '' // }; // // if (menutDetails.TargetAction !== '') { // // menutDetails.TargetAction = menutDetails.TargetAction // // .replace(menutDetails.TargetAction.split(':')[2].split('/')[0], window.location.port); // // } // this.MenuData.push(menutDetails); this.MenuData = this.MenuData.filter(function (data1, i, menudata) { return data1.Menulevel == 1; }); }); } // loadMenuItem($event) { // let portname: string = window.location.port; // if ($event.srcElement.parentNode.port !== '') { // $event.srcElement.parentNode.port = portname; // } // console.log($event.srcElement.parentNode); // } Logout(url) { // localStorage.removeItem('UserID'); localStorage.clear(); // //this.router.navigate(['/login']); location.href = url; } HelpOpenUrlInNewTab(url) { const link = document.createElement('a'); link.target = '_blank'; link.href = url; link.style.display = 'none'; link.click(); } // LogoutMenu(Displaytext, TargetAction) { // if (Displaytext != 'GRM MicroApp') // localStorage.removeItem('UserID'); // location.href = TargetAction; // } }