api bu2

parent c24c76a6
import { Component, EventEmitter, Input, Output } from '@angular/core'; import { Component, EventEmitter, Input, OnInit, } from '@angular/core';
import { Bu1Model, MyBu1Model } from 'src/app/shared/model/bu1.model';
import { Bu2Model, MyBu2Model } from 'src/app/shared/model/bu2.model';
import { Bu1Service } from 'src/app/shared/services/bu1.service';
import { Bu2Service } from 'src/app/shared/services/bu2.service';
@Component({ @Component({
selector: 'app-department-list', selector: 'app-department-list',
templateUrl: './department-list.component.html', templateUrl: './department-list.component.html',
styleUrls: ['./department-list.component.scss'] styleUrls: ['./department-list.component.scss']
}) })
export class DepartmentListComponent { export class DepartmentListComponent implements OnInit {
modalOptions: { currentPage = 1
[nameModal: string]: { // ชื่อตรวจสอบการเปิดปิด page = Array.from({ length: 1 }, (_, i) => i + 1);
isModalOpen: boolean; // เปิด/ปิด bu2List: Bu2Model[] = []
modalSize: string; // ขนาดของ Modal (s,m,l,vw10-vw100 ) bu2: Bu2Model = new MyBu2Model({})
backdropClose: boolean; // (คลิก Backdrop แล้ว true ปิด false ไม่ปิด ) bu1: Bu1Model = new MyBu1Model({})
search = ""
constructor(private bu2Service: Bu2Service,
private bu1Service: Bu1Service
) { }
ngOnInit(): void {
this.getBu2List()
} }
} = { getBu2List() {
"add": { this.bu2Service.getList().subscribe(response => {
isModalOpen: false, console.log("31313 : ",response)
modalSize: 'm', this.bu2List = response
backdropClose: true, this.searchChange()
}, })
"edit": {
isModalOpen: false,
modalSize: 'm',
backdropClose: true,
} }
searchChange() {
this.currentPage = 1
this.page = Array.from({ length: Math.ceil(this.bu2ListFilter().length / 10) }, (_, i) => i + 1);
} }
bu2ListFilter() {
openModal(name: string, size: string, closeOnBackdrop?: boolean) { return this.bu2List.filter(x => x.bu2id.toLowerCase().includes(this.search) ||
this.modalOptions[name].modalSize = size; x.tdesc.toLowerCase().includes(this.search) ||
this.modalOptions[name].backdropClose = closeOnBackdrop || false; x.edesc.toLowerCase().includes(this.search))
this.modalOptions[name].isModalOpen = true;
document.body.style.overflow = 'hidden'; // ล็อก Scroll
} }
selectBu2(bu2: Bu2Model) {
closeModal(name: string) { this.bu1Service.getById(bu2.parent).subscribe(response =>{
this.modalOptions[name].isModalOpen = false; this.bu1 = response
// ตรวจสอบว่ามี Modal อื่นเปิดอยู่หรือไม่ console.log(this.bu1)
if (!this.isAnyModalOpen()) { })
document.body.style.overflow = ''; // คืนค่าการ Scroll เฉพาะเมื่อ Modal ทั้งหมดปิดแล้ว this.bu2 = new MyBu2Model(bu2)
} }
addBu2() {
// this.bu2Service.post(this.bu2).subscribe((response:any) => {
// if (response.success) {
// this.getBu2List()
// }
// })
} }
deleteBu2(bu2: Bu2Model) {
isAnyModalOpen(): boolean { // this.bu2Service.delete(new MyBu2Model(bu2)).subscribe((response:any) => {
// Logic ตรวจสอบว่า Modal อื่นยังเปิดอยู่หรือไม่ // if (response.success) {
return Object.values(this.modalOptions).some(modal => modal.isModalOpen); // หากไม่มี Modal อื่นเปิด // this.getBu2List()
// }
// })
} }
} }
......
...@@ -41,6 +41,7 @@ import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http'; ...@@ -41,6 +41,7 @@ import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { Bu1Service } from 'src/app/shared/services/bu1.service'; import { Bu1Service } from 'src/app/shared/services/bu1.service';
import { HttpRequestInterceptor } from 'src/app/shared/services/http-request.interceptor'; import { HttpRequestInterceptor } from 'src/app/shared/services/http-request.interceptor';
import { FormsModule } from '@angular/forms'; import { FormsModule } from '@angular/forms';
import { Bu2Service } from 'src/app/shared/services/bu2.service';
@NgModule({ @NgModule({
declarations: [ declarations: [
...@@ -88,7 +89,7 @@ import { FormsModule } from '@angular/forms'; ...@@ -88,7 +89,7 @@ import { FormsModule } from '@angular/forms';
HttpClientModule, HttpClientModule,
FormsModule FormsModule
], ],
providers: [Bu1Service, { providers: [Bu1Service,Bu2Service, {
provide: HTTP_INTERCEPTORS, provide: HTTP_INTERCEPTORS,
useClass: HttpRequestInterceptor, useClass: HttpRequestInterceptor,
multi: true, multi: true,
......
export interface Bu2Model {
bu2id: string;
tdesc: string;
edesc: string;
parent: string;
companyId: string;
}
export class MyBu2Model implements Bu2Model {
bu2id: string;
tdesc: string;
edesc: string;
parent: string;
companyId: string;
constructor(data: Partial<Bu2Model>) {
this.bu2id = data.bu2id || ""
this.tdesc = data.tdesc || ""
this.edesc = data.edesc || ""
this.parent = data.parent || ""
this.companyId = data.companyId || ""
}
}
...@@ -14,6 +14,9 @@ export class Bu1Service { ...@@ -14,6 +14,9 @@ export class Bu1Service {
getList(): Observable<Bu1Model[]> { getList(): Observable<Bu1Model[]> {
return this.http.get<Bu1Model[]>(this.urlApi + "/lists") return this.http.get<Bu1Model[]>(this.urlApi + "/lists")
} }
getById(bu1id:string): Observable<Bu1Model> {
return this.http.get<Bu1Model>(this.urlApi + "/"+bu1id)
}
// post(body: Bu1Model) { // post(body: Bu1Model) {
// return this.http.post(this.urlApi, body) // return this.http.post(this.urlApi, body)
// } // }
......
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { environment } from 'src/environments/environment';
import { Bu2Model } from '../model/bu2.model';
@Injectable({
providedIn: 'root'
})
export class Bu2Service {
api = "/bu2"
urlApi = environment.baseUrl + this.api
constructor(private http: HttpClient) {
}
getList(): Observable<Bu2Model[]> {
return this.http.get<Bu2Model[]>(this.urlApi + "/lists")
}
// post(body: Bu1Model) {
// return this.http.post(this.urlApi, body)
// }
// delete(body: Bu1Model) {
// const options = {
// headers: new HttpHeaders({
// "Content-Type": "application/json",
// }),
// body: body
// };
// return this.http.delete(this.urlApi, options)
// }
}
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