import { Component, EventEmitter, Input, Output } from '@angular/core'; import { ToastrService } from 'ngx-toastr'; export interface DataModel { check: boolean; code: string; tdesc: string; edesc: string; } @Component({ selector: 'app-grade-management', templateUrl: './grade-management.component.html', styleUrls: ['./grade-management.component.scss'], }) export class GradeManagementComponent { @Output() sendPathTitle: EventEmitter<string[]> = new EventEmitter<string[]>(); addTab = false; editTab = false; currentPage = 1; page = Array.from({ length: 1 }, (_, i) => i + 1); numDataListChecked = 0; isDataListChecked = false; isDataListCheckedAll = false; search = ''; dataList: DataModel[] = [ { check: false, code: '01', tdesc: 'กลุ่ม 1', edesc: 'Group 1' }, { check: false, code: '02', tdesc: 'กลุ่ม 2', edesc: 'Group 2' }, { check: false, code: '03', tdesc: 'กลุ่ม 3', edesc: 'Group 3' }, { check: false, code: '04', tdesc: 'กลุ่ม 4', edesc: 'Group 4' }, { check: false, code: '05', tdesc: 'กลุ่ม 5', edesc: 'Group 5' }, { check: false, code: '06', tdesc: 'กลุ่ม 6', edesc: 'Group 6' }, { check: false, code: '07', tdesc: 'กลุ่ม 7', edesc: 'Group 7' }, ]; dataSelect: DataModel = { check: false, code: '', tdesc: '', edesc: '' } constructor(private toastr: ToastrService) { this.pathTitleChange(); } pathTitleChange(data?: DataModel) { this.editTab = data ? true : false this.dataSelect = data || { check: false, code: '', tdesc: '', edesc: '' } this.sendPathTitle.emit( this.addTab ? ['การประเมินสมรรถนะ', 'ทะเบียนเกรด', 'การจัดการเกรด', 'เพิ่มกลุ่มเกรด'] : this.editTab ? ['การประเมินสมรรถนะ', 'ทะเบียนเกรด', 'การจัดการเกรด', 'แก้ไขกลุ่มเกรด'] : ['การประเมินสมรรถนะ', 'ทะเบียนเกรด', 'การจัดการเกรด'] ); } searchChange() { this.currentPage = 1; const filteredData = this.dataListFilter(); this.page = Array.from({ length: Math.ceil(filteredData.length / 10) }, (_, i) => i + 1); } dataListFilter() { return this.dataList.filter((x) => { const match = x.code.includes(this.search) || x.tdesc.includes(this.search); if (!match) x.check = false; return match; }); } dataListCheck() { const dataCheck = this.dataListFilter(); this.isDataListChecked = dataCheck.some((x) => x.check); this.isDataListCheckedAll = dataCheck.length ? dataCheck.every((x) => x.check) : false; this.numDataListChecked = dataCheck.filter((x) => x.check).length; } dataListCheckAll() { const selectAll = this.isDataListCheckedAll; this.dataList.forEach((x) => (x.check = selectAll)); this.dataListCheck(); // อัปเดตสถานะการเช็ก } showSuccess() { this.toastr.success('เพิ่มผู้ใช้ใหม่สำเร็จ!', 'เเจ้งเตือน', { timeOut: 3000, positionClass: 'toast-top-right', }); } showEdit() { this.toastr.success('ลบข้อมูลสำเร็จ', 'เเจ้งเตือน', { timeOut: 3000, positionClass: 'toast-top-right', }); } showSuccessDelete() { this.toastr.success('ลบข้อมูลสำเร็จ', 'เเจ้งเตือน', { timeOut: 3000, positionClass: 'toast-top-right', }); } addUser() { } }