Commit 5c57a862 by Nattana Chaiyamat

ตั้งค่าผู้ใช้งาน

parent c4348818
......@@ -38,7 +38,7 @@
</div>
<div *ngIf="currentPage==3" id="underline-3" class="hidden" role="tabpanel"
aria-labelledby="underline-item-3">
จัดการผู้ใช้งาน
<app-manage-user></app-manage-user>
</div>
</div>
</div>
......
import { ChangeDetectorRef, Component, EventEmitter, Input, Output } from '@angular/core';
import { ToastrService } from 'ngx-toastr';
import { MyUserModel, UserModel } from 'src/app/shared/model/user.model';
import { FileService } from 'src/app/shared/services/file.service';
import { UserService } from 'src/app/shared/services/user.service';
export interface DataPassword {
usernameId: string,
empId: string,
companyId: string,
oldPassword: string,
newPassword: string,
}
@Component({
selector: 'app-manage-user',
templateUrl: './manage-user.component.html',
styleUrls: ['./manage-user.component.scss']
})
export class ManageUserComponent {
currentPage = 1
page = Array.from({ length: 1 }, (_, i) => i + 1);
companyId = ""
user: { loading: boolean, select: UserModel, dataList: { check: boolean, data: UserModel }[] } = { loading: false, select: new MyUserModel(), dataList: [] }
search = ""
userPassword: DataPassword = {
usernameId: "",
empId: "",
companyId: "",
oldPassword: "",
newPassword: "",
}
changePassword = false
constructor(private toastr: ToastrService,
private cdr: ChangeDetectorRef,
private userService: UserService) {
this.companyId = this.decodeJWT(sessionStorage.getItem("accessToken") || '').companyid
}
ngOnInit(): void {
this.getUserList()
}
decodeJWT(token: string) {
let base64Url = token.split('.')[1]; // ดึงส่วนที่เป็น Payload
let base64 = base64Url.replace('-', '+').replace('_', '/'); // แก้ไข base64 ให้ถูกต้อง
let jsonPayload = decodeURIComponent(atob(base64).split('').map(function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
return JSON.parse(jsonPayload);
}
getUserList() {
this.user.loading = true
this.userService.getList("false").subscribe({
next: response => {
this.user.dataList = response.map(x => ({ check: false, data: new MyUserModel(x) }))
this.user.loading = false
this.searchChange()
this.cdr.detectChanges()
}, error: error => {
this.user.loading = false
this.cdr.detectChanges()
}
})
}
userListFilter() {
return this.user.dataList.filter(x => {
const data = x.data
const match = data.usernameId.toLowerCase().includes(this.search.toLowerCase()) ||
data.empId.toLowerCase().includes(this.search.toLowerCase()) ||
data.employee.thFullName.toLowerCase().includes(this.search.toLowerCase())
return match
})
}
selectUser(data: UserModel) {
this.user.select = new MyUserModel(data)
this.userPassword = {
usernameId: this.user.select.usernameId,
empId: this.user.select.empId,
companyId: this.user.select.companyId,
oldPassword: "",
newPassword: "",
}
}
updateUserPassword() {
if (this.changePassword) {
this.user.loading = true
this.userService.changePassword(this.userPassword).subscribe({
next: response => {
if (response.success) {
this.updateUser()
} else {
this.showAlert(response.message, 'error')
this.user.loading = false
}
this.cdr.detectChanges()
}, error: error => {
this.showAlert(error.message, 'error')
this.user.loading = false
this.cdr.detectChanges()
}
})
} else {
this.updateUser()
}
}
updateUser() {
this.user.loading = true
this.userService.post(new MyUserModel(this.user.select)).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getUserList()
this.searchChange()
} else {
this.showAlert(response.message, 'error')
this.user.loading = false
}
this.cdr.detectChanges()
}, error: error => {
this.showAlert(error.message, 'error')
this.user.loading = false
this.cdr.detectChanges()
}
})
}
searchChange() {
this.currentPage = 1
this.page = Array.from({ length: Math.ceil(this.userListFilter().length / 10) }, (_, i) => i + 1);
}
selectDataModal(target: { [key: string]: any }, field: string, data: any) {
target[field] = JSON.parse(JSON.stringify(data))
}
showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', {
timeOut: 3000,
positionClass: 'toast-top-right',
})
}
}
\ No newline at end of file
<div class="w-full min-height-50px mb-10px justify-between items-center">
<div class="flex justify-between">
<div class="flex pr-2">
<div class="px-1">
<button type="button" class="ti-btn ti-btn-soft-secondary h-20px m-0 shadow-md"
data-hs-overlay="#user-setting-upload-modal"
(click)="fileInput.value = '';selectedFile=null;selectedFileName = 'กรุณาเลือกไฟล์'">
<i class="ri-add-line"></i>
นำเข้าข้อมูล
</button>
<a class="mx-2 justify-center -mb-px inline-flex items-center gap-2 font-weight-500 font-size-12px text-center text-secondary border-secondary border-b-2 align-items-end"
href="javascript:void(0);">
ดาวน์โหลดตัวอย่างไฟล์
</a>
</div>
</div>
<div class="flex justify-end">
<div class="px-1">
<div class="relative shadow-md">
......@@ -33,7 +18,6 @@
</button>
</div>
</div>
</div>
</div>
<div class="page px-rem">
......@@ -72,11 +56,7 @@
<tbody *ngIf="!user.loading&&userListFilter().length">
<tr
*ngFor="let item of userListFilter() | slice:((currentPage-1) * 10) : (((currentPage-1) * 10) + 10);let i = index">
<td class="text-center">
<input type="checkbox" class="ti-form-checkbox cursor-pointer"
id="checkbox-{{item.data.usernameId}}" [(ngModel)]="item.check">
<label for="checkbox-{{item.data.usernameId}}">&nbsp;{{item.data.usernameId}}</label>
</td>
<td class="text-center">{{item.data.usernameId}} </td>
<td class="text-center">{{item.data.empId}}</td>
<td>{{item.data.employee.fname}}</td>
<td>{{item.data.employee.lname}}</td>
......@@ -148,7 +128,7 @@
<div class="absolute flex">
<div class="px-1">
<button type="button" class="ti-btn ti-btn-soft-indigo h-45px m-0 shadow-md"
(click)="userPassword.oldPassword=='';userPassword.newPassword=''">
(click)="userPassword.oldPassword='';userPassword.newPassword=''">
<svg class="svg-indigo" width="16" height="16" viewBox="0 0 64.00 64.00"
xmlns="http://www.w3.org/2000/svg" fill="none" stroke="#595BEA" stroke-width="3.84"
transform="rotate(45)matrix(-1, 0, 0, 1, 0, 0)">
......@@ -178,49 +158,17 @@
[(ngModel)]="userPassword.usernameId">
<label class="ti-form-label mt-2rem">รหัสพนักงาน</label>
<input type="text" class="ti-form-input bg-input-readonly" readonly [(ngModel)]="userPassword.empId">
<label class="ti-form-label mt-2rem">รหัสผ่านเก่า</label>
<input type="text" class="ti-form-input" [(ngModel)]="userPassword.oldPassword">
<label class="ti-form-label mt-2rem">รหัสผ่านใหม่</label>
<input type="text" class="ti-form-input" [(ngModel)]="userPassword.newPassword">
<label class="ti-form-label mt-2rem">กำหนดผ่านใหม่*</label>
<input type="password" class="ti-form-input" [(ngModel)]="userPassword.newPassword">
<div class="flex justify-end mt-2rem mb-1rem">
<button type="button"
class="hs-dropdown-toggle ti-btn ti-border font-medium bg-white text-gray-700 shadow-sm align-middle hover:bg-gray-50 focus:ring-offset-white focus:ring-primary dark:bg-bgdark dark:hover:bg-black/20 dark:border-white/10 dark:text-white/70 dark:hover:text-white dark:focus:ring-offset-white/10"
data-hs-overlay="#user-setting-modal">
ย้อนกลับ
</button>
<a class="ti-btn ti-btn-success" href="javascript:void(0);"
data-hs-overlay="#user-setting-alert-modal">
<button type="button" class="ti-btn ti-btn-success" data-hs-overlay="#user-setting-alert-modal"
[class.ti-btn-disabled]="!userPassword.newPassword" [disabled]="!userPassword.newPassword">
บันทึกข้อมูล
</a>
</div>
</div>
</div>
</div>
</div>
<div id="user-setting-upload-modal" class="hs-overlay hidden ti-modal">
<div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out rounded-md">
<div class="ti-modal-header bg-primary !rounded-none !rounded-t-sm">
<h5 class="text-xxl font-bold text-white">
นำเข้าผู้ใช้งาน
</h5>
</div>
<div class="ti-modal-body max-h-full overflow-hidden ti-modal-content !rounded-t-none !rounded-b-sm">
<h1 class="mt-2" style="text-align: center;">ไฟล์</h1>
<div class="mt-2 p-2">
<div class="flex rounded-md">
<input #fileInput id="fileInput" type="file" (change)="onFileSelected($event)" hidden>
<input type="text" [value]="selectedFileName" readonly (click)="fileInput.click()"
class="ti-form-input rounded-none ltr:rounded-l-md rtl:rounded-r-md focus:z-10 cursor-pointer">
<button type="button" (click)="fileInput.click()"
class="inline-flex flex-shrink-0 justify-center items-center h-[2.875rem] w-[2.875rem] ltr:rounded-r-md rtl:rounded-l-md border border-transparent font-semibold bg-secondary text-white hover:bg-secondary focus:z-10 focus:outline-none focus:ring-0 focus:ring-secondary transition-all text-sm">
<i class="ti ti-upload"></i>
</button>
</div>
<div class="flex justify-center mt-2rem mb-1rem space-x-4">
<button type="submit" data-hs-overlay="#user-setting-upload-modal" class="ti-btn ti-btn-secondary"
[class.ti-btn-disabled]="!selectedFile" (click)="uploadFile()" [disabled]="!selectedFile">
อัปโหลด
</button>
</div>
</div>
......
......@@ -53,7 +53,7 @@ export class SetAPasswordComponent {
getUserList() {
this.user.loading = true
this.userService.getList().subscribe({
this.userService.getList("true").subscribe({
next: response => {
this.user.dataList = response.map(x => ({ check: false, data: new MyUserModel(x) }))
this.user.loading = false
......@@ -136,9 +136,27 @@ export class SetAPasswordComponent {
this.userService.changePassword(this.userPassword).subscribe({
next: response => {
if (response.success) {
this.updateUser()
} else {
this.showAlert(response.message, 'error')
this.user.loading = false
}
this.cdr.detectChanges()
}, error: error => {
this.showAlert(error.message, 'error')
this.user.loading = false
this.cdr.detectChanges()
}
})
}
updateUser() {
this.user.loading = true
this.userService.post(new MyUserModel({ ...this.user.select, status: '1' })).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getUserList()
this.searchChange()
} else {
this.showAlert(response.message, 'error')
this.user.loading = false
......
......@@ -210,10 +210,12 @@
</div>
</div>
<div class="ti-modal-body padding-16px pt-0 overflow-y-0">
<label class="ti-form-label mt-2rem">ชื่อล็อคอิน</label>
<input type="text" class="ti-form-input" [ngClass]="{'bg-input-readonly':currentModal=='edit'}"
[readonly]="currentModal=='edit'" [(ngModel)]="user.select.usernameId" [maxLength]="20">
<label class="ti-form-label mt-2rem">รหัสพนักงาน</label>
<label class="ti-form-label mt-2rem">ชื่อล็อคอิน*</label>
<input type="text" class="ti-form-input"
oninput="this.value = this.value.replace(/[\u0E00-\u0E7F]/g, '')"
[ngClass]="{'bg-input-readonly':currentModal=='edit'}" [readonly]="currentModal=='edit'"
[(ngModel)]="user.select.usernameId" [maxLength]="20">
<label class="ti-form-label mt-2rem">รหัสพนักงาน*</label>
<div class="grid grid-cols-2 gap-2">
<div class="relative flex rounded-md">
<input type="text" class="ti-form-input" readonly [(ngModel)]="user.select.employee.employeeId">
......@@ -232,7 +234,7 @@
<input type="text" class="ti-form-input bg-input-readonly" readonly
[(ngModel)]="user.select.employee.thFullName">
</div>
<label class="ti-form-label mt-2rem">บทบาท</label>
<label class="ti-form-label mt-2rem">บทบาท*</label>
<div class="grid grid-cols-2 gap-2">
<div class="relative flex rounded-md">
<input type="text" class="ti-form-input" readonly [(ngModel)]="user.select.role.roleId">
......@@ -251,7 +253,7 @@
<input type="text" class="ti-form-input bg-input-readonly" readonly
[(ngModel)]="user.select.role.tdesc">
</div>
<label class="ti-form-label mt-2rem">ระดับ</label>
<label class="ti-form-label mt-2rem">ระดับ*</label>
<div class="grid grid-cols-2 gap-2">
<div class="relative flex rounded-md">
<input type="text" class="ti-form-input" readonly [(ngModel)]="user.select.level.userLevel">
......@@ -270,26 +272,17 @@
<input type="text" class="ti-form-input bg-input-readonly" readonly
[(ngModel)]="user.select.level.tdesc">
</div>
<label class="ti-form-label mt-2rem">สถานะรหัสผ่าน</label>
<select class="ti-form-select w-1/2" placeholder="Select" [(ngModel)]="user.select.status">
<ng-container *ngIf="currentModal=='add'">
<option [ngValue]="'0'">รหัสผ่านถูกตั้งใหม่</option>
</ng-container>
<ng-container *ngIf="currentModal=='edit'">
<option [ngValue]="'0'">รหัสผ่านถูกตั้งใหม่</option>
<option [ngValue]="'1'">รหัสผ่านถูกใช้งาน</option>
</ng-container>
</select>
<div class="flex justify-end mt-2rem mb-1rem">
<button type="button"
class="hs-dropdown-toggle ti-btn ti-border font-medium bg-white text-gray-700 shadow-sm align-middle hover:bg-gray-50 focus:ring-offset-white focus:ring-primary dark:bg-bgdark dark:hover:bg-black/20 dark:border-white/10 dark:text-white/70 dark:hover:text-white dark:focus:ring-offset-white/10"
data-hs-overlay="#user-setting-modal">
ย้อนกลับ
</button>
<a class="ti-btn ti-btn-success" href="javascript:void(0);"
data-hs-overlay="#user-setting-alert-modal">
<button type="button" class="ti-btn ti-btn-success" data-hs-overlay="#user-setting-alert-modal"
[class.ti-btn-disabled]="!user.select.usernameId||!user.select.employee.employeeId||!user.select.role.roleId||!user.select.level.userLevel"
[disabled]="!user.select.usernameId||!user.select.employee.employeeId||!user.select.role.roleId||!user.select.level.userLevel">
บันทึกข้อมูล
</a>
</button>
</div>
</div>
</div>
......@@ -788,7 +781,7 @@
data-hs-overlay="#user-setting-alert-modal">
ย้อนกลับ
</button>
<a class="ti-btn ti-btn-success" href="javascript:void(0);"
<a class="ti-btn ti-btn-danger" href="javascript:void(0);"
data-hs-overlay="#user-setting-alert-modal" (click)="updateUser('delete')">
ลบข้อมูล
</a>
......
......@@ -135,6 +135,7 @@ import { CompetencyGroupGradeService } from 'src/app/shared/services/competency-
import { IndicatorsCoursesService } from 'src/app/shared/services/indicators-courses.service';
import { IdpDevelopmentService } from 'src/app/shared/services/idp-development.service';
import { UserService } from 'src/app/shared/services/user.service';
import { ManageUserComponent } from '../company-components/account-settings/manage-user/manage-user.component';
export const MY_DATE_FORMATS = {
parse: {
......@@ -253,7 +254,8 @@ export class CustomDateAdapter extends NativeDateAdapter {
IdpEvalutionComponent,
CompanyRegistrationPageComponent,
PmsEvalutionComponent,
CEvaluationComponent
CEvaluationComponent,
ManageUserComponent
],
imports: [
CommonModule,
......
......@@ -13,8 +13,8 @@ export class UserService {
urlApi = environment.baseUrl + this.api
constructor(private http: HttpClient) {
}
getList(): Observable<UserModel[]> {
return this.http.get<UserModel[]>(this.urlApi + "/lists")
getList(pwdempty?: string): Observable<UserModel[]> {
return this.http.get<UserModel[]>(this.urlApi + "/lists" + (pwdempty ? '?pwdempty=' + pwdempty : ""))
}
getRoleList(): Observable<RoleModel[]> {
return this.http.get<RoleModel[]>(this.urlApi + "/role/lists")
......
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