Commit f3407a40 by Nakarin Luankla

UPDATE เปลี่ยน modal ข้อมูลลักษณะงาน

parent 4ba38092
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 { EmpGroupModel, MyEmpGroupModel } from 'src/app/shared/model/emp-group.model'; import { EmpGroupModel, MyEmpGroupModel } from 'src/app/shared/model/emp-group.model';
import { EmpGroupService } from 'src/app/shared/services/emp-group.service'; import { EmpGroupService } from 'src/app/shared/services/emp-group.service';
import { FileService } from 'src/app/shared/services/file.service'; import { FileService } from 'src/app/shared/services/file.service';
import Swal from 'sweetalert2';
export interface DataModel { export interface DataModel {
groupId: string groupId: string
tdesc: string tdesc: string
...@@ -46,16 +48,28 @@ export class EmployeeGroupUnit implements OnInit { ...@@ -46,16 +48,28 @@ export class EmployeeGroupUnit implements OnInit {
}; };
search = '' search = ''
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("employeeGroupUnitModal") employeeGroupUnitModal: any;
dialogRef: any
constructor(private empGroupService: EmpGroupService, constructor(private empGroupService: EmpGroupService,
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.getEmpGroupList() this.getEmpGroupList()
} }
openDialog() {
this.dialogRef = this.dialog.open(this.employeeGroupUnitModal, {
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 || "กรุณาเลือกไฟล์"
...@@ -135,25 +149,51 @@ export class EmployeeGroupUnit implements OnInit { ...@@ -135,25 +149,51 @@ export class EmployeeGroupUnit implements OnInit {
} }
addEmp_group() { addEmp_group() {
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการบันทึกข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ยืนยัน',
}).then((result) => {
if (result.isConfirmed) {
this.emp_group.loading = true this.emp_group.loading = true
this.empGroupService.post(this.emp_group.select).subscribe({ this.empGroupService.post(this.emp_group.select).subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
this.showAlert(response.message, 'success') this.showAlert(response.message, 'success')
this.getEmpGroupList() this.getEmpGroupList()
this.closeDialog()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.emp_group.loading = false this.emp_group.loading = false
this.cdr.detectChanges() this.cdr.detectChanges()
this.closeDialog()
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.emp_group.loading = false this.emp_group.loading = false
this.cdr.detectChanges() this.cdr.detectChanges()
this.closeDialog()
}
})
} }
}) })
} }
deleteEmp_group() { deleteEmp_group() {
if (this.numSelectItem() == 0) {
this.showAlert('กรุณาเลือกข้อมูลที่จะลบ', 'error')
return
}
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการลบข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ลบข้อมูล',
}).then((result) => {
if (result.isConfirmed) {
this.emp_group.loading = true this.emp_group.loading = true
const selectedKeys = Array.from(this.selectedItems.data.keys()); const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.emp_group.dataList.filter(x => selectedKeys.includes(x.groupId) && this.selectedItems.data.get(x.groupId)).map(x => new MyEmpGroupModel(x)) const body = this.emp_group.dataList.filter(x => selectedKeys.includes(x.groupId) && this.selectedItems.data.get(x.groupId)).map(x => new MyEmpGroupModel(x))
...@@ -175,11 +215,16 @@ export class EmployeeGroupUnit implements OnInit { ...@@ -175,11 +215,16 @@ export class EmployeeGroupUnit implements OnInit {
} }
}); });
} }
});
}
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 { MyPositionModel, PositionModel } from 'src/app/shared/model/position.model'; import { MyPositionModel, PositionModel } from 'src/app/shared/model/position.model';
import { FileService } from 'src/app/shared/services/file.service'; import { FileService } from 'src/app/shared/services/file.service';
import { PositionService } from 'src/app/shared/services/position.service'; import { PositionService } from 'src/app/shared/services/position.service';
import Swal from 'sweetalert2';
@Component({ @Component({
selector: 'app-position-unit', selector: 'app-position-unit',
templateUrl: './position-unit.component.html', templateUrl: './position-unit.component.html',
...@@ -38,14 +40,27 @@ export class PositionUnitComponent implements OnInit { ...@@ -38,14 +40,27 @@ export class PositionUnitComponent implements OnInit {
}; };
search = '' search = ''
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("positionUnitModal") positionUnitModal: any;
dialogRef: any
constructor(private positionService: PositionService, constructor(private positionService: PositionService,
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.getPositionList() this.getPositionList()
} }
openDialog() {
this.dialogRef = this.dialog.open(this.positionUnitModal, {
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;
...@@ -128,25 +143,51 @@ export class PositionUnitComponent implements OnInit { ...@@ -128,25 +143,51 @@ export class PositionUnitComponent implements OnInit {
} }
addPosition() { addPosition() {
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการบันทึกข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ยืนยัน',
}).then((result) => {
if (result.isConfirmed) {
this.position.loading = true this.position.loading = true
this.positionService.post(this.position.select).subscribe({ this.positionService.post(this.position.select).subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
this.showAlert(response.message, 'success') this.showAlert(response.message, 'success')
this.getPositionList() this.getPositionList()
this.closeDialog()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.position.loading = false this.position.loading = false
this.cdr.detectChanges() this.cdr.detectChanges()
this.closeDialog()
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.position.loading = false this.position.loading = false
this.cdr.detectChanges() this.cdr.detectChanges()
this.closeDialog()
}
})
} }
}) })
} }
deletePosition() { deletePosition() {
if (this.numSelectItem() == 0) {
this.showAlert('กรุณาเลือกข้อมูลที่จะลบ', 'error')
return
}
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการลบข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ลบข้อมูล',
}).then((result) => {
if (result.isConfirmed) {
this.position.loading = true this.position.loading = true
const selectedKeys = Array.from(this.selectedItems.data.keys()); const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.position.dataList.filter(x => selectedKeys.includes(x.positionId) && this.selectedItems.data.get(x.positionId)).map(x => new MyPositionModel(x)) const body = this.position.dataList.filter(x => selectedKeys.includes(x.positionId) && this.selectedItems.data.get(x.positionId)).map(x => new MyPositionModel(x))
...@@ -167,11 +208,16 @@ export class PositionUnitComponent implements OnInit { ...@@ -167,11 +208,16 @@ export class PositionUnitComponent implements OnInit {
} }
}) })
} }
})
}
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