Commit 2f8519d6 by Nakarin Luankla

UPDATE แก้ model ข้อมูลลักษณะงาน

parent f3407a40
import { ChangeDetectorRef, Component, EventEmitter, Input, Output } from '@angular/core'; import { ChangeDetectorRef, Component, EventEmitter, Input, Output, ViewChild } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { ColumnModel } from '@syncfusion/ej2-grids'; import { ColumnModel } from '@syncfusion/ej2-grids';
import { ToastrService } from 'ngx-toastr'; import { ToastrService } from 'ngx-toastr';
import { EmpTypeModel, MyEmpTypeModel } from 'src/app/shared/model/employee-type.model'; import { EmpTypeModel, MyEmpTypeModel } from 'src/app/shared/model/employee-type.model';
import { EmpTypeService } from 'src/app/shared/services/employee-type.service'; import { EmpTypeService } from 'src/app/shared/services/employee-type.service';
import { FileService } from 'src/app/shared/services/file.service'; import { FileService } from 'src/app/shared/services/file.service';
import Swal from 'sweetalert2';
@Component({ @Component({
selector: 'app-employee-categories', selector: 'app-employee-categories',
templateUrl: './employee-categories.component.html', templateUrl: './employee-categories.component.html',
...@@ -40,15 +42,29 @@ export class EmployeeCategories { ...@@ -40,15 +42,29 @@ export class EmployeeCategories {
ignoreCase: false ignoreCase: false
} }
selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() }; selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() };
@ViewChild("employeeCategoriesModal") employeeCategoriesModal: any;
dialogRef: any
constructor(private empTypeService: EmpTypeService, constructor(private empTypeService: EmpTypeService,
private toastr: ToastrService, private toastr: ToastrService,
private cdr: ChangeDetectorRef, private cdr: ChangeDetectorRef,
private fileService: FileService private fileService: FileService,
private dialog: MatDialog
) { } ) { }
ngOnInit(): void { ngOnInit(): void {
this.getEmpTypeList() this.getEmpTypeList()
} }
openDialog() {
this.dialogRef = this.dialog.open(this.employeeCategoriesModal, {
width: '500px',
height: '500px'
})
}
closeDialog() {
this.dialogRef.close()
}
onFileSelected(event: any) { onFileSelected(event: any) {
this.selectedFile = event.target.files.length > 0 ? event.target.files[0] : null; this.selectedFile = event.target.files.length > 0 ? event.target.files[0] : null;
this.selectedFileName = this.selectedFile?.name || "กรุณาเลือกไฟล์" this.selectedFileName = this.selectedFile?.name || "กรุณาเลือกไฟล์"
...@@ -132,12 +148,21 @@ export class EmployeeCategories { ...@@ -132,12 +148,21 @@ export class EmployeeCategories {
addEmp_type() { addEmp_type() {
this.emp_type.loading = true Swal.fire({
this.empTypeService.post(this.emp_type.select).subscribe({ icon: 'warning',
next: response => { title: 'แจ้งเตือน',
if (response.success) { text: 'คุณต้องการเพิ่มประเภทพนักงานหรือไม่',
showCancelButton: true,
confirmButtonText: 'ยืนยัน',
}).then((result) => {
if (result.isConfirmed) {
this.emp_type.loading = true
this.empTypeService.post(this.emp_type.select).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success') this.showAlert(response.message, 'success')
this.getEmpTypeList() this.getEmpTypeList()
this.closeDialog()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.emp_type.loading = false this.emp_type.loading = false
...@@ -146,14 +171,28 @@ export class EmployeeCategories { ...@@ -146,14 +171,28 @@ export class EmployeeCategories {
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.emp_type.loading = false this.emp_type.loading = false
this.cdr.detectChanges() this.cdr.detectChanges()
}
})
} }
}) })
} }
deleteEmp_type() { deleteEmp_type() {
this.emp_type.loading = true if (this.numSelectItem() == 0) {
const selectedKeys = Array.from(this.selectedItems.data.keys()); this.showAlert('กรุณาเลือกข้อมูลที่จะลบ', 'error')
return
}
Swal.fire({
icon: 'warning',
title: 'แจ้งเตือน',
text: 'คุณต้องการลบประเภทพนักงานทั้งหมดหรือไม่',
showCancelButton: true,
confirmButtonText: 'ยืนยัน',
}).then((result) => {
if (result.isConfirmed) {
this.emp_type.loading = true
const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.emp_type.dataList.filter(x => selectedKeys.includes(x.codeId) && this.selectedItems.data.get(x.codeId)).map(x => new MyEmpTypeModel(x)) const body = this.emp_type.dataList.filter(x => selectedKeys.includes(x.codeId) && this.selectedItems.data.get(x.codeId)).map(x => new MyEmpTypeModel(x))
this.empTypeService.delete(body).subscribe({ this.empTypeService.delete(body).subscribe({
next: response => { next: response => {
...@@ -168,16 +207,21 @@ export class EmployeeCategories { ...@@ -168,16 +207,21 @@ export class EmployeeCategories {
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.emp_type.loading = false this.emp_type.loading = false
this.cdr.detectChanges() this.cdr.detectChanges()
}
})
} }
}) })
} }
showAlert(text: string, type: 'success' | 'error') { showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', { Swal.fire({
timeOut: 3000, icon: type,
positionClass: 'toast-top-right', title: 'แจ้งเตือน',
}); text: text,
showCancelButton: false,
confirmButtonText: 'ยืนยัน',
})
} }
......
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { ColumnModel } from '@syncfusion/ej2-grids'; import { ColumnModel } from '@syncfusion/ej2-grids';
import { ToastrService } from 'ngx-toastr'; import { ToastrService } from 'ngx-toastr';
import { MyPLModel, PLModel } from 'src/app/shared/model/pl.model'; import { MyPLModel, PLModel } from 'src/app/shared/model/pl.model';
import { FileService } from 'src/app/shared/services/file.service'; import { FileService } from 'src/app/shared/services/file.service';
import { PLService } from 'src/app/shared/services/pl.service'; import { PLService } from 'src/app/shared/services/pl.service';
import Swal from 'sweetalert2';
@Component({ @Component({
selector: 'app-employee-level', selector: 'app-employee-level',
templateUrl: './employee-level.component.html', templateUrl: './employee-level.component.html',
...@@ -41,16 +43,30 @@ export class EmployeeLevel implements OnInit { ...@@ -41,16 +43,30 @@ export class EmployeeLevel implements OnInit {
ignoreCase: false ignoreCase: false
} }
selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() }; selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() };
@ViewChild("employeeLevelModal") employeeLevelModal: any;
dialogRef: any
constructor(private plService: PLService, constructor(private plService: PLService,
private toastr: ToastrService, private toastr: ToastrService,
private cdr: ChangeDetectorRef, private cdr: ChangeDetectorRef,
private fileService: FileService private fileService: FileService,
private dialog: MatDialog
) { } ) { }
ngOnInit(): void { ngOnInit(): void {
this.getPLList() this.getPLList()
} }
openDialog() {
this.dialogRef = this.dialog.open(this.employeeLevelModal, {
width: '500px',
height: '500px'
})
}
closeDialog() {
this.dialogRef.close()
}
onFileSelected(event: any) { onFileSelected(event: any) {
this.selectedFile = event.target.files.length > 0 ? event.target.files[0] : null; this.selectedFile = event.target.files.length > 0 ? event.target.files[0] : null;
this.selectedFileName = this.selectedFile?.name || "กรุณาเลือกไฟล์" this.selectedFileName = this.selectedFile?.name || "กรุณาเลือกไฟล์"
...@@ -132,11 +148,20 @@ export class EmployeeLevel implements OnInit { ...@@ -132,11 +148,20 @@ export class EmployeeLevel implements OnInit {
} }
addPL() { addPL() {
this.pl.loading = true Swal.fire({
this.plService.post(this.pl.select).subscribe({ icon: 'warning',
next: response => { title: 'แจ้งเตือน',
if (response.success) { text: 'คุณต้องการบันทึกข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ยืนยัน',
}).then((result) => {
if (result.isConfirmed) {
this.pl.loading = true
this.plService.post(this.pl.select).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success') this.showAlert(response.message, 'success')
this.closeDialog()
this.getPLList() this.getPLList()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
...@@ -146,12 +171,26 @@ export class EmployeeLevel implements OnInit { ...@@ -146,12 +171,26 @@ export class EmployeeLevel implements OnInit {
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.pl.loading = true this.pl.loading = true
this.cdr.detectChanges() this.cdr.detectChanges()
}
})
} }
}) })
} }
deletePL() { deletePL() {
if (this.numSelectItem() == 0) {
this.showAlert('กรุณาเลือกข้อมูลที่จะลบ', 'error')
return
}
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการลบข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ลบข้อมูล',
}).then((result) => {
if (result.isConfirmed) {
this.pl.loading = true this.pl.loading = true
const selectedKeys = Array.from(this.selectedItems.data.keys()); const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.pl.dataList.filter(x => selectedKeys.includes(x.plId) && this.selectedItems.data.get(x.plId)).map(x => new MyPLModel(x)) const body = this.pl.dataList.filter(x => selectedKeys.includes(x.plId) && this.selectedItems.data.get(x.plId)).map(x => new MyPLModel(x))
...@@ -169,15 +208,20 @@ export class EmployeeLevel implements OnInit { ...@@ -169,15 +208,20 @@ export class EmployeeLevel implements OnInit {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.pl.loading = true this.pl.loading = true
this.cdr.detectChanges() this.cdr.detectChanges()
}
})
} }
}) })
} }
showAlert(text: string, type: 'success' | 'error') { showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', { Swal.fire({
timeOut: 3000, icon: type,
positionClass: 'toast-top-right', title: 'แจ้งเตือน',
}); text: text,
showCancelButton: false,
confirmButtonText: 'ยืนยัน',
})
} }
......
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