Commit c5f2b417 by Natthaphat

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

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