Commit b2633955 by sawit

Faculty menu

parent 3c399baf
import { TranslateService } from "@ngx-translate/core";
import { BaseModel, baseGetName, checkData } from "./base.model";
export interface FacultyModel {
facultyId: string
thName: string
engName: string
chinaName: string
}
export class FacultyModel extends BaseModel implements FacultyModel {
facultyId: string
thName: string
engName: string
chinaName: string
constructor(data?: Partial<FacultyModel>, translateService?: TranslateService) {
super(data, translateService)
this.facultyId = checkData(data?.facultyId)
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)
}
}
/* 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 { FacultyComponent } from './faculty.component';
describe('FacultyComponent', () => {
let component: FacultyComponent;
let fixture: ComponentFixture<FacultyComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ FacultyComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(FacultyComponent);
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 { FacultyModel } from '../../../models/faculty.model';
import { FacultyService } from '../../../services/faculty.service';
@Component({
selector: 'app-faculty',
templateUrl: './faculty.component.html',
styleUrls: ['./faculty.component.css'],
standalone: true,
imports: [
CommonModule,
SharedModule,
TranslateModule,
NgSelectModule,
FormsModule,
MatPaginator,
RouterModule,
FileUploadModule,
QuillModule,
MatDialogModule
],
})
export class FacultyComponent {
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("FacultyModel") FacultyModel: any;
@ViewChild('profileChangeInput') profileChangeInputRef!: ElementRef;
dialogRef: any
currentContentTab: number = 1;
currentExcerptTab: number = 1;
action = "new";
allSelected = false;
someSelected = false;
itemsList: FacultyModel[] = [];
filterList: FacultyModel[] = [];
selectModel: FacultyModel = new FacultyModel();
selectedItems = new Map<string, boolean>();
// empList: FacultyModel[] = [];
// 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 faculty: FacultyService,
public translate: TranslateService,
private tokenService: TokenService,
private router: Router,
private dialog: MatDialog,
) {
}
getFaculty() {
this.faculty.getList().subscribe({
next: (response: FacultyModel[]) => {
this.itemsList = response.map((x: any) => new FacultyModel(x, this.translate));
// console.log('ข้อมูลตำแหน่ง (itemsList)', this.itemsList);
this.updatePagedItems();
},
error: (error) => {
console.error('error cant get position', error);
swal("ข้อผิดพลาด", "ไม่สามารถดึงข้อมูลตำแหน่งได้", "error");
}
});
}
ngOnInit(): void {
this.getFaculty();
}
filter(v: string) {
return this.itemsList?.filter(
(x) =>
x.facultyId?.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: FacultyModel) {
swal({
title: "คุณแน่ใจหรือไม่?",
text: "คุณจะไม่สามารถกู้คืนข้อมูลนี้ได้!",
icon: "warning",
dangerMode: true,
buttons: ["ยกเลิก", "ใช่, ลบเลย!"],
})
.then((willDelete: any) => {
if (willDelete) {
const newFaculty = new FacultyModel(item)
this.faculty.deleteFaculty(newFaculty).subscribe(result => {
swal("ลบสำเร็จ!!", "ลบข้อมูลสำเร็จ", "success");
this.ngOnInit();
}, error => {
console.error("เกิดข้อผิดพลาดในการลบ:", error);
swal("ข้อผิดพลาด!!", "ไม่สามารถลบข้อมูลได้", "error");
});
}
});
}
new() {
this.action = 'add';
this.selectModel = new FacultyModel();
// this.selectModel.status = 1;
this.selectModel.facultyId = "";
this.selectModel.thName = "";
this.selectModel.engName = "";
this.selectModel.chinaName = "";
}
view(item: FacultyModel) {
this.action = 'edit';
this.selectModel = new FacultyModel(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.faculty.postFaculty(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.facultyId, this.allSelected);
});
this.someSelected = this.itemsList.some(item => this.selectedItems.get(item.facultyId));
}
onCheckboxChange(facultyId: string) {
const isSelected = this.selectedItems.get(facultyId) || false;
this.selectedItems.set(facultyId, !isSelected);
this.allSelected = this.itemsList.every(item => this.selectedItems.get(item.facultyId));
this.someSelected = this.itemsList.some(item => this.selectedItems.get(item.facultyId));
}
deleteSelect() {
let employeeInfo = '';
this.selectedItems.forEach((isSelected, facultyId) => {
if (isSelected) {
const user = this.itemsList.find(user => user.facultyId === facultyId);
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, facultyId) => {
if (isSelected) {
const user = this.itemsList.find(user => user.facultyId === facultyId);
if (user) {
const newFaculty = new FacultyModel(user)
this.faculty.deleteFaculty(newFaculty).subscribe(result => {
swal("Save Success!!", "บันทึกข้อมูลสำเร็จ", "success");
this.ngOnInit();
});
}
}
});
}
});
}
}
......@@ -190,6 +190,11 @@ export const myjob: Routes = [
loadComponent: () =>
import('./company-department/institution/institution.component').then((m) => m.InstitutionComponent),
},
{
path: 'faculty',
loadComponent: () =>
import('./company-department/faculty/faculty.component').then((m) => m.FacultyComponent),
},
...portalRoutes
],
}
......
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { environment } from "../../../environments/environment";
import { FacultyModel } from '../models/faculty.model';
@Injectable({
providedIn: 'root'
})
export class FacultyService {
api = "/faculty"
urlApi = environment.baseUrl + "/faculty"
constructor(private http: HttpClient) { }
getById(facultyId: string): Observable<FacultyModel> {
return this.http.get<FacultyModel>(this.urlApi + "/" + facultyId)
}
getList(): Observable<FacultyModel[]> {
return this.http.get<FacultyModel[]>(this.urlApi + "/lists")
}
postFaculty(body: FacultyModel): Observable<any> {
return this.http.post(this.urlApi, body)
}
deleteFaculty(body: FacultyModel) {
const options = {
headers: new HttpHeaders({
"Content-Type": "application/json",
}),
body: body,
};
return this.http.delete(this.urlApi, options)
}
deleteFacultyById(facultyId: string) {
const options = {
headers: new HttpHeaders({
"Content-Type": "application/json",
}),
body: {facultyId : facultyId},
};
return this.http.delete(this.urlApi, options)
}
}
......@@ -296,6 +296,7 @@ export class NavService implements OnDestroy {
{ path: '/myjob/country-registration', title: 'จัดการประเทศ', type: 'link' },
{ path: '/myjob/provinces', title: 'จัดการจังหวัด', type: 'link' },
{ path: '/myjob/institution', title: 'จัดการสถาบันการศึกษา', type: 'link' },
{ path: '/myjob/faculty', title: 'จัดการคณะ', type: 'link' },
],
},
...this.createPortalMenu('myjob')
......
......@@ -125,5 +125,7 @@
"Article Contents":"Article Contents",
"Publication End Date":"Publication End Date",
"Institution ID" : "Institution ID",
"Institution Information" : "Institution Information"
"Institution Information" : "Institution Information",
"Faculty ID" : "Faculty ID",
"Faculty Information" : "Faculty Information"
}
......@@ -125,6 +125,8 @@
"Article Contents":"เนื้อหาบทความ",
"Publication End Date":"วันที่สิ้นสุดการเผยเเพร่",
"Institution ID" : "รหัสสถาบันการศึกษา",
"Institution Information" : "ข้อมูลสถาบันการศึกษา"
"Institution Information" : "ข้อมูลสถาบันการศึกษา",
"Faculty ID" : "รหัสคณะ",
"Faculty 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