Commit 4b70dbad by Natthaphat

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

ทะเบียนหลักสูตร > หลักสูตรการพัฒนา
parent 9fc248ab
<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">
......@@ -22,7 +9,7 @@
<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>
......@@ -40,226 +27,61 @@
</div>
<div class="px-1">
<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>
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="#development-course-alert-modal"
(click)="currentModal='deleteGroup';selectCompetencycourse()">
(click)="currentModal='delete';deleteDevelopmentCourse()">
<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="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>
<td class="text-center">
<label
for="checkbox-{{item.data.competencyCourseId}}">&nbsp;{{item.data.competencyCourseId}}</label>
</td>
<td>{{item.data.tdesc}}</td>
<td class="flex justify-center">
<i class="ti ti-edit cursor-pointer i-gray fs-l px-1"
(click)="currentModal='edit' ;selectCompetencycourse(item.data)"
data-hs-overlay="#development-course-modal"></i>
<!-- <i class="ti ti-trash cursor-pointer i-gray fs-l px-1"
(click)="currentModal='delete' ;selectCompetencycourse(item.data)"
data-hs-overlay="#development-course-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]="competencyCourse.dataList" [columns]="columns" [selectedItems]="selectedItems"
(sendSelectData)="currentModal='edit';selectCompetencycourse($event);openDialog()"
(sendSelectedItems)="onSelectItemChange($event)">
</app-datagrid-syncfution>
</div>
<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="ti-modal-header bg-primary !rounded-none !rounded-t-sm">
<h5 class="text-xxl font-bold text-white">
นำเข้าหลักสูตรการพัฒนา
</h5>
</div>
<div class="ti-modal-body max-h-full overflow-hidden ti-modal-content !rounded-t-none !rounded-b-sm">
<h1 class="mt-2" style="text-align: center;">ไฟล์</h1>
<div class="mt-2 p-2">
<div class="flex rounded-md">
<input #fileInput id="fileInput" type="file" (change)="onFileSelected($event)" hidden>
<input type="text" [value]="selectedFileName" readonly (click)="fileInput.click()"
class="ti-form-input rounded-none ltr:rounded-l-md rtl:rounded-r-md focus:z-10 cursor-pointer">
<button type="button" (click)="fileInput.click()"
class="inline-flex flex-shrink-0 justify-center items-center h-[2.875rem] w-[2.875rem] ltr:rounded-r-md rtl:rounded-l-md border border-transparent font-semibold bg-secondary text-white hover:bg-secondary focus:z-10 focus:outline-none focus:ring-0 focus:ring-secondary transition-all text-sm">
<i class="ti ti-upload"></i>
</button>
</div>
<div class="flex justify-center mt-2rem ">
<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)="downloadFile()">
ดาวน์โหลดตัวอย่างไฟล์</h1>
</div>
<div class="flex justify-center mt-2rem mb-1rem space-x-4">
<button type="submit" class="ti-btn ti-btn-secondary"
data-hs-overlay="#type-registration-component-upload-modal"
[class.ti-btn-disabled]="!selectedFile" (click)="uploadFile()" [disabled]="!selectedFile"
[disabled]="!selectedFile">
อัปโหลด
</button>
</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'">
แก้ไขหลักสูตรการพัฒนา
<ng-template #developmentCourseModal let-modal>
<h3 mat-dialog-title>
{{currentModal=='add'?'เพิ่มหลักสูตรการพัฒนา':'แก้ไขหลักสูตรการพัฒนา'}}
</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="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)="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>
(click)="selectCompetencycourse()">
<i class="ti ti-eraser text-base"></i>
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()">
<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>
</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">
<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">
<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>
......@@ -268,83 +90,51 @@
[(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">
</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"
data-hs-overlay="#development-course-alert-modal"
<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>
</div>
</div>
</div>
</div>
</div>
</mat-dialog-actions>
</ng-template>
<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 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="ti-modal-header bg-primary !rounded-none !rounded-t-sm">
<h5 class="text-xxl font-bold text-white">
นำเข้าหลักสูตรการพัฒนา
</h5>
</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">
ย้อนกลับ
<div class="ti-modal-body max-h-full overflow-hidden ti-modal-content !rounded-t-none !rounded-b-sm">
<h1 class="mt-2" style="text-align: center;">ไฟล์</h1>
<div class="mt-2 p-2">
<div class="flex rounded-md">
<input #fileInput id="fileInput" type="file" (change)="onFileSelected($event)" hidden>
<input type="text" [value]="selectedFileName" readonly (click)="fileInput.click()"
class="ti-form-input rounded-none ltr:rounded-l-md rtl:rounded-r-md focus:z-10 cursor-pointer">
<button type="button" (click)="fileInput.click()"
class="inline-flex flex-shrink-0 justify-center items-center h-[2.875rem] w-[2.875rem] ltr:rounded-r-md rtl:rounded-l-md border border-transparent font-semibold bg-secondary text-white hover:bg-secondary focus:z-10 focus:outline-none focus:ring-0 focus:ring-secondary transition-all text-sm">
<i class="ti ti-upload"></i>
</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">
ย้อนกลับ
<div class="flex justify-center mt-2rem ">
<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)="downloadFile()">
ดาวน์โหลดตัวอย่างไฟล์</h1>
</div>
<div class="flex justify-center mt-2rem mb-1rem space-x-4">
<button type="submit" class="ti-btn ti-btn-secondary"
data-hs-overlay="#type-registration-component-upload-modal"
[class.ti-btn-disabled]="!selectedFile" (click)="uploadFile()" [disabled]="!selectedFile"
[disabled]="!selectedFile">
อัปโหลด
</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>
......
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 { CompetencyCourseModel, MyCompetencyCourseModel } from 'src/app/shared/model/competency-course.model';
import { MyCompetencycourseModel } from 'src/app/shared/model/competencycourse.model';
import { CompetencycourseService } from 'src/app/shared/services/competencycourse.service';
import { FileService } from 'src/app/shared/services/file.service';
import Swal from 'sweetalert2';
@Component({
selector: 'app-development-course',
templateUrl: './development-course.component.html',
......@@ -12,17 +15,40 @@ import { FileService } from 'src/app/shared/services/file.service';
export class DevelopmentCourseComponent {
currentPage = 1
page = Array.from({ length: 1 }, (_, i) => i + 1);
search = ""
currentModal: 'add' | 'edit' | 'delete' | 'deleteGroup' = "add";
competencyCourse: { loading: boolean, select: CompetencyCourseModel, dataList: { check: boolean, data: CompetencyCourseModel }[] } = { loading: false, select: new MyCompetencyCourseModel(), dataList: [] }
currentModal: 'add' | 'edit' | 'delete' = "add";
competencyCourse: { loading: boolean, select: CompetencyCourseModel, dataList: CompetencyCourseModel[] } = { loading: false, select: new MyCompetencyCourseModel(), dataList: [] }
numDataListChecked = 0
isDataListChecked = false
isDataListCheckedAll = false
selectedFile: File | null = null;
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,
private dialog: MatDialog,
private cdr: ChangeDetectorRef,
private competencycourseService: CompetencycourseService,
private fileService: FileService
......@@ -80,13 +106,16 @@ export class DevelopmentCourseComponent {
getCompetencycourseList() {
this.competencyCourse.loading = true
this.selectedItems.data.clear()
this.competencycourseService.getList().subscribe({
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.isDataListCheckedAll = false
this.dataListCheckAll()
this.searchChange()
this.cdr.detectChanges()
}, error: error => {
this.competencyCourse.loading = false
......@@ -94,85 +123,116 @@ export class DevelopmentCourseComponent {
}
})
}
searchChange() {
this.currentPage = 1
this.page = Array.from({ length: Math.ceil(this.dataListFilter().length / 10) }, (_, i) => i + 1);
this.dataListCheck()
}
dataListFilter() {
return 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;
});
selectCompetencycourse(competencyCourse?: CompetencyCourseModel) {
if (competencyCourse) {
this.competencyCourse.select = new MyCompetencyCourseModel(competencyCourse)
} else if (this.currentModal == 'add') {
this.competencyCourse.select = new MyCompetencyCourseModel()
} else if (this.currentModal == 'edit') {
this.competencyCourse.select = new MyCompetencyCourseModel({ competencyCourseId: this.competencyCourse.select.competencyCourseId })
}
selectCompetencycourse(data?: CompetencyCourseModel) {
this.competencyCourse.select = new MyCompetencyCourseModel(data)
}
updateCompetencyCourse(typeApi: 'post' | 'delete') {
addDevelopmentCourse() {
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการบันทึกข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'บันทึกข้อมูล',
cancelButtonText: 'ย้อนกลับ',
reverseButtons: true,
}).then((result) => {
if (result.isConfirmed) {
this.competencyCourse.loading = true
let body: CompetencyCourseModel | CompetencyCourseModel[]
switch (this.currentModal) {
case ('deleteGroup'): {
body = this.competencyCourse.dataList.filter(x => x.check).map(x => new MyCompetencyCourseModel(x.data))
break;
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
}
default: {
body = new MyCompetencyCourseModel(this.competencyCourse.select)
}, error: error => {
this.showAlert(error.message, 'error')
this.competencyCourse.loading = false
}
})
}
this.competencycourseService[typeApi]((body as any)).subscribe({
})
}
deleteDevelopmentCourse() {
if (!this.numSelectItem()) {
this.showAlert('กรุณาเลือกข้อมูลที่ต้องการลบ', 'error')
return
}
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการลบข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ลบข้อมูล',
cancelButtonText: 'ย้อนกลับ',
reverseButtons: true,
}).then((result) => {
if (result.isConfirmed) {
this.competencyCourse.loading = true
const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.competencyCourse.dataList.filter(x => selectedKeys.includes(x.competencyCourseId) && this.selectedItems.data.get(x.competencyCourseId)).map(x => new MyCompetencyCourseModel(x))
this.competencycourseService.delete(body).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getCompetencycourseList()
this.searchChange()
this.closeDialog()
} else {
this.showAlert(response.message, 'error')
this.competencyCourse.loading = false
}
this.cdr.detectChanges()
}, error: error => {
this.showAlert(error.message, 'error')
this.competencyCourse.loading = 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: 'ตกลง',
});
}
dataListCheckAll() {
const selectAll = this.isDataListCheckedAll;
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();
checkPrimary() {
return this.competencyCourse.dataList.find(x => x.competencyCourseId == this.competencyCourse.select.competencyCourseId)
}
dataListCheck() {
const dataCheck = this.dataListFilter();
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)
onSelectItemChange(arg: any) {
this.selectedItems = arg
}
clearData(modalStatus: string) {
if (modalStatus == 'add') {
this.selectCompetencycourse()
} else if (modalStatus == 'edit') {
this.selectCompetencycourse(new MyCompetencyCourseModel({ competencyCourseId: this.competencyCourse.select.competencyCourseId }))
numSelectItem() {
const selectedKeys = Array.from(this.selectedItems.data.keys());
const num = this.competencyCourse.dataList.filter(x => selectedKeys.includes(x.competencyCourseId) && this.selectedItems.data.get(x.competencyCourseId)).length
return num
}
openDialog() {
this.dialogRef = this.dialog.open(this.developmentCourseModal, {
width: '500px',
disableClose: false,
});
}
checkPrimary() {
return this.competencyCourse.dataList.find(x => x.data.competencyCourseId == this.competencyCourse.select.competencyCourseId)
closeDialog() {
this.dialogRef.close()
}
}
<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">
......@@ -22,7 +9,7 @@
<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>
......@@ -40,7 +27,7 @@
</div>
<div class="px-1">
<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>
Add
</button>
......@@ -48,119 +35,68 @@
<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="#assessment-tool-alert-modal"
(click)="currentModal='deleteGroup';selectAssessment()">
(click)="currentModal='delete';deleteAssessment()">
<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>
<app-datagrid-syncfution [searchSettings]="searchSettings" [searchText]="search" [dataSource]="assessment.dataList"
[columns]="columns" [selectedItems]="selectedItems"
(sendSelectData)="currentModal='edit';selectAssessment($event);openDialog()"
(sendSelectedItems)="onSelectItemChange($event)">
</app-datagrid-syncfution>
</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>
</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>
<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>
</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>
</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 class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out rounded-md">
......@@ -197,145 +133,3 @@
</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 { AssessmentModel, MyAssessmentModel } from 'src/app/shared/model/assessment.model';
import { AssessmentService } from 'src/app/shared/services/assessment.service';
import { FileService } from 'src/app/shared/services/file.service';
export interface DataModel {
id: string
name: string
edesc: string
code: string
checked: boolean
}
import { data } from '../../../datagrid-syncfution/data';
import Swal from 'sweetalert2';
@Component({
selector: 'app-assessment-tool',
templateUrl: './assessment-tool.component.html',
......@@ -18,17 +16,46 @@ export interface DataModel {
export class AssessmentToolComponent {
currentPage = 1
page = Array.from({ length: 1 }, (_, i) => i + 1);
search = ""
numDataListChecked = 0
isDataListChecked = 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;
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,
private dialog: MatDialog,
private cdr: ChangeDetectorRef,
private assessmentService: AssessmentService,
private fileService: FileService
......@@ -85,104 +112,137 @@ export class AssessmentToolComponent {
}
getAssessmentList() {
this.assessment.loading = true
this.selectedItems.data.clear()
this.assessmentService.getList().subscribe({
next: response => {
this.assessment.dataList = response.map(x => ({ check: false, data: new MyAssessmentModel(x) }))
this.isDataListCheckedAll = false
this.dataListCheckAll()
this.assessment.dataList = response.map(x => {
this.selectedItems.data.set(x.assessmentId, false)
return new MyAssessmentModel(x)
})
this.selectedItems.key = 'assessmentId'
this.selectedItems.count = 0
this.assessment.loading = false
this.searchChange()
this.cdr.detectChanges()
}, error: error => {
},
error: error => {
this.assessment.loading = false
this.cdr.detectChanges()
}
})
}
assessmentListFilter() {
return this.assessment.dataList.filter(x => {
const data = x.data
const match = data.assessmentId.toLowerCase().includes(this.search.toLowerCase()) ||
data.tdesc.toLowerCase().includes(this.search.toLowerCase()) ||
data.shortName.toLowerCase().includes(this.search.toLowerCase())
return match
})
}
selectAssessment(data?: AssessmentModel) {
this.assessment.select = new MyAssessmentModel(data)
selectAssessment(assessment?: AssessmentModel) {
if (assessment) {
this.assessment.select = new MyAssessmentModel(assessment)
} else if (this.currentModal == 'add') {
this.assessment.select = new MyAssessmentModel()
} else if (this.currentModal == 'edit') {
this.assessment.select = new MyAssessmentModel({ assessmentId: this.assessment.select.assessmentId })
}
clearAssessment(currentModal: string) {
if (currentModal == 'add') {
this.selectAssessment()
} else if (currentModal == 'edit') {
this.selectAssessment(new MyAssessmentModel({ assessmentId: this.assessment.select.assessmentId }))
}
addAssessment() {
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการบันทึกข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'บันทึกข้อมูล',
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
}
searchChange() {
this.currentPage = 1
this.page = Array.from({ length: Math.ceil(this.assessmentListFilter().length / 10) }, (_, i) => i + 1);
this.dataListCheck()
}, error: error => {
this.showAlert(error.message, 'error')
this.assessment.loading = false
}
showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', {
timeOut: 3000,
positionClass: 'toast-top-right',
})
}
updateAssessment(typeApi: 'post' | 'delete') {
this.assessment.loading = true
let body: AssessmentModel | AssessmentModel[]
switch (this.currentModal) {
case ('delete'): {
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)
})
}
deleteAssessment() {
if (!this.numSelectItem()) {
this.showAlert('กรุณาเลือกข้อมูลที่ต้องการลบ', 'error')
return
}
this.assessmentService[typeApi]((body as any)).subscribe({
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการลบข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ลบข้อมูล',
cancelButtonText: 'ย้อนกลับ',
reverseButtons: true,
}).then((result) => {
if (result.isConfirmed) {
this.assessment.loading = true
const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.assessment.dataList.filter(x => selectedKeys.includes(x.assessmentId) && this.selectedItems.data.get(x.assessmentId)).map(x => new MyAssessmentModel(x))
this.assessmentService.delete(body).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getAssessmentList()
this.searchChange()
this.closeDialog()
} else {
this.showAlert(response.message, 'error')
this.assessment.loading = false
}
this.cdr.detectChanges()
}, error: error => {
this.showAlert(error.message, 'error')
this.assessment.loading = false
this.cdr.detectChanges()
}
})
}
dataListCheckAll() {
const selectAll = this.isDataListCheckedAll;
this.assessment.dataList.filter(x => {
const data = x.data
const match = data.assessmentId.toLowerCase().includes(this.search.toLowerCase()) ||
data.tdesc.toLowerCase().includes(this.search.toLowerCase()) ||
data.shortName.toLowerCase().includes(this.search.toLowerCase())
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)
showAlert(text: string, type: 'success' | 'error') {
Swal.fire({
title: 'แจ้งเตือน',
text: text,
icon: type,
confirmButtonText: 'ตกลง',
});
}
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 {
post(body: AssessmentModel): Observable<AlertModel> {
return this.http.post<AlertModel>(this.urlApi, body)
}
delete(body: AssessmentModel): Observable<AlertModel> {
delete(body: AssessmentModel | AssessmentModel[]): Observable<AlertModel> {
const options = {
headers: new HttpHeaders({
"Content-Type": "application/json",
......
......@@ -25,7 +25,7 @@ export class CompetencycourseService {
post(body: CompetencycourseModel): Observable<AlertModel> {
return this.http.post<AlertModel>(this.urlApi, body)
}
delete(body: CompetencycourseModel): Observable<AlertModel> {
delete(body: CompetencycourseModel | CompetencycourseModel[]): Observable<AlertModel> {
const options = {
headers: new HttpHeaders({
"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