Commit c5f2b417 by Natthaphat

หน้าจัดการสมาชิก

parent 9f29edbd
......@@ -46,6 +46,7 @@ export class UserSettingComponent {
pageIndex = 0;
uploaderProfile: FileUploader | undefined;
uploadErrorMsg: string = "";
modalStatus: "add" | "edit" = "add"
get searchTerm(): string {
return this._searchTerm;
}
......@@ -119,24 +120,25 @@ export class UserSettingComponent {
ngOnInit(): void {
this.userService.getListsProfile().subscribe(result => {
this.itemsList = result
this.updatePagedItems()
})
this.itemsList = result.map(item => new UserProfileModel(item, this.translate));
this.filterList = [...this.itemsList];
});
}
filter(v: string) {
return this.itemsList?.filter(
(x) =>
x.memberId?.toLowerCase().indexOf(v.toLowerCase()) !== -1 ||
x.username?.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
filter(v: string): UserProfileModel[] {
const search = v.toLowerCase();
return this.itemsList?.filter(x =>
x.candidateId?.toLowerCase().includes(search) ||
x.username?.toLowerCase().includes(search) ||
x.email?.toLowerCase().includes(search) ||
x.phoneNumberProfile?.toLowerCase().includes(search) ||
x.getStatus?.()?.toLowerCase().includes(search) ||
x.getName?.()?.toLowerCase().includes(search)
);
}
delete(item: UserProfileModel) {
swal({
title: "Are you sure?",
......@@ -166,7 +168,6 @@ export class UserSettingComponent {
this.action = 'edit'
this.confirmPassword = ''
this.selectModel = new UserProfileModel(item)
console.log(this.selectModel)
}
......@@ -213,23 +214,23 @@ export class UserSettingComponent {
this.allSelected = event.target.checked;
this.selectedItems.clear();
this.itemsList.forEach(item => {
this.selectedItems.set(item.memberId, this.allSelected);
this.selectedItems.set(item.candidateId, this.allSelected);
});
this.someSelected = this.itemsList.some(item => this.selectedItems.get(item.memberId));
this.someSelected = this.itemsList.some(item => this.selectedItems.get(item.candidateId));
}
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));
onCheckboxChange(candidateId: string) {
const isSelected = this.selectedItems.get(candidateId) || false;
this.selectedItems.set(candidateId, !isSelected);
this.allSelected = this.itemsList.every(item => this.selectedItems.get(item.candidateId));
this.someSelected = this.itemsList.some(item => this.selectedItems.get(item.candidateId));
}
deleteSelect() {
let employeeInfo = '';
this.selectedItems.forEach((isSelected, memberId) => {
this.selectedItems.forEach((isSelected, candidateId) => {
if (isSelected) {
const user = this.itemsList.find(user => user.memberId === memberId);
const user = this.itemsList.find(user => user.candidateId === candidateId);
if (user) {
employeeInfo += `${this.translate.instant('Fullname')}: ${user.getFullname()}\n`;
}
......@@ -245,9 +246,9 @@ export class UserSettingComponent {
})
.then((willDelete: any) => {
if (willDelete) {
this.selectedItems.forEach((isSelected, memberId) => {
this.selectedItems.forEach((isSelected, candidateId) => {
if (isSelected) {
const user = this.itemsList.find(user => user.memberId === memberId);
const user = this.itemsList.find(user => user.candidateId === candidateId);
if (user) {
this.userService.delete(user).subscribe(result => {
swal("Save Success!!", "บันทึกข้อมูลสำเร็จ", "success");
......@@ -263,9 +264,9 @@ export class UserSettingComponent {
adjustSelect(status: number) {
let title = "Are you sure?"
let employeeInfo = ''; // ตัวแปรสำหรับเก็บข้อมูลพนักงาน
this.selectedItems.forEach((isSelected, memberId) => {
this.selectedItems.forEach((isSelected, candidateId) => {
if (isSelected) {
const user = this.itemsList.find(user => user.memberId === memberId);
const user = this.itemsList.find(user => user.candidateId === candidateId);
if (user) {
employeeInfo += `${this.translate.instant('Fullname')}: ${user.getFullname()}\n`;
}
......@@ -280,9 +281,9 @@ export class UserSettingComponent {
})
.then((willDelete: any) => {
if (willDelete) {
this.selectedItems.forEach((isSelected, memberId) => {
this.selectedItems.forEach((isSelected, candidateId) => {
if (isSelected) {
const user = this.itemsList.find(user => user.memberId === memberId);
const user = this.itemsList.find(user => user.candidateId === candidateId);
if (user) {
user.status = status
this.userService.update(user).subscribe(result => {
......@@ -298,7 +299,7 @@ export class UserSettingComponent {
}
filterEmp(empId: string) {
this.selectModel = this.empList.filter(e => e.memberId == empId)[0]
this.selectModel = this.empList.filter(e => e.candidateId == empId)[0]
}
}
......@@ -3,6 +3,7 @@ import { BaseModel } from "./base.model";
import { environment } from "../../../environments/environment";
export class UserProfileModel extends BaseModel {
candidateId: string;
memberId: string;
username: string;
password: string;
......@@ -15,48 +16,97 @@ export class UserProfileModel extends BaseModel {
picture: any;
createdAt: string;
updatedAt: string;
thFirstname: string;
thLastname: string;
thFullName: string;
engFirstname: string;
engLastname: string;
engFullName: string;
phoneCurrent: string;
phoneEmergency: string;
phoneGeneral: string;
phoneHome: string;
lastModifiedDate: string;
constructor(
data?: Partial<UserProfileModel>,
translateService?: TranslateService
) {
super(data, translateService);
this.candidateId = data?.candidateId!;
this.memberId = data?.memberId!;
this.username = data?.username!
this.password = data?.password!
this.phoneNumber = data?.phoneNumber || ""
this.firstName = data?.firstName || ""
this.lastName = data?.lastName || ""
this.status = data?.status!
this.email = data?.email!
this.role = data?.role!
this.createdAt = data?.createdAt!
this.updatedAt = data?.updatedAt!
this.username = data?.username!;
this.password = data?.password!;
this.phoneNumber = data?.phoneNumber || "";
this.firstName = data?.firstName || "";
this.lastName = data?.lastName || "";
this.status = data?.status!;
this.email = data?.email!;
this.role = data?.role!;
this.createdAt = data?.createdAt!;
this.updatedAt = data?.updatedAt!;
this.thFirstname = data?.thFirstname!;
this.thLastname = data?.thLastname!;
this.thFullName = data?.thFullName!;
this.engFirstname = data?.engFirstname!;
this.engLastname = data?.engLastname!;
this.engFullName = data?.engFullName!;
this.phoneCurrent = data?.phoneCurrent || "";
this.phoneEmergency = data?.phoneEmergency || "";
this.phoneGeneral = data?.phoneGeneral || "";
this.phoneHome = data?.phoneHome || "";
this.lastModifiedDate = data?.lastModifiedDate || "";
}
// Getter/Setter สำหรับ phoneNumberProfile (fallback เบอร์โทร)
get phoneNumberProfile(): string {
return this.phoneCurrent || this.phoneEmergency || this.phoneGeneral || this.phoneHome || "";
}
set phoneNumberProfile(value: string) {
if (!this.phoneCurrent && !this.phoneEmergency && !this.phoneGeneral && !this.phoneHome) {
this.phoneCurrent = value;
} else if (this.phoneCurrent) {
this.phoneCurrent = value;
} else if (this.phoneEmergency) {
this.phoneEmergency = value;
} else if (this.phoneGeneral) {
this.phoneGeneral = value;
} else {
this.phoneHome = value;
}
}
getRole(): string {
if (this.role == 99) {
return this.translateService.instant('Admin-System')
}
else if (this.role == 1) {
return this.translateService.instant('Admin-Company')
return this.translateService.instant('Admin-System');
} else if (this.role == 1) {
return this.translateService.instant('Admin-Company');
} else {
return this.translateService.instant('User')
return this.translateService.instant('User');
}
}
getStatus(): string {
if (this.status == 1) {
return this.translateService.instant('Active')
return this.translateService.instant('Active');
} else {
return this.translateService.instant('Unactive')
return this.translateService.instant('Unactive');
}
}
getPicture(): string {
return this.picture ? environment.baseUrl + '/images/' + this.picture : './assets/images/faces/1.jpg'
return this.picture ? environment.baseUrl + '/images/' + this.picture : './assets/images/faces/1.jpg';
}
getFullname(): string {
return this.firstName + " " + this.lastName
return this.thFirstname + " " + this.thLastname;
}
getName(): string {
const th = this.thFullName || '';
const en = this.engFullName || '';
return this.translateService?.currentLang === 'th' ? th : en;
}
}
......@@ -39,10 +39,10 @@ export class UserService {
getListsProfile() {
return this.http
.get<UserProfileModel[]>(this.apiBaseUrl+'/manage-profile/lists')
// .pipe(
// map((e) => e.map((e) => new UserProfileModel(e, this.translateService)))
// );
.get<UserProfileModel[]>(this.apiBaseUrl + '/manage-profile/lists')
// .pipe(
// map((e) => e.map((e) => new UserProfileModel(e, this.translateService)))
// );
}
......@@ -101,11 +101,11 @@ export class UserService {
}
save(body: UserProfileModel) {
return this.http.post<ResponseModel>(this.apiBaseUrl, new UserProfileModel(body));
return this.http.post<ResponseModel>(this.apiBaseUrl + '/manage-profile', new UserProfileModel(body));
}
update(body: UserProfileModel) {
return this.http.put<ResponseModel>(this.apiBaseUrl + "/" + body.memberId, new UserProfileModel(body));
return this.http.put<ResponseModel>(this.apiBaseUrl + "/" + body.candidateId, new UserProfileModel(body));
}
......@@ -128,11 +128,10 @@ export class UserService {
delete(body: UserProfileModel) {
const options = {
headers: new HttpHeaders({
"Content-Type": "application/json",
}),
body: new UserProfileModel(body),
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
body: new UserProfileModel(body) // ส่งข้อมูลใน body
};
return this.http.delete<ResponseModel>(this.apiBaseUrl + "/" + body.memberId);
return this.http.delete<ResponseModel>(this.apiBaseUrl + "/manage-profile", options);
}
}
......@@ -9911,6 +9911,13 @@ span.flatpickr-weekday {
@apply text-white;
}
.bg-input-readonly {
background-color: rgb(241 245 249 / var(--tw-bg-opacity));
}
.\!bg-input-readonly {
background-color: rgb(241 245 249) !important;
}
[dir=rtl] pre[class*=language-] > code {
@apply border-l-0 text-right !important;
}
......
......@@ -2,6 +2,7 @@
"Home": "Home",
"All List": "All List",
"Create": "Create",
"Edit": "Edit",
"Delete": "Delete",
"Search": "Search",
"Close": "Close",
......@@ -73,5 +74,6 @@
"Success": "Success",
"Time": "Time",
"Fail": "Fail",
"Mobile": "Mobile"
"Mobile": "Mobile",
"Candidate ID": "Candidate ID"
}
......@@ -2,6 +2,7 @@
"Home": "หน้าแรก",
"All List": "รายการทั้งหมด",
"Create": "สร้าง",
"Edit": "แก้ไข",
"Delete": "ลบ",
"Search": "ค้นหา",
"Close": "ปิด",
......@@ -73,5 +74,6 @@
"Browser" : "เบราว์เซอร์",
"Success" : "สำเร็จ",
"Fail" : "ผิดพลาด",
"Mobile" : "เบอร์ติดต่อ"
"Mobile" : "เบอร์ติดต่อ",
"Candidate ID": "รหัสสมาชิก"
}
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