management-evaluation-cycle.component.ts 2.98 KB
Newer Older
1 2 3
import { ChangeDetectorRef, Component, EventEmitter, Input, Output } from '@angular/core';
import { ToastrService } from 'ngx-toastr';

4
export interface DataModel {
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
    check: boolean,
    code: string,
    period: string,
    year: string,
    startDate: string,
    endDate: string,
    status: string
}

@Component({
    selector: 'app-management-evaluation-cycle',
    templateUrl: './management-evaluation-cycle.component.html',
    styleUrls: ['./management-evaluation-cycle.component.scss']
})
export class ManagementCycleComponent {
    currentPage = 1
    page = Array.from({ length: 1 }, (_, i) => i + 1);
    search = ""
    numDataListChecked = 0
    isDataListChecked = false
    isDataListCheckedAll = false
26
    dataList: DataModel[] = [
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
        {
            check: false,
            code: "Y67P2",
            period: "ช่วงเวลาที่ 2",
            year: "2567",
            startDate: "01-07-2567",
            endDate: "31-12-2567",
            status: "1"
        },
        {
            check: false,
            code: "Y68P1",
            period: "ช่วงเวลาที่ 1",
            year: "2568",
            startDate: "01-01-2568",
            endDate: "30-06-2568",
            status: "2"
        },
        {
            check: false,
            code: "Y67P1",
            period: "ช่วงเวลาที่ 1",
            year: "2567",
            startDate: "01-01-2567",
            endDate: "30-06-2567",
            status: "3"
        }
    ]

56
    dataSelect: DataModel = {
57 58 59 60 61 62 63 64 65 66 67 68
        check: false,
        code: "",
        period: "",
        year: "",
        startDate: "",
        endDate: "",
        status: "",
    }
    modalStatus: "add" | "edit" = "add"
    constructor(private cdr: ChangeDetectorRef) {
    }

69
    dataListSelect(data?: DataModel) {
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
        this.dataSelect = data || {
            check: false,
            code: "",
            period: "",
            year: "",
            startDate: "",
            endDate: "",
            status: "",
        }
        this.cdr.detectChanges()
    }

    dataListFilter() {
        return this.dataList.filter(x => {
            const match = x.code.includes(this.search) || x.period.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();
    }

    searchChange() {
        this.currentPage = 1;
        const filteredData = this.dataListFilter();
        this.page = Array.from({ length: Math.ceil(filteredData.length / 10) }, (_, i) => i + 1);
        this.dataListCheck();
    }

}