Commit 312ede78 by Nattana Chaiyamat

กำหนดสิทธิการเข้าใช้งาน

parent 9c2b0637
import { ChangeDetectorRef, Component } from '@angular/core';
import { ConfigService } from '@ks89/angular-modal-gallery/lib/services/config.service';
import { ColumnModel } from '@syncfusion/ej2-grids';
import { ToastrService } from 'ngx-toastr';
import { ConfigPermissionModel, MenuBodyModel, MyConfigPermissionModel, MyMenuBodyModel } from 'src/app/shared/model/config-permission.model';
import { ConfigPermissionService } from 'src/app/shared/services/config-permission.service';
......@@ -11,21 +12,40 @@ import { NavService } from 'src/app/shared/services/navservice';
})
export class RolePermissionConfigComponent {
pathTitle = ['การจัดการข้อมูลองค์กร', 'กำหนดสิทธิการเข้าใช้งาน']
pageSize = 10
currentPage = 1
page = Array.from({ length: 1 }, (_, i) => i + 1);
search = ""
numDataListChecked = 0
isDataListChecked = false
isDataListCheckedAll = false
currentModal: 'add' | 'edit' | 'delete' | 'updateMenu' = "add"
setMenuPage = false
configPermission: { loading: boolean, select: ConfigPermissionModel, dataList: { check: boolean, data: ConfigPermissionModel }[] } = { loading: false, select: new MyConfigPermissionModel(), dataList: [] }
configPermission: { loading: boolean, select: ConfigPermissionModel, dataList: ConfigPermissionModel[] } = { loading: false, select: new MyConfigPermissionModel(), dataList: [] }
menuItems: MenuBodyModel[] = []
menuItemsShow: Map<string, boolean> = new Map();
companyId = ""
user_level = ""
columns: ColumnModel[] = [{
field: "userLevel",
headerText: "ระดับ",
type: "string",
isPrimaryKey: true,
},
{
field: "tdesc",
headerText: "รายละเอียด (ไทย)",
type: "string"
},
{
field: "edesc",
headerText: "รายละเอียด (อังกฤษ)",
type: "string"
}]
searchSettings = {
fields: ['userLevel', 'tdesc', 'edesc'],
operator: 'contains',
ignoreCase: false
}
selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() };
constructor(private toastr: ToastrService,
private cdr: ChangeDetectorRef,
private navServices: NavService,
......@@ -52,11 +72,13 @@ export class RolePermissionConfigComponent {
this.configPermission.dataList = []
this.configPermissionService.getList().subscribe({
next: response => {
this.configPermission.dataList = response.map(x => ({ check: false, data: new MyConfigPermissionModel(x) }))
this.configPermission.dataList = response.map(x => {
this.selectedItems.data.set(x.userLevel, false)
return new MyConfigPermissionModel(x)
})
this.selectedItems.key = 'userLevel'
this.selectedItems.count = 0
this.configPermission.loading = false
this.isDataListCheckedAll = false
this.dataListCheckAll()
this.searchChange()
if (this.currentModal == 'updateMenu' && (this.configPermission.select.userLevel == this.user_level)) {
window.location.reload();
}
......@@ -68,14 +90,7 @@ export class RolePermissionConfigComponent {
})
}
configPermissionListFilter() {
return this.configPermission.dataList.filter(x => {
const data = x.data
return data.userLevel.toLowerCase().includes(this.search.toLowerCase()) ||
data.tdesc.toLowerCase().includes(this.search.toLowerCase()) ||
data.edesc.toLowerCase().includes(this.search.toLowerCase())
})
}
selectConfigPermission(data?: ConfigPermissionModel) {
this.configPermission.select = new MyConfigPermissionModel(data)
const menuBody: MenuBodyModel[] = JSON.parse(JSON.stringify(this.configPermission.select.menuBody))
......@@ -104,24 +119,6 @@ export class RolePermissionConfigComponent {
this.cdr.detectChanges()
}
searchChange() {
this.currentPage = 1
this.page = Array.from({ length: Math.ceil(this.configPermissionListFilter().length / 10) }, (_, i) => i + 1);
this.dataListCheck()
}
dataListCheckAll() {
const selectAll = this.isDataListCheckedAll;
this.configPermissionListFilter().forEach(x => x.check = selectAll);
this.dataListCheck();
}
dataListCheck() {
const dataCheck = this.configPermissionListFilter();
this.isDataListCheckedAll = dataCheck.length ? dataCheck.every(x => x.check) : false;
this.numDataListChecked = this.configPermission.dataList.filter(x => x.check).length;
this.isDataListChecked = Boolean(this.numDataListChecked)
}
clearData() {
if (this.currentModal == 'add') {
......@@ -137,7 +134,8 @@ export class RolePermissionConfigComponent {
let deleteBody: ConfigPermissionModel[] = []
switch (this.currentModal) {
case ('delete'): {
deleteBody = this.configPermission.dataList.filter(x => x.check).map(x => new MyConfigPermissionModel(x.data))
const selectedKeys = Array.from(this.selectedItems.data.keys());
deleteBody = this.configPermission.dataList.filter(x => selectedKeys.includes(x.userLevel) && this.selectedItems.data.get(x.userLevel)).map(x => new MyConfigPermissionModel(x))
break;
}
default: {
......@@ -183,8 +181,17 @@ export class RolePermissionConfigComponent {
})
}
checkPrimary() {
return this.configPermission.dataList.find(x => x.data.userLevel == this.configPermission.select.userLevel)
return this.configPermission.dataList.find(x => x.userLevel == this.configPermission.select.userLevel)
}
numSelectItem() {
const selectedKeys = Array.from(this.selectedItems.data.keys());
const num = this.configPermission.dataList.filter(x => selectedKeys.includes(x.userLevel) && this.selectedItems.data.get(x.userLevel)).length
return num
}
onSelectItemChange(arg: any) {
this.selectedItems = arg
}
}
......@@ -35,9 +35,9 @@
<span class="font-size-12px font-weight-700 text-primary">การจัดการ</span>
</ng-template>
<ng-template #template let-data *ngIf="actionSetting">
<i class="ti ti-eye cursor-pointer i-gray fs-l px-1" (click)="onNextPage(data)" *ngIf="canChild"></i>
<i class="ti ti-edit cursor-pointer i-gray fs-l px-1" [attr.data-hs-overlay]="modalName" *ngIf="canEdit"
(click)="onSelectData(data)"></i>
<i class="ti ti-menu-2 cursor-pointer i-gray fs-l px-1" (click)="onNextPage(data)" *ngIf="canChild"></i>
</ng-template>
</e-column>
</e-columns>
......
......@@ -101,6 +101,8 @@ export class DatagridSyncfutionComponent implements OnInit {
selectedItemsAll = false
@Output() sendSelectedItems = new EventEmitter<any>();
@Input() modalName = ''
@Input() canChild = false
@Output() sendNextPage = new EventEmitter<any>();
@Input() checkBoxSetting = true
@Input() actionSetting = true
......@@ -124,7 +126,6 @@ export class DatagridSyncfutionComponent implements OnInit {
@Input() editSettings? = { allowEditing: true, mode: 'Batch' };
@Input() initialPage? = { pageSizes: true, pageSize: 10 };
@Input() canDelete = true
@Input() canChild = false
@Input() canEdit = true
// ... เป็นต้น
public query: Query = new Query().addParams('dataCount', '1000');
......@@ -176,7 +177,7 @@ export class DatagridSyncfutionComponent implements OnInit {
this.sendSelectData.emit(args);
}
onNextPage(args: any) {
// console.log(args)
this.sendNextPage.emit(args);
}
toolbarClick(args: any): void {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment