Commit 2f0cb762 by Nattana Chaiyamat

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

parents 94077098 49d037fa
import { Component, EventEmitter, Input, Output } from '@angular/core'; import { ChangeDetectorRef, Component, EventEmitter, Input, Output } from '@angular/core';
import { ToastrService } from 'ngx-toastr'; import { ToastrService } from 'ngx-toastr';
import { EmployeeModel, MyEmployeeModel } from 'src/app/shared/model/employee.model';
import { GroupApproveModel, MyGroupApproveModel } from 'src/app/shared/model/group-approve.model';
import { EmployeeService } from 'src/app/shared/services/employee.service';
import { GroupApproveService } from 'src/app/shared/services/group-approve.service';
interface table {
currentPage: number,
page: number[],
search: string
}
@Component({ @Component({
selector: 'app-set-approvers', selector: 'app-set-approvers',
...@@ -9,77 +18,155 @@ import { ToastrService } from 'ngx-toastr'; ...@@ -9,77 +18,155 @@ import { ToastrService } from 'ngx-toastr';
export class SetApproversComponent { export class SetApproversComponent {
@Input() pathTitle = ['การประเมินจัดประเมินสมรรถนะ', 'การจัดการสมรรถนะ', 'กำหนดผู้ประเมิน']; @Input() pathTitle = ['การประเมินจัดประเมินสมรรถนะ', 'การจัดการสมรรถนะ', 'กำหนดผู้ประเมิน'];
@Output() sendPathTitle: EventEmitter<string[]> = new EventEmitter<string[]>(); @Output() sendPathTitle: EventEmitter<string[]> = new EventEmitter<string[]>();
activeTab: string = 'tab1'; // กำหนด tab เริ่มต้น activeTab: string = 'tab1';
// ฟังก์ชันในการเปลี่ยนแท็บ
changeTab(tab: { id: string, text: string }) { changeTab(tab: { id: string, text: string }) {
this.sendPathTitle.emit(['การสมรรถนะจัดประเมินสมรรถนะ', 'การจัดการประเมิน', tab.text]); this.sendPathTitle.emit(['การสมรรถนะจัดประเมินสมรรถนะ', 'การจัดการประเมิน', tab.text]);
this.activeTab = tab.id; this.activeTab = tab.id;
} }
// การจัดการการเปิดปิด modal currentPage = 1
modalOptions: { page = Array.from({ length: 1 }, (_, i) => i + 1);
[nameModal: string]: { groupapprove_list: GroupApproveModel[] = []
isModalOpen: boolean; groupapprove_listLoading = false
modalSize: string; groupapprove: GroupApproveModel = new MyGroupApproveModel()
backdropClose: boolean; search = ""
};
} = { employee_list: EmployeeModel[] = []
"add": { employee_listLoading = false
isModalOpen: false, employee: EmployeeModel = new MyEmployeeModel({})
modalSize: 'm', employeeModal: table = {
backdropClose: true, currentPage: 1,
}, page: Array.from({ length: 1 }, (_, i) => i + 1),
"edit": { search: ""
isModalOpen: false, }
modalSize: 'm', empnumber = 0
backdropClose: true,
} currentModel: 'add' | 'edit' | 'delete' = "add"
}; constructor(private groupapproveService: GroupApproveService,
private toastr: ToastrService,
openModal(name: string, size: string, closeOnBackdrop?: boolean) { private cdr: ChangeDetectorRef,
this.modalOptions[name].modalSize = size; private employeeService: EmployeeService,
this.modalOptions[name].backdropClose = closeOnBackdrop || false; ) { }
this.modalOptions[name].isModalOpen = true; ngOnInit(): void {
this.currentModal = name; // ตั้งค่าค่าของ currentModal เป็น 'add' หรือ 'edit' this.getGroupapprove_list()
document.body.style.overflow = 'hidden'; this.getEemployeeList()
} }
closeModal(name: string) { getEemployeeList() {
this.modalOptions[name].isModalOpen = false; this.employee_listLoading = true
if (!this.isAnyModalOpen()) { this.employeeService.getList().subscribe({
document.body.style.overflow = ''; // คืนค่าการ Scroll เฉพาะเมื่อ Modal ทั้งหมดปิดแล้ว next: response => {
this.employee_list = response.map(x => {
return new MyEmployeeModel(x)
})
this.employee_listLoading = false
this.searchEMP()
this.cdr.detectChanges()
}, error: error => {
this.employee_listLoading = false
this.cdr.detectChanges()
} }
})
} }
employee_listFilter() {
isAnyModalOpen(): boolean { console.log(this.employee)
return Object.values(this.modalOptions).some(modal => modal.isModalOpen); // ตรวจสอบว่า modal อื่นยังเปิดอยู่หรือไม่ return this.employee_list.filter(x => x.fname.toLowerCase().includes(this.search.toLowerCase()) ||
x.lname.toLowerCase().includes(this.search.toLowerCase()))
} }
searchEMP() {
// ฟังก์ชัน toggle checkbox this.employeeModal.currentPage = 1
isChecked: boolean = false; // ใช้สำหรับตรวจสอบสถานะของ checkbox this.employeeModal.page = Array.from({ length: Math.ceil(this.employee_listFilter().length / 10) }, (_, i) => i + 1);
toggleCheckbox() {
this.isChecked = !this.isChecked; // สลับสถานะ
} }
empChange() {
// ฟังก์ชันสำหรับการเพิ่ม ลบ หรือแก้ไข ข้อมูล const employee = this.employee_list.find(x => x.employeeId == this.employee.employeeId)
addUser() { this.selectEMP(employee || new MyEmployeeModel({ employeeId: this.employee.employeeId }))
console.log('เพิ่มผู้ใช้งาน');
} }
selectEMP(employee?: EmployeeModel) {
deleteUser() { const data = new MyEmployeeModel(employee || {});
console.log('ลบผู้ใช้งาน'); if (this.empnumber == 1) {
this.groupapprove.apsapprove1 = data
} else if (this.empnumber == 2) {
this.groupapprove.apsapprove2 = data
} else if (this.empnumber == 3) {
this.groupapprove.apsapprove3 = data
} else if (this.empnumber == 4) {
this.groupapprove.apsapprove4 = data
} else if (this.empnumber == 5) {
this.groupapprove.apsapprove5 = data
} }
editUser() { }
console.log('แก้ไขผู้ใช้งาน'); getGroupapprove_list() {
this.groupapprove_listLoading = true
this.groupapproveService.getList().subscribe({
next: response => {
this.groupapprove_list = response.map(x => new MyGroupApproveModel(x))
this.groupapprove_listLoading = false
this.searchChange()
this.cdr.detectChanges()
}, error: error => {
this.groupapprove_listLoading = false
this.cdr.detectChanges()
}
})
}
searchChange() {
this.currentPage = 1
this.page = Array.from({ length: Math.ceil(this.groupapprove_listFilter().length / 10) }, (_, i) => i + 1);
}
groupapprove_listFilter() {
console.log(this.groupapprove)
return this.groupapprove_list.filter(x => x.apsapprove1.employeeId||x.apsapprove2.employeeId||x.apsapprove3.employeeId||x.apsapprove4.employeeId||x.apsapprove5.employeeId.toLowerCase().includes(this.search.toLowerCase()) ||
x.apsapprove1.fname || x.apsapprove1.lname.toLowerCase().includes(this.search.toLowerCase()) ||
x.apsapprove2.fname || x.apsapprove2.lname.toLowerCase().includes(this.search.toLowerCase()) ||
x.apsapprove3.fname || x.apsapprove3.lname.toLowerCase().includes(this.search.toLowerCase()) ||
x.apsapprove4.fname || x.apsapprove4.lname.toLowerCase().includes(this.search.toLowerCase()) ||
x.apsapprove5.fname || x.apsapprove5.lname.toLowerCase().includes(this.search.toLowerCase()))
} }
currentModal = ""; selectGroupapprove(groupapprove?: GroupApproveModel) {
this.groupapprove = new MyGroupApproveModel(groupapprove)
}
constructor(private toastr: ToastrService) { } showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', {
timeOut: 3000,
positionClass: 'toast-top-right',
})
}
addgroupapprove() {
this.groupapprove_listLoading = true
this.groupapproveService.post(this.groupapprove).subscribe({
next: response => {
if (response.success) {
this.getGroupapprove_list()
} else {
this.showAlert(response.message, 'error')
this.groupapprove_listLoading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.groupapprove_listLoading = false
}
})
}
deletegroupapprove() {
this.groupapprove_listLoading = true
this.groupapproveService.delete(this.groupapprove).subscribe({
next: response => {
if (response.success) {
this.getGroupapprove_list()
} else {
this.showAlert(response.message, 'error')
this.groupapprove_listLoading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.groupapprove_listLoading = false
}
})
}
showSuccess() { showSuccess() {
this.toastr.success('บันทึกข้อมูลสำเร็จ', 'เเจ้งเตือน', { this.toastr.success('บันทึกข้อมูลสำเร็จ', 'เเจ้งเตือน', {
......
...@@ -134,6 +134,7 @@ import { FileService } from 'src/app/shared/services/file.service'; ...@@ -134,6 +134,7 @@ import { FileService } from 'src/app/shared/services/file.service';
import { CompetencyGroupGradeService } from 'src/app/shared/services/competency-group-grade.service'; import { CompetencyGroupGradeService } from 'src/app/shared/services/competency-group-grade.service';
import { IndicatorsCoursesService } from 'src/app/shared/services/indicators-courses.service'; import { IndicatorsCoursesService } from 'src/app/shared/services/indicators-courses.service';
import { IdpDevelopmentService } from 'src/app/shared/services/idp-development.service'; import { IdpDevelopmentService } from 'src/app/shared/services/idp-development.service';
import { GroupApproveService } from 'src/app/shared/services/group-approve.service';
import { UserService } from 'src/app/shared/services/user.service'; import { UserService } from 'src/app/shared/services/user.service';
import { ManageUserComponent } from '../company-components/account-settings/manage-user/manage-user.component'; import { ManageUserComponent } from '../company-components/account-settings/manage-user/manage-user.component';
...@@ -301,6 +302,7 @@ export class CustomDateAdapter extends NativeDateAdapter { ...@@ -301,6 +302,7 @@ export class CustomDateAdapter extends NativeDateAdapter {
CompetencyGroupGradeService, CompetencyGroupGradeService,
IndicatorsCoursesService, IndicatorsCoursesService,
IdpDevelopmentService, IdpDevelopmentService,
GroupApproveService,
UserService, UserService,
{ {
provide: HTTP_INTERCEPTORS, provide: HTTP_INTERCEPTORS,
......
import { EmployeeModel, MyEmployeeModel } from "./employee.model";
import { MyPLModel, PLModel } from "./pl.model";
export interface GroupApproveModel {
personalLevel: PLModel;
apsassessy: EmployeeModel;
companyId: string;
apsapprove1: EmployeeModel;
apsapprove2: EmployeeModel;
apsapprove3: EmployeeModel;
apsapprove4: EmployeeModel;
apsapprove5: EmployeeModel;
}
export class MyGroupApproveModel implements GroupApproveModel {
personalLevel: PLModel;
apsassessy: EmployeeModel
companyId: string;
apsapprove1: EmployeeModel;
apsapprove2: EmployeeModel;
apsapprove3: EmployeeModel;
apsapprove4: EmployeeModel;
apsapprove5: EmployeeModel;
constructor(data: Partial<GroupApproveModel> = {}) {
this.personalLevel = new MyPLModel(data.personalLevel || {});
this.apsassessy = new MyEmployeeModel(data.apsassessy || {})
this.companyId = data.companyId || '';
this.apsapprove1 = new MyEmployeeModel(data.apsapprove1 || {});
this.apsapprove2 = new MyEmployeeModel(data.apsapprove2 || {});
this.apsapprove3 = new MyEmployeeModel(data.apsapprove3 || {});
this.apsapprove4 = new MyEmployeeModel(data.apsapprove4 || {});
this.apsapprove5 = new MyEmployeeModel(data.apsapprove5 || {});
}
}
\ No newline at end of file
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { environment } from 'src/environments/environment';
import { GroupApproveModel } from '../model/group-approve.model';
import { AlertModel } from '../model/alert.model';
@Injectable({
providedIn: 'root'
})
export class GroupApproveService {
api = "/group-approve"
urlApi = environment.baseUrl + this.api
constructor(private http: HttpClient) {
}
getByPersonalLevel(plId: string): Observable<GroupApproveModel> {
return this.http.get<GroupApproveModel>(this.urlApi + "/" + plId);
}
getList(): Observable<GroupApproveModel[]> {
return this.http.get<GroupApproveModel[]>(this.urlApi + "/lists")
}
post(body: GroupApproveModel): Observable<AlertModel> {
return this.http.post<AlertModel>(this.urlApi, body)
}
delete(body: GroupApproveModel) : Observable<AlertModel> {
const options = {
headers: new HttpHeaders({
"Content-Type": "application/json",
}),
body: body
};
return this.http.delete<AlertModel>(this.urlApi, options)
}
}
\ No newline at end of file
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