Commit d6af63e3 by Nakarin Luankla

Merge branch 'DEV' of https://mygit.myhr.co.th/angular/myAppraisal into DEV

parents eb2ea248 6198a78e
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, } from '@angular/core';
import { ColumnModel } from '@syncfusion/ej2-grids';
import { ToastrService } from 'ngx-toastr';
import { Bu1Model, MyBu1Model } from 'src/app/shared/model/bu1.model';
import { Bu2Model, MyBu2Model } from 'src/app/shared/model/bu2.model';
......@@ -17,8 +18,31 @@ interface table {
styleUrls: ['./department-list.component.scss']
})
export class DepartmentListComponent implements OnInit {
bu2List: { check: boolean, data: Bu2Model }[] = []
columns: ColumnModel[] = [{
field: "bu2id",
headerText: "ทะเบียนแผนก",
type: "string",
isPrimaryKey: true,
},
{
field: "tdesc",
headerText: "ทะเบียนแผนก(ไทย)",
type: "string"
},
{
field: "edesc",
headerText: "ทะเบียนแผนก(อังกฤษ)",
type: "string"
}]
searchSettings = {
fields: ['bu2id', 'tdesc', 'edesc'],
operator: 'contains',
ignoreCase: false
};
search = ""
selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() };
bu2List: Bu2Model[] = []
bu2ListLoading = false
bu2: Bu2Model = new MyBu2Model()
bu2Table: table = {
......@@ -47,10 +71,6 @@ export class DepartmentListComponent implements OnInit {
}
currentModal: 'add' | 'edit' | 'delete' = "add"
numDataListChecked = 0
isDataListChecked = false
isDataListCheckedAll = false
constructor(private bu2Service: Bu2Service,
private bu1Service: Bu1Service,
private toastr: ToastrService,
......@@ -114,11 +134,13 @@ export class DepartmentListComponent implements OnInit {
this.bu2ListLoading = true
this.bu2Service.getList().subscribe({
next: response => {
this.bu2List = response.map(x => ({ check: false, data: new MyBu2Model(x) }))
this.bu2List = response.map(x => {
this.selectedItems.data.set(x.bu2id, false)
return new MyBu2Model(x)
})
this.selectedItems.key = 'bu2id'
this.selectedItems.count = 0
this.bu2ListLoading = false
this.onBu2TableSearchChange()
this.isDataListCheckedAll = false
this.dataListCheckAll()
this.cdr.detectChanges()
}, error: error => {
this.bu2ListLoading = false
......@@ -126,18 +148,7 @@ export class DepartmentListComponent implements OnInit {
}
})
}
onBu2TableSearchChange() {
this.bu2Table.currentPage = 1
this.bu2Table.page = Array.from({ length: Math.ceil(this.filterBu2Table().length / 10) }, (_, i) => i + 1);
}
filterBu2Table() {
return this.bu2List.filter(x => {
const data = x.data
return data.bu2id.toLowerCase().includes(this.bu2Table.search.toLowerCase()) ||
data.tdesc.toLowerCase().includes(this.bu2Table.search.toLowerCase()) ||
data.edesc.toLowerCase().includes(this.bu2Table.search.toLowerCase())
})
}
selectBu2(bu2?: Bu2Model) {
this.bu2 = new MyBu2Model(bu2)
this.selectBu1()
......@@ -148,24 +159,6 @@ export class DepartmentListComponent implements OnInit {
})
}
}
// bu2idChange() {
// const bu2 = this.bu2List.find(x => x.bu2id == this.bu2.bu2id)
// this.selectBu2(bu2 || new MyBu2Model({ bu2id: this.bu2.bu2id }))
// }
onBu2ModalSearchChange() {
this.bu2Modal.currentPage = 1
this.bu2Modal.page = Array.from({ length: Math.ceil(this.filterBu2Modal().length / 10) }, (_, i) => i + 1);
this.dataListCheck()
}
filterBu2Modal() {
return this.bu2List.filter(x => {
const data = x.data
return data.bu2id.toLowerCase().includes(this.bu2Table.search.toLowerCase()) ||
data.tdesc.toLowerCase().includes(this.bu2Table.search.toLowerCase()) ||
data.edesc.toLowerCase().includes(this.bu2Table.search.toLowerCase())
})
}
getBu1List() {
this.bu1Service.getList().subscribe(response => {
......@@ -215,38 +208,36 @@ export class DepartmentListComponent implements OnInit {
}
deleteBu2() {
this.bu2ListLoading = true
const body = this.bu2List.filter(x => x.check).map(x => new MyBu2Model(x.data))
this.bu2Service.delete(body).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getBu2List()
} else {
this.showAlert(response.message, 'error')
this.bu2ListLoading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.bu2ListLoading = false
}
})
// const body = this.bu2List.filter(x => x.check).map(x => new MyBu2Model(x.data))
// this.bu2Service.delete(body).subscribe({
// next: response => {
// if (response.success) {
// this.showAlert(response.message, 'success')
// this.getBu2List()
// } else {
// this.showAlert(response.message, 'error')
// this.bu2ListLoading = false
// }
// }, error: error => {
// this.showAlert(error.message, 'error')
// this.bu2ListLoading = false
// }
// })
}
dataListCheckAll() {
const selectAll = this.isDataListCheckedAll;
this.filterBu2Table().forEach(x => x.check = selectAll);
this.dataListCheck();
checkPrimary() {
return this.bu2List.find(x => x.bu2id == this.bu2.bu2id)
}
dataListCheck() {
const dataCheck = this.filterBu2Table();
this.isDataListCheckedAll = dataCheck.length ? dataCheck.every(x => x.check) : false;
this.numDataListChecked = this.bu2List.filter(x => x.check).length
this.isDataListChecked = Boolean(this.numDataListChecked)
onSelectItemChange(arg: any) {
this.selectedItems = arg
}
checkPrimary() {
return this.bu2List.find(x => x.data.bu2id == this.bu2.bu2id)
numSelectItem() {
const selectedKeys = Array.from(this.selectedItems.data.keys());
const num = this.bu2List.filter(x => selectedKeys.includes(x.bu2id) && this.selectedItems.data.get(x.bu2id)).length
return num
}
}
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, } from '@angular/core';
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, ViewChild, } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { ColumnModel } from '@syncfusion/ej2-grids';
import { ar } from 'date-fns/locale';
import { ToastrService } from 'ngx-toastr';
import { Bu1Model, MyBu1Model } from 'src/app/shared/model/bu1.model';
import { Bu1Service } from 'src/app/shared/services/bu1.service';
import { FileService } from 'src/app/shared/services/file.service';
import Swal from 'sweetalert2';
@Component({
selector: 'app-department-register',
......@@ -19,11 +20,11 @@ export class DepartmentRegisterComponent implements OnInit {
selectedFile: File | null = null;
selectedFileName: string = 'กรุณาเลือกไฟล์';
selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() };
currentModel: 'add' | 'edit' | 'delete' = "add"
currentModal: 'add' | 'edit' | 'delete' = "add"
bu1: { loading: boolean, select: Bu1Model, dataList: Bu1Model[] } = { loading: false, select: new MyBu1Model(), dataList: [] }
columns: ColumnModel[] = [{
field: "bu1id",
headerText: "รหัสกลุ่มการอนุมัติ",
headerText: "รหัสฝ่าย",
type: "string",
isPrimaryKey: true,
},
......@@ -42,8 +43,10 @@ export class DepartmentRegisterComponent implements OnInit {
operator: 'contains',
ignoreCase: false
};
@ViewChild("departmentRegisterModal") departmentRegisterModal: any;
dialogRef: any
constructor(private bu1Service: Bu1Service,
private toastr: ToastrService,
private dialog: MatDialog,
private cdr: ChangeDetectorRef,
private fileService: FileService
) { }
......@@ -119,54 +122,87 @@ export class DepartmentRegisterComponent implements OnInit {
selectBu1(bu1?: Bu1Model) {
if (bu1) {
this.bu1.select = new MyBu1Model(bu1)
} else if (this.currentModel == 'add') {
} else if (this.currentModal == 'add') {
this.bu1.select = new MyBu1Model()
} else if (this.currentModel == 'edit') {
} else if (this.currentModal == 'edit') {
this.bu1.select = new MyBu1Model({ bu1id: this.bu1.select.bu1id })
}
}
showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', {
timeOut: 3000,
positionClass: 'toast-top-right',
})
Swal.fire({
title: 'แจ้งเตือน',
text: text,
icon: type,
confirmButtonText: 'ตกลง',
});
}
addBu1() {
this.bu1.loading = true
this.bu1Service.post(this.bu1.select).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getBu1List()
} else {
this.showAlert(response.message, 'error')
this.bu1.loading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.bu1.loading = false
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการบันทึกข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'บันทึกข้อมูล',
cancelButtonText: 'ย้อนกลับ',
reverseButtons: true,
}).then((result) => {
if (result.isConfirmed) {
console.log(" 🐒 result:", result)
// this.bu1.loading = true
// this.bu1Service.post(this.bu1.select).subscribe({
// next: response => {
// if (response.success) {
// this.showAlert(response.message, 'success')
// this.getBu1List()
// } else {
// this.showAlert(response.message, 'error')
// this.bu1.loading = false
// }
// }, error: error => {
// this.showAlert(error.message, 'error')
// this.bu1.loading = false
// }
// })
}
})
}
deleteBu1() {
this.bu1.loading = true
const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.bu1.dataList.filter(x => selectedKeys.includes(x.bu1id) && this.selectedItems.data.get(x.bu1id)).map(x => new MyBu1Model(x))
this.bu1Service.delete(body).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getBu1List()
} else {
this.showAlert(response.message, 'error')
this.bu1.loading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.bu1.loading = false
if (!this.numSelectItem()) {
this.showAlert('กรุณาเลือกข้อมูลที่ต้องการลบ', 'error')
return
}
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการลบข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ลบข้อมูล',
cancelButtonText: 'ย้อนกลับ',
reverseButtons: true,
}).then((result) => {
if (result.isConfirmed) {
console.log(" 🐒 result:", result)
// this.bu1.loading = true
// const selectedKeys = Array.from(this.selectedItems.data.keys());
// const body = this.bu1.dataList.filter(x => selectedKeys.includes(x.bu1id) && this.selectedItems.data.get(x.bu1id)).map(x => new MyBu1Model(x))
// this.bu1Service.delete(body).subscribe({
// next: response => {
// if (response.success) {
// this.showAlert(response.message, 'success')
// this.getBu1List()
// } else {
// this.showAlert(response.message, 'error')
// this.bu1.loading = false
// }
// }, error: error => {
// this.showAlert(error.message, 'error')
// this.bu1.loading = false
// }
// })
}
})
});
}
checkPrimary() {
......@@ -176,4 +212,20 @@ export class DepartmentRegisterComponent implements OnInit {
onSelectItemChange(arg: any) {
this.selectedItems = arg
}
openDialog() {
this.dialogRef = this.dialog.open(this.departmentRegisterModal, {
width: '500px',
disableClose: false,
});
}
closeDialog() {
this.dialogRef.close()
}
numSelectItem() {
const selectedKeys = Array.from(this.selectedItems.data.keys());
const num = this.bu1.dataList.filter(x => selectedKeys.includes(x.bu1id) && this.selectedItems.data.get(x.bu1id)).length
return num
}
}
\ No newline at end of file
......@@ -21,14 +21,14 @@
</div>
<div class="px-1">
<button type="button" class="ti-btn ti-btn-soft-secondary h-45px m-0 shadow-md"
(click)="modalStatus='add';setData()" (click)="openDialog()">
(click)="currentModal='add';setData()" (click)="openDialog()">
<i class="ri-add-line"></i>
Add
</button>
</div>
<div class="px-1">
<button href="javascript:void(0);" class="ti-btn ti-btn-soft-danger h-45px m-0 shadow-md"
(click)="modalStatus='deleteGroup';setData();deleteCompany()">
(click)="currentModal='delete';setData();deleteCompany()">
<i class="ri-delete-bin-6-line"></i>
Delete
</button>
......@@ -39,14 +39,14 @@
<div class="page px-rem">
<app-datagrid-syncfution [searchSettings]="searchSettings" [searchText]="search" [dataSource]="dataList"
[columns]="columns" [selectedItems]="selectedItems"
(sendSelectData)="modalStatus='edit';setData($event);openDialog()"
(sendSelectedItems)="onSelectItemChange($event)" (sendOpenDialog)="openDialog()">
(sendSelectData)="currentModal='edit';setData($event);openDialog()"
(sendSelectedItems)="onSelectItemChange($event)">
</app-datagrid-syncfution>
</div>
<ng-template #registrationModal let-modal>
<h3 mat-dialog-title>
{{modalStatus=='add'?'เพิ่มข้อมูลบริษัท':'แก้ไขข้อมูลบริษัท'}}
{{currentModal=='add'?'เพิ่มข้อมูลบริษัท':'แก้ไขข้อมูลบริษัท'}}
</h3>
<div class="w-full flex justify-end">
<div class="absolute flex">
......@@ -61,13 +61,13 @@
<mat-dialog-content>
<label for="input-label" class="ti-form-label mt-2rem">รหัสบริษัท<span class="text-danger">
*
<ng-container *ngIf="modalStatus=='add'&&checkPrimary()">
<ng-container *ngIf="currentModal=='add'&&checkPrimary()">
รหัสบริษัทซ้ำ
</ng-container>
</span></label>
<input type="text" id="input-label" class="ti-form-input w-1/2"
[class.!border-red]="modalStatus=='add'&&checkPrimary()"
[ngClass]="{'!bg-input-readonly':modalStatus=='edit'}" [readonly]="modalStatus=='edit'"
[class.!border-red]="currentModal=='add'&&checkPrimary()"
[ngClass]="{'!bg-input-readonly':currentModal=='edit'}" [readonly]="currentModal=='edit'"
[(ngModel)]="dataSelect.code" [maxLength]="5">
<label for="detail_th" class="ti-form-label mt-2rem">รายละเอียด (ไทย)<span class="text-danger">*</span></label>
<input type="text" id="detail_th" class="ti-form-input h-16" [(ngModel)]="dataSelect.tdesc">
......@@ -84,8 +84,8 @@
ย้อนกลับ
</button>
<button type="button" class="ti-btn ti-btn-success" mat-button (click)="addCompany()"
[class.ti-btn-disabled]="!dataSelect.code||!dataSelect.tdesc||(modalStatus=='add'&&checkPrimary())"
[disabled]="!dataSelect.code||!dataSelect.tdesc||(modalStatus=='add'&&checkPrimary())">
[class.ti-btn-disabled]="!dataSelect.code||!dataSelect.tdesc||(currentModal=='add'&&checkPrimary())"
[disabled]="!dataSelect.code||!dataSelect.tdesc||(currentModal=='add'&&checkPrimary())">
บันทึกข้อมูล
</button>
......@@ -97,7 +97,7 @@
<div class="max-h-full overflow-hidden ti-modal-content">
<div class="ti-modal-header">
<h3 class="text-xxl font-bold text-primary">
{{modalStatus=='add'?'เพิ่มข้อมูลบริษัท':'แก้ไขข้อมูลบริษัท'}}
{{currentModal=='add'?'เพิ่มข้อมูลบริษัท':'แก้ไขข้อมูลบริษัท'}}
</h3>
<div class="flex justify-end">
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
......@@ -132,13 +132,13 @@
<div class="ti-modal-body padding-16px pt-0 overflow-y-0">
<label for="input-label" class="ti-form-label mt-2rem">รหัสบริษัท<span class="text-danger">
*
<ng-container *ngIf="modalStatus=='add'&&checkPrimary()">
<ng-container *ngIf="currentModal=='add'&&checkPrimary()">
รหัสบริษัทซ้ำ
</ng-container>
</span></label>
<input type="text" id="input-label" class="ti-form-input w-1/2"
[class.!border-red]="modalStatus=='add'&&checkPrimary()"
[ngClass]="{'bg-input-readonly':modalStatus=='edit'}" [readonly]="modalStatus=='edit'"
[class.!border-red]="currentModal=='add'&&checkPrimary()"
[ngClass]="{'bg-input-readonly':currentModal=='edit'}" [readonly]="currentModal=='edit'"
[(ngModel)]="dataSelect.code" [maxLength]="5">
<label for="detail_th" class="ti-form-label mt-2rem">รายละเอียด (ไทย)<span
class="text-danger">*</span></label>
......@@ -157,8 +157,8 @@
</button>
<button type="button" class="ti-btn ti-btn-success"
data-hs-overlay="#company-registration-page-alert-modal"
[class.ti-btn-disabled]="!dataSelect.code||!dataSelect.tdesc||(modalStatus=='add'&&checkPrimary())"
[disabled]="!dataSelect.code||!dataSelect.tdesc||(modalStatus=='add'&&checkPrimary())">
[class.ti-btn-disabled]="!dataSelect.code||!dataSelect.tdesc||(currentModal=='add'&&checkPrimary())"
[disabled]="!dataSelect.code||!dataSelect.tdesc||(currentModal=='add'&&checkPrimary())">
บันทึกข้อมูล
</button>
</div>
......@@ -175,14 +175,14 @@
แจ้งเตือน
</h3>
<div class="flex justify-end">
<ng-container *ngIf="modalStatus=='add'||modalStatus=='edit'">
<ng-container *ngIf="currentModal=='add'||currentModal=='edit'">
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
data-hs-overlay="#company-registration-page-modal">
<span class="sr-only">Close</span>
<i class="ti ti-circle-x fs-xxl"></i>
</button>
</ng-container>
<ng-container *ngIf="modalStatus=='delete'||modalStatus=='deleteGroup'">
<ng-container *ngIf="currentModal=='delete'||currentModal=='deleteGroup'">
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
data-hs-overlay="#company-registration-page-alert-modal">
<span class="sr-only">Close</span>
......@@ -193,10 +193,10 @@
</div>
<div class="ti-modal-body ">
<p class="mt-1 text-gray-800 dark:text-white/70">
<ng-container *ngIf="modalStatus=='add'||modalStatus=='edit'">
<ng-container *ngIf="currentModal=='add'||currentModal=='edit'">
ยืนยันการบันทึกข้อมูลหรือไม่
</ng-container>
<ng-container *ngIf="modalStatus=='delete'||modalStatus=='deleteGroup'">
<ng-container *ngIf="currentModal=='delete'||currentModal=='deleteGroup'">
<ng-container *ngIf="numSelectItem()">
ยืนยันการลบข้อมูลหรือไม่
</ng-container>
......@@ -207,7 +207,7 @@
</p>
<div class="flex justify-end mt-2rem mb-1rem">
<ng-container *ngIf="modalStatus=='add'||modalStatus=='edit'">
<ng-container *ngIf="currentModal=='add'||currentModal=='edit'">
<button type="button"
class="hs-dropdown-toggle ti-btn ti-border font-medium bg-white text-gray-700 shadow-sm align-middle hover:bg-gray-50 focus:ring-offset-white focus:ring-primary dark:bg-bgdark dark:hover:bg-black/20 dark:border-white/10 dark:text-white/70 dark:hover:text-white dark:focus:ring-offset-white/10"
data-hs-overlay="#company-registration-page-modal">
......@@ -218,7 +218,7 @@
บันทึกข้อมูล
</a>
</ng-container>
<ng-container *ngIf="modalStatus=='delete'||modalStatus=='deleteGroup'">
<ng-container *ngIf="currentModal=='delete'||currentModal=='deleteGroup'">
<button type="button"
class="hs-dropdown-toggle ti-btn ti-border font-medium bg-white text-gray-700 shadow-sm align-middle hover:bg-gray-50 focus:ring-offset-white focus:ring-primary dark:bg-bgdark dark:hover:bg-black/20 dark:border-white/10 dark:text-white/70 dark:hover:text-white dark:focus:ring-offset-white/10"
data-hs-overlay="#company-registration-page-alert-modal">
......
......@@ -24,7 +24,7 @@ export class CompanyRegistrationPageComponent {
currentPage = 1
page = Array.from({ length: 1 }, (_, i) => i + 1);
search = ""
modalStatus = 'add'
currentModal: 'add' | 'edit' | 'delete' = 'add'
dataList: DataModel[] = []
dataLoading = false
dataSelect: DataModel = { code: "", tdesc: "", edesc: "", address: "", contact: "" }
......@@ -54,8 +54,7 @@ export class CompanyRegistrationPageComponent {
selectedFile: File | null = null;
selectedFileName: string = 'กรุณาเลือกไฟล์';
dialogRef: any
constructor(private toastr: ToastrService,
private companyService: CompanyService,
constructor(private companyService: CompanyService,
private cdr: ChangeDetectorRef,
private dialog: MatDialog,
private fileService: FileService) { }
......@@ -217,7 +216,7 @@ export class CompanyRegistrationPageComponent {
})
}
clearData() {
if (this.modalStatus == 'add') {
if (this.currentModal == 'add') {
this.setData()
} else {
this.setData({ code: this.dataSelect.code, tdesc: "", edesc: "", address: "", contact: "" })
......
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