Commit 251b8d1c by Ooh-Ao

admin

parent 3c3ffaf1
...@@ -12,6 +12,9 @@ import { TokenService } from "../../../shared/services/token.service"; ...@@ -12,6 +12,9 @@ import { TokenService } from "../../../shared/services/token.service";
import { FileUploadModule } from 'ng2-file-upload'; import { FileUploadModule } from 'ng2-file-upload';
import { FileItem, FileUploader, ParsedResponseHeaders } from "ng2-file-upload"; import { FileItem, FileUploader, ParsedResponseHeaders } from "ng2-file-upload";
import { environment } from "../../../../environments/environment"; import { environment } from "../../../../environments/environment";
import { EquipmentModel } from "../../models/equipments.model";
import { EquipmentService } from "../../services/equirement.service";
import { HttpClient } from "@angular/common/http";
@Component({ @Component({
selector: 'app-admin-manage', selector: 'app-admin-manage',
...@@ -30,20 +33,17 @@ import { environment } from "../../../../environments/environment"; ...@@ -30,20 +33,17 @@ import { environment } from "../../../../environments/environment";
}) })
export class AdminManageComponent { export class AdminManageComponent {
@ViewChild('closeModal') public childModal?: ElementRef; @ViewChild('closeModal') public childModal?: ElementRef;
@ViewChild('closeModalFace') public childModalFace?: ElementRef;
@ViewChild('modalDetail') public modalDetail?: ElementRef; @ViewChild('modalDetail') public modalDetail?: ElementRef;
action = "new";
allSelected = false; allSelected = false;
someSelected = false; someSelected = false;
confirmPassword = ""
itemsList: UserProfileModel[] = []
filterList: UserProfileModel[] = []
selectedItems = new Map<string, boolean>();
selectModel: UserProfileModel = new UserProfileModel()
empList: UserProfileModel[] = []
descName = 'engName'
pageIndex = 0;
uploaderProfile: FileUploader | undefined; uploaderProfile: FileUploader | undefined;
uploadErrorMsg: string = ""; uploadErrorMsg: string = "";
itemsList: EquipmentModel[] = []
filterList: EquipmentModel[] = []
selectModel: EquipmentModel = new EquipmentModel()
selectedItems = new Map<string, boolean>();
pageIndex = 0;
get searchTerm(): string { get searchTerm(): string {
return this._searchTerm; return this._searchTerm;
} }
...@@ -57,12 +57,23 @@ export class AdminManageComponent { ...@@ -57,12 +57,23 @@ export class AdminManageComponent {
this.updatePagedItems() this.updatePagedItems()
} }
} }
companyId = ""
_searchTerm = ""; _searchTerm = "";
constructor(private userService: UserService, public translate: TranslateService, private tokenService: TokenService) { isEdit = false;
constructor(private http: HttpClient, private eqService: EquipmentService, public translate: TranslateService, private tokenService: TokenService) {
this.uploadConfig() this.uploadConfig()
this.companyId = this.tokenService.getSelectCompany().companyId;
} }
@ViewChild('video') video: ElementRef;
@ViewChild('canvas') canvas: ElementRef;
capturedImage: string | null = null;
uploadStatus: string = '';
checkMatch = false;
memberId = ""
isFaceDetected = false; // Flag to determine if a face is detected
uploadConfig() { uploadConfig() {
this.uploaderProfile = new FileUploader({ this.uploaderProfile = new FileUploader({
url: environment.baseUrl + "/api/upload-image", url: environment.baseUrl + "/api/upload-image",
...@@ -114,28 +125,23 @@ export class AdminManageComponent { ...@@ -114,28 +125,23 @@ export class AdminManageComponent {
}; };
} }
ngOnInit(): void { ngOnInit(): void {
this.userService.getLists().subscribe(result => { this.eqService.getLists().subscribe(result => {
this.itemsList = result.filter(e => e.role == 99) this.itemsList = result
this.updatePagedItems() this.updatePagedItems()
}) })
} }
filter(v: string) { filter(v: string) {
this.pageIndex = 0;
return this.itemsList?.filter( return this.itemsList?.filter(
(x) => (x) =>
x.memberId?.toLowerCase().indexOf(v.toLowerCase()) !== -1 || x.equipment_name.toLowerCase().indexOf(v.toLowerCase()) !== -1 ||
x.username?.toLowerCase().indexOf(v.toLowerCase()) !== -1 || x.description?.toLowerCase().indexOf(v.toLowerCase()) !== -1
x.email?.toLowerCase().indexOf(v.toLowerCase()) !== -1 ||
x.phoneNumber?.toLowerCase().indexOf(v.toLowerCase()) !== -1 ||
x.getRole()?.toLowerCase().indexOf(v.toLowerCase()) !== -1 ||
x.getStatus()?.toLowerCase().indexOf(v.toLowerCase()) !== -1 ||
x.getFullname()?.toLowerCase().indexOf(v.toLowerCase()) !== -1
); );
} }
delete(item: UserProfileModel) { delete(item: EquipmentModel) {
swal({ swal({
title: "Are you sure?", title: "Are you sure?",
text: "You won't be able to revert this!", text: "You won't be able to revert this!",
...@@ -146,7 +152,7 @@ export class AdminManageComponent { ...@@ -146,7 +152,7 @@ export class AdminManageComponent {
}) })
.then((willDelete: any) => { .then((willDelete: any) => {
if (willDelete) { if (willDelete) {
this.userService.delete(item).subscribe(result => { this.eqService.delete(item).subscribe(result => {
swal("Save Success!!", "บันทึกข้อมูลสำเร็จ", "success"); swal("Save Success!!", "บันทึกข้อมูลสำเร็จ", "success");
this.ngOnInit() this.ngOnInit()
}) })
...@@ -156,16 +162,14 @@ export class AdminManageComponent { ...@@ -156,16 +162,14 @@ export class AdminManageComponent {
} }
new() { new() {
this.action = 'add' this.isEdit = false
this.selectModel = new UserProfileModel() this.selectModel = new EquipmentModel()
} }
view(item: UserProfileModel) { view(item: EquipmentModel) {
this.action = 'edit' console.log(item)
this.confirmPassword = '' this.isEdit = true;
this.selectModel = new UserProfileModel(item) this.selectModel = item
console.log(this.selectModel)
} }
save() { save() {
...@@ -178,126 +182,60 @@ export class AdminManageComponent { ...@@ -178,126 +182,60 @@ export class AdminManageComponent {
}) })
.then((willDelete: any) => { .then((willDelete: any) => {
if (willDelete) { if (willDelete) {
this.selectModel.role = 99 if (!this.isEdit) {
if (this.action == 'add') { this.eqService.save(this.selectModel).subscribe(result => {
this.userService.save(this.selectModel).subscribe(result => { swal("Save Success!!", "บันทึกข้อมูลสำเร็จ", "success");
console.log(result)
swal("Save Success!!", "บันทึกข้อมูลสมาชิก", "success");
this.ngOnInit() this.ngOnInit()
this.childModal?.nativeElement.click() this.childModal?.nativeElement.click()
}) })
} else if (this.action == 'edit') { } else {
this.userService.update(this.selectModel).subscribe(result => { this.eqService.update(this.selectModel).subscribe(result => {
console.log(result) swal("Save Success!!", "บันทึกข้อมูลสำเร็จ", "success");
swal("Update Success!!", "บันทึกข้อมูลสมาชิก", "success");
this.ngOnInit() this.ngOnInit()
this.childModal?.nativeElement.click() this.childModal?.nativeElement.click()
}) })
}
} }
// this.selectModel.member.role = 0
});
}
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.memberId, this.allSelected);
}); });
this.someSelected = this.itemsList.some(item => this.selectedItems.get(item.memberId));
}
onCheckboxChange(memberId: string) {
const isSelected = this.selectedItems.get(memberId) || false;
this.selectedItems.set(memberId, !isSelected);
this.allSelected = this.itemsList.every(item => this.selectedItems.get(item.memberId));
this.someSelected = this.itemsList.some(item => this.selectedItems.get(item.memberId));
}
deleteSelect() {
let employeeInfo = '';
this.selectedItems.forEach((isSelected, memberId) => {
if (isSelected) {
const user = this.itemsList.find(user => user.memberId === memberId);
if (user) {
employeeInfo += `${this.translate.instant('Fullname')}: ${user.getFullname()}\n`;
} }
}
});
updateEmp() {
swal({ swal({
title: "Are you sure?", title: "Are you sure?",
text: employeeInfo, text: "คุณต้องการบันทึกหรือไม่",
icon: "warning",
dangerMode: true,
buttons: ["Cancel", "Yes, Delete it!"],
})
.then((willDelete: any) => {
if (willDelete) {
this.selectedItems.forEach((isSelected, memberId) => {
if (isSelected) {
const user = this.itemsList.find(user => user.memberId === memberId);
if (user) {
this.userService.delete(user).subscribe(result => {
swal("Save Success!!", "บันทึกข้อมูลสำเร็จ", "success");
this.ngOnInit();
});
}
}
});
}
});
}
adjustSelect(status: number) {
let title = "Are you sure?"
let employeeInfo = ''; // ตัวแปรสำหรับเก็บข้อมูลพนักงาน
this.selectedItems.forEach((isSelected, memberId) => {
if (isSelected) {
const user = this.itemsList.find(user => user.memberId === memberId);
if (user) {
employeeInfo += `${this.translate.instant('Fullname')}: ${user.getFullname()}\n`;
}
}
});
swal({
title: title,
text: employeeInfo,
icon: "warning", icon: "warning",
dangerMode: false, dangerMode: false,
buttons: ["Cancel", "Confirm"], buttons: ["Cancel", "Confirm"],
}) })
.then((willDelete: any) => { .then((willDelete: any) => {
if (willDelete) { if (willDelete) {
this.selectedItems.forEach((isSelected, memberId) => { this.eqService.save(this.selectModel).subscribe(result => {
if (isSelected) {
const user = this.itemsList.find(user => user.memberId === memberId);
if (user) {
user.status = status
this.userService.update(user).subscribe(result => {
swal("Save Success!!", "บันทึกข้อมูลสำเร็จ", "success"); swal("Save Success!!", "บันทึกข้อมูลสำเร็จ", "success");
this.ngOnInit(); this.ngOnInit()
}); this.childModal?.nativeElement.click()
} })
}
});
} }
}); });
} }
filterEmp(empId: string) { // filterEmp(empId: string) {
this.selectModel = this.empList.filter(e => e.memberId == empId)[0] // this.selectModel.supervisor = this.itemsList.filter(e => e.employeeId == empId)[0]
// }
updatePagedItems() {
const startIndex = this.pageIndex * 10;
const endIndex = startIndex + 10;
// this.filterList = this.itemsList.slice(startIndex, endIndex);
this.filterList = this.itemsList
} }
} }
...@@ -119,7 +119,7 @@ export class UserSettingComponent { ...@@ -119,7 +119,7 @@ export class UserSettingComponent {
ngOnInit(): void { ngOnInit(): void {
this.userService.getLists().subscribe(result => { this.userService.getLists().subscribe(result => {
this.itemsList = result.filter(e => e.role != 99) this.itemsList = result
this.updatePagedItems() this.updatePagedItems()
}) })
} }
......
import { TranslateService } from "@ngx-translate/core";
import { BaseModel } from "./base.model";
import { environment } from "../../../environments/environment";
export class EquipmentModel extends BaseModel {
equipment_id: string;
picture: string;
equipment_name: string;
description?: string;
quantity_total: number;
is_returnable: boolean;
location?: string;
created_at: string;
updated_at: string;
constructor(data?: Partial<EquipmentModel>, translateService?: TranslateService) {
super(data, translateService);
this.picture = data?.picture ?? '';
this.equipment_id = data?.equipment_id ?? '';
this.equipment_name = data?.equipment_name ?? '';
this.description = data?.description ?? '';
this.quantity_total = data?.quantity_total ?? 0;
this.is_returnable = data?.is_returnable ?? true;
this.location = data?.location ?? '';
this.created_at = data?.created_at ?? new Date().toISOString();
this.updated_at = data?.updated_at ?? new Date().toISOString();
}
getPicture(): string {
return this.picture ? environment.baseUrl + '/images/' + this.picture : './assets/images/faces/9.jpg'
}
}
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { EquipmentModel } from '../models/equipments.model';
import { map, tap, switchMap, filter, reduce } from "rxjs/operators";
@Injectable({
providedIn: 'root'
})
export class EquipmentService {
apiBaseUrl = "/equipments";
constructor(
private http: HttpClient
) { }
getById(id: string) {
return this.http
.get<EquipmentModel>(this.apiBaseUrl + "/" + id)
.pipe(map((e) => new EquipmentModel(e)));
}
getLists() {
return this.http
.get<EquipmentModel[]>(this.apiBaseUrl)
.pipe(
map((e) => e.map((e) => new EquipmentModel(e)))
);
}
save(body: EquipmentModel) {
return this.http.post<{
"message": string,
"user": EquipmentModel
}>(this.apiBaseUrl, new EquipmentModel(body));
}
update(body: EquipmentModel) {
return this.http.put<{
"message": string,
"user": EquipmentModel
}>(this.apiBaseUrl + "/" + body.equipment_id, new EquipmentModel(body));
}
delete(body: EquipmentModel) {
return this.http.delete<{
"message": string,
"user": EquipmentModel
}>(this.apiBaseUrl + "/" + body.equipment_id);
}
}
...@@ -127,7 +127,7 @@ export class NavService implements OnDestroy { ...@@ -127,7 +127,7 @@ export class NavService implements OnDestroy {
active: false, active: false,
children: [ children: [
{ path: '/admin/member-manage', title: 'การจัดการสมาชิก', type: 'link' }, { path: '/admin/member-manage', title: 'การจัดการสมาชิก', type: 'link' },
{ path: '/admin/product-management', title: 'การจัดการอุปกรณ์', type: 'link' }, { path: '/admin/admin-manage', title: 'การจัดการอุปกรณ์', type: 'link' },
{ {
path: '/admin/manage-companys', path: '/admin/manage-companys',
title: 'การจัดการโครงการ', title: 'การจัดการโครงการ',
......
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