import { Component, OnInit } from '@angular/core'; import { EnumDataPermissionType, EnumMenuPermissionStatus, EnumUserType } from '../../_models/enums'; import { FormsModule } from '@angular/forms'; import { Subscription } from 'rxjs'; import { AuthService } from '../../_services/auth/auth.service'; import { loadingPanelService } from '../../hrm-loding panel/loding.panel.service'; import { UntilityHandlerService } from '../../utility.hanldler.service'; import { HRMNotificationService } from '../../app.notification.service'; import { DataTransferService } from '../../data.transfer.service'; import { ApiService } from '../../app.api.service'; import { User } from '../../_models/Authentication/user'; import { EnumAuthStatus, EnumExtension, TempEnumAuthStatus } from '../../_models/enums'; import { PayrollType } from '../../_models/Authentication/payrollType'; import { Employee } from '../../_models/Employee/employee'; import { Grade } from '../../_models/Basic/grade'; import { Department } from '../../_models/Basic/department'; import { Designation } from '../../_models/HRBasic/designation'; import { Location } from '../../_models/Basic/location'; import { DynamicPicker, EnumDynamicpickerType } from '../../picker/dynamic-picker/Dynamic-Picker'; import { DataPermission } from 'src/app/_models/Basic/DataPermission'; @Component({ selector: 'app-data-permssion', templateUrl: './data-permssion.component.html', styleUrls: ['./data-permssion.component.scss'] }) export class DataPermssionComponent implements OnInit { permissionTypes: any = EnumExtension.getNamesAndValues(EnumDataPermissionType); selectedUserType: EnumUserType; public _getUserSubscriber$: Subscription; public users: User[]; public selectedUser: User; currentUser: User; _dataPermissionGrid: DataPermission[]; _selectedRoleType: { name: string, value: EnumUserType }; roleTypes: any = EnumExtension.getNamesAndValues(EnumUserType); payrollType: PayrollType[]; _employee: Employee; _categoryPicker: DynamicPicker; _departmentPicker: DynamicPicker; _gradePicker: DynamicPicker; _locationPicker: DynamicPicker; _selectedUser: any; _selectedPayroll: any; _permissionType: any; _userID: number; public isDepartment: boolean = false; public isCategory: boolean = false; public isGrade: boolean = false; public isLocation: boolean = false; onUserTypeChange(_selectedRoleType: any): void { if (this._selectedRoleType.value != null) { this.utilityHandlerService.ShowLoadingPanel = true; this.userService.GetUsers(this._selectedRoleType.value).subscribe( (x) => { this.users = x; this.utilityHandlerService.ShowLoadingPanel = false; }, (x) => { this.notificationService.showError(x); this.utilityHandlerService.ShowLoadingPanel = false; }, () => { this.utilityHandlerService.ShowLoadingPanel = false; }); } else { this.users = []; this.selectedUser = undefined; } } EventPermissionType(selectedPermissionType: any): void { this.isDepartment = false; this.isCategory = false; this.isGrade = false; this.isLocation = false; this._permissionType = selectedPermissionType; if (this._permissionType.value == 3) { this.isDepartment = true; } else if (this._permissionType.value == 1) { this.isCategory = true; } else if (this._permissionType.value == 4) { this.isLocation = true; } else if (this._permissionType.value == 2) { this.isGrade = true; } } onUserChange(selectedUserID: any): void { if(selectedUserID.id != null){ this._selectedUser = selectedUserID; this._userID = this._selectedUser.id; if (this._userID != undefined && this._selectedPayroll != undefined) this.loadGridView() } } onPayrollChange(selectedPayrollID: any): void { this._selectedPayroll = selectedPayrollID; //console.log(this._selectedPayroll); this._departmentPicker.payrollTypeID = this._selectedPayroll; this._locationPicker.payrollTypeID = this._selectedPayroll; this._gradePicker.payrollTypeID = this._selectedPayroll; this._categoryPicker.payrollTypeID = this._selectedPayroll; if (this._userID != undefined && this._selectedPayroll != undefined) this.loadGridView() } constructor(public userService: AuthService, public apiservice: ApiService, public notificationService: HRMNotificationService, public loadingPanel: loadingPanelService, public datatransferservice: DataTransferService, public utilityHandlerService: UntilityHandlerService) { this.utilityHandlerService.ShowLoadingPanel = false; this.apiservice.selectedMenuName = 'User Data Permission'; this._categoryPicker = new DynamicPicker(EnumDynamicpickerType.Category, false); this._departmentPicker = new DynamicPicker(EnumDynamicpickerType.Department, false); this._gradePicker = new DynamicPicker(EnumDynamicpickerType.Grade, false); this._locationPicker = new DynamicPicker(EnumDynamicpickerType.Location, false); this.GetPayroll(); } ngOnInit() { this._selectedRoleType.value = EnumUserType.User; this.loadCurrentUser(); } GetPayroll() { this.utilityHandlerService.ShowLoadingPanel = true; this.userService.GetAllPayrollTypes().subscribe( (x) => { this.payrollType = x; //console.log(this.payrollType); this.utilityHandlerService.ShowLoadingPanel = false; }, (x) => { this.notificationService.showError(x); this.utilityHandlerService.ShowLoadingPanel = false; }, () => { this.utilityHandlerService.ShowLoadingPanel = false; }); } loadCurrentUser() { this.userService.GetCurrentUser().subscribe( (resp) => { this.currentUser = resp; }, (x) => { }, () => { }, ); } addPermission() { if (this._selectedUser === undefined || this._selectedPayroll === undefined || this._permissionType === undefined || this._permissionType === undefined) { this.notificationService.showWarning('Please Select Necessary Fields'); return; } var referenceid: number = 0; if (this._permissionType.value == 3) { referenceid = this._departmentPicker.selectedID; } else if (this._permissionType.value == 1) { referenceid = this._categoryPicker.selectedID; } else if (this._permissionType.value == 4) { referenceid = this._locationPicker.selectedID; } else if (this._permissionType.value == 2) { referenceid = this._gradePicker.selectedID; } if (referenceid == 0) { this.notificationService.showError("Please a Permission item"); return; } const data = { userID: this._selectedUser.id, payrollTypeID: this._selectedPayroll, permissionTypeID: this._permissionType.value, refitemid: referenceid, permissionStatus: 2 }; this.loadingPanel.ShowLoadingPanel = true; this.userService.addPermission(data).subscribe( (resp) => { this.notificationService.showSuccess("Added permission successfully."); this.loadGridView(); }, (x) => { this.loadingPanel.ShowLoadingPanel = false; this.notificationService.showSuccess(x.error); }, () => { this.loadingPanel.ShowLoadingPanel = false; }, ); } deletepermission(item: any) { if (!confirm('Are you sure to delete the Item')) { return; } this.userService.DeletedataPermission(item).subscribe( (x) => { }, (x) => { this.notificationService.showError(x); }, () => { this.notificationService.showSuccess("data deleted successfully."); this.loadGridView(); }); } loadGridView() { this.userService.loadDataPermission(this._userID, this._selectedPayroll).subscribe( (x) => { this._dataPermissionGrid = x; }, (x) => { this.notificationService.showError(x); }, () => { }); } getStatusString(status: EnumDataPermissionType): string { var item: string; switch (status) { case EnumDataPermissionType.Cagtegory: item = 'Cagtegory'; break; case EnumDataPermissionType.Grade: item = 'Grade'; break; case EnumDataPermissionType.Department: item = 'Department'; break; case EnumDataPermissionType.Location: item = 'Location'; break; } return item; } getPermissionStatus(status: EnumMenuPermissionStatus): string { var item: string; switch (status) { case EnumMenuPermissionStatus.Approved: item = 'Approved'; break; case EnumMenuPermissionStatus.Added: item = 'Added'; break; case EnumMenuPermissionStatus.Removed: item = 'Removed'; break; } return item; } }