import { AfterViewInit, Component, Input, OnDestroy, OnInit } from '@angular/core'; import { Spinkit } from 'ng-http-loader'; import { ActivatedRoute, Router } from '@angular/router'; import { ReplaySubject } from 'rxjs'; import { OrderListComponent } from '../order/order-list/order-list.component'; import { ViewChild } from '@angular/core'; import { CommonService } from '../../services/common.service'; // import { AuthService } from 'ng-social-login-module'; import { ElementRef } from '@angular/core'; import { DashboardDataService } from '../../services/dashboard/dashboard.service'; import { FormControl } from '@angular/forms'; import { MatSelect } from '@angular/material/select'; import { AdminService } from '../../services/adminuser-profile/adminuser-profile.service'; declare var $: any; import { CommonEnum } from 'src/app/models/common-enum'; import { CookieService } from 'ngx-cookie-service'; import { environment } from 'src/environments/environment'; import { PublicClientApplication } from '@azure/msal-browser'; import * as lodash from 'lodash'; import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser'; @Component({ selector: 'app-master', templateUrl: './master.component.html', styleUrls: ['./master.component.css'] }) export class MasterComponent implements OnInit, AfterViewInit, OnDestroy { public spinkit = Spinkit; MenuManagementAPIResponse: any; loggedInEmail: string = this.common.b64_to_utf8(this.cookieService.get(CommonEnum.Email)); loggedInUserType: string = this.common.b64_to_utf8(this.cookieService.get('InternalOrExternal')); globalSearchModel = { type: 'rdOrderNo', search: '' } title = 'Siding Portal'; iframeEnable: boolean = false; DynamicDefault: string; @Input() _paramId: number = 5; UserId = Number(this.common.b64_to_utf8(this.cookieService.get(CommonEnum.UserId))); EditMyCompanyAPIResponse: any; companyLogoData: String = ""; faviconData: String = ""; featureInfo: any[] = []; featureInfoPGWData: any[] = []; featureInfoSOData: any[] = []; featureInfoEPData: any[] = []; featureInfoCOData: any[] = []; filterFeature: any[] = []; filterFeaturePGW: any[] = []; filterFeatureSO: any[] = []; filterFeatureEP: any[] = []; filterFeatureCO: any[] = []; featureData: any[] = []; featureDataAll: any[] = []; roleInfo: any[] = []; datalist: boolean = true; public bankCtrl: FormControl = new FormControl(); public bankFilterCtrl: FormControl = new FormControl(); @ViewChild('singleSelect') singleSelect: MatSelect; public filteredBanks: ReplaySubject = new ReplaySubject(1); @ViewChild(OrderListComponent) orderList: OrderListComponent; @ViewChild('#closeBtn') closeBtn: ElementRef; @ViewChild('#closeHeader') closeHeader: ElementRef; filterdOptions = []; UserAPIResponse: any; CSUserListData = []; BrandAPIResponse: any; CustomerAPIResponse: any; imageName_PS: string = ''; imageData_PS: string = './assets/img/profile.png'; defaultImage: string = './assets/img/ProfileImage3.png'; imageType: string = ""; CustomerData: any[] = []; BrandData: any[] = []; selectedUserIds: string; selectedCustomerIds: string; selectedUser: any[] = []; selectedData: string; jquery = $; usertypeId: any; roleCode: any; roleName: any; roleId = Number(this.common.b64_to_utf8(this.cookieService.get(CommonEnum.RoleID))); adminURL: any = environment.adminAppUrl + "?NavigateToAdmin=Yes"; currentUrl: SafeResourceUrl; html; config = { auth: { clientId: '33c6c2da-8f7c-4770-97be-0586f28e4b2e', redirectUri: environment.logoutURL, postLogoutRedirectUri: environment.logoutURL } } constructor(public router: Router, private route: ActivatedRoute, private common: CommonService, private serivcedashboard: DashboardDataService, private adminService: AdminService, public cookieService: CookieService, private sanitizer: DomSanitizer ) { this.currentUrl = this.sanitizer.bypassSecurityTrustResourceUrl(this.adminURL); } ngOnDestroy(): void { // this.common.masterResponseFound.unsubscribe(); } ngOnInit(): void { sessionStorage.setItem('IsDashboard', '0'); sessionStorage.setItem('token', this.common.b64_to_utf8(this.cookieService.get(CommonEnum.token))); sessionStorage.setItem('Email', this.loggedInEmail); if (!sessionStorage.getItem(CommonEnum.GlobalSearchCustomerID)) { sessionStorage.setItem(CommonEnum.GlobalSearchCustomerID, this.common.b64_to_utf8(this.cookieService.get(CommonEnum.GlobalSearchCustomerID))); } if (!sessionStorage.getItem(CommonEnum.GlobalSearchCustomerName)) { sessionStorage.setItem(CommonEnum.GlobalSearchCustomerName, this.common.b64_to_utf8(this.cookieService.get(CommonEnum.GlobalSearchCustomerName))); } if (!sessionStorage.getItem('MapingCustomer')) { sessionStorage.setItem('MapingCustomer', this.common.b64_to_utf8(this.cookieService.get(CommonEnum.MapingCustomer))); } if (!sessionStorage.getItem('UserType')) { sessionStorage.setItem('UserType', this.common.b64_to_utf8(this.cookieService.get('InternalOrExternal'))); } if (!sessionStorage.getItem(CommonEnum.UserId)) { sessionStorage.setItem(CommonEnum.UserId, this.common.b64_to_utf8(this.cookieService.get(CommonEnum.UserId))); } if (!sessionStorage.getItem(CommonEnum.homeAccountId)) { sessionStorage.setItem(CommonEnum.homeAccountId, this.common.b64_to_utf8(this.cookieService.get(CommonEnum.homeAccountId))); } if (this.loggedInEmail == '' || this.loggedInEmail == undefined || this.loggedInEmail == 'null' || this.loggedInEmail == null) { this.common.logout(); } this._paramId = Number(this.route.snapshot.params.id); this.common.checkUserExistence(); this.getUserAllInfo(); } ngAfterViewInit() { /*$(".hide-icon").hide();*/ $(document).ready(() => { $("#drpCustomer").click(() => { $("#drpCustomer").attr("placeholder", "Search"); $('#drpCustomer').find(".ng-placeholder")[0].innerHTML = "Search"; $("#Search_Icon").removeClass('hide-icon'); $("#Search_Icon").addClass('show-icon'); /* $(".hide-icon").slideToggle();*/ }); //$(".hide-icon").hide(); //$(".dd").show(); //$('.dd').click(function () { // $(".hide-icon").slideToggle(); //}); $("#drpCustomer").focusout(() => { if ($('#drpCustomer').find(".ng-value-label")[0] === undefined) { $('#drpCustomer').find(".ng-placeholder")[0].innerHTML = "Select"; $("#Search_Icon").removeClass('show-icon'); $("#Search_Icon").addClass('hide-icon'); } }); $("#drpBrand").click(() => { $("#drpBrand").attr("placeholder", "Search"); $('#drpBrand').find(".ng-placeholder")[0].innerHTML = "Search"; $("#Search_Icons").removeClass('hide-icon'); $("#Search_Icons").addClass('show-icon'); }); $("#drpBrand").focusout(() => { if ($('#drpBrand').find(".ng-value-label")[0] === undefined) { $('#drpBrand').find(".ng-placeholder")[0].innerHTML = "Select"; $("#Search_Icons").removeClass('show-icon'); $("#Search_Icons").addClass('hide-icon'); } }); }); } showDiv = { resource: false, marketing: false, tevent: false, policies: false, mainmenu: false, profile: false, contacts: false, adminlinks: false } showSearch = { searchFilter: false } CloseContactModal() { this.contacts = false; if (this.contacts) this.closeBtn.nativeElement.classList.remove('d-none'); else this.closeBtn.nativeElement.classList.add('d-none'); } CloseHeader() { this.header = false; if (this.header) this.closeHeader.nativeElement.classList.remove('d-none'); else this.closeHeader.nativeElement.classList.add('d-none'); } SearchClick() { if (this.globalSearchModel.search.trim() != '') { sessionStorage.setItem('searchData', JSON.stringify(this.globalSearchModel)); //this.globalSearchModel.search = ''; // Search this.router.navigate(['/order/order-list', (this.globalSearchModel.type), (this.globalSearchModel.search.trim())]); } else { this.common.showWarning("Please Enter a PO # or Order #", ""); //this.router.navigate(['/order/order-list']); } } filterUsers(value: string): void { this.CustomerData = this.selectedUser.filter( (val) => val.CUSTOMERNAME.toLowerCase().includes(value) ); } menu: boolean = false; profile: boolean = false; contacts: boolean = false; header: boolean = false; admin: boolean = false; clickMenu() { this.menu = !this.menu; this.profile = false, this.contacts = false, this.admin = false } clickProfile() { this.profile = !this.profile; this.menu = false, this.contacts = false, this.admin = false } getUserAllInfo() { this.adminService.getUserFeatureById(this.UserId, data => { this.UserAPIResponse = data; if (this.UserAPIResponse.objResponse.responseContent.length > 0) { this.featureInfo = this.common.copy(this.UserAPIResponse.objResponse.responseContent); this.featureData = this.common.copy(this.featureInfo); let viewPricingFeature = this.featureData.filter(d => { return d.FeatureID == CommonEnum.View_Pricing_Menu; }) if (viewPricingFeature.length > 0) { sessionStorage.setItem(CommonEnum.ViewPricing, viewPricingFeature[0].IsViewAccess); } if (lodash.includes(this.common.externalUserWithNoAccessOfAdmin, this.UserAPIResponse.objResponse.responseContent[0].UserTypeId)) { this.featureData = this.featureData.filter(d => { return d.FeatureID != CommonEnum.Admin_Menu; }) } // Plygem Menu Item this.filterFeaturePGW = this.featureData.filter(d => { return !lodash.includes(this.common.featureInfoPGW, d.FeatureID) }) // Signout Menu Item this.filterFeatureSO = this.featureData.filter(d => { return !lodash.includes(this.common.featureInfoSO, d.FeatureID) }) // Edit Profile Menu Item this.filterFeatureEP = this.featureData.filter(d => { return !lodash.includes(this.common.featureInfoEP, d.FeatureID) }) //Contact Menu Item this.filterFeatureCO = this.featureData.filter(d => { return !lodash.includes(this.common.featureInfoCO, d.FeatureID) }) // Remaining Menu Items this.filterFeature = this.featureData.filter(d => { return !lodash.includes(this.common.featureInfoAll, d.FeatureID) }) if (this.loggedInUserType == 'Internal') { this.bindDropDownForCustomer(); } else { this.getContactInfo(); } } else { this.common.logout(); } }, (error) => { console.error('Error: ' + error); return error(error); }); } // For Fetching Customers as per the Role ID Of the user bindDropDownForCustomer() { this.serivcedashboard.getCustomerList(this.roleId, this.loggedInEmail, data => { this.CustomerAPIResponse = data; // this.common.CustomerData = this.CustomerData = this.CustomerAPIResponse.objResponse.responseContent; this.common.CustomerData = this.CustomerData = this.common.copy(data); this.selectedUser = this.CustomerData; if (sessionStorage.getItem(CommonEnum.GlobalSearchCustomerID) != undefined && sessionStorage.getItem(CommonEnum.GlobalSearchCustomerID) != '' && sessionStorage.getItem(CommonEnum.GlobalSearchCustomerID) != null) { this.selectedCustomerIds = String(sessionStorage.getItem(CommonEnum.GlobalSearchCustomerID)); sessionStorage.setItem(CommonEnum.MapingCustomer, String(this.selectedCustomerIds)); this.bindDropDownForBrand(); } }, (error) => { console.error('Error: ' + error); return error(error); }); } // Change event for Customer Selection getCustomerValues() { sessionStorage.setItem(CommonEnum.GlobalSearchCustomerID, String(this.selectedCustomerIds)); sessionStorage.setItem(CommonEnum.MapingCustomer, String(this.selectedCustomerIds)); this.cookieService.set(CommonEnum.GlobalSearchCustomerID, this.common.utf8_to_b64(this.selectedCustomerIds)); sessionStorage.setItem('GlobalSearchShipToAddressID', String(this.selectedCustomerIds)); let selectedCustomer = this.CustomerData.filter(d => { return d.Shipto == this.selectedCustomerIds; }); if (selectedCustomer.length > 0) { sessionStorage.setItem(CommonEnum.GlobalSearchCustomerName, selectedCustomer[0].shiptoname); } this.bindDropDownForBrand(); if (window.location.href.includes("order-list") || window.location.href.includes("dashboard")) { window.location.reload(); } else { this.router.navigate(['/dashboard/dashboard']); } } ClearShipToAddressSearch() { this.cookieService.delete(CommonEnum.GlobalSearchCustomerID); sessionStorage.removeItem(CommonEnum.GlobalSearchCustomerID); sessionStorage.removeItem('GlobalSearchShipToAddressID'); sessionStorage.removeItem(CommonEnum.MapingCustomer); window.location.reload(); } bindDropDownForBrand() { if (Number(sessionStorage.getItem(CommonEnum.GlobalSearchCustomerID)) > 0) { this.serivcedashboard.getBrandList(Number(sessionStorage.getItem(CommonEnum.GlobalSearchCustomerID)), this.loggedInEmail, this.loggedInUserType, data => { this.BrandAPIResponse = data; this.common.BrandData = this.BrandData = this.BrandAPIResponse.objResponse.responseContent; }, (error) => { console.error('Error: ' + error); return error(error); }); } } // For Fetching CS Users, only will get called if user type is external getContactInfo() { this.serivcedashboard.getByCSUserId(Number(sessionStorage.getItem(CommonEnum.GlobalSearchCustomerID)), data => { this.CSUserListData = data.objResponse.responseContent; }, (error) => { console.error('Error: ' + error); return error(error); }); } clickContacts() { this.contacts = !this.contacts; this.profile = false, this.menu = false, this.admin = false } clickAdmin() { this.admin = !this.admin; this.profile = false, this.contacts = false, this.menu = false } closeMenu() { this.admin = false, this.profile = false, this.contacts = false, this.menu = false, this.showDiv.mainmenu = false, this.showDiv.profile = false, this.showDiv.contacts = false, this.showDiv.adminlinks = false } redirectToAdmin(url) { // If customer selected in Siding, then need to select its parent company in Admin Hierarchy // or if parent company selected in Siding then same to be selected in Admin Hierarchy as well. if (this.loggedInUserType == 'Internal' && this.selectedCustomerIds && this.selectedCustomerIds !== '' && url == '/adminhierarchy') { let selectedCustomer = this.CustomerData.filter(d => { return d.Shipto == this.selectedCustomerIds; }); if (selectedCustomer.length > 0) { location.href = environment.adminAppUrl + "?NavigateToAdmin=Yes&ParentCustomerShipTo=" + selectedCustomer[0].parentcustomerno; } } else { if (url == '/adminhierarchy') { // createframe(); // var iframe = document.getElementById("iframe"); // iframe['src'] = environment.adminAppUrl + "?NavigateToAdmin=Yes"; // var wasSrc = iframe['src'] // iframe.onload = () => { // iframe.onload = undefined; // iframe['src'] = wasSrc; // } // $("#iframe").attr("src", environment.adminAppUrl + "?NavigateToAdmin=Yes"); // $("#iframe").contentWindow.location.reload(true); // window.history.replaceState("", "", "https://devportal.cornerstonebuildingbrands.com/"); // window.history.pushState("", "", '/order/order-list'); // this.router.navigate(["/"]).then(result=>{window.location.href = environment.adminAppUrl + "?NavigateToAdmin=Yes";}); // this.location.go(environment.adminAppUrl + "?NavigateToAdmin=Yes"); // this.router.navigateByUrl("/test"); // this.router.navigate(['admin']); // this.router.navigate(['/externalRedirect', { externalUrl: environment.adminAppUrl + "?NavigateToAdmin=Yes" }], { // skipLocationChange: true, // }); location.href = environment.adminAppUrl + "?NavigateToAdmin=Yes"; } } } logout() { this.cookieService.deleteAll(); const myMsal = new PublicClientApplication(this.config); const logoutRequest = { account: myMsal.getAccountByHomeId(sessionStorage.getItem(CommonEnum.homeAccountId)), mainWindowRedirectUri: environment.logoutURL, redirectUri : environment.logoutURL } sessionStorage.clear(); myMsal.logoutRedirect(logoutRequest); } hoverStateIn() { this.admin = false, this.profile = false, this.contacts = false, this.menu = false, this.showDiv.mainmenu = false, this.showDiv.profile = false, this.showDiv.contacts = false, this.showDiv.adminlinks = false, this.showDiv.resource = false, this.showDiv.marketing = false, this.showDiv.tevent = false, this.showDiv.policies = false, this.showSearch.searchFilter = false } } // function createframe() { // var ahead = document.body; // var mainfs = document.createElement('FRAMESET'); // mainfs.setAttribute("name", "mainframeset"); // mainfs.setAttribute("id", "mfs"); // ahead.appendChild(mainfs); // var ifrm = document.createElement("IFRAME"); // ifrm.setAttribute("src", environment.adminAppUrl); // document.getElementById('mfs').appendChild(ifrm); // }