241 lines
8.0 KiB
TypeScript
241 lines
8.0 KiB
TypeScript
|
|
import {Component, OnInit, ChangeDetectionStrategy} from '@angular/core';
|
||
|
|
import {MenuService} from './app.menu.service';
|
||
|
|
// import {PrimeNGConfig} from 'primeng/api';
|
||
|
|
import {AppComponent} from './app.component';
|
||
|
|
import { AuthService } from './_services/auth/auth.service';
|
||
|
|
import { ApiService } from './app.api.service';
|
||
|
|
import { JwtHelperService } from '@auth0/angular-jwt';
|
||
|
|
import { AuthGuard } from './_guards/auth.guard';
|
||
|
|
import { CommonModule } from '@angular/common';
|
||
|
|
import { AppTopBarComponent } from './app.topbar.component';import { Routes } from '@angular/router';
|
||
|
|
|
||
|
|
export const routes: Routes = [];
|
||
|
|
|
||
|
|
import { AppMenuComponent } from './app.menu.component';
|
||
|
|
import { AppFooterComponent } from './app.footer.component';
|
||
|
|
import { LoginComponent } from './login.component';
|
||
|
|
import { ForgotPasswordComponent } from './forgot-password.component';
|
||
|
|
import { RouterModule } from '@angular/router';
|
||
|
|
@Component({
|
||
|
|
selector: 'app-main',
|
||
|
|
templateUrl: './app.main.component.html',
|
||
|
|
styleUrls: ['./app.component.css'],
|
||
|
|
changeDetection: ChangeDetectionStrategy.Eager,
|
||
|
|
standalone: false,
|
||
|
|
|
||
|
|
})
|
||
|
|
export class AppMainComponent {
|
||
|
|
rotateMenuButton: boolean;
|
||
|
|
topbarMenuActive: boolean;
|
||
|
|
overlayMenuActive: boolean;
|
||
|
|
staticMenuDesktopInactive: boolean;
|
||
|
|
staticMenuMobileActive: boolean;
|
||
|
|
menuClick: boolean;
|
||
|
|
topbarItemClick: boolean;
|
||
|
|
configClick: boolean;
|
||
|
|
activeTopbarItem: any;
|
||
|
|
menuHoverActive: boolean;
|
||
|
|
configActive: boolean;
|
||
|
|
inlineMenuActive: boolean;
|
||
|
|
inlineMenuClick: boolean;
|
||
|
|
isAuthenticated : boolean = false;
|
||
|
|
constructor(private menuService: MenuService,
|
||
|
|
// private primengConfig: PrimeNGConfig,
|
||
|
|
public apiService: ApiService,
|
||
|
|
public app: AppComponent,
|
||
|
|
public authService: AuthService,
|
||
|
|
public _auth : AuthGuard) {
|
||
|
|
if (performance.navigation.type == performance.navigation.TYPE_RELOAD) {
|
||
|
|
} else {
|
||
|
|
this.authService.logout();
|
||
|
|
}
|
||
|
|
this.IsSelfService();
|
||
|
|
}
|
||
|
|
IsSelfService(){
|
||
|
|
const jwtHelper = new JwtHelperService();
|
||
|
|
const user = jwtHelper.decodeToken(localStorage.getItem('token'));
|
||
|
|
this.apiService.menuItems = [];
|
||
|
|
if(user !== null){
|
||
|
|
if(user.UserType === "1" || user.UserType === "0"){
|
||
|
|
this.apiService.isSelService = false;
|
||
|
|
}
|
||
|
|
if(user.UserType === "2"){
|
||
|
|
this.apiService.isSelService = true;
|
||
|
|
this.apiService.menuItems = this._auth.getUserMenu();
|
||
|
|
}
|
||
|
|
if(this.apiService.isSelService === true){
|
||
|
|
this.staticMenuDesktopInactive = true;
|
||
|
|
if(this.apiService.menuItems && this.apiService.menuItems.length > 0){
|
||
|
|
this.ProcessSelfServiceMenu(this.apiService.menuItems);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else{
|
||
|
|
this.staticMenuDesktopInactive = false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
ProcessSelfServiceMenu(menuItems : any){
|
||
|
|
if(menuItems && menuItems.length > 0){
|
||
|
|
menuItems.forEach(item => {
|
||
|
|
if(item.routerLink && item.routerLink !== "" && item.routerLink !== "/"){
|
||
|
|
item.command = (event) => this.menuService.onMenuClickForSelfService(event.item);
|
||
|
|
}
|
||
|
|
if(item.items && item.items.length > 0){
|
||
|
|
this.ProcessSelfServiceMenu(item.items);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
public payrollTypesImg = [
|
||
|
|
{ id: 1, imagePath: 'assets/payrolltype-img/payrolltype1.png' },
|
||
|
|
{ id: 2, imagePath: 'assets/payrolltype-img/payrolltype2.png' },
|
||
|
|
{ id: 3, imagePath: 'assets/payrolltype-img/payrolltype3.png' },
|
||
|
|
{ id: 4, imagePath: 'assets/payrolltype-img/payrolltype4.png' },
|
||
|
|
{ id: 5, imagePath: 'assets/payrolltype-img/payrolltype5.png' }
|
||
|
|
];
|
||
|
|
public getImagePath(): string {
|
||
|
|
const a = ApiService.USERTYPE;
|
||
|
|
const typeImage = this.payrollTypesImg.find(img => img.id === ApiService.PAYROLLTYPEID);
|
||
|
|
return typeImage ? typeImage.imagePath : 'assets/layout/images/Logo.png';
|
||
|
|
}
|
||
|
|
onLayoutClick() {
|
||
|
|
if (!this.topbarItemClick) {
|
||
|
|
this.activeTopbarItem = null;
|
||
|
|
this.topbarMenuActive = false;
|
||
|
|
}
|
||
|
|
if (!this.menuClick || (this.inlineMenuClick && this.isSlim())) {
|
||
|
|
if (this.isHorizontal() || this.isSlim()) {
|
||
|
|
this.menuService.reset();
|
||
|
|
}
|
||
|
|
if (this.overlayMenuActive || this.staticMenuMobileActive) {
|
||
|
|
this.hideOverlayMenu();
|
||
|
|
}
|
||
|
|
this.menuHoverActive = false;
|
||
|
|
}
|
||
|
|
if (this.configActive && !this.configClick) {
|
||
|
|
this.configActive = false;
|
||
|
|
}
|
||
|
|
if (this.inlineMenuActive && !this.inlineMenuClick && !this.isStatic()) {
|
||
|
|
this.inlineMenuActive = false;
|
||
|
|
}
|
||
|
|
this.inlineMenuClick = false;
|
||
|
|
this.configClick = false;
|
||
|
|
this.topbarItemClick = false;
|
||
|
|
this.menuClick = false;
|
||
|
|
}
|
||
|
|
onMenuButtonClick(event) {
|
||
|
|
debugger;
|
||
|
|
this.menuClick = true;
|
||
|
|
this.rotateMenuButton = !this.rotateMenuButton;
|
||
|
|
this.topbarMenuActive = false;
|
||
|
|
|
||
|
|
if (this.app.layoutMode === 'overlay' && (!this.isMobile() && !this.isTablet())) {
|
||
|
|
this.overlayMenuActive = !this.overlayMenuActive;
|
||
|
|
} else {
|
||
|
|
if (this.isDesktop()) {
|
||
|
|
this.staticMenuDesktopInactive = !this.staticMenuDesktopInactive;
|
||
|
|
} else {
|
||
|
|
this.staticMenuMobileActive = !this.staticMenuMobileActive;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
event.preventDefault();
|
||
|
|
}
|
||
|
|
onMenuClick($event) {
|
||
|
|
this.menuClick = true;
|
||
|
|
|
||
|
|
if (this.inlineMenuActive && !this.inlineMenuClick && !this.isStatic()) {
|
||
|
|
this.inlineMenuActive = false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
onInlineMenuClick(event) {
|
||
|
|
this.inlineMenuActive = !this.inlineMenuActive;
|
||
|
|
this.inlineMenuClick = true;
|
||
|
|
}
|
||
|
|
onTopbarMenuButtonClick(event) {
|
||
|
|
debugger;
|
||
|
|
this.topbarItemClick = true;
|
||
|
|
this.topbarMenuActive = !this.topbarMenuActive;
|
||
|
|
|
||
|
|
this.hideOverlayMenu();
|
||
|
|
|
||
|
|
event.preventDefault();
|
||
|
|
}
|
||
|
|
onTopbarItemClick(event, item) {
|
||
|
|
this.topbarItemClick = true;
|
||
|
|
|
||
|
|
if (this.activeTopbarItem === item) {
|
||
|
|
this.activeTopbarItem = null;
|
||
|
|
} else {
|
||
|
|
this.activeTopbarItem = item;
|
||
|
|
localStorage.setItem('selectedMenu', JSON.stringify(this.menuService.clickedMenuItem));
|
||
|
|
}
|
||
|
|
|
||
|
|
event.preventDefault();
|
||
|
|
}
|
||
|
|
onTopbarSubItemClick(event) {
|
||
|
|
event.preventDefault();
|
||
|
|
}
|
||
|
|
onConfigClick(event) {
|
||
|
|
this.configClick = true;
|
||
|
|
}
|
||
|
|
onRippleChange(event) {
|
||
|
|
this.app.ripple = event.checked;
|
||
|
|
// this.primengConfig = event.checked;
|
||
|
|
}
|
||
|
|
hideOverlayMenu() {
|
||
|
|
this.rotateMenuButton = false;
|
||
|
|
this.overlayMenuActive = false;
|
||
|
|
this.staticMenuMobileActive = false;
|
||
|
|
}
|
||
|
|
isTablet() {
|
||
|
|
const width = window.innerWidth;
|
||
|
|
return width <= 1024 && width > 640;
|
||
|
|
}
|
||
|
|
isDesktop() {
|
||
|
|
return window.innerWidth > 1024;
|
||
|
|
}
|
||
|
|
isMobile() {
|
||
|
|
return window.innerWidth <= 640;
|
||
|
|
}
|
||
|
|
isOverlay() {
|
||
|
|
return this.app.layoutMode === 'overlay';
|
||
|
|
}
|
||
|
|
isHorizontal() {
|
||
|
|
return this.app.layoutMode === 'horizontal';
|
||
|
|
}
|
||
|
|
isSlim() {
|
||
|
|
return this.app.layoutMode === 'slim';
|
||
|
|
}
|
||
|
|
isStatic() {
|
||
|
|
return this.app.layoutMode === 'static';
|
||
|
|
}
|
||
|
|
isLoginForm(): boolean {
|
||
|
|
const token = localStorage.getItem('token');
|
||
|
|
if (token != null) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
const forgot = localStorage.getItem('forgotpass');
|
||
|
|
if (forgot != null) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
else return true;
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|
||
|
|
forgotpassword(): boolean {
|
||
|
|
const token = localStorage.getItem('token');
|
||
|
|
if (token != null) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
const forgot = localStorage.getItem('forgotpass');
|
||
|
|
if (forgot != null) {
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
else return false;
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|