Commit 14e5a470 by Nattana Chaiyamat

การจัดการข้อมูลองค์กร > ข้อมูลลักษณะงาน

การจัดการข้อมูลองค์กร > ตั้งค่าผู้ใช้งาน
parent ca6384bb
...@@ -28,13 +28,17 @@ ...@@ -28,13 +28,17 @@
</a> </a>
</nav> </nav>
</div> </div>
<div class="mt-3 px-3rem !-mt-3 pt-50px"> <div class="mt-3 px-2rem !-mt-3 pt-50px">
<div *ngIf="currentPage==1" id="underline-1" role="tabpanel" aria-labelledby="underline-item-1"> <div *ngIf="currentPage==1" id="underline-1" role="tabpanel" aria-labelledby="underline-item-1">
<app-user-settings></app-user-settings> <app-user-settings></app-user-settings>
</div> </div>
<div *ngIf="currentPage==2" id="underline-2" class="hidden" role="tabpanel" <div *ngIf="currentPage==2" id="underline-2" class="hidden" role="tabpanel"
aria-labelledby="underline-item-2"> aria-labelledby="underline-item-2">
<app-set-a-password [pathTitle]="pathTitle" (sendPathTitle)="pathTitle=$event"></app-set-a-password> <app-set-a-password></app-set-a-password>
</div>
<div *ngIf="currentPage==3" id="underline-3" class="hidden" role="tabpanel"
aria-labelledby="underline-item-3">
จัดการผู้ใช้งาน
</div> </div>
</div> </div>
</div> </div>
......
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 { MyUserModel, UserModel } from 'src/app/shared/model/user.model';
import { FileService } from 'src/app/shared/services/file.service';
import { UserService } from 'src/app/shared/services/user.service';
export interface DataPassword {
usernameId: string,
empId: string,
companyId: string,
oldPassword: string,
newPassword: string,
}
@Component({ @Component({
selector: 'app-set-a-password', selector: 'app-set-a-password',
templateUrl: './set-a-password.component.html', templateUrl: './set-a-password.component.html',
styleUrls: ['./set-a-password.component.scss'] styleUrls: ['./set-a-password.component.scss']
}) })
export class SetAPasswordComponent { export class SetAPasswordComponent {
@Input() pathTitle = ['การจัดการข้อมูลองค์กร', 'ตั้งค่าผู้ใช้งาน', 'สร้างรหัสผู้ใช้งาน'] selectedFile: File | null = null;
@Output() sendPathTitle: EventEmitter<string[]> = new EventEmitter<string[]>(); selectedFileName: string = 'กรุณาเลือกไฟล์';
activeTab: string = 'tab1'; // กำหนด tab เริ่มต้น currentPage = 1
page = Array.from({ length: 1 }, (_, i) => i + 1);
companyId = ""
user: { loading: boolean, select: UserModel, dataList: { check: boolean, data: UserModel }[] } = { loading: false, select: new MyUserModel(), dataList: [] }
search = ""
// ฟังก์ชันในการเปลี่ยนแท็บ userPassword: DataPassword = {
changeTab(tab: { id: string, text: string }) { usernameId: "",
this.sendPathTitle.emit(['การจัดการข้อมูลองค์กร', 'ตั้งค่าผู้ใช้งาน', tab.text]) empId: "",
this.activeTab = tab.id; companyId: "",
oldPassword: "",
newPassword: "",
}
constructor(private toastr: ToastrService,
private cdr: ChangeDetectorRef,
private userService: UserService,
private fileService: FileService) {
this.companyId = this.decodeJWT(sessionStorage.getItem("accessToken") || '').companyid
}
ngOnInit(): void {
this.getUserList()
} }
modalOptions: {
[nameModal: string]: { // ชื่อตรวจสอบการเปิดปิด
isModalOpen: boolean; // เปิด/ปิด
modalSize: string; // ขนาดของ Modal (s,m,l,vw10-vw100 )
backdropClose: boolean; // (คลิก Backdrop แล้ว true ปิด false ไม่ปิด )
}
} = {
"add": {
isModalOpen: false,
modalSize: 'm',
backdropClose: true,
},
"edit": {
isModalOpen: false,
modalSize: 'm',
backdropClose: true,
}
}
constructor(private toastr: ToastrService) { }
openModal(name: string, size: string, closeOnBackdrop?: boolean) { decodeJWT(token: string) {
this.modalOptions[name].modalSize = size; let base64Url = token.split('.')[1]; // ดึงส่วนที่เป็น Payload
this.modalOptions[name].backdropClose = closeOnBackdrop || false; let base64 = base64Url.replace('-', '+').replace('_', '/'); // แก้ไข base64 ให้ถูกต้อง
this.modalOptions[name].isModalOpen = true; let jsonPayload = decodeURIComponent(atob(base64).split('').map(function (c) {
document.body.style.overflow = 'hidden'; // ล็อก Scroll return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
return JSON.parse(jsonPayload);
} }
closeModal(name: string) {
this.modalOptions[name].isModalOpen = false; getUserList() {
// ตรวจสอบว่ามี Modal อื่นเปิดอยู่หรือไม่ this.user.loading = true
if (!this.isAnyModalOpen()) { this.userService.getList().subscribe({
document.body.style.overflow = ''; // คืนค่าการ Scroll เฉพาะเมื่อ Modal ทั้งหมดปิดแล้ว next: response => {
this.user.dataList = response.map(x => ({ check: false, data: new MyUserModel(x) }))
this.user.loading = false
this.searchChange()
this.cdr.detectChanges()
}, error: error => {
this.user.loading = false
this.cdr.detectChanges()
}
})
}
userListFilter() {
return this.user.dataList.filter(x => {
const data = x.data
const match = data.usernameId.toLowerCase().includes(this.search.toLowerCase()) ||
data.empId.toLowerCase().includes(this.search.toLowerCase()) ||
data.employee.thFullName.toLowerCase().includes(this.search.toLowerCase())
return match
})
}
selectUser(data?: UserModel) {
this.user.select = new MyUserModel({ ...data, companyId: data?.companyId || this.companyId, status: data?.status || '0' })
this.userPassword = {
usernameId: this.user.select.usernameId,
empId: this.user.select.empId,
companyId: this.user.select.companyId,
oldPassword: "",
newPassword: "",
}
}
onFileSelected(event: any) {
this.selectedFile = event.target.files.length > 0 ? event.target.files[0] : null;
this.selectedFileName = this.selectedFile?.name || "กรุณาเลือกไฟล์"
}
uploadFile() {
if (!this.selectedFile) {
alert('กรุณาเลือกไฟล์ก่อนอัปโหลด')
return
} }
const formData = new FormData();
formData.append('file', this.selectedFile);
this.user.loading = true
this.fileService.upload(formData, 'mbu1').subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getUserList()
} else {
this.showAlert(response.message, 'error')
this.user.loading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.user.loading = false
}
})
} }
downloadFile() {
const fileName = 'IMPORT_USER.xlsx'
this.fileService.download(fileName).subscribe({
next: response => {
const url = window.URL.createObjectURL(response);
const a = document.createElement("a");
a.href = url;
a.download = fileName;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, error: error => {
this.showAlert(error.message, 'error')
}
})
isAnyModalOpen(): boolean {
// Logic ตรวจสอบว่า Modal อื่นยังเปิดอยู่หรือไม่
return Object.values(this.modalOptions).some(modal => modal.isModalOpen); // หากไม่มี Modal อื่นเปิด
} }
showSuccessAdd() {
this.toastr.success('บันทึกข้อมูลสำเร็จ', 'แจ้งเตือน', {
timeOut: 3000, updateUserPassword() {
positionClass: 'toast-top-right', this.user.loading = true
}); this.userService.changePassword(this.userPassword).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getUserList()
this.searchChange()
} else {
this.showAlert(response.message, 'error')
this.user.loading = false
}
this.cdr.detectChanges()
}, error: error => {
this.showAlert(error.message, 'error')
this.user.loading = false
this.cdr.detectChanges()
}
})
} }
showSuccessEdit() { searchChange() {
this.toastr.success('แก้ไขข้อมูลสำเร็จ', 'แจ้งเตือน', { this.currentPage = 1
timeOut: 3000, this.page = Array.from({ length: Math.ceil(this.userListFilter().length / 10) }, (_, i) => i + 1);
positionClass: 'toast-top-right',
});
} }
showSuccessDelete() { selectDataModal(target: { [key: string]: any }, field: string, data: any) {
this.toastr.success('ลบข้อมูลสำเร็จ', 'แจ้งเตือน', { target[field] = JSON.parse(JSON.stringify(data))
}
showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', {
timeOut: 3000, timeOut: 3000,
positionClass: 'toast-top-right', positionClass: 'toast-top-right',
}); })
} }
}
} \ No newline at end of file
...@@ -16,16 +16,6 @@ export interface DataModel { ...@@ -16,16 +16,6 @@ export interface DataModel {
styleUrls: ['./employee-categories.component.scss'] styleUrls: ['./employee-categories.component.scss']
}) })
export class EmployeeCategories { export class EmployeeCategories {
@Input() pathTitle = ['การจัดการข้อมูลองค์กร', 'ข้อมูลลักษณะงาน', 'กลุ่มพนักงาน']
@Output() sendPathTitle: EventEmitter<string[]> = new EventEmitter<string[]>();
activeTab: string = 'tab1'; // กำหนด tab เริ่มต้น
// ฟังก์ชันในการเปลี่ยนแท็บ
changeTab(tab: { id: string, text: string }) {
this.sendPathTitle.emit(['การจัดการข้อมูลองค์กร', 'ข้อมูลลักษณะงาน', tab.text])
this.activeTab = tab.id;
}
currentPage = 1 currentPage = 1
page = Array.from({ length: 1 }, (_, i) => i + 1); page = Array.from({ length: 1 }, (_, i) => i + 1);
search = "" search = ""
...@@ -39,6 +29,9 @@ export class EmployeeCategories { ...@@ -39,6 +29,9 @@ export class EmployeeCategories {
selectedFile: File | null = null; selectedFile: File | null = null;
selectedFileName: string = 'กรุณาเลือกไฟล์'; selectedFileName: string = 'กรุณาเลือกไฟล์';
numDataListChecked = 0
isDataListChecked = false
isDataListCheckedAll = false
constructor(private empTypeService: EmpTypeService, constructor(private empTypeService: EmpTypeService,
private toastr: ToastrService, private toastr: ToastrService,
private cdr: ChangeDetectorRef, private cdr: ChangeDetectorRef,
...@@ -59,6 +52,7 @@ export class EmployeeCategories { ...@@ -59,6 +52,7 @@ export class EmployeeCategories {
return return
} }
const formData = new FormData(); const formData = new FormData();
this.dataLoading = true
formData.append('file', this.selectedFile); formData.append('file', this.selectedFile);
this.fileService.upload(formData, 'employment_type').subscribe({ this.fileService.upload(formData, 'employment_type').subscribe({
next: response => { next: response => {
...@@ -67,9 +61,13 @@ export class EmployeeCategories { ...@@ -67,9 +61,13 @@ export class EmployeeCategories {
this.getEmpTypeList() this.getEmpTypeList()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.dataLoading = false
this.cdr.detectChanges();
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.dataLoading = false
this.cdr.detectChanges();
} }
}) })
} }
...@@ -99,6 +97,8 @@ export class EmployeeCategories { ...@@ -99,6 +97,8 @@ export class EmployeeCategories {
next: response => { next: response => {
this.emp_typelist = response.map(x => ({ check: false, data: { codeId: x.codeId, tdesc: x.tdesc, edesc: x.edesc, companyId: x.companyId } })) this.emp_typelist = response.map(x => ({ check: false, data: { codeId: x.codeId, tdesc: x.tdesc, edesc: x.edesc, companyId: x.companyId } }))
this.dataLoading = false this.dataLoading = false
this.isDataListCheckedAll = false
this.dataListCheckAll()
this.searchChange(); this.searchChange();
this.cdr.detectChanges(); this.cdr.detectChanges();
}, error: error => { }, error: error => {
...@@ -112,11 +112,12 @@ export class EmployeeCategories { ...@@ -112,11 +112,12 @@ export class EmployeeCategories {
searchChange() { searchChange() {
this.currentPage = 1 this.currentPage = 1
this.page = Array.from({ length: Math.ceil(this.emp_typeListFilter().length / 10) }, (_, i) => i + 1); this.page = Array.from({ length: Math.ceil(this.emp_typeListFilter().length / 10) }, (_, i) => i + 1);
this.dataListCheck()
} }
emp_typeListFilter() { emp_typeListFilter() {
return this.emp_typelist.filter(x => { return this.emp_typelist.filter(x => {
const data = x.data const data = x.data
const match = data.codeId.toLowerCase().includes(this.search) || data.tdesc.toLowerCase().includes(this.search) || data.edesc.toLowerCase().includes(this.search); const match = data.codeId.toLowerCase().includes(this.search.toLowerCase()) || data.tdesc.toLowerCase().includes(this.search.toLowerCase()) || data.edesc.toLowerCase().includes(this.search.toLowerCase());
return match; return match;
}); });
} }
...@@ -126,6 +127,7 @@ export class EmployeeCategories { ...@@ -126,6 +127,7 @@ export class EmployeeCategories {
addEmp_type() { addEmp_type() {
const body = new MyEmpTypeModel({ codeId: this.dataSelect.codeId, tdesc: this.dataSelect.tdesc, edesc: this.dataSelect.edesc, companyId: this.dataSelect.companyId }) const body = new MyEmpTypeModel({ codeId: this.dataSelect.codeId, tdesc: this.dataSelect.tdesc, edesc: this.dataSelect.edesc, companyId: this.dataSelect.companyId })
this.dataLoading = true
this.empTypeService.post(body).subscribe({ this.empTypeService.post(body).subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
...@@ -133,9 +135,13 @@ export class EmployeeCategories { ...@@ -133,9 +135,13 @@ export class EmployeeCategories {
this.getEmpTypeList() this.getEmpTypeList()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.dataLoading = false
this.cdr.detectChanges()
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.dataLoading = false
this.cdr.detectChanges()
} }
}) })
} }
...@@ -147,6 +153,7 @@ export class EmployeeCategories { ...@@ -147,6 +153,7 @@ export class EmployeeCategories {
} else { } else {
body = this.emp_typelist.filter(x => x.check).map(x => new MyEmpTypeModel({ codeId: x.data.codeId, tdesc: x.data.tdesc, edesc: x.data.edesc, companyId: x.data.companyId })) body = this.emp_typelist.filter(x => x.check).map(x => new MyEmpTypeModel({ codeId: x.data.codeId, tdesc: x.data.tdesc, edesc: x.data.edesc, companyId: x.data.companyId }))
} }
this.dataLoading = true
this.empTypeService.delete(body).subscribe({ this.empTypeService.delete(body).subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
...@@ -154,9 +161,13 @@ export class EmployeeCategories { ...@@ -154,9 +161,13 @@ export class EmployeeCategories {
this.getEmpTypeList() this.getEmpTypeList()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.dataLoading = false
this.cdr.detectChanges()
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.dataLoading = false
this.cdr.detectChanges()
} }
}) })
} }
...@@ -167,4 +178,32 @@ export class EmployeeCategories { ...@@ -167,4 +178,32 @@ export class EmployeeCategories {
positionClass: 'toast-top-right', positionClass: 'toast-top-right',
}); });
} }
dataListCheckAll() {
const selectAll = this.isDataListCheckedAll;
this.emp_typelist.filter(x => {
const data = x.data
const match = data.codeId.toLowerCase().includes(this.search.toLowerCase()) || data.tdesc.toLowerCase().includes(this.search.toLowerCase()) || data.edesc.toLowerCase().includes(this.search.toLowerCase());
return match;
}).forEach(x => x.check = selectAll);
this.dataListCheck();
}
dataListCheck() {
const dataCheck = this.emp_typeListFilter();
this.isDataListCheckedAll = dataCheck.length ? dataCheck.every(x => x.check) : false;
this.numDataListChecked = this.emp_typelist.filter(x => x.check).length;
this.isDataListChecked = Boolean(this.numDataListChecked)
}
clearEmp_type(modalStatus: string) {
if (modalStatus == 'add') {
this.dataSelect.codeId = ''
this.dataSelect.tdesc = ''
this.dataSelect.edesc = ''
} else if (modalStatus == 'edit') {
this.dataSelect.tdesc = ''
this.dataSelect.edesc = ''
}
}
} }
...@@ -17,19 +17,9 @@ export interface DataModel { ...@@ -17,19 +17,9 @@ export interface DataModel {
styleUrls: ['./employee-group-unit.component.scss'] styleUrls: ['./employee-group-unit.component.scss']
}) })
export class EmployeeGroupUnit implements OnInit { export class EmployeeGroupUnit implements OnInit {
@Input() pathTitle = ['การจัดการข้อมูลองค์กร', 'ข้อมูลลักษณะงาน', 'กลุ่มพนักงาน']
@Output() sendPathTitle: EventEmitter<string[]> = new EventEmitter<string[]>();
activeTab: string = 'tab1'; // กำหนด tab เริ่มต้น
// ฟังก์ชันในการเปลี่ยนแท็บ
changeTab(tab: { id: string, text: string }) {
this.sendPathTitle.emit(['การจัดการข้อมูลองค์กร', 'ข้อมูลลักษณะงาน', tab.text])
this.activeTab = tab.id;
}
currentPage = 1 currentPage = 1
selectedItems: string[] = []; selectedItems: string[] = [];
modalStatus = 'add' modalStatus: 'add' | 'edit' | 'delete' | 'deleteGroup' = 'add'
page = Array.from({ length: 1 }, (_, i) => i + 1); page = Array.from({ length: 1 }, (_, i) => i + 1);
dataLoading = false dataLoading = false
dataSelect: DataModel = { groupId: "", tdesc: "", edesc: "", companyId: "", checked: false } dataSelect: DataModel = { groupId: "", tdesc: "", edesc: "", companyId: "", checked: false }
...@@ -39,6 +29,9 @@ export class EmployeeGroupUnit implements OnInit { ...@@ -39,6 +29,9 @@ export class EmployeeGroupUnit implements OnInit {
selectedFile: File | null = null; selectedFile: File | null = null;
selectedFileName: string = 'กรุณาเลือกไฟล์'; selectedFileName: string = 'กรุณาเลือกไฟล์';
numDataListChecked = 0
isDataListChecked = false
isDataListCheckedAll = false
constructor(private empGroupService: EmpGroupService, constructor(private empGroupService: EmpGroupService,
private toastr: ToastrService, private toastr: ToastrService,
private cdr: ChangeDetectorRef, private cdr: ChangeDetectorRef,
...@@ -61,6 +54,7 @@ export class EmployeeGroupUnit implements OnInit { ...@@ -61,6 +54,7 @@ export class EmployeeGroupUnit implements OnInit {
} }
const formData = new FormData(); const formData = new FormData();
formData.append('file', this.selectedFile); formData.append('file', this.selectedFile);
this.dataLoading = true
this.fileService.upload(formData, 'mgroup').subscribe({ this.fileService.upload(formData, 'mgroup').subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
...@@ -68,9 +62,11 @@ export class EmployeeGroupUnit implements OnInit { ...@@ -68,9 +62,11 @@ export class EmployeeGroupUnit implements OnInit {
this.getEmpGroupList() this.getEmpGroupList()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.dataLoading = false
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.dataLoading = false
} }
}) })
} }
...@@ -101,6 +97,8 @@ export class EmployeeGroupUnit implements OnInit { ...@@ -101,6 +97,8 @@ export class EmployeeGroupUnit implements OnInit {
this.emp_groupList = response.map(x => ({ check: false, data: { groupId: x.groupId, tdesc: x.tdesc, edesc: x.edesc, companyId: x.companyId, checked: false } })) this.emp_groupList = response.map(x => ({ check: false, data: { groupId: x.groupId, tdesc: x.tdesc, edesc: x.edesc, companyId: x.companyId, checked: false } }))
this.dataLoading = false this.dataLoading = false
this.searchChange() this.searchChange()
this.isDataListCheckedAll = false
this.dataListCheckAll()
this.cdr.detectChanges() this.cdr.detectChanges()
}, error: error => { }, error: error => {
this.dataLoading = false this.dataLoading = false
...@@ -112,11 +110,12 @@ export class EmployeeGroupUnit implements OnInit { ...@@ -112,11 +110,12 @@ export class EmployeeGroupUnit implements OnInit {
searchChange() { searchChange() {
this.currentPage = 1 this.currentPage = 1
this.page = Array.from({ length: Math.ceil(this.emp_groupListFilter().length / 10) }, (_, i) => i + 1); this.page = Array.from({ length: Math.ceil(this.emp_groupListFilter().length / 10) }, (_, i) => i + 1);
this.dataListCheck()
} }
emp_groupListFilter() { emp_groupListFilter() {
return this.emp_groupList.filter(x => { return this.emp_groupList.filter(x => {
const data = x.data const data = x.data
const match = data.groupId.toLowerCase().includes(this.search) || data.tdesc.toLowerCase().includes(this.search) || data.edesc.toLowerCase().includes(this.search); const match = data.groupId.toLowerCase().includes(this.search.toLowerCase()) || data.tdesc.toLowerCase().includes(this.search.toLowerCase()) || data.edesc.toLowerCase().includes(this.search.toLowerCase());
return match; return match;
}); });
} }
...@@ -126,6 +125,7 @@ export class EmployeeGroupUnit implements OnInit { ...@@ -126,6 +125,7 @@ export class EmployeeGroupUnit implements OnInit {
addEmp_group() { addEmp_group() {
const body = new MyEmpGroupModel({ groupId: this.dataSelect.groupId, tdesc: this.dataSelect.tdesc, edesc: this.dataSelect.edesc, companyId: this.dataSelect.companyId }) const body = new MyEmpGroupModel({ groupId: this.dataSelect.groupId, tdesc: this.dataSelect.tdesc, edesc: this.dataSelect.edesc, companyId: this.dataSelect.companyId })
this.dataLoading = true
this.empGroupService.post(body).subscribe({ this.empGroupService.post(body).subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
...@@ -133,20 +133,24 @@ export class EmployeeGroupUnit implements OnInit { ...@@ -133,20 +133,24 @@ export class EmployeeGroupUnit implements OnInit {
this.getEmpGroupList() this.getEmpGroupList()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.dataLoading = false
this.cdr.detectChanges()
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.dataLoading = false
this.cdr.detectChanges()
} }
}) })
} }
deleteEmp_group() { deleteEmp_group() {
let body: EmpGroupModel | EmpGroupModel[] = []; let body: EmpGroupModel | EmpGroupModel[] = [];
if (this.dataSelect.groupId) { if (this.dataSelect.groupId) {
body = new MyEmpGroupModel({groupId: this.dataSelect.groupId, tdesc: this.dataSelect.tdesc, edesc: this.dataSelect.edesc, companyId: this.dataSelect.companyId }); body = new MyEmpGroupModel({ groupId: this.dataSelect.groupId, tdesc: this.dataSelect.tdesc, edesc: this.dataSelect.edesc, companyId: this.dataSelect.companyId });
} else { } else {
body = this.emp_groupList.filter(x => x.check).map(x => new MyEmpGroupModel({ groupId: x.data.groupId, tdesc: x.data.tdesc, edesc: x.data.edesc, companyId: x.data.companyId })); body = this.emp_groupList.filter(x => x.check).map(x => new MyEmpGroupModel({ groupId: x.data.groupId, tdesc: x.data.tdesc, edesc: x.data.edesc, companyId: x.data.companyId }));
} }
this.dataLoading = true
this.empGroupService.delete(body).subscribe({ this.empGroupService.delete(body).subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
...@@ -154,28 +158,34 @@ export class EmployeeGroupUnit implements OnInit { ...@@ -154,28 +158,34 @@ export class EmployeeGroupUnit implements OnInit {
this.getEmpGroupList(); this.getEmpGroupList();
} else { } else {
this.showAlert(response.message, 'error'); this.showAlert(response.message, 'error');
this.dataLoading = false
this.cdr.detectChanges()
} }
}, },
error: error => { error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.dataLoading = false
this.cdr.detectChanges()
} }
}); });
} }
toggleSelectAll(event: Event) { dataListCheckAll() {
const checked = (event.target as HTMLInputElement).checked; const selectAll = this.isDataListCheckedAll;
this.emp_groupList.filter(x => {
this.emp_groupList.forEach(item => { const data = x.data
item.check = checked; // อัปเดตค่า check ใน emp_groupList const match = data.groupId.toLowerCase().includes(this.search.toLowerCase()) || data.tdesc.toLowerCase().includes(this.search.toLowerCase()) || data.edesc.toLowerCase().includes(this.search.toLowerCase());
}); return match;
}).forEach(x => x.check = selectAll);
// อัปเดตรายการ selectedItems ด้วย groupId ของรายการที่ถูกเลือก this.dataListCheck();
this.selectedItems = checked ? this.emp_groupList.map(item => item.data.groupId) : [];
this.cdr.detectChanges(); // แจ้ง Angular ให้รีเฟรช UI
} }
dataListCheck() {
const dataCheck = this.emp_groupListFilter();
this.isDataListCheckedAll = dataCheck.length ? dataCheck.every(x => x.check) : false;
this.numDataListChecked = this.emp_groupList.filter(x => x.check).length;
this.isDataListChecked = Boolean(this.numDataListChecked)
}
showAlert(text: string, type: 'success' | 'error') { showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', { this.toastr[type](text, 'แจ้งเตือน', {
...@@ -183,4 +193,15 @@ export class EmployeeGroupUnit implements OnInit { ...@@ -183,4 +193,15 @@ export class EmployeeGroupUnit implements OnInit {
positionClass: 'toast-top-right', positionClass: 'toast-top-right',
}) })
} }
clearEmp_group(modalStatus: string) {
if (modalStatus == 'add') {
this.dataSelect.groupId = ''
this.dataSelect.tdesc = ''
this.dataSelect.edesc = ''
} else if (modalStatus == 'edit') {
this.dataSelect.tdesc = ''
this.dataSelect.edesc = ''
}
}
} }
...@@ -16,15 +16,6 @@ export interface DataModel { ...@@ -16,15 +16,6 @@ export interface DataModel {
styleUrls: ['./employee-level.component.scss'] styleUrls: ['./employee-level.component.scss']
}) })
export class EmployeeLevel implements OnInit { export class EmployeeLevel implements OnInit {
@Input() pathTitle = ['การจัดการข้อมูลองค์กร', 'ข้อมูลลักษณะงาน', 'กลุ่มพนักงาน']
@Output() sendPathTitle: EventEmitter<string[]> = new EventEmitter<string[]>();
activeTab: string = 'tab1'; // กำหนด tab เริ่มต้น
// ฟังก์ชันในการเปลี่ยนแท็บ
changeTab(tab: { id: string, text: string }) {
this.sendPathTitle.emit(['การจัดการข้อมูลองค์กร', 'ข้อมูลลักษณะงาน', tab.text])
this.activeTab = tab.id;
}
currentPage = 1 currentPage = 1
page = Array.from({ length: 1 }, (_, i) => i + 1); page = Array.from({ length: 1 }, (_, i) => i + 1);
search = "" search = ""
...@@ -38,6 +29,10 @@ export class EmployeeLevel implements OnInit { ...@@ -38,6 +29,10 @@ export class EmployeeLevel implements OnInit {
selectedFile: File | null = null; selectedFile: File | null = null;
selectedFileName: string = 'กรุณาเลือกไฟล์'; selectedFileName: string = 'กรุณาเลือกไฟล์';
numDataListChecked = 0
isDataListChecked = false
isDataListCheckedAll = false
constructor(private plService: PLService, constructor(private plService: PLService,
private toastr: ToastrService, private toastr: ToastrService,
private cdr: ChangeDetectorRef, private cdr: ChangeDetectorRef,
...@@ -60,6 +55,7 @@ export class EmployeeLevel implements OnInit { ...@@ -60,6 +55,7 @@ export class EmployeeLevel implements OnInit {
} }
const formData = new FormData(); const formData = new FormData();
formData.append('file', this.selectedFile); formData.append('file', this.selectedFile);
this.dataLoading = true
this.fileService.upload(formData, 'pl').subscribe({ this.fileService.upload(formData, 'pl').subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
...@@ -67,9 +63,13 @@ export class EmployeeLevel implements OnInit { ...@@ -67,9 +63,13 @@ export class EmployeeLevel implements OnInit {
this.getPLList() this.getPLList()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.dataLoading = false
this.cdr.detectChanges()
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.dataLoading = false
this.cdr.detectChanges()
} }
}) })
} }
...@@ -99,6 +99,8 @@ export class EmployeeLevel implements OnInit { ...@@ -99,6 +99,8 @@ export class EmployeeLevel implements OnInit {
next: response => { next: response => {
this.plList = response.map(x => ({ check: false, data: { plId: x.plId, tdesc: x.tdesc, edesc: x.edesc, companyId: x.companyId } })) this.plList = response.map(x => ({ check: false, data: { plId: x.plId, tdesc: x.tdesc, edesc: x.edesc, companyId: x.companyId } }))
this.dataLoading = false this.dataLoading = false
this.isDataListCheckedAll = false
this.dataListCheckAll()
this.searchChange(); this.searchChange();
this.cdr.detectChanges(); this.cdr.detectChanges();
}, error: error => { }, error: error => {
...@@ -112,12 +114,14 @@ export class EmployeeLevel implements OnInit { ...@@ -112,12 +114,14 @@ export class EmployeeLevel implements OnInit {
searchChange() { searchChange() {
this.currentPage = 1 this.currentPage = 1
this.page = Array.from({ length: Math.ceil(this.plListFilter().length / 10) }, (_, i) => i + 1); this.page = Array.from({ length: Math.ceil(this.plListFilter().length / 10) }, (_, i) => i + 1);
this.dataListCheck();
this.cdr.detectChanges()
} }
plListFilter() { plListFilter() {
return this.plList.filter(x => { return this.plList.filter(x => {
const data = x.data const data = x.data
const match = data.plId.toLowerCase().includes(this.search) || data.tdesc.toLowerCase().includes(this.search) || data.edesc.toLowerCase().includes(this.search); const match = data.plId.toLowerCase().includes(this.search.toLowerCase()) || data.tdesc.toLowerCase().includes(this.search.toLowerCase()) || data.edesc.toLowerCase().includes(this.search.toLowerCase());
return match; return match;
}); });
} }
...@@ -128,6 +132,7 @@ export class EmployeeLevel implements OnInit { ...@@ -128,6 +132,7 @@ export class EmployeeLevel implements OnInit {
addPL() { addPL() {
const body = new MyPLModel({ plId: this.dataSelect.plId, tdesc: this.dataSelect.tdesc, edesc: this.dataSelect.edesc, companyId: this.dataSelect.companyId }) const body = new MyPLModel({ plId: this.dataSelect.plId, tdesc: this.dataSelect.tdesc, edesc: this.dataSelect.edesc, companyId: this.dataSelect.companyId })
this.dataLoading = true
this.plService.post(body).subscribe({ this.plService.post(body).subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
...@@ -135,9 +140,13 @@ export class EmployeeLevel implements OnInit { ...@@ -135,9 +140,13 @@ export class EmployeeLevel implements OnInit {
this.getPLList() this.getPLList()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.dataLoading = true
this.cdr.detectChanges()
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.dataLoading = true
this.cdr.detectChanges()
} }
}) })
} }
...@@ -149,6 +158,7 @@ export class EmployeeLevel implements OnInit { ...@@ -149,6 +158,7 @@ export class EmployeeLevel implements OnInit {
} else { } else {
body = this.plList.filter(x => x.check).map(x => new MyPLModel({ plId: x.data.plId, tdesc: x.data.tdesc, edesc: x.data.edesc, companyId: x.data.companyId })) body = this.plList.filter(x => x.check).map(x => new MyPLModel({ plId: x.data.plId, tdesc: x.data.tdesc, edesc: x.data.edesc, companyId: x.data.companyId }))
} }
this.dataLoading = true
this.plService.delete(body).subscribe({ this.plService.delete(body).subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
...@@ -156,9 +166,13 @@ export class EmployeeLevel implements OnInit { ...@@ -156,9 +166,13 @@ export class EmployeeLevel implements OnInit {
this.getPLList() this.getPLList()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.dataLoading = true
this.cdr.detectChanges()
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.dataLoading = true
this.cdr.detectChanges()
} }
}) })
} }
...@@ -169,4 +183,32 @@ export class EmployeeLevel implements OnInit { ...@@ -169,4 +183,32 @@ export class EmployeeLevel implements OnInit {
positionClass: 'toast-top-right', positionClass: 'toast-top-right',
}); });
} }
dataListCheckAll() {
const selectAll = this.isDataListCheckedAll;
this.plList.filter(x => {
const data = x.data
const match = data.plId.toLowerCase().includes(this.search.toLowerCase()) || data.tdesc.toLowerCase().includes(this.search.toLowerCase()) || data.edesc.toLowerCase().includes(this.search.toLowerCase());
return match;
}).forEach(x => x.check = selectAll);
this.dataListCheck();
}
dataListCheck() {
const dataCheck = this.plListFilter();
this.isDataListCheckedAll = dataCheck.length ? dataCheck.every(x => x.check) : false;
this.numDataListChecked = this.plList.filter(x => x.check).length
this.isDataListChecked = Boolean(this.numDataListChecked)
}
clearPl(modalStatus: string) {
if (modalStatus == 'add') {
this.dataSelect.plId = ''
this.dataSelect.tdesc = ''
this.dataSelect.edesc = ''
} else if (modalStatus == 'edit') {
this.dataSelect.tdesc = ''
this.dataSelect.edesc = ''
}
}
} }
...@@ -10,44 +10,56 @@ ...@@ -10,44 +10,56 @@
<nav class="-mb-0.5 flex space-x-6 rtl:space-x-reverse"> <nav class="-mb-0.5 flex space-x-6 rtl:space-x-reverse">
<a class="text-base font-medium hs-tab-active:text-lg hs-tab-active:font-bold hs-tab-active:border-secondary hs-tab-active:text-secondary pb-3 inline-flex items-center gap-2 border-b-[3px] border-transparent whitespace-nowrap text-gray-500 dark:text-white/70 hover:text-secondary active" <a class="text-base font-medium hs-tab-active:text-lg hs-tab-active:font-bold hs-tab-active:border-secondary hs-tab-active:text-secondary pb-3 inline-flex items-center gap-2 border-b-[3px] border-transparent whitespace-nowrap text-gray-500 dark:text-white/70 hover:text-secondary active"
href="javascript:void(0);" id="underline-item-1" data-hs-tab="#underline-1" href="javascript:void(0);" id="underline-item-1" data-hs-tab="#underline-1"
aria-controls="underline-1" (click)="pathTitle = ['การจัดการข้อมูลองค์กร','ข้อมูลลักษณะงาน','กลุ่มพนักงาน']"> aria-controls="underline-1"
(click)="currentPath = 1;pathTitle = ['การจัดการข้อมูลองค์กร','ข้อมูลลักษณะงาน','กลุ่มพนักงาน']">
กลุ่มพนักงาน กลุ่มพนักงาน
</a> </a>
<a class="text-base font-medium hs-tab-active:text-lg hs-tab-active:font-bold hs-tab-active:border-secondary hs-tab-active:text-secondary pb-3 px-1 inline-flex items-center gap-2 border-b-[3px] border-transparent whitespace-nowrap text-gray-500 dark:text-white/70 hover:text-secondary" <a class="text-base font-medium hs-tab-active:text-lg hs-tab-active:font-bold hs-tab-active:border-secondary hs-tab-active:text-secondary pb-3 px-1 inline-flex items-center gap-2 border-b-[3px] border-transparent whitespace-nowrap text-gray-500 dark:text-white/70 hover:text-secondary"
href="javascript:void(0);" id="underline-item-2" data-hs-tab="#underline-2" href="javascript:void(0);" id="underline-item-2" data-hs-tab="#underline-2"
aria-controls="underline-2" (click)="pathTitle = ['การจัดการข้อมูลองค์กร','ข้อมูลลักษณะงาน','ตำเเหน่ง']"> aria-controls="underline-2"
(click)="currentPath = 2;pathTitle = ['การจัดการข้อมูลองค์กร','ข้อมูลลักษณะงาน','ตำเเหน่ง']">
ตำเเหน่ง ตำเเหน่ง
</a> </a>
<!-- <a class="text-base font-medium hs-tab-active:text-lg hs-tab-active:font-bold hs-tab-active:border-secondary hs-tab-active:text-secondary pb-3 px-1 inline-flex items-center gap-2 border-b-[3px] border-transparent whitespace-nowrap text-gray-500 dark:text-white/70 hover:text-secondary"
href="javascript:void(0);" id="underline-item-3" data-hs-tab="#underline-3"
aria-controls="underline-3"
(click)="currentPath = 3;pathTitle = ['การจัดการข้อมูลองค์กร','ข้อมูลลักษณะงาน','ลักษณะงาน']">
ลักษณะงาน
</a> -->
<a class="text-base font-medium hs-tab-active:text-lg hs-tab-active:font-bold hs-tab-active:border-secondary hs-tab-active:text-secondary pb-3 px-1 inline-flex items-center gap-2 border-b-[3px] border-transparent whitespace-nowrap text-gray-500 dark:text-white/70 hover:text-secondary" <a class="text-base font-medium hs-tab-active:text-lg hs-tab-active:font-bold hs-tab-active:border-secondary hs-tab-active:text-secondary pb-3 px-1 inline-flex items-center gap-2 border-b-[3px] border-transparent whitespace-nowrap text-gray-500 dark:text-white/70 hover:text-secondary"
href="javascript:void(0);" id="underline-item-4" data-hs-tab="#underline-4" href="javascript:void(0);" id="underline-item-4" data-hs-tab="#underline-4"
aria-controls="underline-4" (click)="pathTitle = ['การจัดการข้อมูลองค์กร','ข้อมูลลักษณะงาน','ประเภทพนักงาน']"> aria-controls="underline-4"
(click)="currentPath = 4;pathTitle = ['การจัดการข้อมูลองค์กร','ข้อมูลลักษณะงาน','ประเภทพนักงาน']">
ประเภทพนักงาน ประเภทพนักงาน
</a> </a>
<a class="text-base font-medium hs-tab-active:text-lg hs-tab-active:font-bold hs-tab-active:border-secondary hs-tab-active:text-secondary pb-3 px-1 inline-flex items-center gap-2 border-b-[3px] border-transparent whitespace-nowrap text-gray-500 dark:text-white/70 hover:text-secondary" <a class="text-base font-medium hs-tab-active:text-lg hs-tab-active:font-bold hs-tab-active:border-secondary hs-tab-active:text-secondary pb-3 px-1 inline-flex items-center gap-2 border-b-[3px] border-transparent whitespace-nowrap text-gray-500 dark:text-white/70 hover:text-secondary"
href="javascript:void(0);" id="underline-item-5" data-hs-tab="#underline-5" href="javascript:void(0);" id="underline-item-5" data-hs-tab="#underline-5"
aria-controls="underline-5" (click)="pathTitle = ['การจัดการข้อมูลองค์กร','ข้อมูลลักษณะงาน','ระดับพนักงาน (PL)']"> aria-controls="underline-5"
(click)="currentPath = 5;pathTitle = ['การจัดการข้อมูลองค์กร','ข้อมูลลักษณะงาน','ระดับพนักงาน (PL)']">
ระดับพนักงาน (PL) ระดับพนักงาน (PL)
</a> </a>
</nav> </nav>
</div> </div>
<div class="mt-3 px-3rem !-mt-3 pt-50px"> <div class="mt-3 px-2rem !-mt-3 pt-50px">
<div id="underline-1" role="tabpanel" aria-labelledby="underline-item-1" > <div *ngIf="currentPath == 1" id="underline-1" role="tabpanel" aria-labelledby="underline-item-1">
<app-employee-group-unit [pathTitle]="pathTitle" <app-employee-group-unit></app-employee-group-unit>
(sendPathTitle)="pathTitle=$event"></app-employee-group-unit>
</div> </div>
<div id="underline-2" class="hidden" role="tabpanel" aria-labelledby="underline-item-2"> <div *ngIf="currentPath == 2" id="underline-2" class="hidden" role="tabpanel"
<app-position-unit [pathTitle]="pathTitle" (sendPathTitle)="pathTitle=$event"></app-position-unit> aria-labelledby="underline-item-2">
<app-position-unit></app-position-unit>
</div> </div>
<div id="underline-3" class="hidden" role="tabpanel" aria-labelledby="underline-item-3"> <div *ngIf="currentPath == 3" id="underline-3" class="hidden" role="tabpanel"
aria-labelledby="underline-item-3">
ลักษณะงาน ลักษณะงาน
</div> </div>
<div id="underline-4" class="hidden" role="tabpanel" aria-labelledby="underline-item-4"> <div *ngIf="currentPath == 4" id="underline-4" class="hidden" role="tabpanel"
<app-employee-categories [pathTitle]="pathTitle" aria-labelledby="underline-item-4">
(sendPathTitle)="pathTitle=$event"></app-employee-categories> <app-employee-categories></app-employee-categories>
</div> </div>
<div id="underline-5" class="hidden" role="tabpanel" aria-labelledby="underline-item-5"> <div *ngIf="currentPath == 5" id="underline-5" class="hidden" role="tabpanel"
<app-employee-level [pathTitle]="pathTitle" (sendPathTitle)="pathTitle=$event"></app-employee-level> aria-labelledby="underline-item-5">
<app-employee-level></app-employee-level>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
\ No newline at end of file
...@@ -6,5 +6,6 @@ import { Component } from '@angular/core'; ...@@ -6,5 +6,6 @@ import { Component } from '@angular/core';
styleUrls: ['./job-description.component.scss'] styleUrls: ['./job-description.component.scss']
}) })
export class JobDescriptionComponent { export class JobDescriptionComponent {
pathTitle = ['การจัดการข้อมูลองค์กร','ข้อมูลลักษณะงาน', 'กลุ่มพนักงาน'] pathTitle = ['การจัดการข้อมูลองค์กร', 'ข้อมูลลักษณะงาน', 'กลุ่มพนักงาน']
currentPath = 1
} }
...@@ -18,15 +18,6 @@ export interface DataModel { ...@@ -18,15 +18,6 @@ export interface DataModel {
styleUrls: ['./position-unit.component.scss'] styleUrls: ['./position-unit.component.scss']
}) })
export class PositionUnitComponent implements OnInit { export class PositionUnitComponent implements OnInit {
@Input() pathTitle = ['การจัดการข้อมูลองค์กร', 'ข้อมูลลักษณะงาน', 'กลุ่มพนักงาน']
@Output() sendPathTitle: EventEmitter<string[]> = new EventEmitter<string[]>();
activeTab: string = 'tab1'; // กำหนด tab เริ่มต้น
// ฟังก์ชันในการเปลี่ยนแท็บ
changeTab(tab: { id: string, text: string }) {
this.sendPathTitle.emit(['การจัดการข้อมูลองค์กร', 'ข้อมูลลักษณะงาน', tab.text])
this.activeTab = tab.id;
}
currentPage = 1 currentPage = 1
selectedItems: string[] = []; selectedItems: string[] = [];
search = "" search = ""
...@@ -39,6 +30,9 @@ export class PositionUnitComponent implements OnInit { ...@@ -39,6 +30,9 @@ export class PositionUnitComponent implements OnInit {
dataLoading = false dataLoading = false
dataSelect: DataModel = { positionId: "", tdesc: "", edesc: "", consolidate: "", shortName: "", companyId: "" } dataSelect: DataModel = { positionId: "", tdesc: "", edesc: "", consolidate: "", shortName: "", companyId: "" }
numDataListChecked = 0
isDataListChecked = false
isDataListCheckedAll = false
constructor(private positionService: PositionService, constructor(private positionService: PositionService,
private toastr: ToastrService, private toastr: ToastrService,
private cdr: ChangeDetectorRef, private cdr: ChangeDetectorRef,
...@@ -60,6 +54,7 @@ export class PositionUnitComponent implements OnInit { ...@@ -60,6 +54,7 @@ export class PositionUnitComponent implements OnInit {
} }
const formData = new FormData(); const formData = new FormData();
formData.append('file', this.selectedFile); formData.append('file', this.selectedFile);
this.dataLoading = true
this.fileService.upload(formData, 'mposition').subscribe({ this.fileService.upload(formData, 'mposition').subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
...@@ -67,9 +62,13 @@ export class PositionUnitComponent implements OnInit { ...@@ -67,9 +62,13 @@ export class PositionUnitComponent implements OnInit {
this.getPositionList() this.getPositionList()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.dataLoading = false
this.cdr.detectChanges();
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.dataLoading = false
this.cdr.detectChanges();
} }
}) })
} }
...@@ -96,8 +95,10 @@ export class PositionUnitComponent implements OnInit { ...@@ -96,8 +95,10 @@ export class PositionUnitComponent implements OnInit {
this.dataLoading = true this.dataLoading = true
this.positionService.getList().subscribe({ this.positionService.getList().subscribe({
next: response => { next: response => {
this.positionList = response.map(x => ({ check: false, data: { positionId: x.positionId, tdesc: x.tdesc, edesc: x.edesc, consolidate: x.consolidate, shortName: x.shortName, companyId: x.companyId } })) this.positionList = response.map(x => new MyPositionModel(x)).map(x => ({ check: false, data: { positionId: x.positionId, tdesc: x.tdesc, edesc: x.edesc, consolidate: x.consolidate, shortName: x.shortName, companyId: x.companyId } }))
this.dataLoading = false this.dataLoading = false
this.isDataListCheckedAll = false
this.dataListCheckAll()
this.searchChange() this.searchChange()
this.cdr.detectChanges(); this.cdr.detectChanges();
}, error: error => { }, error: error => {
...@@ -110,28 +111,23 @@ export class PositionUnitComponent implements OnInit { ...@@ -110,28 +111,23 @@ export class PositionUnitComponent implements OnInit {
searchChange() { searchChange() {
this.currentPage = 1 this.currentPage = 1
this.page = Array.from({ length: Math.ceil(this.positionListFilter().length / 10) }, (_, i) => i + 1); this.page = Array.from({ length: Math.ceil(this.positionListFilter().length / 10) }, (_, i) => i + 1);
this.dataListCheck()
} }
positionListFilter() { positionListFilter() {
return this.positionList.filter(x => { return this.positionList.filter(x => {
const data = x.data; const data = x.data
const searchLower = this.search.toLowerCase(); const match = data.positionId.toLowerCase().includes(this.search.toLowerCase()) || data.tdesc.toLowerCase().includes(this.search.toLowerCase()) || data.edesc.toLowerCase().includes(this.search.toLowerCase());
return match;
return (
(data.positionId?.toLowerCase() || '').includes(searchLower) ||
(data.tdesc?.toLowerCase() || '').includes(searchLower) ||
(data.edesc?.toLowerCase() || '').includes(searchLower) ||
(data.consolidate?.toLowerCase() || '').includes(searchLower) ||
(data.shortName?.toLowerCase() || '').includes(searchLower)
);
}); });
} }
setData(data?: DataModel) { setData(data?: DataModel) {
this.dataSelect = JSON.parse(JSON.stringify(data || { positionId: "", tdesc: "", edesc: "", consolidate: "", shortName: "", companyId: "" })); this.dataSelect = JSON.parse(JSON.stringify(data || { positionId: "", tdesc: "", edesc: "", consolidate: "", shortName: "", companyId: "" }));
} }
addPosition() { addPosition() {
const body = new MyPositionModel({ positionId: this.dataSelect.positionId, tdesc: this.dataSelect.tdesc, edesc: this.dataSelect.edesc, consolidate: this.dataSelect.consolidate, shortName: this.dataSelect.shortName, companyId: this.dataSelect.companyId }) const body = new MyPositionModel({ positionId: this.dataSelect.positionId, tdesc: this.dataSelect.tdesc, edesc: this.dataSelect.edesc, consolidate: this.dataSelect.consolidate, shortName: this.dataSelect.shortName, companyId: this.dataSelect.companyId })
this.dataLoading = true
this.positionService.post(body).subscribe({ this.positionService.post(body).subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
...@@ -139,9 +135,13 @@ export class PositionUnitComponent implements OnInit { ...@@ -139,9 +135,13 @@ export class PositionUnitComponent implements OnInit {
this.getPositionList() this.getPositionList()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.dataLoading = false
this.cdr.detectChanges()
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.dataLoading = false
this.cdr.detectChanges()
} }
}) })
} }
...@@ -152,6 +152,7 @@ export class PositionUnitComponent implements OnInit { ...@@ -152,6 +152,7 @@ export class PositionUnitComponent implements OnInit {
} else { } else {
body = this.positionList.filter(x => x.check).map(x => new MyPositionModel({ positionId: x.data.positionId, tdesc: x.data.tdesc, edesc: x.data.edesc, consolidate: x.data.consolidate, shortName: x.data.shortName, companyId: x.data.companyId })) body = this.positionList.filter(x => x.check).map(x => new MyPositionModel({ positionId: x.data.positionId, tdesc: x.data.tdesc, edesc: x.data.edesc, consolidate: x.data.consolidate, shortName: x.data.shortName, companyId: x.data.companyId }))
} }
this.dataLoading = true
this.positionService.delete(body).subscribe({ this.positionService.delete(body).subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
...@@ -159,9 +160,13 @@ export class PositionUnitComponent implements OnInit { ...@@ -159,9 +160,13 @@ export class PositionUnitComponent implements OnInit {
this.getPositionList() this.getPositionList()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.dataLoading = false
this.cdr.detectChanges()
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.dataLoading = false
this.cdr.detectChanges()
} }
}) })
} }
...@@ -171,5 +176,33 @@ export class PositionUnitComponent implements OnInit { ...@@ -171,5 +176,33 @@ export class PositionUnitComponent implements OnInit {
positionClass: 'toast-top-right', positionClass: 'toast-top-right',
}); });
} }
dataListCheckAll() {
const selectAll = this.isDataListCheckedAll;
this.positionList.filter(x => {
const data = x.data
const match = data.positionId.toLowerCase().includes(this.search.toLowerCase()) || data.tdesc.toLowerCase().includes(this.search.toLowerCase()) || data.edesc.toLowerCase().includes(this.search.toLowerCase());
return match;
}).forEach(x => x.check = selectAll);
this.dataListCheck();
}
dataListCheck() {
const dataCheck = this.positionListFilter();
this.isDataListCheckedAll = dataCheck.length ? dataCheck.every(x => x.check) : false;
this.numDataListChecked = this.positionList.filter(x => x.check).length;
this.isDataListChecked = Boolean(this.numDataListChecked)
}
clearPosition(modalStatus: string) {
if (modalStatus == 'add') {
this.dataSelect.positionId = ''
this.dataSelect.tdesc = ''
this.dataSelect.edesc = ''
} else if (modalStatus == 'edit') {
this.dataSelect.tdesc = ''
this.dataSelect.edesc = ''
}
}
} }
...@@ -4,6 +4,7 @@ import { Observable } from 'rxjs'; ...@@ -4,6 +4,7 @@ import { Observable } from 'rxjs';
import { environment } from 'src/environments/environment'; import { environment } from 'src/environments/environment';
import { AlertModel } from '../model/alert.model'; import { AlertModel } from '../model/alert.model';
import { UserModel } from '../model/user.model'; import { UserModel } from '../model/user.model';
import { RoleModel } from '../model/role.model';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
...@@ -15,9 +16,24 @@ export class UserService { ...@@ -15,9 +16,24 @@ export class UserService {
getList(): Observable<UserModel[]> { getList(): Observable<UserModel[]> {
return this.http.get<UserModel[]>(this.urlApi + "/lists") return this.http.get<UserModel[]>(this.urlApi + "/lists")
} }
getRoleList(): Observable<RoleModel[]> {
return this.http.get<RoleModel[]>(this.urlApi + "/role/lists")
}
getLevelList(): Observable<RoleModel[]> {
return this.http.get<RoleModel[]>(this.urlApi + "/level/lists")
}
checkUser(username: string): Observable<AlertModel> { checkUser(username: string): Observable<AlertModel> {
return this.http.get<AlertModel>(this.urlApi + "/validate-username/" + username) return this.http.get<AlertModel>(this.urlApi + "/validate-username/" + username)
} }
changePassword(body: {
usernameId: string,
empId: string,
companyId: string,
oldPassword: string,
newPassword: string,
}): Observable<AlertModel> {
return this.http.post<AlertModel>(this.urlApi + "/change-password", body)
}
post(body: UserModel): Observable<AlertModel> { post(body: UserModel): Observable<AlertModel> {
return this.http.post<AlertModel>(this.urlApi + "/create", body) return this.http.post<AlertModel>(this.urlApi + "/create", body)
} }
...@@ -28,6 +44,6 @@ export class UserService { ...@@ -28,6 +44,6 @@ export class UserService {
}), }),
body: body body: body
}; };
return this.http.delete<AlertModel>(this.urlApi+'/delete', options) return this.http.delete<AlertModel>(this.urlApi + '/delete', options)
} }
} }
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