Commit 7dfbe0f3 by Natthaphat

การประเมินสมรรถนะ > ทะเบียนกำหนดชื่อ > หัวข้อสมรรถนะ

parent 127d762b
......@@ -31,7 +31,14 @@
</ng-container>
<!-- <td class="flex justify-center">
<i class="ti ti-eye cursor-pointer i-gray fs-l px-1"
(click)="selectIndicatorsCourses(item);seeTab=true;editTab=false;pathTitleChange()"></i>
<i class="ti ti-edit cursor-pointer i-gray fs-l px-1"
(click)="selectIndicatorsCourses(item);seeTab=false;editTab=true;pathTitleChange()"></i>
<i *ngIf="item.file" class="ti ti-file-download cursor-pointer i-gray fs-l px-1"
(click)="dowloadExam(item.file)"></i>
</td> -->
<ng-container *ngIf="editTab||seeTab">
<app-edit-group-indicators [competencytopic]="indicatorsCourses" [seeTab]="seeTab"
......
<div class="w-full min-height-50px mb-10px justify-between items-center">
<div class="flex justify-between">
<div class="flex">
<div class="flex items-center">
<input type="checkbox" class="ti-form-checkbox pointer-events-none" id="hs-default-checkbox"
[(ngModel)]="isDataListChecked">
<label for="hs-default-checkbox" class="text-sm text-gray-500 mx-2 pointer-events-none">
{{numDataListChecked}} Selected</label>
</div>
<div class="mx-1 flex items-center">
<button (click)="isDataListCheckedAll = !isDataListCheckedAll;dataListCheckAll()" id="checkbox"
class="focus:ring-2 focus:ring-primary rounded-sm flex item-center">
<i class="fs-l transition-all duration-200"
[ngClass]="{'ri-checkbox-multiple-line text-gray-500': !isDataListCheckedAll, 'ri-checkbox-multiple-fill text-primary': isDataListCheckedAll}"></i>
</button>
<label class="text-sm text-gray-500 ml-2" for="checkbox">Select All</label>
</div>
</div>
<div class="flex justify-end">
<div class="px-1">
<div class="relative shadow-md">
<input type="text" id="hs-leading-icon" name="hs-leading-icon"
class="ti-form-input ltr:pl-11 rtl:pr-11 focus:z-10 " placeholder="Search by No. or Name"
[(ngModel)]="search" (ngModelChange)="searchChange()" style="height: 40px;">
[(ngModel)]="search" style="height: 40px;">
<div
class="absolute inset-y-0 ltr:left-0 rtl:right-0 flex items-center pointer-events-none z-20 ltr:pl-4 rtl:pr-4">
<i class="ri-search-line text-gray"></i>
......@@ -39,599 +26,193 @@
</div>
<div class="px-1">
<button type="button" class="ti-btn ti-btn-soft-secondary h-10 m-0 shadow-md"
data-hs-overlay="#competency-topic-page-modal"
(click)="modalStatus='add';setData();fileInputMedium.value = '';examFile=null;examFileName = 'กรุณาเลือกไฟล์'">
(click)="currentModal='add';examFile=null;examFileName = 'กรุณาเลือกไฟล์';openDialog();selectCompetencyTopic()">
<i class="ri-add-line"></i>
Add
</button>
</div>
<div class="px-1">
<button href="javascript:void(0);" class="ti-btn ti-btn-soft-danger h-10 m-0 shadow-md"
data-hs-overlay="#competency-topic-page-alert-modal" (click)="modalStatus='deleteGroup';setData()">
(click)="currentModal='delete';deleteCompetency_topic()">
<i class="ri-delete-bin-6-line"></i>
Delete
</button>
</div>
<!-- <div class="px-1">
<button href="javascript:void(0);" class="ti-btn ti-btn-soft-warning h-10 m-0 shadow-md">
<i class="ti ti-book fs-l"></i>
Help
</button>
</div> -->
</div>
</div>
</div>
<div class="page px-rem">
<div class="overflow-auto shadow-md rounded-t-md">
<table class="ti-custom-table ti-custom-table-head ti-custom-table-hover table-bordered">
<thead>
<tr>
<ng-container
*ngFor="let item of ['','รหัส','ชื่อหัวข้อ','ประเภท','การจัดการ']; let f = first; let l = last; let i = index">
<th scope="col" class="relative px-10px py-10px bg-soft-secondary text-primary !text-center">
<span class="font-size-12px font-weight-700">{{ item }}</span>
<div class="absolute top-1/2 transform -translate-y-1/2 right-0" *ngIf="!f&&!l">
<i class="ti ti-dots-vertical fs-l"></i>
</div>
</th>
</ng-container>
</tr>
</thead>
<tbody *ngIf="dataLoading">
<tr>
<td class="text-center" colspan="100%">
<div *ngFor="let item of [1,2,3]" class="ti-spinner w-8 h-8 text-secondary mx-1" role="status"
aria-label="loading">
<span class="sr-only">Loading...</span>
</div>
</td>
</tr>
</tbody>
<tbody *ngIf="!dataLoading&&!dataListFilter().length">
<tr>
<td class="text-center" colspan="100%">
ไม่พบข้อมูล
</td>
</tr>
</tbody>
<tbody *ngIf="!dataLoading&&dataListFilter().length">
<tr
*ngFor="let item of dataListFilter()| slice:((currentPage-1) * 10) : (((currentPage-1) * 10) + 10);let i = index">
<td class="text-center">
<input type="checkbox" class="ti-form-checkbox cursor-pointer" id="checkbox-{{item.data.id}}"
[(ngModel)]="item.check" (change)="dataListCheck()">
</td>
<td class="text-center">
<label for="checkbox-{{item.data.id}}">&nbsp;{{item.data.id}}</label>
</td>
<td>{{item.data.name}}</td>
<td class="text-center">{{item.data.code}}</td>
<td class="flex justify-center">
<i class="ti ti-edit cursor-pointer i-gray fs-l px-1"
(click)="modalStatus='edit';setData(item.data)"
data-hs-overlay="#competency-topic-page-modal"></i>
<!-- <i class="ti ti-trash cursor-pointer i-gray fs-l px-1"
(click)="modalStatus='delete';setData(item.data)"
data-hs-overlay="#competency-topic-page-alert-modal"></i> -->
</td>
</tr>
</tbody>
</table>
</div>
<nav class="pagination-style-3 overflow-auto my-5" *ngIf="page.length">
<ul class="ti-pagination">
<li>
<a aria-label="anchor" class="page-link" href="javascript:void(0);"
(click)="currentPage = (currentPage-1 || 1)">
<i class="ri-arrow-left-s-line align-middle rtl:rotate-180"></i>
</a>
</li>
<li *ngFor="let item of page;let f = first;let l = last">
<ng-container *ngIf="item==3&&currentPage!=1&&currentPage!=2&&currentPage!=3">
<a aria-label="anchor" class="page-link" href="javascript:void(0);"><i class="ri-more-line"></i>
</a>
</ng-container>
<ng-container *ngIf="(f||l)||(item==currentPage-1||item==currentPage||item==currentPage+1)">
<a class="page-link" href="javascript:void(0);" [class.active]="item==currentPage"
(click)="currentPage=item">{{item}}
</a>
</ng-container>
<ng-container
*ngIf="item==page.length-2&&currentPage!=page.length&&currentPage!=page.length-1&&currentPage!=page.length-2">
<a aria-label="anchor" class="page-link" href="javascript:void(0);"><i class="ri-more-line"></i>
</a>
</ng-container>
</li>
<li>
<a aria-label="anchor" class="page-link" href="javascript:void(0);"
(click)="currentPage = (currentPage > page.length-1 ? currentPage: currentPage+1 )">
<i class="ri-arrow-right-s-line align-middle rtl:rotate-180"></i>
</a>
</li>
</ul>
<ul class="nav-tabs mt-3">
<span>Show {{((currentPage-1) * 10)+1}} to {{dataListFilter().length<10 ?dataListFilter().length:
(currentPage==page.length ? ((currentPage * 10) - ((currentPage * 10) - dataListFilter().length) )
:(currentPage * 10) ) }} of {{dataListFilter().length}} items</span>
</ul>
</nav>
<app-datagrid-syncfution [searchSettings]="searchSettings" [searchText]="search"
[dataSource]="competencyTopic.dataList" [columns]="columns" [selectedItems]="selectedItems"
(sendSelectData)="currentModal='edit';selectCompetencyTopic($event);openDialog()"
(sendSelectedItems)="onSelectItemChange($event)">
</app-datagrid-syncfution>
</div>
<div id="competency-topic-page-modal" class="hs-overlay hidden ti-modal">
<div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out h-[calc(100%-3.5rem)]">
<div class="max-h-full overflow-hidden ti-modal-content">
<div class="ti-modal-header">
<h3 class="text-xxl font-bold text-primary">
{{modalStatus=='add'?'เพิ่มหัวข้อสมรรถนะ':'แก้ไขหัวข้อสมรรถนะ'}}
</h3>
<div class="flex justify-end">
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
data-hs-overlay="#competency-topic-page-modal">
<span class="sr-only">Close</span>
<i class="ti ti-circle-x fs-xxl"></i>
</button>
</div>
</div>
<div class="ti-modal-center">
<div class="flex justify-end" style="padding-right: 1rem;">
<div class="px-1">
<button type="button" class="ti-btn ti-btn-soft-indigo h-45px m-0 shadow-md"
(click)="clearData(modalStatus)">
<svg class="svg-indigo" width="16" height="16" viewBox="0 0 64.00 64.00"
xmlns="http://www.w3.org/2000/svg" fill="none" stroke="#595BEA" stroke-width="3.84"
transform="rotate(45)matrix(-1, 0, 0, 1, 0, 0)">
<g id="SVGRepo_bgCarrier" stroke-width="0"></g>
<g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g>
<g id="SVGRepo_iconCarrier">
<path d="M15 49A24 24 0 0 1 32 8"></path>
<path d="M49 15a24 24 0 0 1-17 41"></path>
<polyline points="15.03 40 15.03 48.97 8 48.97"></polyline>
<polyline points="48.97 24 48.97 15.03 56 15.03"></polyline>
</g>
</svg>
Clear
</button>
</div>
<!-- <div class="px-1">
<button href="javascript:void(0);" class="ti-btn ti-btn-soft-warning h-45px m-0 shadow-md">
<i class="ti ti-book fs-l"></i>
Help
</button>
</div> -->
</div>
</div>
<div class="ti-modal-body mt-1">
<label for="input-label" class="ti-form-label">รหัส<span class="text-danger">*<ng-container
*ngIf="modalStatus=='add'&&checkPrimary()">
รหัสซ้ำ
</ng-container></span></label>
<input type="text" id="input-label" class="ti-form-input w-1/2"
[ngClass]="{'bg-input-readonly':modalStatus=='edit'}" [readonly]="modalStatus=='edit'"
[(ngModel)]="dataSelect.id">
<label for="detail_th" class="ti-form-label mt-2rem">ชื่อหัวข้อ (ไทย)<span
class="text-danger">*</span></label>
<input type="text" id="detail_th" class="ti-form-input h-10" [(ngModel)]="dataSelect.name">
<label for="detail_eng" class="ti-form-label mt-2rem">ชื่อหัวข้อ (อังกฤษ)</label>
<input type="text" id="detail_eng" class="ti-form-input h-10" [(ngModel)]="dataSelect.edesc">
<label for="detail_eng" class="ti-form-label mt-2rem">นิยามสมรรถนะ</label>
<textarea type="text" id="detail_eng" class="ti-form-input" rows="4" cols="50"
[(ngModel)]="dataSelect.definition"> </textarea>
<label class="ti-form-label mt-2rem">ประเภท Competency<span class="text-danger">*</span></label>
<div class="flex">
<div class="relative flex rounded-md w-1/2">
<input type="text" id="hs-leading-button-add-on-with-icon-and-button"
name="hs-leading-button-add-on-with-icon-and-button"
class="ti-form-input rounded-md ltr:rounded-r-md rtl:rounded-l-md focus:z-10"
style="padding-right: 2.5rem;" readonly [(ngModel)]="dataSelect.type.code">
<div
class="absolute inset-y-0 ltr:right-0 rtl:left-0 flex items-center z-20 ltr:pr-4 rtl:pl-4 space-x-2">
<button type="button" class="flex items-center text-red-500"
(click)="dataSelect.type.code=''">
<i class="ti ti-circle-x cursor-pointer"></i>
</button>
<button type="button" class="flex items-center text-gray-500 dark:text-white/70"
(click)="searchCompetencytypeChange()"
data-hs-overlay="#competency-topic-table-modal-select">
<i class="ri-search-line cursor-pointer text-gray"></i>
</button>
</div>
</div>
</div>
<label class="ti-form-label mt-2rem">แนบไฟล์ข้อสอบ</label>
<div class="flex rounded-md">
<label class="sr-only">อัปโหลดไฟล์</label>
<input #fileInputMedium id="fileInputMedium" type="file" (change)="onExamSelected($event)" hidden>
<input type="text" [value]="examFileName" readonly onclick="fileInputMedium.click();"
class=" cursor-pointer block w-full border border-gray-200 focus:shadow-sm dark:focus:shadow-white/10 ltr:rounded-l-md rtl:rounded-r-none text-sm focus:z-10 focus:outline-0 focus:border-gray-200 dark:focus:border-white/10 dark:border-white/10 dark:text-white/70 file:border-0 file:bg-gray-100 ltr:file:mr-4 rtl:file:ml-4 file:py-3 file:px-4 dark:file:bg-black/20 dark:file:text-white/70">
<span
class="px-4 inline-flex items-center min-w-fit ltr:rounded-r-md rtl:rounded-l-none border ltr:border-l-0 rtl:border-r-0 border-gray-200 bg-gray-50 text-sm dark:bg-black/20 dark:border-white/10">
<button class="text-sm text-gray-500 dark:text-white/70"
onclick="fileInputMedium.click();">Browse</button>
</span>
<div class="flex items-center ml-2">
<button href="javascript:void(0);"
class="ti-btn ti-btn-soft-danger h-10px m-0 shadow-md rounded-md"
(click)="fileInputMedium.value = '';examFile=null;examFileName = 'กรุณาเลือกไฟล์'">
<i class="ri-delete-bin-6-line"></i>
Delete
</button>
</div>
</div>
<div class="flex" *ngIf="examFileName==dataSelect.file">
<h1 class="cursor-pointer justify-center -mb-px inline-flex items-center gap-2 font-weight-500 font-size-12px
text-center text-secondary border-secondary border-b-2 align-items-end"
(click)="dowloadExam(examFileName)">
ดาวน์โหลดไฟล์ข้อสอบ</h1>
</div>
<div class="flex justify-end mt-3rem mb-1rem space-x-4">
<button type="button"
class="hs-dropdown-toggle ti-btn ti-border font-medium bg-white text-gray-700 shadow-sm align-middle hover:bg-gray-50 focus:ring-offset-white focus:ring-primary dark:bg-bgdark dark:hover:bg-black/20 dark:border-white/10 dark:text-white/70 dark:hover:text-white dark:focus:ring-offset-white/10"
data-hs-overlay="#competency-topic-page-modal">
ย้อนกลับ
</button>
<button type="button" class="ti-btn ti-btn-success"
data-hs-overlay="#competency-topic-page-alert-modal"
[class.ti-btn-disabled]="!dataSelect.id||!dataSelect.name||!dataSelect.type.code||(modalStatus=='add'&&checkPrimary())"
[disabled]="!dataSelect.id||!dataSelect.name||!dataSelect.type.code||(modalStatus=='add'&&checkPrimary())">
บันทึกข้อมูล
</button>
</div>
<ng-template #competencyTopicModal let-modal>
<h3 mat-dialog-title>
{{currentModal=='add'?'เพิ่มหัวข้อสมรรถนะ':'แก้ไขหัวข้อสมรรถนะ'}}
</h3>
<div class="w-full flex justify-end mb-1rem">
<div class="absolute flex">
<div class="px-1">
<button type="button" class="ti-btn ti-btn-soft-indigo h-45px m-0 shadow-md"
(click)="selectCompetencyTopic()">
<i class="ti ti-eraser text-base"></i>
Clear
</button>
</div>
</div>
</div>
</div>
<div id="competency-topic-table-modal-select" class="hs-overlay hidden ti-modal">
<div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out lg:!max-w-4xl lg:w-full m-3 lg:!mx-auto">
<div class="max-h-full overflow-hidden ti-modal-content">
<div class="ti-modal-header">
<h3 class="text-xxl font-bold text-primary">
ประเภทสมรรถนะ
</h3>
<div class="flex justify-end">
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
data-hs-overlay="#competency-topic-page-modal">
<span class="sr-only">Close</span>
<i class="ti ti-circle-x fs-xxl"></i>
<mat-dialog-content>
<label for="input-label" class="ti-form-label">รหัส<span class="text-danger">*<ng-container
*ngIf="currentModal=='add'&&checkPrimary()">
รหัสซ้ำ
</ng-container></span></label>
<input type="text" id="input-label" class="ti-form-input w-1/2"
[ngClass]="{'!bg-input-readonly':currentModal=='edit'}" [readonly]="currentModal=='edit'"
[(ngModel)]="competencyTopic.select.competencyTopicId">
<label for="detail_th" class="ti-form-label mt-2rem">ชื่อหัวข้อ (ไทย)<span class="text-danger">*</span></label>
<input type="text" id="detail_th" class="ti-form-input h-10" [(ngModel)]="competencyTopic.select.tdesc">
<label for="detail_eng" class="ti-form-label mt-2rem">ชื่อหัวข้อ (อังกฤษ)</label>
<input type="text" id="detail_eng" class="ti-form-input h-10" [(ngModel)]="competencyTopic.select.edesc">
<label for="detail_eng" class="ti-form-label mt-2rem">นิยามสมรรถนะ</label>
<textarea type="text" id="detail_eng" class="ti-form-input" rows="4" cols="50"
[(ngModel)]="competencyTopic.select.competencyDetail"> </textarea>
<label class="ti-form-label mt-2rem">ประเภท Competency<span class="text-danger">*</span></label>
<div class="flex">
<div class="relative flex rounded-md w-1/2">
<input type="text" id="hs-leading-button-add-on-with-icon-and-button"
name="hs-leading-button-add-on-with-icon-and-button"
class="ti-form-input rounded-md ltr:rounded-r-md rtl:rounded-l-md focus:z-10"
style="padding-right: 2.5rem;" readonly
[(ngModel)]="competencyTopic.select.competencyType.shortName">
<div
class="absolute inset-y-0 ltr:right-0 rtl:left-0 flex items-center z-20 ltr:pr-4 rtl:pl-4 space-x-2">
<button type="button" class="flex items-center text-red-500"
(click)="competencyTopic.select.competencyType.shortName=''">
<i class="ti ti-circle-x cursor-pointer"></i>
</button>
<button type="button" class="flex items-center text-gray-500 dark:text-white/70"
(click)="openDialogType()" data-hs-overlay="#competency-topic-table-modal-select">
<i class="ri-search-line cursor-pointer text-gray"></i>
</button>
</div>
</div>
<div class="ti-modal-body">
<div class="flex justify-end pb-1rem">
<div class="px-1">
<div class="relative shadow-md">
<input type="text" id="hs-leading-icon" name="hs-leading-icon"
class="ti-form-input ltr:pl-11 rtl:pr-11 focus:z-10 "
placeholder="Search by No. or Name" [(ngModel)]="searchModal"
(ngModelChange)="searchCompetencytypeChange()">
<div
class="absolute inset-y-0 ltr:left-0 rtl:right-0 flex items-center pointer-events-none z-20 ltr:pl-4 rtl:pr-4">
<i class="ri-search-line text-gray"></i>
</div>
</div>
</div>
<!-- <div class="px-1">
<button href="javascript:void(0);" class="ti-btn ti-btn-soft-warning h-45px m-0 shadow-md">
<i class="ti ti-book fs-l"></i>
Help
</button>
</div> -->
</div>
<div class="overflow-auto table-bordered" style="border-radius: 5px;">
<div class="overflow-auto border">
<table class="ti-custom-table ti-custom-table-head ti-custom-table-hover">
<thead>
<tr>
<ng-container
*ngFor="let item of ['รหัส','ชื่อประเภท','ชื่อย่อ','การจัดการ']; let f = first; let l = last; let i = index">
<th scope="col" class="relative px-10px py-10px bg-soft-secondary text-primary"
[class.!text-center]="f||l">
<span class="font-size-12px font-weight-700">{{ item }}</span>
<div class="absolute top-1/2 transform -translate-y-1/2 right-0"
*ngIf="!f && !l">
<i class="ti ti-dots-vertical fs-l"></i>
</div>
</th>
</ng-container>
</tr>
</thead>
<tbody *ngIf="competencytypeListLoading">
<tr>
<td class="text-center" colspan="100%">
<div *ngFor="let item of [1,2,3]" class="ti-spinner w-8 h-8 text-secondary mx-1"
role="status" aria-label="loading">
<span class="sr-only">Loading...</span>
</div>
</td>
</tr>
</tbody>
<tbody *ngIf="!competencytypeListLoading&&!competencytypeListFilter().length">
<tr>
<td class="text-center" colspan="100%">
ไม่พบข้อมูล
</td>
</tr>
</tbody>
<tbody *ngIf="!competencytypeListLoading&&competencytypeListFilter().length">
<tr
*ngFor="let item of competencytypeListFilter()| slice:((currentPageModal-1) * 10) : (((currentPageModal-1) * 10) + 10);let i = index">
<td class="text-center">{{item.id}}</td>
<td>{{item.name}}</td>
<td class="text-center">{{item.code}}</td>
<td class="flex justify-center">
<div class="px-1">
<button type="button"
class="ti-btn ti-btn-soft-secondary h-20px m-0 shadow-md"
data-hs-overlay="#competency-topic-page-modal"
(click)="selectCompetencytype(item)">
<i class="ri-add-line"></i>
Select
</button>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<nav class="pagination-style-3 overflow-auto my-5" *ngIf="pageModal.length">
<ul class="ti-pagination">
<li>
<a aria-label="anchor" class="page-link" href="javascript:void(0);"
(click)="currentPageModal = (currentPageModal-1 || 1)">
<i class="ri-arrow-left-s-line align-middle rtl:rotate-180"></i>
</a>
</li>
<li *ngFor="let item of pageModal;let f = first;let l = last">
<ng-container
*ngIf="item==3&&currentPageModal!=1&&currentPageModal!=2&&currentPageModal!=3">
<a aria-label="anchor" class="page-link" href="javascript:void(0);"><i
class="ri-more-line"></i>
</a>
</ng-container>
<ng-container
*ngIf="(f||l)||(item==currentPageModal-1||item==currentPageModal||item==currentPageModal+1)">
<a class="page-link" href="javascript:void(0);" [class.active]="item==currentPageModal"
(click)="currentPageModal=item">{{item}}
</a>
</ng-container>
<ng-container
*ngIf="item==pageModal.length-2&&currentPageModal!=pageModal.length&&currentPageModal!=pageModal.length-1&&currentPageModal!=pageModal.length-2">
<a aria-label="anchor" class="page-link" href="javascript:void(0);"><i
class="ri-more-line"></i>
</a>
</ng-container>
</li>
<li>
<a aria-label="anchor" class="page-link" href="javascript:void(0);"
(click)="currentPageModal = (currentPageModal > pageModal.length-1 ? currentPageModal: currentPageModal+1 )">
<i class="ri-arrow-right-s-line align-middle rtl:rotate-180"></i>
</a>
</li>
</ul>
<ul class="nav-tabs mt-3">
<span>Show {{((currentPageModal-1) * 10)+1}} to {{competencytypeListFilter().length<10
?competencytypeListFilter().length: (currentPageModal==pageModal.length ?
((currentPageModal * 10) - ((currentPageModal * 10) - competencytypeListFilter().length)
) :(currentPageModal * 10) ) }} of {{competencytypeListFilter().length}} items</span>
</ul>
</nav>
</div>
<label class="ti-form-label mt-2rem">แนบไฟล์ข้อสอบ</label>
<div class="flex rounded-md">
<label class="sr-only">อัปโหลดไฟล์</label>
<input #fileInputMedium id="fileInputMedium" type="file" (change)="onExamSelected($event)" hidden>
<input type="text" [value]="examFileName" readonly onclick="fileInputMedium.click();"
class=" cursor-pointer block w-full border border-gray-200 focus:shadow-sm dark:focus:shadow-white/10 ltr:rounded-l-md rtl:rounded-r-none text-sm focus:z-10 focus:outline-0 focus:border-gray-200 dark:focus:border-white/10 dark:border-white/10 dark:text-white/70 file:border-0 file:bg-gray-100 ltr:file:mr-4 rtl:file:ml-4 file:py-3 file:px-4 dark:file:bg-black/20 dark:file:text-white/70">
<span
class="px-4 inline-flex items-center min-w-fit ltr:rounded-r-md rtl:rounded-l-none border ltr:border-l-0 rtl:border-r-0 border-gray-200 bg-gray-50 text-sm dark:bg-black/20 dark:border-white/10">
<button class="text-sm text-gray-500 dark:text-white/70"
onclick="fileInputMedium.click();">Browse</button>
</span>
<div class="flex items-center ml-2">
<button href="javascript:void(0);" class="ti-btn ti-btn-soft-danger h-10px m-0 shadow-md rounded-md"
(click)="fileInputMedium.value = '';examFile=null;examFileName = 'กรุณาเลือกไฟล์'">
<i class="ri-delete-bin-6-line"></i>
Delete
</button>
</div>
</div>
</div>
</div>
<div class="flex" *ngIf="examFileName==competencyTopic.select.competencyFiles">
<h1 class="cursor-pointer justify-center -mb-px inline-flex items-center gap-2 font-weight-500 font-size-12px
text-center text-secondary border-secondary border-b-2 align-items-end"
(click)="dowloadExam(examFileName)">
ดาวน์โหลดไฟล์ข้อสอบ</h1>
</div>
</mat-dialog-content>
<mat-dialog-actions align="end">
<button type="button" mat-button [mat-dialog-close]
class="hs-dropdown-toggle ti-btn ti-border font-medium bg-white text-gray-700 shadow-sm align-middle hover:bg-gray-50 focus:ring-offset-white focus:ring-primary dark:bg-bgdark dark:hover:bg-black/20 dark:border-white/10 dark:text-white/70 dark:hover:text-white dark:focus:ring-offset-white/10">
ย้อนกลับ
</button>
<button type="button" class="ti-btn ti-btn-success" mat-button (click)="confirmAddCompetency_topic()"
[class.ti-btn-disabled]="!competencyTopic.select.competencyType.competencyTypeId||!competencyTopic.select.tdesc||!competencyTopic.select.competencyType.shortName||(currentModal=='add'&&checkPrimary())"
[disabled]="!competencyTopic.select.competencyType.competencyTypeId||!competencyTopic.select.tdesc||!competencyTopic.select.competencyType.shortName||(currentModal=='add'&&checkPrimary())">
บันทึกข้อมูล
</button>
</mat-dialog-actions>
</ng-template>
<div id="competency-topic-table-modal-edit" class="hs-overlay hidden ti-modal">
<div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out lg:!max-w-4xl lg:w-full m-3 lg:!mx-auto">
<div class="max-h-full overflow-hidden ti-modal-content">
<div class="ti-modal-header">
<h3 class="text-xxl font-bold text-primary">
ประเภทสมรรถนะ
</h3>
<div class="flex justify-end">
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
data-hs-overlay="#competency-topic-modal-edit">
<span class="sr-only">Close</span>
<i class="ti ti-circle-x fs-xxl"></i>
</button>
</div>
</div>
<div class="ti-modal-body">
<div class="flex justify-end pb-1rem">
<div class="px-1">
<div class="relative shadow-md">
<input type="text" id="hs-leading-icon" name="hs-leading-icon"
class="ti-form-input ltr:pl-11 rtl:pr-11 focus:z-10 "
placeholder="Search by No. or Name" [(ngModel)]="searchModal"
(ngModelChange)="searchCompetencytypeChange()">
<div
class="absolute inset-y-0 ltr:left-0 rtl:right-0 flex items-center pointer-events-none z-20 ltr:pl-4 rtl:pr-4">
<i class="ri-search-line text-gray"></i>
</div>
</div>
</div>
<!-- <div class="px-1">
<button href="javascript:void(0);" class="ti-btn ti-btn-soft-warning h-45px m-0 shadow-md">
<i class="ti ti-book fs-l"></i>
Help
</button>
</div> -->
</div>
<div class="overflow-auto table-bordered" style="border-radius: 5px;">
<div class="overflow-auto border">
<table class="ti-custom-table ti-custom-table-head ti-custom-table-hover">
<thead>
<tr>
<ng-container
*ngFor="let item of ['รหัส','ชื่อประเภท','ชื่อย่อ','การจัดการ']; let f = first; let l = last; let i = index">
<th scope="col" class="relative px-10px py-10px bg-soft-secondary text-primary"
[class.!text-center]="f||l">
<span class="font-size-12px font-weight-700">{{ item }}</span>
<div class="absolute top-1/2 transform -translate-y-1/2 right-0"
*ngIf="!f && !l">
<i class="ti ti-dots-vertical fs-l"></i>
</div>
</th>
</ng-container>
</tr>
</thead>
<tbody *ngIf="competencytypeListLoading">
<tr>
<td class="text-center" colspan="100%">
<div *ngFor="let item of [1,2,3]" class="ti-spinner w-8 h-8 text-secondary mx-1"
role="status" aria-label="loading">
<span class="sr-only">Loading...</span>
</div>
</td>
</tr>
</tbody>
<tbody *ngIf="!competencytypeListLoading&&!competencytypeListFilter().length">
<tr>
<td class="text-center" colspan="100%">
ไม่พบข้อมูล
</td>
</tr>
</tbody>
<tbody *ngIf="!competencytypeListLoading&&competencytypeListFilter().length">
<tr
*ngFor="let item of competencytypeListFilter()| slice:((currentPage-1) * 10) : (((currentPage-1) * 10) + 10);let i = index">
<td class="text-center">{{item.id}}</td>
<td>{{item.name}}</td>
<td class="text-center">{{item.code}}</td>
<td class="flex justify-center">
<div class="px-1">
<button type="button"
class="ti-btn ti-btn-soft-secondary h-20px m-0 shadow-md"
data-hs-overlay="#competency-topic-modal-edit"
(click)="selectCompetencytype(item)">
<i class="ri-add-line"></i>
Select
</button>
</div>
</td>
</tr>
</tbody>
</table>
<ng-template #competencyTypeTableModal let-modal>
<h3 mat-dialog-title>
ประเภทสมรรถนะ
</h3>
<mat-dialog-content>
<div class="flex justify-end pb-1rem">
<div class="px-1">
<div class="relative shadow-md">
<input type="text" id="hs-leading-icon" name="hs-leading-icon"
class="ti-form-input ltr:pl-11 rtl:pr-11 focus:z-10 " placeholder="Search by No. or Name"
[(ngModel)]="typeModal.search" (ngModelChange)="searchCompetencytypeChange()">
<div
class="absolute inset-y-0 ltr:left-0 rtl:right-0 flex items-center pointer-events-none z-20 ltr:pl-4 rtl:pr-4">
<i class="ri-search-line text-gray"></i>
</div>
</div>
<nav class="pagination-style-3 overflow-auto my-5" *ngIf="pageModal.length">
<ul class="ti-pagination">
<li>
<a aria-label="anchor" class="page-link" href="javascript:void(0);"
(click)="currentPageModal = (currentPageModal-1 || 1)">
<i class="ri-arrow-left-s-line align-middle rtl:rotate-180"></i>
</a>
</li>
<li *ngFor="let item of page;let f = first;let l = last">
<ng-container
*ngIf="item==3&&currentPageModal!=1&&currentPageModal!=2&&currentPageModal!=3">
<a aria-label="anchor" class="page-link" href="javascript:void(0);"><i
class="ri-more-line"></i>
</a>
</ng-container>
<ng-container
*ngIf="(f||l)||(item==currentPageModal-1||item==currentPageModal||item==currentPageModal+1)">
<a class="page-link" href="javascript:void(0);" [class.active]="item==currentPageModal"
(click)="currentPageModal=item">{{item}}
</a>
</ng-container>
<ng-container
*ngIf="item==pageModal.length-2&&currentPageModal!=pageModal.length&&currentPageModal!=pageModal.length-1&&currentPageModal!=pageModal.length-2">
<a aria-label="anchor" class="page-link" href="javascript:void(0);"><i
class="ri-more-line"></i>
</a>
</ng-container>
</li>
<li>
<a aria-label="anchor" class="page-link" href="javascript:void(0);"
(click)="currentPageModal = (currentPageModal > pageModal.length-1 ? currentPageModal: currentPageModal+1 )">
<i class="ri-arrow-right-s-line align-middle rtl:rotate-180"></i>
</a>
</li>
</ul>
<ul class="nav-tabs mt-3">
<span>Show {{((currentPageModal-1) * 10)+1}} to {{competencytypeListFilter().length<10
?competencytypeListFilter().length: (currentPageModal==pageModal.length ?
((currentPageModal * 10) - ((currentPageModal * 10) - competencytypeListFilter().length)
) :(currentPageModal * 10) ) }} of {{competencytypeListFilter().length}} items</span>
</ul>
</nav>
</div>
</div>
</div>
</div>
<div id="competency-topic-page-alert-modal" class="hs-overlay hidden ti-modal">
<div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out h-[calc(100%-3.5rem)] flex items-center">
<div class="max-h-full overflow-hidden ti-modal-content w-full">
<div class="ti-modal-header">
<h3 class="text-xxl font-bold text-primary">
แจ้งเตือน
</h3>
<div class="flex justify-end">
<ng-container *ngIf="modalStatus=='add'||modalStatus=='edit'">
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
data-hs-overlay="#competency-topic-page-modal">
<span class="sr-only">Close</span>
<i class="ti ti-circle-x fs-xxl"></i>
</button>
</ng-container>
<ng-container *ngIf="modalStatus=='delete'||modalStatus=='deleteGroup'">
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
data-hs-overlay="#competency-topic-page-alert-modal">
<span class="sr-only">Close</span>
<i class="ti ti-circle-x fs-xxl"></i>
</button>
</ng-container>
</div>
</div>
<div class="ti-modal-body ">
<p class="mt-1 text-gray-800 dark:text-white/70">
<ng-container *ngIf="modalStatus=='add'||modalStatus=='edit'">
ยืนยันการบันทึกข้อมูลหรือไม่
</ng-container>
<ng-container *ngIf="modalStatus=='delete'||modalStatus=='deleteGroup'">
<ng-container *ngIf="numDataListChecked">
ยืนยันการลบข้อมูลหรือไม่
</ng-container>
<ng-container *ngIf="!numDataListChecked">
เลือกข้อมูลที่ต้องการลบ
<div class="overflow-auto border">
<table class="ti-custom-table ti-custom-table-head ti-custom-table-hover">
<thead>
<tr>
<ng-container
*ngFor="let item of ['รหัส','ชื่อประเภท','ชื่อย่อ','การจัดการ']; let f = first; let l = last">
<th scope="col" class="relative px-10px py-10px bg-soft-secondary text-primary"
[class.!text-center]="f">
<span class="text-sm">{{ item }}</span>
<div class="absolute top-1/2 transform -translate-y-1/2 right-0" *ngIf="!l">
<i class="ti ti-dots-vertical fs-l"></i>
</div>
</th>
</ng-container>
</ng-container>
</p>
<div class="flex justify-end mt-2rem mb-1rem">
<ng-container *ngIf="modalStatus=='add'||modalStatus=='edit'">
<button type="button"
class="hs-dropdown-toggle ti-btn ti-border font-medium bg-white text-gray-700 shadow-sm align-middle hover:bg-gray-50 focus:ring-offset-white focus:ring-primary dark:bg-bgdark dark:hover:bg-black/20 dark:border-white/10 dark:text-white/70 dark:hover:text-white dark:focus:ring-offset-white/10"
data-hs-overlay="#competency-topic-page-modal">
ย้อนกลับ
</button>
<a class="ti-btn ti-btn-success" href="javascript:void(0);"
data-hs-overlay="#competency-topic-page-alert-modal" (click)="addCompetency_topic()">
บันทึกข้อมูล
</a>
</ng-container>
<ng-container *ngIf="modalStatus=='delete'||modalStatus=='deleteGroup'">
<button type="button"
class="hs-dropdown-toggle ti-btn ti-border font-medium bg-white text-gray-700 shadow-sm align-middle hover:bg-gray-50 focus:ring-offset-white focus:ring-primary dark:bg-bgdark dark:hover:bg-black/20 dark:border-white/10 dark:text-white/70 dark:hover:text-white dark:focus:ring-offset-white/10"
data-hs-overlay="#competency-topic-page-alert-modal">
ย้อนกลับ
</button>
<a class="ti-btn ti-btn-danger" href="javascript:void(0);" *ngIf="numDataListChecked"
data-hs-overlay="#competency-topic-page-alert-modal" (click)="deleteCompetency_topic()">
ลบข้อมูล
</a>
</ng-container>
</div>
</div>
</tr>
</thead>
<tbody *ngIf="!competencytypeListFilter().length">
<tr>
<td class="text-center" colspan="100%">
ไม่พบข้อมูล
</td>
</tr>
</tbody>
<tbody *ngIf="competencytypeListFilter().length">
<tr
*ngFor="let item of competencytypeListFilter()| slice:((typeModal.currentPage-1) * 10) : (((typeModal.currentPage-1) * 10) + 10);let i = index">
<td>{{item.competencyTypeId}}</td>
<td>{{item.tdesc}}</td>
<td>{{item.shortName}}</td>
<td class="flex justify-center">
<div class="px-1">
<button type="button" class="ti-btn ti-btn-soft-secondary h-20px m-0 shadow-md"
(click)="selectCompetencytype(item);closeDialogType()">
<i class="ri-add-line"></i>
Select
</button>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<app-pagination [totalItems]="competencytypeListFilter().length" [pageSize]="typeModal.pageSize"
(pageChange)="typeModal.currentPage = $event"
(pageSizeChange)="typeModal.pageSize = $event;typeModal.currentPage = 1"></app-pagination>
</mat-dialog-content>
<mat-dialog-actions align="end">
<button type="button" mat-button [mat-dialog-close]
class="hs-dropdown-toggle ti-btn ti-border font-medium bg-white text-gray-700 shadow-sm align-middle hover:bg-gray-50 focus:ring-offset-white focus:ring-primary dark:bg-bgdark dark:hover:bg-black/20 dark:border-white/10 dark:text-white/70 dark:hover:text-white dark:focus:ring-offset-white/10">
ย้อนกลับ
</button>
</mat-dialog-actions>
</ng-template>
<div id="competency-topic-upload-modal" class="hs-overlay hidden ti-modal">
<div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out rounded-md">
......
import { ChangeDetectorRef, Component, EventEmitter, Input, 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 { ToastrService } from 'ngx-toastr';
import { MyCompetencytopicModel } from 'src/app/shared/model/competencytopic.model';
import { MyCompetencytypeModel } from 'src/app/shared/model/competencytype.model';
import { CompetencyTopicModel } from 'src/app/shared/model/appraisal-aps.model';
import { CompetencytopicModel, MyCompetencytopicModel } from 'src/app/shared/model/competencytopic.model';
import { CompetencytypeModel, MyCompetencytypeModel } from 'src/app/shared/model/competencytype.model';
import { CompetencytopicService } from 'src/app/shared/services/competencytopic.service';
import { CompetencytypeService } from 'src/app/shared/services/competencytype.service';
import { FileService } from 'src/app/shared/services/file.service';
export interface DataModel {
id: string
name: string
edesc: string
code: string
definition: string
type: DataModel2
file: string
checked: boolean
}
export interface DataModel2 {
id: string
name: string
edesc: string
code: string
level: string
import Swal from 'sweetalert2';
import { data } from '../../../datagrid-syncfution/data';
import { TokenService } from 'src/app/shared/services/token.service';
interface table {
currentPage: number,
page: number[],
search: string,
pageSize: number
}
@Component({
selector: 'app-competency-topic',
templateUrl: './competency-topic.component.html',
styleUrls: ['./competency-topic.component.scss']
})
export class CompetencyTopic {
export class CompetencyTopic implements OnInit {
competencyTopic: { loading: boolean, select: CompetencytopicModel, dataList: CompetencytopicModel[] } = { loading: false, select: new MyCompetencytopicModel({}), dataList: [] }
selectedFile: File | null = null;
selectedFileName: string = 'กรุณาเลือกไฟล์';
examFile: File | null = null;
examFileName: string = 'กรุณาเลือกไฟล์';
topicModal: table = {
currentPage: 1,
page: Array.from({ length: 1 }, (_, i) => i + 1),
search: "",
pageSize: 10
}
typeList: CompetencytypeModel[] = []
type: CompetencytypeModel = new MyCompetencytypeModel()
typeModal: table = {
currentPage: 1,
page: Array.from({ length: 1 }, (_, i) => i + 1),
search: "",
pageSize: 10
}
currentPage = 1
page = Array.from({ length: 1 }, (_, i) => i + 1);
......@@ -36,19 +55,12 @@ export class CompetencyTopic {
pageModal = Array.from({ length: 1 }, (_, i) => i + 1);
searchModal = ""
isChecked: boolean = false; // ใช้สำหรับตรวจสอบสถานะของ checkbox
currentModal = "";
dataLoading = false
topicList: CompetencytopicService[] = [];
dataSelect: DataModel = { id: "", name: "", edesc: "", code: "", definition: "", file: "", type: { id: "", name: "", edesc: "", code: "", level: "" }, checked: false }
currentModal: 'add' | 'edit' | 'delete' = 'add'
competoncytopicList: CompetencytopicModel[] = [];
competencytypeListLoading = false
competencytypeList: DataModel2[] = []
competoncyTopicList: { check: boolean; data: DataModel & { checked?: boolean } }[] = []
modalStatus = 'add'
selectedFile: File | null = null;
selectedFileName: string = 'กรุณาเลือกไฟล์';
examFile: File | null = null;
examFileName: string = 'กรุณาเลือกไฟล์';
competoncy_type: CompetencytypeModel = new MyCompetencytypeModel({})
competoncy_topic: CompetencytopicModel = new MyCompetencytopicModel({})
numDataListChecked = 0
......@@ -56,67 +68,78 @@ export class CompetencyTopic {
isDataListCheckedAll = false
columns: ColumnModel[] = [{
field: "competencyTypeId",
headerText: "รหัส",
type: "string",
isPrimaryKey: true,
},
{
field: "tdesc",
headerText: "ชื่อหัวข้อ",
type: "string"
},
{
field: "shortName",
headerText: "ประะภท",
type: "string"
}]
searchSettings = {
fields: ['competencyTypeId', 'tdesc', 'shortName'],
operator: 'contains',
ignoreCase: false
};
search = ''
selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() };
field: "competencyTopicId",
headerText: "รหัส",
type: "string",
isPrimaryKey: true,
},
{
field: "tdesc",
headerText: "ชื่อหัวข้อ",
type: "string"
},
{
field: "competencyType.shortName",
headerText: "ประะภท",
type: "string"
}]
searchSettings = {
fields: ['competencyTopicId', 'tdesc', 'competencyType.shortName'],
operator: 'contains',
ignoreCase: false
};
search = ''
selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() };
@ViewChild("competencyTopicModal") competencyTopicModal: any;
@ViewChild("competencyTypeTableModal") competencyTypeTableModal: any;
@ViewChild("fileInputMedium") fileInputMedium: any;
dialogRef: any
dialogRefType: any
constructor(private toastr: ToastrService,
private dialog: MatDialog,
private cdr: ChangeDetectorRef,
private fileService: FileService,
private competencytopicService: CompetencytopicService,
private competencytypeService: CompetencytypeService
private competencytypeService: CompetencytypeService,
private tokenService: TokenService
) { }
ngOnInit(): void {
this.getCompetencytopicList()
this.getCompetencytypeList()
}
onExamSelected(event: any) {
this.examFile = event.target.files.length > 0 ? event.target.files[0] : null;
this.examFileName = this.examFile?.name || "กรุณาเลือกไฟล์"
}
uploadExam() {
if (!this.examFile) {
return
}
if (!this.examFile) return;
const formData = new FormData();
formData.append('file', this.examFile);
this.fileService.uploadFiles(formData).subscribe({
next: response => {
if (response.success) {
this.examFile = null
this.addCompetency_topic(response.resultObject)
this.examFile = null;
this.addCompetency_topic(response.resultObject); // ส่งชื่อไฟล์เข้าฟังก์ชัน
} else {
this.showAlert(response.message, 'error')
this.cdr.detectChanges()
this.showAlert(response.message, 'error');
this.cdr.detectChanges();
}
}, error: error => {
this.showAlert(error.message, 'error')
this.cdr.detectChanges()
},
error: error => {
this.showAlert(error.message, 'error');
this.cdr.detectChanges();
}
})
});
}
dowloadExam(fileName: string) {
this.fileService.dowloadFiles(fileName).subscribe({
next: response => {
......@@ -148,7 +171,7 @@ export class CompetencyTopic {
}
const formData = new FormData();
formData.append('file', this.selectedFile);
this.dataLoading = true
this.competencyTopic.loading = true
this.fileService.uploadExcel(formData, 'competency_topic').subscribe({
next: response => {
if (response.success) {
......@@ -157,12 +180,12 @@ export class CompetencyTopic {
this.getCompetencytopicList()
} else {
this.showAlert(response.message, 'error')
this.dataLoading = false
this.competencyTopic.loading = false
this.cdr.detectChanges()
}
}, error: error => {
this.showAlert(error.message, 'error')
this.dataLoading = false
this.competencyTopic.loading = false
this.cdr.detectChanges()
}
})
......@@ -189,11 +212,16 @@ export class CompetencyTopic {
getCompetencytypeList() {
this.competencytypeListLoading = true
this.selectedItems.data.clear()
this.competencytypeService.getList().subscribe({
next: response => {
this.competencytypeList = response.map(x => ({ id: x.competencyTypeId, name: x.tdesc, edesc: x.edesc, code: x.shortName, level: x.expectationLevel, checked: false }))
this.typeList = response.map(x => {
this.selectedItems.data.set(x.competencyTypeId, false)
return new MyCompetencytypeModel(x)
})
this.selectedItems.key = 'competencyTypeId'
this.selectedItems.count = 0
this.competencytypeListLoading = false
this.searchChange()
this.cdr.detectChanges()
}, error: error => {
this.competencytypeListLoading = false
......@@ -201,155 +229,190 @@ export class CompetencyTopic {
}
})
}
selectCompetencyTopic(CompetencyTopic?: CompetencyTopicModel) {
if (CompetencyTopic) {
this.competencyTopic.select = new MyCompetencytopicModel(CompetencyTopic)
} else if (this.currentModal == 'add') {
this.competencyTopic.select = new MyCompetencytopicModel({})
} else if (this.currentModal == 'edit') {
this.competencyTopic.select = new MyCompetencytopicModel({ competencyTopicId: this.competencyTopic.select.competencyTopicId })
}
this.examFileName = this.competencyTopic.select.competencyFiles || 'กรุณาเลือกไฟล์'
}
searchCompetencytypeChange() {
this.currentPageModal = 1
this.pageModal = Array.from({ length: Math.ceil(this.competencytypeListFilter().length / 10) }, (_, i) => i + 1);
this.typeModal.currentPage = 1
this.typeModal.page = Array.from({ length: Math.ceil(this.competencytypeListFilter().length / 10) }, (_, i) => i + 1);
}
competencytypeListFilter() {
return this.competencytypeList.filter(x => {
const data = x
const match = data.id.toLowerCase().includes(this.searchModal) || data.name.toLowerCase().includes(this.searchModal) || data.code.toLowerCase().includes(this.searchModal);
return match;
});
return this.typeList.filter(x =>
x.competencyTypeId.toLowerCase().includes(this.typeModal.search.toLowerCase()) ||
x.tdesc.toLowerCase().includes(this.typeModal.search.toLowerCase()) ||
x.shortName.toLowerCase().includes(this.typeModal.search.toLowerCase()))
}
selectCompetencytype(data: DataModel2) {
this.dataSelect.type = JSON.parse(JSON.stringify(data));
selectCompetencytype(data: CompetencytypeModel) {
this.competencyTopic.select.competencyType = JSON.parse(JSON.stringify(data));
}
getCompetencytopicList() {
this.dataLoading = true
this.competencyTopic.loading = true
this.selectedItems.data.clear()
this.competencytopicService.getList().subscribe({
next: response => {
this.competoncyTopicList = response.map(x => ({
check: false, data: {
id: x.competencyTopicId, name: x.tdesc, edesc: x.edesc, code: x.competencyType.shortName, definition: x.competencyDetail, file: x.competencyFiles,
type: { id: x.competencyType.competencyTypeId, name: x.competencyType.tdesc, edesc: x.competencyType.edesc, code: x.competencyType.shortName, level: x.expectationLevel },
checked: false
}
}))
this.isDataListCheckedAll = false
this.dataListCheckAll()
this.dataLoading = false
this.searchChange()
this.competencyTopic.dataList = response.map(x => {
this.selectedItems.data.set(x.competencyTopicId, false)
return new MyCompetencytopicModel(x)
})
this.selectedItems.key = 'competencyTopicId'
this.selectedItems.count = 0
this.competencyTopic.loading = false
this.cdr.detectChanges()
}, error: error => {
this.dataLoading = false
this.competencyTopic.loading = false
this.cdr.detectChanges()
}
})
}
searchChange() {
this.currentPage = 1
this.page = Array.from({ length: Math.ceil(this.dataListFilter().length / 10) }, (_, i) => i + 1);
this.dataListCheck()
addCompetency_topic(competencyFiles?: string) {
if (this.examFile) {
this.uploadExam();
return;
}
const user = this.tokenService.getUser();
const body = new MyCompetencytopicModel({
...this.competencyTopic.select,
companyId: user?.companyid,
competencyFiles: competencyFiles || ((this.examFileName == this.competencyTopic.select.competencyFiles) ? this.competencyTopic.select.competencyFiles : '')
});
this.competencyTopic.loading = true;
this.competencytopicService.post(body).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success');
this.getCompetencytypeList();
this.getCompetencytopicList();
this.closeDialog()
} else {
this.showAlert(response.message, 'error');
this.competencyTopic.loading = false;
this.cdr.detectChanges();
}
},
error: error => {
this.showAlert(error.message, 'error');
this.competencyTopic.loading = false;
this.cdr.detectChanges();
}
});
}
dataListFilter() {
return this.competoncyTopicList.filter(x => {
const data = x.data
const match = data.id?.toLowerCase().includes(this.search.toLowerCase()) || data.name?.toLowerCase().includes(this.search.toLowerCase()) || data.code?.toLowerCase().includes(this.search.toLowerCase());
return match;
confirmAddCompetency_topic() {
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการบันทึกข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'บันทึกข้อมูล',
cancelButtonText: 'ย้อนกลับ',
reverseButtons: true,
}).then(result => {
if (result.isConfirmed) {
this.addCompetency_topic();
}
});
}
setData(data?: DataModel) {
this.examFileName = data?.file || 'กรุณาเลือกไฟล์'
this.dataSelect = JSON.parse(JSON.stringify(data || { id: "", name: "", edesc: "", code: "", definition: "", file: "", type: { id: "", name: "", edesc: "", code: "", level: "" }, checked: false }));
deleteCompetency_topic() {
if (!this.numSelectItem()) {
this.showAlert('กรุณาเลือกข้อมูลที่ต้องการลบ', 'error');
return;
}
addCompetency_topic(competencyFiles?: string) {
if (this.examFile) {
this.uploadExam()
} else {
const body = new MyCompetencytopicModel({
competencyTopicId: this.dataSelect.id, tdesc: this.dataSelect.name, edesc: this.dataSelect.edesc, competencyDetail: this.dataSelect.definition,
competencyType: new MyCompetencytypeModel({ competencyTypeId: this.dataSelect.type.id, tdesc: this.dataSelect.type.name, edesc: this.dataSelect.type.edesc, shortName: this.dataSelect.type.code, expectationLevel: this.dataSelect.type.level }),
competencyFiles: competencyFiles || ((this.examFileName == this.dataSelect.file) ? this.dataSelect.file : '')
})
this.dataLoading = true
this.competencytopicService.post(body).subscribe({
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการลบข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ลบข้อมูล',
cancelButtonText: 'ย้อนกลับ',
reverseButtons: true,
}).then(result => {
if (result.isConfirmed) {
let body: MyCompetencytopicModel[] = [];
if (this.currentModal === "delete") {
const selectedKeys = Array.from(this.selectedItems.data.keys());
body = this.competencyTopic.dataList
.filter(x => selectedKeys.includes(x.competencyTopicId) && this.selectedItems.data.get(x.competencyTopicId))
.map(x => new MyCompetencytopicModel(x));
}
this.competencyTopic.loading = true;
this.competencytopicService.delete(body).subscribe({
next: response => {
this.competencyTopic.loading = false;
if (response.success) {
this.showAlert(response.message, 'success')
this.getCompetencytypeList()
this.getCompetencytopicList()
this.showAlert(response.message, 'success');
this.getCompetencytypeList();
this.getCompetencytopicList();
} else {
this.showAlert(response.message, 'error')
this.dataLoading = false
this.cdr.detectChanges()
this.showAlert(response.message, 'error');
this.cdr.detectChanges();
}
}, error: error => {
this.showAlert(error.message, 'error')
this.dataLoading = false
this.cdr.detectChanges()
},
error: error => {
this.competencyTopic.loading = false;
this.showAlert(error.message, 'error');
this.cdr.detectChanges();
}
})
}
}
deleteCompetency_topic() {
let body: any
if (this.modalStatus == "deleteGroup") {
body = this.competoncyTopicList.filter(x => x.check).map(x => new MyCompetencytopicModel({
competencyTopicId: x.data.id, tdesc: x.data.name, edesc: x.data.edesc, competencyDetail: x.data.definition,
competencyType: new MyCompetencytypeModel({ competencyTypeId: x.data.type.id, tdesc: x.data.type.name, edesc: x.data.type.edesc, shortName: x.data.type.code, expectationLevel: x.data.type.level }),
}))
} else {
body = new MyCompetencytopicModel({
competencyTopicId: this.dataSelect.id, tdesc: this.dataSelect.name, edesc: this.dataSelect.edesc, competencyDetail: this.dataSelect.definition,
competencyType: new MyCompetencytypeModel({ competencyTypeId: this.dataSelect.type.id, tdesc: this.dataSelect.type.name, edesc: this.dataSelect.type.edesc, shortName: this.dataSelect.type.code, expectationLevel: this.dataSelect.type.level }),
})
});
}
this.dataLoading = true
this.competencytopicService.delete(body).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getCompetencytypeList()
this.getCompetencytopicList()
this.dataLoading = false
} else {
this.showAlert(response.message, 'error')
this.dataLoading = false
this.cdr.detectChanges()
}
}, error: error => {
this.showAlert(error.message, 'error')
this.dataLoading = false
this.cdr.detectChanges()
}
})
}
});
}
showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', {
timeOut: 3000,
positionClass: 'toast-top-right',
})
Swal.fire({
title: 'แจ้งเตือน',
text: text,
icon: type,
confirmButtonText: 'ตกลง',
});
}
clearData(modalStatus: string) {
if (modalStatus == 'add') {
this.setData()
} else if (modalStatus == 'edit') {
this.setData({ id: this.dataSelect.id, name: "", edesc: "", code: "", definition: "", file: "", type: { id: "", name: "", edesc: "", code: "", level: "" }, checked: this.dataSelect.checked })
}
checkPrimary() {
return this.competencyTopic.dataList.find(x => x.competencyTopicId == this.competencyTopic.select.competencyTopicId)
}
dataListCheckAll() {
const selectAll = this.isDataListCheckedAll;
this.competoncyTopicList.filter(x => {
const data = x.data
const match = data.id.toLowerCase().includes(this.search.toLowerCase()) || data.name.toLowerCase().includes(this.search.toLowerCase()) || data.code.toLowerCase().includes(this.search.toLowerCase());
return match;
}).forEach(x => x.check = selectAll);
this.dataListCheck();
numSelectItem() {
const selectedKeys = Array.from(this.selectedItems.data.keys());
const num = selectedKeys.filter(key => this.selectedItems.data.get(key)).length;
return num;
}
dataListCheck() {
const dataCheck = this.dataListFilter();
this.isDataListCheckedAll = dataCheck.length ? dataCheck.every(x => x.check) : false;
this.numDataListChecked = this.competoncyTopicList.filter(x => x.check).length;
this.isDataListChecked = Boolean(this.numDataListChecked)
onSelectItemChange(arg: any) {
this.selectedItems = arg
}
checkPrimary() {
return this.competoncyTopicList.find(x => x.data.id == this.dataSelect.id)
openDialog() {
this.dialogRef = this.dialog.open(this.competencyTopicModal, {
width: '500px',
disableClose: false,
});
}
openDialogType() {
this.fileInputMedium.value = ""
this.dialogRefType = this.dialog.open(this.competencyTypeTableModal, {
width: '800px',
disableClose: false,
})
}
closeDialog() {
this.dialogRef.close()
}
closeDialogType() {
this.dialogRefType.close()
}
}
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