Commit f908e039 by sawit

Major menu

parent a02d4d4f
......@@ -5,17 +5,20 @@ export interface LanguagesModel {
languagesId: string
thName: string
engName: string
chinaName: string
}
export class LanguagesModel extends BaseModel implements LanguagesModel {
languagesId: string
thName: string
engName: string
chinaName: string
constructor(data?: Partial<LanguagesModel>, translateService?: TranslateService) {
super(data, translateService)
this.languagesId = checkData(data?.languagesId)
this.thName = checkData(data?.thName)
this.engName = checkData(data?.engName)
this.chinaName = checkData(data?.chinaName)
}
getName() {
......
import { TranslateService } from "@ngx-translate/core";
import { BaseModel, baseGetName, checkData } from "./base.model";
export interface MajorModel {
majorId: string
thName: string
engName: string
chinaName: string
}
export class MajorModel extends BaseModel implements MajorModel {
majorId: string
thName: string
engName: string
chinaName: string
constructor(data?: Partial<MajorModel>, translateService?: TranslateService) {
super(data, translateService)
this.majorId = checkData(data?.majorId)
this.thName = checkData(data?.thName)
this.engName = checkData(data?.engName)
this.chinaName = checkData(data?.chinaName)
}
getName() {
return baseGetName(this.thName, this.engName, this.translateService?.currentLang)
}
}
<app-page-header [title]="'จัดการสาขาวิชา'" [activeTitle]="'ผู้ดูแลระบบ'" [title1]="'จัดการสาขาวิชา'"></app-page-header>
<div class="grid grid-cols-12 gap-6">
<div class="xl:col-span-12 col-span-12">
<div class="box">
<div class="box-header justify-between">
<div class="box-title">
{{ 'All List' | translate}} <span
class="badge bg-light text-default rounded-full ms-1 text-[0.75rem] align-middle">{{itemsList.length}}</span>
</div>
<div class="flex flex-wrap gap-2">
<a href="javascript:void(0);" class="hs-dropdown-toggle ti-btn ti-btn-primary-full me-2" (click)="new()"
data-hs-overlay="#modal-detail"><i
class="ri-add-line font-semibold align-middle"></i>{{ 'Create' |
translate}}
</a>
<a href="javascript:void(0);" class="hs-dropdown-toggle ti-btn ti-btn-danger-full me-2" *ngIf="someSelected"
(click)="deleteSelect()"><i class="ri-delete-bin-line font-semibold align-middle"></i>{{ 'Delete' | translate}}</a>
<div>
<input class="form-control form-control" type="text" placeholder="ค้นหาสาขาวิชา"
aria-label=".form-control-sm example" [(ngModel)]='searchTerm'>
</div>
</div>
</div>
<div class="box-body">
<div class="table-responsive">
<table class="table whitespace-nowrap min-w-full ti-custom-table-hover">
<thead>
<tr class="border-b border-defaultborder">
<th scope="col" class="!text-start">
<input class="form-check-input check-all" type="checkbox" id="all-products"
(change)="toggleAll($event)" [checked]="allSelected" aria-label="...">
</th>
<th scope="col" class="text-start">{{ 'Major ID' | translate}}</th>
<th scope="col" class="text-start">{{ 'Description(TH)' | translate}}</th>
<th scope="col" class="text-start">{{ 'Description(ENG)' | translate}}</th>
<th scope="col" class="text-start">{{ 'Description(CHINA)' | translate}}</th>
<!-- <th scope="col" class="text-start">{{ 'Remark' | translate}}</th> -->
<th scope="col" class="text-start">{{ 'Action' | translate}}</th>
</tr>
</thead>
<tbody>
@if (filterList.length > 0) {
@for (item of filterList; track item.majorId) {
<tr class="border border-defaultborder dark:border-defaultborder/10">
<td class="product-checkbox">
<input class="form-check-input" type="checkbox" [checked]="selectedItems.get(item.majorId) || false"
(change)="onCheckboxChange(item.majorId)" aria-label="...">
</td>
<td>
<span class="block mb-1">
{{item.majorId}}
</span>
</td>
<td>
<div>
<span class="block mb-1">
{{item.thName}}
</span>
</div>
</td>
<td>
<div>
<span class="block mb-1">
{{item.engName}}
</span>
</div>
</td>
<td>
<div>
<span class="block mb-1">
{{item.chinaName}}
</span>
</div>
</td>
<!-- <td>
<div>
<span class="block mb-1">
{{item.remark}}
</span>
</div>
</td> -->
<td>
<div class="flex flex-row items-center !gap-2 ">
<a aria-label="anchor" (click)="view(item)" data-hs-overlay="#modal-detail"
class="ti-btn ti-btn-wave !gap-0 !m-0 bg-info/10 text-info hover:bg-info hover:text-white hover:border-info">
<i class="ri-pencil-line"></i>
</a>
<a aria-label="anchor" href="javascript:void(0);" (click)="delete(item)"
class="ti-btn ti-btn-wave product-btn !gap-0 !m-0 bg-danger/10 text-danger hover:bg-danger hover:text-white hover:border-danger">
<i class="ri-delete-bin-line"></i>
</a>
</div>
</td>
</tr>
}
} @else {
<tr>
<td [attr.colspan]="6" class="text-center py-4">
<ng-container *ngIf="itemsList.length === 0 && !searchTerm">
<p>กำลังโหลดข้อมูล หรือไม่มีข้อมูลเลย...</p>
</ng-container>
<ng-container *ngIf="itemsList.length > 0 && filterList.length === 0 && searchTerm">
<p>ไม่พบข้อมูลที่ค้นหา...</p>
</ng-container>
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
<div class="box-footer">
<div class="flex items-center flex-wrap overflow-auto" *ngIf="filterList.length > 0">
<div class="mb-2 sm:mb-0">
<div>
{{'Showing' | translate}} {{filterList.length}} {{'entries'
| translate}} <i class="bi bi-arrow-right ms-2 font-semibold"></i>
</div>
</div>
<div class="ms-auto">
<nav aria-label="Page navigation">
<ul class="ti-pagination mb-0">
<li *ngIf="pageIndex>0" class="page-item {{pageIndex==0 ? 'disabled' : ''}}"><a
class="page-link px-3 py-[0.375rem] cursor-pointer"
(click)="pageIndex = pageIndex-1;updatePagedItems()">{{'Previous' | translate}}</a></li>
<li class="page-item"><a class="page-link px-3 py-[0.375rem]" href="javascript:void(0);"
*ngIf="pageIndex-1>0" (click)="pageIndex = pageIndex-2;updatePagedItems()">{{pageIndex-1}}</a></li>
<li class="page-item"><a class="page-link px-3 py-[0.375rem]" href="javascript:void(0);"
*ngIf="pageIndex>0 && ((pageIndex-1)*10 < (searchTerm == '' ? itemsList.length : filterList.length))"
(click)="pageIndex = pageIndex-1;updatePagedItems()">{{pageIndex}}</a></li>
<li class="page-item"><a class="page-link active px-3 py-[0.375rem]"
href="javascript:void(0);">{{pageIndex +1}}</a>
</li>
<li class="page-item"><a class="page-link px-3 py-[0.375rem]" href="javascript:void(0);"
*ngIf="(pageIndex+1)*10 < (searchTerm == '' ? itemsList.length : filterList.length)"
(click)="pageIndex = pageIndex+1;updatePagedItems()">{{pageIndex +2}}</a></li>
<li class="page-item"><a class="page-link px-3 py-[0.375rem]" href="javascript:void(0);"
*ngIf="(pageIndex+2)*10 < (searchTerm == '' ? itemsList.length : filterList.length)"
(click)="pageIndex = pageIndex+2;updatePagedItems()">{{pageIndex +3}}</a></li>
<li *ngIf="(pageIndex+1)*10 < (searchTerm == '' ? itemsList.length : filterList.length)"
class="page-item"><a class="page-link px-3 py-[0.375rem] cursor-pointer"
(click)="pageIndex = pageIndex+1;updatePagedItems()">{{'Next' |
translate}}</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Start:: Create Contact -->
<div id="modal-detail" class="hs-overlay hidden ti-modal [--overlay-backdrop:static]">
<div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out">
<div class="ti-modal-content">
<div class="ti-modal-header">
<h6 class="modal-title text-[1rem] font-semibold text-defaulttextcolor" id="mail-ComposeLabel">
{{ (action == 'add' ? ('Create' | translate) : ('Edit' | translate)) + ' ' + ('Major Information' | translate) }}
</h6>
<button type="button" class="hs-dropdown-toggle !text-[1rem] !font-semibold !text-defaulttextcolor"
data-hs-overlay="#modal-detail" #closeModal>
<span class="sr-only">{{'Close' | translate}}</span>
<i class="ri-close-line"></i>
</button>
</div>
<div class="ti-modal-body px-4">
<div class="grid grid-cols-12 gap-4">
<div class="xl:col-span-12 col-span-12">
<label for="deal-title" class="form-label">{{'Major ID' | translate}}</label>
<input type="text" class="form-control" [ngClass]="{ '!bg-input-readonly': action === 'edit' }"
id="deal-title" placeholder="" [(ngModel)]="selectModel.majorId" [readonly]="action === 'edit'">
<div class="text-danger" *ngIf="!selectModel.majorId">
{{'Please fill in information' | translate}}
</div>
</div>
<div class="xl:col-span-12 col-span-12">
<label for="deal-title" class="form-label">{{ 'Description(TH)' | translate}}</label>
<input type="text" class="form-control" id="deal-title" placeholder=""
[(ngModel)]="selectModel.thName">
<div class="text-danger" *ngIf="!selectModel.thName">
{{'Please fill in information' | translate}}
</div>
</div>
<div class="xl:col-span-12 col-span-12">
<label for="deal-title" class="form-label">{{ 'Description(ENG)' | translate}}</label>
<input type="text" class="form-control" id="deal-title" placeholder="" [(ngModel)]="selectModel.engName">
<div class="text-danger" *ngIf="!selectModel.engName">
{{'Please fill in information' | translate}}
</div>
</div>
<div class="xl:col-span-12 col-span-12">
<label for="deal-title" class="form-label">{{ 'Description(CHINA)' | translate}}</label>
<input type="text" class="form-control" id="deal-title" placeholder="" [(ngModel)]="selectModel.chinaName">
<div class="text-danger" *ngIf="!selectModel.chinaName">
{{'Please fill in information' | translate}}
</div>
</div>
</div>
</div>
<div class="ti-modal-footer">
<button type="button" class="hs-dropdown-toggle ti-btn ti-btn-light align-middle"
data-hs-overlay="#modal-detail">
{{'Cancel' | translate}}
</button>
<button type="button" (click)="save()" class="ti-btn bg-primary text-white !font-medium"
[class.ti-btn-disabled]="!selectModel.majorId||!selectModel.thName||!selectModel.engName||!selectModel.chinaName"
[disabled]="!selectModel.majorId||!selectModel.thName||!selectModel.engName||!selectModel.chinaName">{{'Save' | translate}}</button>
</div>
</div>
</div>
</div>
/* tslint:disable:no-unused-variable */
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { MajorComponent } from './major.component';
describe('MajorComponent', () => {
let component: MajorComponent;
let fixture: ComponentFixture<MajorComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ MajorComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(MajorComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, ElementRef, ViewChild } from '@angular/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
import { Router, RouterModule } from '@angular/router';
import { SharedModule } from '../../../../shared/shared.module';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import swal from 'sweetalert';
import { MatPaginator } from '@angular/material/paginator';
import { FormsModule } from '@angular/forms';
import { NgSelectModule } from '@ng-select/ng-select';
import { CommonModule } from '@angular/common';
import { FileUploadModule } from 'ng2-file-upload';
import { FileItem, FileUploader, ParsedResponseHeaders } from "ng2-file-upload";
import { environment } from '../../../../../environments/environment';
import { TokenService } from '../../../../shared/services/token.service'
import { QuillModule } from 'ngx-quill';
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
import { MajorModel } from '../../../models/major.model';
import { MajorService } from '../../../services/major.service';
@Component({
selector: 'app-major',
templateUrl: './major.component.html',
styleUrls: ['./major.component.css'],
standalone: true,
imports: [
CommonModule,
SharedModule,
TranslateModule,
NgSelectModule,
FormsModule,
MatPaginator,
RouterModule,
FileUploadModule,
QuillModule,
MatDialogModule
],
})
export class MajorComponent {
quillConfig = {
toolbar: [
['link'], // เพิ่มปุ่มลิงก์
['bold', 'italic', 'underline', 'strike'], // toggled buttons
['blockquote', 'code-block'],
[{ 'header': 1 }, { 'header': 2 }], // custom button values
[{ 'list': 'ordered' }, { 'list': 'bullet' }],
[{ 'script': 'sub' }, { 'script': 'super' }], // superscript/subscript
[{ 'indent': '-1' }, { 'indent': '+1' }], // outdent/indent
[{ 'direction': 'rtl' }], // text direction
[{ 'size': ['small', false, 'large', 'huge'] }], // custom dropdown
[{ 'header': [1, 2, 3, 4, 5, 6, false] }],
[{ 'color': [] }, { 'background': [] }], // dropdown with defaults from theme
[{ 'align': [] }],
['clean'], // remove formatting button
]
};
@ViewChild('closeModal') public childModal?: ElementRef;
@ViewChild('modalDetail') public modalDetail?: ElementRef;
@ViewChild("MajorModel") MajorModel: any;
@ViewChild('profileChangeInput') profileChangeInputRef!: ElementRef;
dialogRef: any
currentContentTab: number = 1;
currentExcerptTab: number = 1;
action = "new";
allSelected = false;
someSelected = false;
itemsList: MajorModel[] = [];
filterList: MajorModel[] = [];
selectModel: MajorModel = new MajorModel();
selectedItems = new Map<string, boolean>();
// empList: MajorModel[] = [];
// descName = 'engName';
pageIndex = 0;
uploaderProfile: FileUploader | undefined;
uploadErrorMsg: string = "";
modalStatus: "add" | "edit" = "add"
get searchTerm(): string {
return this._searchTerm;
}
set searchTerm(val: string) {
this.pageIndex = 0;
this.allSelected = false;
this._searchTerm = val;
if (val != '') {
this.filterList = this.filter(val);
} else {
this.updatePagedItems();
}
}
_searchTerm = "";
constructor(
private major: MajorService,
public translate: TranslateService,
private tokenService: TokenService,
private router: Router,
private dialog: MatDialog,
) {
}
getMajor() {
this.major.getList().subscribe({
next: (response: MajorModel[]) => {
this.itemsList = response.map((x: any) => new MajorModel(x, this.translate));
// console.log('ข้อมูลตำแหน่ง (itemsList)', this.itemsList);
this.updatePagedItems();
},
error: (error) => {
console.error('error cant get position', error);
swal("ข้อผิดพลาด", "ไม่สามารถดึงข้อมูลตำแหน่งได้", "error");
}
});
}
ngOnInit(): void {
this.getMajor();
}
filter(v: string) {
return this.itemsList?.filter(
(x) =>
x.majorId?.toLowerCase().indexOf(v.toLowerCase()) !== -1 ||
x.thName?.toLowerCase().indexOf(v.toLowerCase()) !== -1 ||
x.engName?.toLowerCase().indexOf(v.toLowerCase()) !== -1 ||
x.chinaName?.toLowerCase().indexOf(v.toLowerCase()) !== -1
);
}
delete(item: MajorModel) {
swal({
title: "คุณแน่ใจหรือไม่?",
text: "คุณจะไม่สามารถกู้คืนข้อมูลนี้ได้!",
icon: "warning",
dangerMode: true,
buttons: ["ยกเลิก", "ใช่, ลบเลย!"],
})
.then((willDelete: any) => {
if (willDelete) {
const newMajor = new MajorModel(item)
this.major.deleteMajor(newMajor).subscribe(result => {
swal("ลบสำเร็จ!!", "ลบข้อมูลสำเร็จ", "success");
this.ngOnInit();
}, error => {
console.error("เกิดข้อผิดพลาดในการลบ:", error);
swal("ข้อผิดพลาด!!", "ไม่สามารถลบข้อมูลได้", "error");
});
}
});
}
new() {
this.action = 'add';
this.selectModel = new MajorModel();
// this.selectModel.status = 1;
this.selectModel.majorId = "";
this.selectModel.thName = "";
this.selectModel.engName = "";
this.selectModel.chinaName = "";
}
view(item: MajorModel) {
this.action = 'edit';
this.selectModel = new MajorModel(item);
console.log(this.selectModel);
}
save() {
console.log('Before Save, selectModel is:', this.selectModel);
swal({
title: "คุณแน่ใจหรือไม่?",
text: "คุณต้องการบันทึกหรือไม่",
icon: "warning",
dangerMode: false,
buttons: ["ยกเลิก", "ยืนยัน"],
})
.then((willSave: any) => {
if (willSave) {
this.major.postMajor(this.selectModel).subscribe(result => {
console.log(result);
swal("บันทึกสำเร็จ!!", "บันทึกข้อมูลสมาชิก", "success");
this.ngOnInit();
this.childModal?.nativeElement.click();
}, error => {
console.error("เกิดข้อผิดพลาดในการบันทึก/อัปเดต:", error);
swal("ข้อผิดพลาด!!", "ไม่สามารถบันทึก/อัปเดตข้อมูลได้", "error");
});
}
});
}
updatePagedItems() {
const startIndex = this.pageIndex * 10;
const endIndex = startIndex + 10;
this.filterList = this.itemsList.slice(startIndex, endIndex);
}
toggleAll(event: any) {
this.allSelected = event.target.checked;
this.selectedItems.clear();
this.itemsList.forEach(item => {
this.selectedItems.set(item.majorId, this.allSelected);
});
this.someSelected = this.itemsList.some(item => this.selectedItems.get(item.majorId));
}
onCheckboxChange(majorId: string) {
const isSelected = this.selectedItems.get(majorId) || false;
this.selectedItems.set(majorId, !isSelected);
this.allSelected = this.itemsList.every(item => this.selectedItems.get(item.majorId));
this.someSelected = this.itemsList.some(item => this.selectedItems.get(item.majorId));
}
deleteSelect() {
let employeeInfo = '';
this.selectedItems.forEach((isSelected, majorId) => {
if (isSelected) {
const user = this.itemsList.find(user => user.majorId === majorId);
if (user) {
employeeInfo += `${this.translate.instant('thName')}: ${user.thName}\n`;
}
}
});
swal({
title: "Are you sure?",
text: employeeInfo,
icon: "warning",
dangerMode: true,
buttons: ["Cancel", "Yes, Delete it!"],
})
.then((willDelete: any) => {
if (willDelete) {
this.selectedItems.forEach((isSelected, majorId) => {
if (isSelected) {
const user = this.itemsList.find(user => user.majorId === majorId);
if (user) {
const newMajor = new MajorModel(user)
this.major.deleteMajor(newMajor).subscribe(result => {
swal("Save Success!!", "บันทึกข้อมูลสำเร็จ", "success");
this.ngOnInit();
});
}
}
});
}
});
}
}
......@@ -195,6 +195,11 @@ export const myjob: Routes = [
loadComponent: () =>
import('./company-department/faculty/faculty.component').then((m) => m.FacultyComponent),
},
{
path: 'major',
loadComponent: () =>
import('./company-department/major/major.component').then((m) => m.MajorComponent),
},
...portalRoutes
],
}
......
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { environment } from "../../../environments/environment";
import { MajorModel } from '../models/major.model';
@Injectable({
providedIn: 'root'
})
export class MajorService {
api = "/major"
urlApi = environment.baseUrl + "/major"
constructor(private http: HttpClient) { }
getById(majorId: string): Observable<MajorModel> {
return this.http.get<MajorModel>(this.urlApi + "/" + majorId)
}
getList(): Observable<MajorModel[]> {
return this.http.get<MajorModel[]>(this.urlApi + "/lists")
}
postMajor(body: MajorModel): Observable<any> {
return this.http.post(this.urlApi, body)
}
deleteMajor(body: MajorModel) {
const options = {
headers: new HttpHeaders({
"Content-Type": "application/json",
}),
body: body,
};
return this.http.delete(this.urlApi, options)
}
deleteMajorById(majorId: string) {
const options = {
headers: new HttpHeaders({
"Content-Type": "application/json",
}),
body: {majorId : majorId},
};
return this.http.delete(this.urlApi, options)
}
}
......@@ -297,6 +297,7 @@ export class NavService implements OnDestroy {
{ path: '/myjob/provinces', title: 'จัดการจังหวัด', type: 'link' },
{ path: '/myjob/institution', title: 'จัดการสถาบันการศึกษา', type: 'link' },
{ path: '/myjob/faculty', title: 'จัดการคณะ', type: 'link' },
{ path: '/myjob/major', title: 'จัดการสาขาวิชา', type: 'link' },
],
},
...this.createPortalMenu('myjob')
......
......@@ -127,5 +127,7 @@
"Institution ID" : "Institution ID",
"Institution Information" : "Institution Information",
"Faculty ID" : "Faculty ID",
"Faculty Information" : "Faculty Information"
"Faculty Information" : "Faculty Information",
"Major ID" : "Major ID",
"Major Information" : "Major Information"
}
......@@ -127,6 +127,8 @@
"Institution ID" : "รหัสสถาบันการศึกษา",
"Institution Information" : "ข้อมูลสถาบันการศึกษา",
"Faculty ID" : "รหัสคณะ",
"Faculty Information" : "ข้อมูลคณะ"
"Faculty Information" : "ข้อมูลคณะ",
"Major ID" : "รหัสสาขาวิชา",
"Major Information" : "ข้อมูลสาขาวิชา"
}
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