Commit 4b70dbad by Natthaphat

ทะเบียนเครื่องมือ > เครื่องมือประเมิน

ทะเบียนหลักสูตร > หลักสูตรการพัฒนา
parent 9fc248ab
<div class="w-full min-height-50px mb-10px justify-between items-center"> <div class="w-full min-height-50px mb-10px justify-between items-center">
<div class="flex justify-between"> <div class="flex justify-between">
<div class="flex"> <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>
<div class="flex justify-end"> <div class="flex justify-end">
...@@ -22,7 +9,7 @@ ...@@ -22,7 +9,7 @@
<div class="relative shadow-md"> <div class="relative shadow-md">
<input type="text" id="hs-leading-icon" name="hs-leading-icon" <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" 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 <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"> 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> <i class="ri-search-line text-gray"></i>
...@@ -40,127 +27,82 @@ ...@@ -40,127 +27,82 @@
</div> </div>
<div class="px-1"> <div class="px-1">
<button type="button" class="ti-btn ti-btn-soft-secondary h-10 m-0 shadow-md" <button type="button" class="ti-btn ti-btn-soft-secondary h-10 m-0 shadow-md"
data-hs-overlay="#development-course-modal" (click)="currentModal='add';selectCompetencycourse()"> (click)="currentModal='add';selectCompetencycourse();openDialog()">
<i class="ri-add-line"></i> <i class="ri-add-line"></i>
Add Add
</button> </button>
</div> </div>
<div class="px-1"> <div class="px-1">
<button href="javascript:void(0);" class="ti-btn ti-btn-soft-danger h-10 m-0 shadow-md" <button href="javascript:void(0);" class="ti-btn ti-btn-soft-danger h-10 m-0 shadow-md"
data-hs-overlay="#development-course-alert-modal" (click)="currentModal='delete';deleteDevelopmentCourse()">
(click)="currentModal='deleteGroup';selectCompetencycourse()">
<i class="ri-delete-bin-6-line"></i> <i class="ri-delete-bin-6-line"></i>
Delete Delete
</button> </button>
</div> </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>
</div> </div>
<div class="page px-rem"> <div class="page px-rem">
<div class="overflow-auto shadow-md rounded-t-md"> <app-datagrid-syncfution [searchSettings]="searchSettings" [searchText]="search"
<table class="ti-custom-table ti-custom-table-head ti-custom-table-hover table-bordered"> [dataSource]="competencyCourse.dataList" [columns]="columns" [selectedItems]="selectedItems"
<thead> (sendSelectData)="currentModal='edit';selectCompetencycourse($event);openDialog()"
<tr> (sendSelectedItems)="onSelectItemChange($event)">
<ng-container </app-datagrid-syncfution>
*ngFor="let item of ['','รหัส','ชื่อหัวข้อ','การจัดการ']; let f = first; let l = last; let i = index"> </div>
<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="competencyCourse.loading">
<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="!competencyCourse.loading&&!dataListFilter().length">
<tr>
<td class="text-center" colspan="100%">
ไม่พบข้อมูล
</td>
</tr>
</tbody>
<tbody *ngIf="!competencyCourse.loading&&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.competencyCourseId}}" [(ngModel)]="item.check"
(change)="dataListCheck()">
</td> <ng-template #developmentCourseModal let-modal>
<td class="text-center"> <h3 mat-dialog-title>
<label {{currentModal=='add'?'เพิ่มหลักสูตรการพัฒนา':'แก้ไขหลักสูตรการพัฒนา'}}
for="checkbox-{{item.data.competencyCourseId}}">&nbsp;{{item.data.competencyCourseId}}</label> </h3>
</td> <div class="w-full flex justify-end">
<td>{{item.data.tdesc}}</td> <div class="absolute flex">
<td class="flex justify-center"> <div class="px-1">
<i class="ti ti-edit cursor-pointer i-gray fs-l px-1" <button type="button" class="ti-btn ti-btn-soft-indigo h-45px m-0 shadow-md"
(click)="currentModal='edit' ;selectCompetencycourse(item.data)" (click)="selectCompetencycourse()">
data-hs-overlay="#development-course-modal"></i> <i class="ti ti-eraser text-base"></i>
<!-- <i class="ti ti-trash cursor-pointer i-gray fs-l px-1" Clear
(click)="currentModal='delete' ;selectCompetencycourse(item.data)" </button>
data-hs-overlay="#development-course-alert-modal"></i> --> </div>
</td> </div>
</tr>
</tbody>
</table>
</div> </div>
<nav class="pagination-style-3 overflow-auto my-5" *ngIf="page.length"> <mat-dialog-content>
<ul class="ti-pagination"> <label for="input-label" class="ti-form-label mt-2rem">รหัสหลักสูตร
<li> <span class="text-danger">*
<a aria-label="anchor" class="page-link" href="javascript:void(0);" <ng-container *ngIf="checkPrimary()&&currentModal=='add'">
(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>
<ng-container *ngIf="(f||l)||(item==currentPage-1||item==currentPage||item==currentPage+1)"> </span>
<a class="page-link" href="javascript:void(0);" [class.active]="item==currentPage" </label>
(click)="currentPage=item">{{item}} <input type="text" id="input-label" class="ti-form-input w-1/2"
</a> [ngClass]="{'bg-input-readonly':currentModal=='edit'}" [readonly]="currentModal=='edit'"
</ng-container> [(ngModel)]="competencyCourse.select.competencyCourseId">
<ng-container <label for="detail_th" class="ti-form-label mt-2rem">ชื่อหลักสูตร (ไทย)<span
*ngIf="item==page.length-2&&currentPage!=page.length&&currentPage!=page.length-1&&currentPage!=page.length-2"> class="text-danger">*</span></label>
<a aria-label="anchor" class="page-link" href="javascript:void(0);"><i class="ri-more-line"></i> <input type="text" id="detail_th" class="ti-form-input h-10" [(ngModel)]="competencyCourse.select.tdesc">
</a> <label for="detail_eng" class="ti-form-label mt-2rem">ชื่อหลักสูตร (อังกฤษ)</label>
</ng-container> <input type="text" id="detail_eng" class="ti-form-input h-10" [(ngModel)]="competencyCourse.select.edesc">
</li> <label for="detail_eng" class="ti-form-label mt-2rem">วัตถุประสงค์</label>
<li> <textarea type="text" id="detail_eng" class="ti-form-input" rows="4" cols="50"
<a aria-label="anchor" class="page-link" href="javascript:void(0);" [(ngModel)]="competencyCourse.select.courseDetail"> </textarea>
(click)="currentPage = (currentPage > page.length-1 ? currentPage: currentPage+1 )"> <label for="detail_eng" class="ti-form-label mt-2rem">หัวข้อเรื่อง</label>
<i class="ri-arrow-right-s-line align-middle rtl:rotate-180"></i> <textarea type="text" id="detail_eng" class="ti-form-input" rows="4" cols="50"
</a> [(ngModel)]="competencyCourse.select.courseTopic"> </textarea>
</li> <label class="ti-form-label mt-2rem">Link myLearn</label>
</ul> <input type="text" class="ti-form-input h-10" [(ngModel)]="competencyCourse.select.courseLinkMylearn">
<ul class="nav-tabs mt-3"> </mat-dialog-content>
<span>Show {{((currentPage-1) * 10)+1}} to {{dataListFilter().length<10 ?dataListFilter().length: <mat-dialog-actions align="end">
(currentPage==page.length ? ((currentPage * 10) - ((currentPage * 10) - dataListFilter().length) ) <button type="button" mat-button [mat-dialog-close]
:(currentPage * 10) ) }} of {{dataListFilter().length}} items</span> 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">
</ul> ย้อนกลับ
</nav> </button>
</div> <button type="button" class="ti-btn ti-btn-success" (click)="addDevelopmentCourse()"
[class.ti-btn-disabled]="!competencyCourse.select.competencyCourseId||!competencyCourse.select.tdesc||(currentModal=='add'&&checkPrimary())"
[disabled]="!competencyCourse.select.competencyCourseId||!competencyCourse.select.tdesc||(currentModal=='add'&&checkPrimary())">
บันทึกข้อมูล
</button>
</mat-dialog-actions>
</ng-template>
<div id="development-course-upload-modal" class="hs-overlay hidden ti-modal"> <div id="development-course-upload-modal" class="hs-overlay hidden ti-modal">
<div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out rounded-md"> <div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out rounded-md">
...@@ -198,155 +140,3 @@ ...@@ -198,155 +140,3 @@
</div> </div>
</div> </div>
</div> </div>
<div id="development-course-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" *ngIf="currentModal=='add'">
เพิ่มหลักสูตรการพัฒนา
</h3>
<h3 class="text-xxl font-bold text-primary" *ngIf="currentModal=='edit'">
แก้ไขหลักสูตรการพัฒนา
</h3>
<div class="flex justify-end">
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
data-hs-overlay="#development-course-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(currentModal)">
<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="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)]="competencyCourse.select.competencyCourseId">
<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)]="competencyCourse.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)]="competencyCourse.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)]="competencyCourse.select.courseDetail"> </textarea>
<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)]="competencyCourse.select.courseTopic"> </textarea>
<label class="ti-form-label mt-2rem">Link myLearn</label>
<input type="text" class="ti-form-input h-10" [(ngModel)]="competencyCourse.select.courseLinkMylearn">
<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="#development-course-modal">
ย้อนกลับ
</button>
<button type="button" class="ti-btn ti-btn-success"
data-hs-overlay="#development-course-alert-modal"
[class.ti-btn-disabled]="!competencyCourse.select.competencyCourseId||!competencyCourse.select.tdesc||(currentModal=='add'&&checkPrimary())"
[disabled]="!competencyCourse.select.competencyCourseId||!competencyCourse.select.tdesc||(currentModal=='add'&&checkPrimary())">
บันทึกข้อมูล
</button>
</div>
</div>
</div>
</div>
</div>
<div id="development-course-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">
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
*ngIf="currentModal=='add'||currentModal=='edit'" data-hs-overlay="#development-course-modal">
<span class="sr-only">Close</span>
<i class="ti ti-circle-x fs-xxl"></i>
</button>
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
*ngIf="currentModal=='delete'||currentModal=='deleteGroup'"
data-hs-overlay="#development-course-alert-modal">
<span class="sr-only">Close</span>
<i class="ti ti-circle-x fs-xxl"></i>
</button>
</div>
</div>
<div class="ti-modal-body ">
<p class="mt-1 text-gray-800 dark:text-white/70" *ngIf="currentModal=='add'||currentModal=='edit'">
ยืนยันการบันทึกข้อมูลหรือไม่
</p>
<p class="mt-1 text-gray-800 dark:text-white/70"
*ngIf="currentModal=='delete'||currentModal=='deleteGroup'">
<ng-container *ngIf="numDataListChecked">
ยืนยันการลบข้อมูลหรือไม่
</ng-container>
<ng-container *ngIf="!numDataListChecked">
เลือกข้อมูลที่ต้องการลบ
</ng-container>
</p>
<div class="flex justify-end mt-2rem mb-1rem" *ngIf="currentModal=='add'||currentModal=='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="#development-course-modal">
ย้อนกลับ
</button>
<a class="ti-btn ti-btn-success" href="javascript:void(0);"
data-hs-overlay="#development-course-alert-modal" (click)="updateCompetencyCourse('post')">
บันทึกข้อมูล
</a>
</div>
<div class="flex justify-end mt-2rem mb-1rem"
*ngIf="currentModal=='delete'||currentModal=='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="#development-course-alert-modal">
ย้อนกลับ
</button>
<a class="ti-btn ti-btn-danger" href="javascript:void(0);"
data-hs-overlay="#development-course-alert-modal" (click)="updateCompetencyCourse('delete')"
*ngIf="numDataListChecked">
ลบข้อมูล
</a>
</div>
</div>
</div>
</div>
</div>
\ No newline at end of file
import { ChangeDetectorRef, Component, EventEmitter, Input, Output } from '@angular/core'; import { ChangeDetectorRef, Component, EventEmitter, Input, Output, ViewChild } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { ColumnModel } from '@syncfusion/ej2-grids';
import { ToastrService } from 'ngx-toastr'; import { ToastrService } from 'ngx-toastr';
import { CompetencyCourseModel, MyCompetencyCourseModel } from 'src/app/shared/model/competency-course.model'; import { CompetencyCourseModel, MyCompetencyCourseModel } from 'src/app/shared/model/competency-course.model';
import { MyCompetencycourseModel } from 'src/app/shared/model/competencycourse.model'; import { MyCompetencycourseModel } from 'src/app/shared/model/competencycourse.model';
import { CompetencycourseService } from 'src/app/shared/services/competencycourse.service'; import { CompetencycourseService } from 'src/app/shared/services/competencycourse.service';
import { FileService } from 'src/app/shared/services/file.service'; import { FileService } from 'src/app/shared/services/file.service';
import Swal from 'sweetalert2';
@Component({ @Component({
selector: 'app-development-course', selector: 'app-development-course',
templateUrl: './development-course.component.html', templateUrl: './development-course.component.html',
...@@ -12,17 +15,40 @@ import { FileService } from 'src/app/shared/services/file.service'; ...@@ -12,17 +15,40 @@ import { FileService } from 'src/app/shared/services/file.service';
export class DevelopmentCourseComponent { export class DevelopmentCourseComponent {
currentPage = 1 currentPage = 1
page = Array.from({ length: 1 }, (_, i) => i + 1); page = Array.from({ length: 1 }, (_, i) => i + 1);
search = ""
currentModal: 'add' | 'edit' | 'delete' | 'deleteGroup' = "add"; currentModal: 'add' | 'edit' | 'delete' = "add";
competencyCourse: { loading: boolean, select: CompetencyCourseModel, dataList: { check: boolean, data: CompetencyCourseModel }[] } = { loading: false, select: new MyCompetencyCourseModel(), dataList: [] } competencyCourse: { loading: boolean, select: CompetencyCourseModel, dataList: CompetencyCourseModel[] } = { loading: false, select: new MyCompetencyCourseModel(), dataList: [] }
numDataListChecked = 0 numDataListChecked = 0
isDataListChecked = false isDataListChecked = false
isDataListCheckedAll = false isDataListCheckedAll = false
selectedFile: File | null = null; selectedFile: File | null = null;
selectedFileName: string = 'กรุณาเลือกไฟล์'; selectedFileName: string = 'กรุณาเลือกไฟล์';
columns: ColumnModel[] = [{
field: "competencyCourseId",
headerText: "รหัส",
type: "string",
isPrimaryKey: true,
},
{
field: "tdesc",
headerText: "ชื่อเครื่องมือประเมิน",
type: "string"
}]
searchSettings = {
fields: ['competencyCourseId', 'tdesc'],
operator: 'contains',
ignoreCase: false
};
search = ''
selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() };
@ViewChild("developmentCourseModal") developmentCourseModal: any;
dialogRef: any
constructor(private toastr: ToastrService, constructor(private toastr: ToastrService,
private dialog: MatDialog,
private cdr: ChangeDetectorRef, private cdr: ChangeDetectorRef,
private competencycourseService: CompetencycourseService, private competencycourseService: CompetencycourseService,
private fileService: FileService private fileService: FileService
...@@ -80,13 +106,16 @@ export class DevelopmentCourseComponent { ...@@ -80,13 +106,16 @@ export class DevelopmentCourseComponent {
getCompetencycourseList() { getCompetencycourseList() {
this.competencyCourse.loading = true this.competencyCourse.loading = true
this.selectedItems.data.clear()
this.competencycourseService.getList().subscribe({ this.competencycourseService.getList().subscribe({
next: response => { next: response => {
this.competencyCourse.dataList = response.map(x => ({ check: false, data: new MyCompetencyCourseModel(x) })) this.competencyCourse.dataList = response.map(x => {
this.selectedItems.data.set(x.competencyCourseId, false)
return new MyCompetencyCourseModel(x)
})
this.selectedItems.key = 'competencyCourseId'
this.selectedItems.count = 0
this.competencyCourse.loading = false this.competencyCourse.loading = false
this.isDataListCheckedAll = false
this.dataListCheckAll()
this.searchChange()
this.cdr.detectChanges() this.cdr.detectChanges()
}, error: error => { }, error: error => {
this.competencyCourse.loading = false this.competencyCourse.loading = false
...@@ -94,85 +123,116 @@ export class DevelopmentCourseComponent { ...@@ -94,85 +123,116 @@ export class DevelopmentCourseComponent {
} }
}) })
} }
searchChange() {
this.currentPage = 1 selectCompetencycourse(competencyCourse?: CompetencyCourseModel) {
this.page = Array.from({ length: Math.ceil(this.dataListFilter().length / 10) }, (_, i) => i + 1); if (competencyCourse) {
this.dataListCheck() this.competencyCourse.select = new MyCompetencyCourseModel(competencyCourse)
} } else if (this.currentModal == 'add') {
dataListFilter() { this.competencyCourse.select = new MyCompetencyCourseModel()
return this.competencyCourse.dataList.filter(x => { } else if (this.currentModal == 'edit') {
const data = x.data this.competencyCourse.select = new MyCompetencyCourseModel({ competencyCourseId: this.competencyCourse.select.competencyCourseId })
const match = data.competencyCourseId.toLowerCase().includes(this.search.toLowerCase()) || data.tdesc.toLowerCase().includes(this.search.toLowerCase()) }
return match;
});
}
selectCompetencycourse(data?: CompetencyCourseModel) {
this.competencyCourse.select = new MyCompetencyCourseModel(data)
} }
updateCompetencyCourse(typeApi: 'post' | 'delete') { addDevelopmentCourse() {
this.competencyCourse.loading = true Swal.fire({
let body: CompetencyCourseModel | CompetencyCourseModel[] icon: 'question',
switch (this.currentModal) { title: 'แจ้งเตือน',
case ('deleteGroup'): { text: 'ยืนยันการบันทึกข้อมูลหรือไม่',
body = this.competencyCourse.dataList.filter(x => x.check).map(x => new MyCompetencyCourseModel(x.data)) showCancelButton: true,
break; confirmButtonText: 'บันทึกข้อมูล',
} cancelButtonText: 'ย้อนกลับ',
default: { reverseButtons: true,
body = new MyCompetencyCourseModel(this.competencyCourse.select) }).then((result) => {
if (result.isConfirmed) {
this.competencyCourse.loading = true
this.competencycourseService.post(this.competencyCourse.select).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getCompetencycourseList()
this.closeDialog()
} else {
this.showAlert(response.message, 'error')
this.competencyCourse.loading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.competencyCourse.loading = false
}
})
} }
})
}
deleteDevelopmentCourse() {
if (!this.numSelectItem()) {
this.showAlert('กรุณาเลือกข้อมูลที่ต้องการลบ', 'error')
return
} }
this.competencycourseService[typeApi]((body as any)).subscribe({ Swal.fire({
next: response => { icon: 'question',
if (response.success) { title: 'แจ้งเตือน',
this.showAlert(response.message, 'success') text: 'ยืนยันการลบข้อมูลหรือไม่',
this.getCompetencycourseList() showCancelButton: true,
this.searchChange() confirmButtonText: 'ลบข้อมูล',
} else { cancelButtonText: 'ย้อนกลับ',
this.showAlert(response.message, 'error') reverseButtons: true,
this.competencyCourse.loading = false }).then((result) => {
} if (result.isConfirmed) {
this.cdr.detectChanges() this.competencyCourse.loading = true
}, error: error => { const selectedKeys = Array.from(this.selectedItems.data.keys());
this.showAlert(error.message, 'error') const body = this.competencyCourse.dataList.filter(x => selectedKeys.includes(x.competencyCourseId) && this.selectedItems.data.get(x.competencyCourseId)).map(x => new MyCompetencyCourseModel(x))
this.competencyCourse.loading = false this.competencycourseService.delete(body).subscribe({
this.cdr.detectChanges() next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getCompetencycourseList()
this.closeDialog()
} else {
this.showAlert(response.message, 'error')
this.competencyCourse.loading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.competencyCourse.loading = false
}
})
} }
}) });
} }
showAlert(text: string, type: 'success' | 'error') { showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', { Swal.fire({
timeOut: 3000, title: 'แจ้งเตือน',
positionClass: 'toast-top-right', text: text,
}) icon: type,
confirmButtonText: 'ตกลง',
});
} }
dataListCheckAll() { checkPrimary() {
const selectAll = this.isDataListCheckedAll; return this.competencyCourse.dataList.find(x => x.competencyCourseId == this.competencyCourse.select.competencyCourseId)
this.competencyCourse.dataList.filter(x => {
const data = x.data
const match = data.competencyCourseId.toLowerCase().includes(this.search.toLowerCase()) || data.tdesc.toLowerCase().includes(this.search.toLowerCase())
return match;
}).forEach(x => x.check = selectAll);
this.dataListCheck();
} }
dataListCheck() { onSelectItemChange(arg: any) {
const dataCheck = this.dataListFilter(); this.selectedItems = arg
this.isDataListCheckedAll = dataCheck.length ? dataCheck.every(x => x.check) : false;
this.numDataListChecked = this.competencyCourse.dataList.filter(x => x.check).length;
this.isDataListChecked = Boolean(this.numDataListChecked)
} }
clearData(modalStatus: string) { numSelectItem() {
if (modalStatus == 'add') { const selectedKeys = Array.from(this.selectedItems.data.keys());
this.selectCompetencycourse() const num = this.competencyCourse.dataList.filter(x => selectedKeys.includes(x.competencyCourseId) && this.selectedItems.data.get(x.competencyCourseId)).length
} else if (modalStatus == 'edit') { return num
this.selectCompetencycourse(new MyCompetencyCourseModel({ competencyCourseId: this.competencyCourse.select.competencyCourseId }))
}
} }
checkPrimary() { openDialog() {
return this.competencyCourse.dataList.find(x => x.data.competencyCourseId == this.competencyCourse.select.competencyCourseId) this.dialogRef = this.dialog.open(this.developmentCourseModal, {
width: '500px',
disableClose: false,
});
}
closeDialog() {
this.dialogRef.close()
} }
} }
<div class="w-full min-height-50px mb-10px justify-between items-center"> <div class="w-full min-height-50px mb-10px justify-between items-center">
<div class="flex justify-between"> <div class="flex justify-between">
<div class="flex"> <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>
<div class="flex justify-end"> <div class="flex justify-end">
...@@ -22,7 +9,7 @@ ...@@ -22,7 +9,7 @@
<div class="relative shadow-md"> <div class="relative shadow-md">
<input type="text" id="hs-leading-icon" name="hs-leading-icon" <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" 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 <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"> 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> <i class="ri-search-line text-gray"></i>
...@@ -40,7 +27,7 @@ ...@@ -40,7 +27,7 @@
</div> </div>
<div class="px-1"> <div class="px-1">
<button type="button" class="ti-btn ti-btn-soft-secondary h-10 m-0 shadow-md" <button type="button" class="ti-btn ti-btn-soft-secondary h-10 m-0 shadow-md"
data-hs-overlay="#assessment-tool-modal" (click)="currentModal='add';selectAssessment()"> (click)="currentModal='add';selectAssessment();openDialog()">
<i class="ri-add-line"></i> <i class="ri-add-line"></i>
Add Add
</button> </button>
...@@ -48,119 +35,68 @@ ...@@ -48,119 +35,68 @@
<div class="px-1"> <div class="px-1">
<button href="javascript:void(0);" class="ti-btn ti-btn-soft-danger h-10 m-0 shadow-md" <button href="javascript:void(0);" class="ti-btn ti-btn-soft-danger h-10 m-0 shadow-md"
data-hs-overlay="#assessment-tool-alert-modal" data-hs-overlay="#assessment-tool-alert-modal"
(click)="currentModal='deleteGroup';selectAssessment()"> (click)="currentModal='delete';deleteAssessment()">
<i class="ri-delete-bin-6-line"></i> <i class="ri-delete-bin-6-line"></i>
Delete Delete
</button> </button>
</div> </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>
</div> </div>
<div class="page px-rem"> <div class="page px-rem">
<div class="overflow-auto shadow-md rounded-t-md"> <app-datagrid-syncfution [searchSettings]="searchSettings" [searchText]="search" [dataSource]="assessment.dataList"
<table class="ti-custom-table ti-custom-table-head ti-custom-table-hover table-bordered"> [columns]="columns" [selectedItems]="selectedItems"
<thead> (sendSelectData)="currentModal='edit';selectAssessment($event);openDialog()"
<tr> (sendSelectedItems)="onSelectItemChange($event)">
<ng-container </app-datagrid-syncfution>
*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="assessment.loading">
<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="!assessment.loading&&!assessmentListFilter().length">
<tr>
<td class="text-center" colspan="100%">
ไม่พบข้อมูล
</td>
</tr>
</tbody>
<tbody *ngIf="!assessment.loading&&assessmentListFilter().length">
<tr
*ngFor="let item of assessmentListFilter()| 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.assessmentId}}" [(ngModel)]="item.check"
(ngModelChange)="dataListCheck()">
</td>
<td class="text-center">
<label for="checkbox-{{item.data.assessmentId}}">&nbsp;{{item.data.assessmentId}}</label>
</td>
<td>{{item.data.tdesc}}</td>
<td class="text-center">{{item.data.shortName}}</td>
<td class="flex justify-center">
<i class="ti ti-edit cursor-pointer i-gray fs-l px-1" data-hs-overlay="#assessment-tool-modal"
(click)="currentModal='edit';selectAssessment(item.data)"></i>
<!-- <i class="ti ti-trash cursor-pointer i-gray fs-l px-1"
data-hs-overlay="#assessment-tool-alert-modal"
(click)="currentModal='delete';selectAssessment(item.data)"></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 {{assessmentListFilter().length<10
?assessmentListFilter().length: (currentPage==page.length ? ((currentPage * 10) - ((currentPage *
10) - assessmentListFilter().length) ) :(currentPage * 10) ) }} of {{assessmentListFilter().length}}
items</span>
</ul>
</nav>
</div> </div>
<ng-template #AssessmentModal let-modal>
<h3 mat-dialog-title>
{{currentModal=='add'?'เพิ่มเครื่องมือประเมิน':'แก้ไขเครื่องมือประเมิน'}}
</h3>
<div class="w-full flex justify-end">
<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)="selectAssessment()">
<i class="ti ti-eraser text-base"></i>
Clear
</button>
</div>
</div>
</div>
<mat-dialog-content>
<label for="input-label" class="ti-form-label mt-2rem">รหัส
<span class="text-danger">*
<ng-container *ngIf="checkPrimary()&&currentModal=='add'">
รหัสซ้ำ
</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)]="assessment.select.assessmentId">
<label for="detail_th" class="ti-form-label mt-1rem">ชื่อเครื่องมือประเมิน (ไทย)<span
class="text-danger">*</span></label>
<input type="text" id="detail_th" class="ti-form-input w-full" [(ngModel)]="assessment.select.tdesc">
<label for="detail_eng" class="ti-form-label mt-1rem">ชื่อเครื่องมือประเมิน (อังกฤษ)</label>
<input type="text" id="detail_eng" class="ti-form-input w-full" [(ngModel)]="assessment.select.edesc">
<label for="detail_eng" class="ti-form-label mt-1rem">ชื่อที่ใช้เเสดง<span class="text-danger">*</span></label>
<input type="text" id="showname" class="ti-form-input w-full" [(ngModel)]="assessment.select.shortName">
</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" (click)="addAssessment()"
[class.ti-btn-disabled]="!assessment.select.assessmentId||!assessment.select.tdesc||!assessment.select.shortName||(currentModal=='add'&&checkPrimary())"
[disabled]="!assessment.select.assessmentId||!assessment.select.tdesc||!assessment.select.shortName||(currentModal=='add'&&checkPrimary())">
บันทึกข้อมูล
</button>
</mat-dialog-actions>
</ng-template>
<div id="assessment-tool-upload-modal" class="hs-overlay hidden ti-modal"> <div id="assessment-tool-upload-modal" class="hs-overlay hidden ti-modal">
<div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out rounded-md"> <div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out rounded-md">
...@@ -197,145 +133,3 @@ ...@@ -197,145 +133,3 @@
</div> </div>
</div> </div>
</div> </div>
<div id="assessment-tool-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" *ngIf="currentModal=='add'">
เพิ่มเครื่องมือประเมิน
</h3>
<h3 class="text-xxl font-bold text-primary" *ngIf="currentModal=='edit'">
แก้ไขเครื่องมือประเมิน
</h3>
<div class="flex justify-end">
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
data-hs-overlay="#assessment-tool-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)="clearAssessment(currentModal)">
<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" style="padding-top: 0px;">
<label for="input-label" class="ti-form-label mt-1rem">รหัส<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)]="assessment.select.assessmentId">
<label for="detail_th" class="ti-form-label mt-1rem">ชื่อเครื่องมือประเมิน (ไทย)<span
class="text-danger">*</span></label>
<input type="text" id="detail_th" class="ti-form-input w-full" [(ngModel)]="assessment.select.tdesc">
<label for="detail_eng" class="ti-form-label mt-1rem">ชื่อเครื่องมือประเมิน (อังกฤษ)</label>
<input type="text" id="detail_eng" class="ti-form-input w-full" [(ngModel)]="assessment.select.edesc">
<label for="detail_eng" class="ti-form-label mt-1rem">ชื่อที่ใช้เเสดง<span
class="text-danger">*</span></label>
<input type="text" id="showname" class="ti-form-input w-full" [(ngModel)]="assessment.select.shortName">
<div class="flex justify-end mt-2rem mb-1rem">
<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="#assessment-tool-modal">
ย้อนกลับ
</button>
<button type="button" class="ti-btn ti-btn-success" data-hs-overlay="#assessment-tool-alert-modal"
[class.ti-btn-disabled]="!assessment.select.assessmentId||!assessment.select.tdesc||!assessment.select.shortName||(currentModal=='add'&&checkPrimary())"
[disabled]="!assessment.select.assessmentId||!assessment.select.tdesc||!assessment.select.shortName||(currentModal=='add'&&checkPrimary())">
บันทึกข้อมูล
</button>
</div>
</div>
</div>
</div>
</div>
<div id="assessment-tool-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" *ngIf="currentModal=='add'||currentModal=='edit'">
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
data-hs-overlay="#assessment-tool-modal">
<span class="sr-only">Close</span>
<i class="ti ti-circle-x fs-xxl"></i>
</button>
</div>
<div class="flex justify-end" *ngIf="currentModal=='delete'||currentModal=='deleteGroup'">
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
data-hs-overlay="#assessment-tool-alert-modal">
<span class="sr-only">Close</span>
<i class="ti ti-circle-x fs-xxl"></i>
</button>
</div>
</div>
<div class="ti-modal-body ">
<p class="mt-1 text-gray-800 dark:text-white/70" *ngIf="currentModal=='add'||currentModal=='edit'">
ยืนยันการบันทึกข้อมูลหรือไม่
</p>
<p class="mt-1 text-gray-800 dark:text-white/70"
*ngIf="currentModal=='delete'||currentModal=='deleteGroup'">
<ng-container *ngIf="numDataListChecked">
ยืนยันการลบข้อมูลหรือไม่
</ng-container>
<ng-container *ngIf="!numDataListChecked">
เลือกข้อมูลที่ต้องการลบ
</ng-container>
</p>
<div class="flex justify-end mt-2rem mb-1rem" *ngIf="currentModal=='add'||currentModal=='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="#assessment-tool-modal">
ย้อนกลับ
</button>
<button type="button" class="ti-btn ti-btn-success" data-hs-overlay="#assessment-tool-alert-modal"
(click)="updateAssessment('post')">
บันทึกข้อมูล
</button>
</div>
<div class="flex justify-end mt-2rem mb-1rem"
*ngIf="currentModal=='delete'||currentModal=='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="#assessment-tool-alert-modal">
ย้อนกลับ
</button>
<button type="button" class="ti-btn ti-btn-danger" data-hs-overlay="#assessment-tool-alert-modal"
*ngIf="numDataListChecked" (click)="updateAssessment('delete')">
ลบข้อมูล
</button>
</div>
</div>
</div>
</div>
</div>
\ No newline at end of file
import { ChangeDetectorRef, Component, EventEmitter, Input, Output } from '@angular/core'; import { ChangeDetectorRef, Component, EventEmitter, Input, Output, ViewChild } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { ColumnModel } from '@syncfusion/ej2-grids';
import { ToastrService } from 'ngx-toastr'; import { ToastrService } from 'ngx-toastr';
import { AssessmentModel, MyAssessmentModel } from 'src/app/shared/model/assessment.model'; import { AssessmentModel, MyAssessmentModel } from 'src/app/shared/model/assessment.model';
import { AssessmentService } from 'src/app/shared/services/assessment.service'; import { AssessmentService } from 'src/app/shared/services/assessment.service';
import { FileService } from 'src/app/shared/services/file.service'; import { FileService } from 'src/app/shared/services/file.service';
export interface DataModel { import { data } from '../../../datagrid-syncfution/data';
id: string import Swal from 'sweetalert2';
name: string
edesc: string
code: string
checked: boolean
}
@Component({ @Component({
selector: 'app-assessment-tool', selector: 'app-assessment-tool',
templateUrl: './assessment-tool.component.html', templateUrl: './assessment-tool.component.html',
...@@ -18,17 +16,46 @@ export interface DataModel { ...@@ -18,17 +16,46 @@ export interface DataModel {
export class AssessmentToolComponent { export class AssessmentToolComponent {
currentPage = 1 currentPage = 1
page = Array.from({ length: 1 }, (_, i) => i + 1); page = Array.from({ length: 1 }, (_, i) => i + 1);
search = ""
numDataListChecked = 0 numDataListChecked = 0
isDataListChecked = false isDataListChecked = false
isDataListCheckedAll = false isDataListCheckedAll = false
assessment: { loading: boolean, select: AssessmentModel, dataList: { check: boolean, data: AssessmentModel }[] } = { loading: false, select: new MyAssessmentModel(), dataList: [] } assessment: { loading: boolean, select: AssessmentModel, dataList: AssessmentModel[] } = { loading: false, select: new MyAssessmentModel(), dataList: [] }
currentModal: 'add' | 'edit' | 'delete' | 'deleteGroup' = "add" currentModal: 'add' | 'edit' | 'delete' = "add"
selectedFile: File | null = null; selectedFile: File | null = null;
selectedFileName: string = 'กรุณาเลือกไฟล์'; selectedFileName: string = 'กรุณาเลือกไฟล์';
columns: ColumnModel[] = [{
field: "assessmentId",
headerText: "รหัส",
type: "string",
isPrimaryKey: true,
},
{
field: "tdesc",
headerText: "ชื่อเครื่องมือประเมิน",
type: "string"
},
{
field: "shortName",
headerText: "ชื่อที่เเสดง",
type: "string"
}]
searchSettings = {
fields: ['assessmentId', 'tdesc', 'shortName'],
operator: 'contains',
ignoreCase: false
};
search = ''
selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() };
@ViewChild("AssessmentModal") AssessmentModal: any;
dialogRef: any
constructor(private toastr: ToastrService, constructor(private toastr: ToastrService,
private dialog: MatDialog,
private cdr: ChangeDetectorRef, private cdr: ChangeDetectorRef,
private assessmentService: AssessmentService, private assessmentService: AssessmentService,
private fileService: FileService private fileService: FileService
...@@ -85,104 +112,137 @@ export class AssessmentToolComponent { ...@@ -85,104 +112,137 @@ export class AssessmentToolComponent {
} }
getAssessmentList() { getAssessmentList() {
this.assessment.loading = true this.assessment.loading = true
this.selectedItems.data.clear()
this.assessmentService.getList().subscribe({ this.assessmentService.getList().subscribe({
next: response => { next: response => {
this.assessment.dataList = response.map(x => ({ check: false, data: new MyAssessmentModel(x) })) this.assessment.dataList = response.map(x => {
this.isDataListCheckedAll = false this.selectedItems.data.set(x.assessmentId, false)
this.dataListCheckAll() return new MyAssessmentModel(x)
})
this.selectedItems.key = 'assessmentId'
this.selectedItems.count = 0
this.assessment.loading = false this.assessment.loading = false
this.searchChange()
this.cdr.detectChanges() this.cdr.detectChanges()
}, error: error => { },
error: error => {
this.assessment.loading = false this.assessment.loading = false
this.cdr.detectChanges() this.cdr.detectChanges()
} }
}) })
} }
assessmentListFilter() {
return this.assessment.dataList.filter(x => { selectAssessment(assessment?: AssessmentModel) {
const data = x.data if (assessment) {
const match = data.assessmentId.toLowerCase().includes(this.search.toLowerCase()) || this.assessment.select = new MyAssessmentModel(assessment)
data.tdesc.toLowerCase().includes(this.search.toLowerCase()) || } else if (this.currentModal == 'add') {
data.shortName.toLowerCase().includes(this.search.toLowerCase()) this.assessment.select = new MyAssessmentModel()
return match } else if (this.currentModal == 'edit') {
}) this.assessment.select = new MyAssessmentModel({ assessmentId: this.assessment.select.assessmentId })
}
selectAssessment(data?: AssessmentModel) {
this.assessment.select = new MyAssessmentModel(data)
}
clearAssessment(currentModal: string) {
if (currentModal == 'add') {
this.selectAssessment()
} else if (currentModal == 'edit') {
this.selectAssessment(new MyAssessmentModel({ assessmentId: this.assessment.select.assessmentId }))
} }
} }
searchChange() {
this.currentPage = 1 addAssessment() {
this.page = Array.from({ length: Math.ceil(this.assessmentListFilter().length / 10) }, (_, i) => i + 1); Swal.fire({
this.dataListCheck() icon: 'question',
} title: 'แจ้งเตือน',
showAlert(text: string, type: 'success' | 'error') { text: 'ยืนยันการบันทึกข้อมูลหรือไม่',
this.toastr[type](text, 'แจ้งเตือน', { showCancelButton: true,
timeOut: 3000, confirmButtonText: 'บันทึกข้อมูล',
positionClass: 'toast-top-right', cancelButtonText: 'ย้อนกลับ',
reverseButtons: true,
}).then((result) => {
if (result.isConfirmed) {
this.assessment.loading = true
this.assessmentService.post(this.assessment.select).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getAssessmentList()
this.closeDialog()
} else {
this.showAlert(response.message, 'error')
this.assessment.loading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.assessment.loading = false
}
})
}
}) })
} }
updateAssessment(typeApi: 'post' | 'delete') {
this.assessment.loading = true deleteAssessment() {
let body: AssessmentModel | AssessmentModel[] if (!this.numSelectItem()) {
switch (this.currentModal) { this.showAlert('กรุณาเลือกข้อมูลที่ต้องการลบ', 'error')
case ('delete'): { return
body = new MyAssessmentModel(this.assessment.select)
break;
}
case ('deleteGroup'): {
body = this.assessment.dataList.filter(x => x.check).map(x => new MyAssessmentModel(x.data))
break;
}
default: {
body = new MyAssessmentModel(this.assessment.select)
}
} }
this.assessmentService[typeApi]((body as any)).subscribe({ Swal.fire({
next: response => { icon: 'question',
if (response.success) { title: 'แจ้งเตือน',
this.showAlert(response.message, 'success') text: 'ยืนยันการลบข้อมูลหรือไม่',
this.getAssessmentList() showCancelButton: true,
this.searchChange() confirmButtonText: 'ลบข้อมูล',
} else { cancelButtonText: 'ย้อนกลับ',
this.showAlert(response.message, 'error') reverseButtons: true,
this.assessment.loading = false }).then((result) => {
} if (result.isConfirmed) {
this.cdr.detectChanges() this.assessment.loading = true
}, error: error => { const selectedKeys = Array.from(this.selectedItems.data.keys());
this.showAlert(error.message, 'error') const body = this.assessment.dataList.filter(x => selectedKeys.includes(x.assessmentId) && this.selectedItems.data.get(x.assessmentId)).map(x => new MyAssessmentModel(x))
this.assessment.loading = false this.assessmentService.delete(body).subscribe({
this.cdr.detectChanges() next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getAssessmentList()
this.closeDialog()
} else {
this.showAlert(response.message, 'error')
this.assessment.loading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.assessment.loading = false
}
})
} }
}) });
} }
dataListCheckAll() {
const selectAll = this.isDataListCheckedAll; showAlert(text: string, type: 'success' | 'error') {
this.assessment.dataList.filter(x => { Swal.fire({
const data = x.data title: 'แจ้งเตือน',
const match = data.assessmentId.toLowerCase().includes(this.search.toLowerCase()) || text: text,
data.tdesc.toLowerCase().includes(this.search.toLowerCase()) || icon: type,
data.shortName.toLowerCase().includes(this.search.toLowerCase()) confirmButtonText: 'ตกลง',
return match });
}).forEach(x => x.check = selectAll);
this.dataListCheck();
}
dataListCheck() {
const dataCheck = this.assessmentListFilter();
this.isDataListCheckedAll = dataCheck.length ? dataCheck.every(x => x.check) : false;
this.numDataListChecked = this.assessment.dataList.filter(x => x.check).length;
this.isDataListChecked = Boolean(this.numDataListChecked)
} }
checkPrimary() { checkPrimary() {
return this.assessment.dataList.find(x => x.data.assessmentId == this.assessment.select.assessmentId) return this.assessment.dataList.find(x => x.assessmentId == this.assessment.select.assessmentId)
}
onSelectItemChange(arg: any) {
this.selectedItems = arg
}
numSelectItem() {
const selectedKeys = Array.from(this.selectedItems.data.keys());
const num = this.assessment.dataList.filter(x => selectedKeys.includes(x.assessmentId) && this.selectedItems.data.get(x.assessmentId)).length
return num
}
openDialog() {
this.dialogRef = this.dialog.open(this.AssessmentModal, {
width: '500px',
disableClose: false,
});
}
closeDialog() {
this.dialogRef.close()
} }
} }
...@@ -21,7 +21,7 @@ export class AssessmentService { ...@@ -21,7 +21,7 @@ export class AssessmentService {
post(body: AssessmentModel): Observable<AlertModel> { post(body: AssessmentModel): Observable<AlertModel> {
return this.http.post<AlertModel>(this.urlApi, body) return this.http.post<AlertModel>(this.urlApi, body)
} }
delete(body: AssessmentModel): Observable<AlertModel> { delete(body: AssessmentModel | AssessmentModel[]): Observable<AlertModel> {
const options = { const options = {
headers: new HttpHeaders({ headers: new HttpHeaders({
"Content-Type": "application/json", "Content-Type": "application/json",
......
...@@ -25,7 +25,7 @@ export class CompetencycourseService { ...@@ -25,7 +25,7 @@ export class CompetencycourseService {
post(body: CompetencycourseModel): Observable<AlertModel> { post(body: CompetencycourseModel): Observable<AlertModel> {
return this.http.post<AlertModel>(this.urlApi, body) return this.http.post<AlertModel>(this.urlApi, body)
} }
delete(body: CompetencycourseModel): Observable<AlertModel> { delete(body: CompetencycourseModel | CompetencycourseModel[]): Observable<AlertModel> {
const options = { const options = {
headers: new HttpHeaders({ headers: new HttpHeaders({
"Content-Type": "application/json", "Content-Type": "application/json",
......
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