Commit bedbea55 by Natthaphat

แก้ไขสามารถเลือกแล้วเปลี่ยน สถานะได้เลย

parent 3c490f8b
......@@ -14,6 +14,17 @@
translate}}
</a>
<a href="javascript:void(0);" class="hs-dropdown-toggle ti-btn ti-btn-success-full me-2"
*ngIf="someSelected" (click)="adjustSelect(1)"><i
class="ri-user-follow-line font-semibold align-middle"></i>{{ 'Active' |
translate}}
</a>
<a href="javascript:void(0);" class="hs-dropdown-toggle ti-btn ti-btn-secondary-full me-2"
*ngIf="someSelected" (click)="adjustSelect(0)"><i
class="ri-user-unfollow-line font-semibold align-middle"></i>{{ 'Unactive' |
translate}}
</a>
<a href="javascript:void(0);" class="hs-dropdown-toggle ti-btn ti-btn-danger-full me-2" *ngIf="someSelected"
(click)="deleteSelect()"><i class="ri-delete-bin-line font-semibold align-middle"></i>{{ 'Delete' |
......@@ -170,30 +181,30 @@
<div class="xl:col-span-12 col-span-12">
<label for="deal-title" class="form-label">{{'version' | translate}}</label>
<input type="text" class="form-control" [ngClass]="{ '!bg-input-readonly': modalStatus === 'edit' }"
id="deal-title" placeholder="" [(ngModel)]="consent.version" [readonly]="modalStatus === 'edit'">
<div class="text-danger" *ngIf="!consent.version">
id="deal-title" placeholder="" [(ngModel)]="pdpa.version" [readonly]="modalStatus === 'edit'">
<div class="text-danger" *ngIf="!pdpa.version">
{{'Please fill in information' | translate}}
</div>
</div>
<div class="xl:col-span-6 col-span-12" *ngIf="modalStatus=='add'">
<label for="deal-title" class="form-label">{{'วันที่เริ่ม' | translate}}</label>
<input type="text" class="form-control" id="deal-title" placeholder="" [(ngModel)]="consent.startDate">
<div class="text-danger" *ngIf="!consent.startDate">
<input type="text" class="form-control" id="deal-title" placeholder="" [(ngModel)]="pdpa.startDate">
<div class="text-danger" *ngIf="!pdpa.startDate">
{{'Please fill in information' | translate}}
</div>
</div>
<div class="xl:col-span-6 col-span-12" *ngIf="modalStatus=='add'">
<label for="deal-title" class="form-label">{{'วันที่สินสุด' | translate}}</label>
<input type="text" class="form-control" id="deal-title" placeholder="" [(ngModel)]="consent.endDate">
<div class="text-danger" *ngIf="!consent.endDate">
<input type="text" class="form-control" id="deal-title" placeholder="" [(ngModel)]="pdpa.endDate">
<div class="text-danger" *ngIf="!pdpa.endDate">
{{'Please fill in information' | translate}}
</div>
</div>
<div class="xl:col-span-12 col-span-12">
<label class="form-label">{{'Status' | translate}}</label>
<ng-select name="choices-multiple-remove-button2" id="choices-multiple-remove-button2" placeholder=""
[(ngModel)]="consent.status">
[(ngModel)]="pdpa.status">
<ng-option [value]="0">{{'Unactive' | translate}}</ng-option>
<ng-option [value]="1">{{'Active' | translate}}</ng-option>
</ng-select>
......@@ -240,9 +251,9 @@
<div class="flex flex-col">
<label class="ti-form-label mb-2 text-primary font-bold">Version *</label>
<input type="text" class="ti-form-input w-full"
[ngClass]="{ '!bg-input-readonly': modalStatus === 'edit' }" [(ngModel)]="consent.version"
[ngClass]="{ '!bg-input-readonly': modalStatus === 'edit' }" [(ngModel)]="pdpa.version"
[readonly]="modalStatus === 'edit'" />
<div class="text-danger text-sm mt-1" *ngIf="!consent.version">
<div class="text-danger text-sm mt-1" *ngIf="!pdpa.version">
Please fill in information
</div>
</div>
......@@ -252,17 +263,17 @@
<div class="flex items-center space-x-6">
<label class="inline-flex items-center space-x-2">
<input type="radio" name="status" [(ngModel)]="consent.status" value="1" />
<input type="radio" name="status" [(ngModel)]="pdpa.status" value="1" />
<span>{{ 'Active' | translate }}</span>
</label>
<label class="inline-flex items-center space-x-2">
<input type="radio" name="status" [(ngModel)]="consent.status" value="0" />
<input type="radio" name="status" [(ngModel)]="pdpa.status" value="0" />
<span>{{ 'Unactive' | translate }}</span>
</label>
</div>
<div class="text-danger text-sm mt-1" *ngIf="consent.status === null || consent.status === undefined">
<div class="text-danger text-sm mt-1" *ngIf="pdpa.status === null || pdpa.status === undefined">
Please fill in information
</div>
</div>
......@@ -270,16 +281,16 @@
<div class="flex flex-col">
<label class="ti-form-label mb-2 text-primary font-bold">Start Date </label>
<input type="datetime-local" class="ti-form-input w-full" [(ngModel)]="consent.startDate" />
<div class="text-danger text-sm mt-1" *ngIf="!consent.startDate">
<input type="datetime-local" class="ti-form-input w-full" [(ngModel)]="pdpa.startDate" />
<div class="text-danger text-sm mt-1" *ngIf="!pdpa.startDate">
Please fill in information
</div>
</div>
<div class="flex flex-col">
<label class="ti-form-label mb-2 text-primary font-bold">End Date</label>
<input type="datetime-local" class="ti-form-input w-full" [(ngModel)]="consent.endDate" />
<div class="text-danger text-sm mt-1" *ngIf="!consent.endDate">
<input type="datetime-local" class="ti-form-input w-full" [(ngModel)]="pdpa.endDate" />
<div class="text-danger text-sm mt-1" *ngIf="!pdpa.endDate">
Please fill in information
</div>
</div>
......@@ -307,17 +318,17 @@
<div>
<div *ngIf="currentTab == 1">
<quill-editor [modules]="quillConfig" [styles]="{ 'height': '400px', 'overflow-y': 'auto' }"
[(ngModel)]="consent.requestConsentThai" [ngModelOptions]="{ standalone: true }"
[(ngModel)]="pdpa.requestConsentThai" [ngModelOptions]="{ standalone: true }"
theme="snow"></quill-editor>
</div>
<div *ngIf="currentTab == 2">
<quill-editor [modules]="quillConfig" [styles]="{ 'height': '400px', 'overflow-y': 'auto' }"
[(ngModel)]="consent.requestConsentEng" [ngModelOptions]="{ standalone: true }"
[(ngModel)]="pdpa.requestConsentEng" [ngModelOptions]="{ standalone: true }"
theme="snow"></quill-editor>
</div>
<div *ngIf="currentTab == 3">
<quill-editor [modules]="quillConfig" [styles]="{ 'height': '400px', 'overflow-y': 'auto' }"
[(ngModel)]="consent.requestConsentChina" [ngModelOptions]="{ standalone: true }"
[(ngModel)]="pdpa.requestConsentChina" [ngModelOptions]="{ standalone: true }"
theme="snow"></quill-editor>
</div>
</div>
......
......@@ -13,12 +13,11 @@ import { UserRoleModel } from "../../models/user-role-model";
import { TokenService } from "../../../shared/services/token.service";
import { environment } from "../../../../environments/environment";
import { PdpaService } from "../../services/pdpa.service";
import { MyPdpaConsentModel, MyPdpaModel, PdpaConsentModel, PdpaModel } from "../../models/pdpa.model";
import { PdpaConfigModel } from "../../models/pdpaConfig.model";
import { Router } from "@angular/router";
import { PdpaConfigComponent } from "./pdpa-config/pdpa-config.component";
import { QuillModule } from "ngx-quill";
import { MatDialog } from "@angular/material/dialog";
import { MyPdpaConfigModel, PdpaConfigModel } from '../../models/pdpaConfig.model';
@Component({
selector: 'app-pdpa-manage',
......@@ -60,16 +59,16 @@ export class PdpaManageComponent {
modalRef: any;
pdpaconfig!: MyPdpaConsentModel;
pdpaconfig!: MyPdpaConfigModel;
edit = false
currentTab = 1
allSelected = false;
someSelected = false;
itemsList: MyPdpaConsentModel[] = []
filterList: MyPdpaConsentModel[] = []
consent: MyPdpaConsentModel = new MyPdpaConsentModel()
itemsList: MyPdpaConfigModel[] = []
filterList: MyPdpaConfigModel[] = []
pdpa: MyPdpaConfigModel = new MyPdpaConfigModel()
selectedItems = new Map<string, boolean>();
pageIndex = 0;
......@@ -97,12 +96,12 @@ export class PdpaManageComponent {
ngOnInit(): void {
this.pdpaService.getConfigList().subscribe(res => {
this.itemsList = res.map(item => new MyPdpaConsentModel(item, this.translate));
this.itemsList = res.map(item => new MyPdpaConfigModel(item, this.translate));
this.filterList = [...this.itemsList];
});
}
filter(v: string): MyPdpaConsentModel[] {
filter(v: string): MyPdpaConfigModel[] {
const search = v.toLowerCase();
return this.itemsList.filter(x =>
x.version?.toLowerCase().includes(search) ||
......@@ -114,77 +113,63 @@ export class PdpaManageComponent {
new() {
this.modalStatus = 'add'
this.consent = new MyPdpaConsentModel(); // สร้างอ็อบเจกต์ใหม่เสมอเมื่อเปิดหน้าต่างเพิ่ม
this.pdpa = new MyPdpaConfigModel();
this.openModal();
}
view(item: MyPdpaConsentModel) {
view(item: MyPdpaConfigModel) {
this.modalStatus = 'edit';
// สร้าง MyPdpaConsentModel ใหม่จาก item เพื่อให้ไม่กระทบข้อมูลเดิม
// และเรียกใช้ formatDatesForDatetimeLocal เพื่อปรับรูปแบบวันที่
this.consent = new MyPdpaConsentModel(item, this.translate);
this.formatDatesForDatetimeLocal(this.consent); // เพิ่มโค้ดนี้
this.pdpa = new MyPdpaConfigModel(item, this.translate);
this.formatDatesForDatetimeLocal(this.pdpa);
this.openModal();
}
// --- เพิ่มฟังก์ชันนี้เข้าไปในคลาส PdpaManageComponent ---
private formatDatesForDatetimeLocal(consentModel: MyPdpaConsentModel): void {
private formatDatesForDatetimeLocal(consentModel: MyPdpaConfigModel): void {
if (consentModel.startDate) {
// ตัดสตริงให้เหลือแค่ YYYY-MM-DDTHH:mm
consentModel.startDate = consentModel.startDate.substring(0, 16);
}
if (consentModel.endDate) {
// ตัดสตริงให้เหลือแค่ YYYY-MM-DDTHH:mm
consentModel.endDate = consentModel.endDate.substring(0, 16);
}
}
// ----------------------------------------------------
save() {
if (this.isSaving) return;
swal({
title: "Are you sure?",
text: "คุณต้องการบันทึกหรือไม่",
icon: "warning",
dangerMode: false,
buttons: ["Cancel", "Confirm"],
}).then(willSave => {
if (willSave) {
this.isSaving = true;
// 🔧 สร้าง payload เปล่า (ถ้ายังไม่ได้แก้ class)
const payload = {
version: this.consent.version,
startDate: this.consent.startDate,
endDate: this.consent.endDate,
status: this.consent.status,
requestConsentThai: this.consent.requestConsentThai,
requestConsentEng: this.consent.requestConsentEng,
requestConsentChina: this.consent.requestConsentChina
};
})
.then((willDelete: any) => {
if (willDelete) {
this.pdpaService.postConfig(payload).subscribe({
next: res => {
swal("Success", "บันทึกแล้ว", "success");
this.isSaving = false;
this.ngOnInit();
this.modalRef.close();
},
error: err => {
swal("Error", "เกิดข้อผิดพลาด", "error");
this.isSaving = false;
if (this.modalStatus == 'add') {
console.log(this.pdpa);
this.pdpaService.postConfig(this.pdpa).subscribe(result => {
swal("Save Success!!", "บันทึกเวอร์ชั่นสำเร็จ", "success");
this.ngOnInit()
this.childModal?.nativeElement.click()
})
} else if (this.modalStatus == 'edit') {
const respone = new MyPdpaConfigModel(this.pdpa);
this.pdpaService.update(respone).subscribe(result => {
console.log(result)
swal("Update Success!!", "บันทึกเวอร์ชั่นสำเร็จ", "success");
this.ngOnInit()
this.childModal?.nativeElement.click()
})
}
});
}
});
}
deleteVersion(item: PdpaConsentModel) {
deleteVersion(item: PdpaConfigModel) {
const versionText = `${this.translate.instant('Version')}: ${item.version}`;
swal({
title: "Are you sure?",
text: "You won't be able to revert this!",
text: `Confirm to delete :\n${versionText}\!`,
icon: "warning",
dangerMode: true,
buttons: ["Cancel", "Yes,Delete it!"],
......@@ -199,19 +184,19 @@ export class PdpaManageComponent {
}
deleteSelect() {
let employeeInfo = '';
let pdpaConfig = '';
this.selectedItems.forEach((isSelected, version) => {
if (isSelected) {
const pdpa = this.itemsList.find(pdpa => pdpa.version === version) as MyPdpaConsentModel;
const pdpa = this.itemsList.find(pdpa => pdpa.version === version) as MyPdpaConfigModel;
if (pdpa) {
employeeInfo += `${this.translate.instant('version')}: ${pdpa.version}\n`;
pdpaConfig += `${this.translate.instant('Version')}: ${pdpa.version}\n`;
}
}
});
swal({
title: "Are you sure?",
text: employeeInfo,
text: pdpaConfig,
icon: "warning",
dangerMode: true,
buttons: ["Cancel", "Yes, Delete it!"],
......@@ -233,6 +218,53 @@ export class PdpaManageComponent {
});
}
adjustSelect(status: number) {
let title = "Are you sure?";
let pdpaConfig = ''; // เก็บข้อมูลเวอร์ชันที่เลือก
this.selectedItems.forEach((isSelected, version) => {
if (isSelected) {
const pdpa = this.itemsList.find(pdpa => pdpa.version === version);
if (pdpa) {
pdpaConfig += `${this.translate.instant('Version')}: ${pdpa.version}\n`;
}
}
});
swal({
title: title,
text: pdpaConfig,
icon: "warning",
dangerMode: false,
buttons: ["Cancel", "Confirm"],
}).then((willDelete: any) => {
if (willDelete) {
this.selectedItems.forEach((isSelected, version) => {
if (isSelected) {
const pdpa = this.itemsList.find(pdpa => pdpa.version === version);
if (pdpa) {
// แปลง pdpa ให้เป็น Plain Object เพื่อป้องกัน JSON.stringify error
const cleanPdpa = {
version: pdpa.version,
startDate: pdpa.startDate,
endDate: pdpa.endDate,
status: status.toString(),
requestConsentThai: pdpa.requestConsentThai,
requestConsentEng: pdpa.requestConsentEng,
requestConsentChina: pdpa.requestConsentChina
};
this.pdpaService.update(cleanPdpa).subscribe(result => {
swal("Save Success!!", "บันทึกข้อมูลสำเร็จ", "success");
this.ngOnInit();
});
}
}
});
}
});
}
updatePagedItems() {
const startIndex = this.pageIndex * 10;
const endIndex = startIndex + 10;
......@@ -267,7 +299,7 @@ export class PdpaManageComponent {
}
filterEmp(empId: string) {
this.consent = this.itemsList.filter(e => e.version == empId)[0]
this.pdpa = this.itemsList.filter(e => e.version == empId)[0]
}
}
\ No newline at end of file
......@@ -92,7 +92,7 @@ export class MyPdpaConsentModel extends BaseModel implements PdpaConsentModel {
this.endDate = data?.endDate || ''
this.status = data?.status || ''
this.requestConsentThai = data?.requestConsentThai || ''
this.requestConsentThai = data?.requestConsentThai || ''
this.requestConsentEng = data?.requestConsentEng || ''
this.requestConsentChina = data?.requestConsentChina || ''
}
......
import { TranslateService } from "@ngx-translate/core"
import { BaseModel } from "./base.model"
export interface PdpaConfigModel {
version: string
startDate: string
......@@ -7,3 +10,30 @@ export interface PdpaConfigModel {
requestConsentEng: string
requestConsentChina: string
}
export class MyPdpaConfigModel extends BaseModel implements PdpaConfigModel {
version: string
startDate: string
endDate: string
status: string
requestConsentThai: string
requestConsentEng: string
requestConsentChina: string
constructor(data?: Partial<PdpaConfigModel>, translateService?: TranslateService) {
super(data, translateService)
this.version = data?.version || ''
this.startDate = data?.startDate || ''
this.endDate = data?.endDate || ''
this.status = data?.status || ''
this.requestConsentThai = data?.requestConsentThai || ''
this.requestConsentEng = data?.requestConsentEng || ''
this.requestConsentChina = data?.requestConsentChina || ''
}
getStatus(): string {
if (this.status == "1") {
return this.translateService.instant('Active');
} else {
return this.translateService.instant('Unactive');
}
}
}
\ No newline at end of file
import { TranslateService } from "@ngx-translate/core"
import { BaseModel } from "./base.model"
export interface PdpaSummaryModel {
consentProfile: number
nonConsentProfile: number
totalProfile: number
}
export class MyPdpaSummaryModel extends BaseModel implements PdpaSummaryModel {
consentProfile: number
nonConsentProfile: number
totalProfile: number
constructor(data?: Partial<PdpaSummaryModel>, translateService?: TranslateService) {
super(data, translateService)
this.consentProfile = data?.consentProfile!;
this.nonConsentProfile = data?.nonConsentProfile!;
this.totalProfile = data?.totalProfile!;
}
}
......@@ -4,7 +4,8 @@ import { Observable } from 'rxjs';
import { PdpaConsentModel, PdpaModel } from '../models/pdpa.model';
import { environment } from '../../../environments/environment';
import { PdpaSummaryModel } from '../models/pdpaSummary.model';
import { PdpaConfigModel } from '../models/pdpaConfig.model';
import { MyPdpaConfigModel, PdpaConfigModel } from '../models/pdpaConfig.model';
import { ResponseModel } from '../models/base.model';
@Injectable({
providedIn: 'root'
......@@ -34,16 +35,21 @@ export class PdpaService {
}
// ใช้กับ PdpaConfigModel
getConfigList(): Observable<PdpaConsentModel[]> {
return this.http.get<PdpaConsentModel[]>(`${environment.baseUrl}/pdpa/config/lists`);
getConfigList(): Observable<PdpaConfigModel[]> {
return this.http.get<PdpaConfigModel[]>(`${environment.baseUrl}/pdpa/config/lists`);
}
getConfigByVersion(version: string): Observable<PdpaConsentModel> {
return this.http.get<PdpaConsentModel>(`${environment.baseUrl}/pdpa/config/${version}`);
getConfigByVersion(version: string): Observable<PdpaConfigModel> {
return this.http.get<PdpaConfigModel>(`${environment.baseUrl}/pdpa/config/${version}`);
}
postConfig(data: PdpaConfigModel): Observable<any> {
return this.http.post<ResponseModel>(`${environment.baseUrl}/pdpa/config`, data);
}
postConfig(data: PdpaConsentModel): Observable<any> {
return this.http.post(`${environment.baseUrl}/pdpa/config`, data);
update(body: PdpaConfigModel): Observable<any> {
return this.http.post<ResponseModel>(`${environment.baseUrl}/pdpa/config`, body);
}
deleteConfig(version: string): Observable<any> {
......@@ -59,7 +65,7 @@ export class PdpaService {
return this.http.get<PdpaSummaryModel>(`${environment.baseUrl}/pdpa/consent-profile/total/${version}`);
}
getLastVersion(): Observable<PdpaConsentModel> {
return this.http.get<PdpaConsentModel>(`${environment.baseUrl}/pdpa/consent-profile/last`);
getLastVersion(): Observable<PdpaConfigModel> {
return this.http.get<PdpaConfigModel>(`${environment.baseUrl}/pdpa/consent-profile/last`);
}
}
......@@ -105,7 +105,7 @@ export class UserService {
}
update(body: UserProfileModel) {
return this.http.put<ResponseModel>(this.apiBaseUrl + "/" + body.candidateId, new UserProfileModel(body));
return this.http.post<ResponseModel>(this.apiBaseUrl + "/manage-profile", new UserProfileModel(body));
}
......
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