Commit 9b7d69c1 by Nakarin Luankla

แก้ model bu1-4

parent b4ff8dbf
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, } from '@angular/core';
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, ViewChild, } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { ColumnModel } from '@syncfusion/ej2-grids';
import { ToastrService } from 'ngx-toastr';
import { Bu1Model, MyBu1Model } from 'src/app/shared/model/bu1.model';
......@@ -6,6 +7,7 @@ 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';
import { FileService } from 'src/app/shared/services/file.service';
import Swal from 'sweetalert2';
interface table {
currentPage: number,
page: number[],
......@@ -70,18 +72,38 @@ export class DepartmentListComponent implements OnInit {
pageSize: 10
}
currentModal: 'add' | 'edit' | 'delete' = "add"
@ViewChild("departmentListModal") departmentListModal: any;
@ViewChild("departmentListBu1Modal") departmentListBu1Modal: any;
dialogRef: any
dialogRefBu1: any
constructor(private bu2Service: Bu2Service,
private bu1Service: Bu1Service,
private toastr: ToastrService,
private cdr: ChangeDetectorRef,
private fileService: FileService
private fileService: FileService,
private dialog: MatDialog
) { }
ngOnInit(): void {
this.getBu2List()
this.getBu1List()
}
openDialog() {
this.dialogRef = this.dialog.open(this.departmentListModal, {
width: '500px',
})
}
openBu1Dialog() {
this.dialogRefBu1 = this.dialog.open(this.departmentListBu1Modal, {
width: '800px',
})
}
closeDialog() {
this.dialogRef.close()
}
closeBu1Dialog() {
this.dialogRefBu1.close()
}
onFileSelected(event: any) {
this.selectedFile = event.target.files.length > 0 ? event.target.files[0] : null;
this.selectedFileName = this.selectedFile?.name || "กรุณาเลือกไฟล์"
......@@ -185,45 +207,80 @@ export class DepartmentListComponent implements OnInit {
}
showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', {
timeOut: 3000,
positionClass: 'toast-top-right',
})
Swal.fire({
title: 'แจ้งเตือน',
text: text,
icon: type,
confirmButtonText: 'ตกลง',
});
}
addBu2() {
this.bu2ListLoading = true
this.bu2Service.post({ ...this.bu2, parent: this.bu1.bu1id }).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getBu2List()
} else {
this.showAlert(response.message, 'error')
this.bu2ListLoading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.bu2ListLoading = false
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการบันทึกข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'บันทึกข้อมูล',
cancelButtonText: 'ย้อนกลับ',
reverseButtons: true,
}).then((result) => {
if (result.isConfirmed) {
this.bu2ListLoading = true
this.bu2Service.post({ ...this.bu2, parent: this.bu1.bu1id }).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getBu2List()
this.closeDialog();
} else {
this.showAlert(response.message, 'error')
this.bu2ListLoading = false
this.closeDialog();
}
}, error: error => {
this.showAlert(error.message, 'error')
this.bu2ListLoading = false
this.closeDialog();
}
})
}
})
});
}
deleteBu2() {
this.bu2ListLoading = true
// const body = this.bu2List.filter(x => x.check).map(x => new MyBu2Model(x.data))
// this.bu2Service.delete(body).subscribe({
// next: response => {
// if (response.success) {
// this.showAlert(response.message, 'success')
// this.getBu2List()
// } else {
// this.showAlert(response.message, 'error')
// this.bu2ListLoading = false
// }
// }, error: error => {
// this.showAlert(error.message, 'error')
// this.bu2ListLoading = false
// }
// })
if (!this.numSelectItem()) {
this.showAlert('กรุณาเลือกข้อมูลที่ต้องการลบ', 'error')
return
}
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการลบข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ลบข้อมูล',
cancelButtonText: 'ย้อนกลับ',
reverseButtons: true,
}).then((result) => {
if (result.isConfirmed) {
this.bu2ListLoading = true
const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.bu2List.filter(x => selectedKeys.includes(x.bu2id) && this.selectedItems.data.get(x.bu2id)).map(x => new MyBu2Model(x))
this.bu2Service.delete(body).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getBu2List()
} else {
this.showAlert(response.message, 'error')
this.bu2ListLoading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.bu2ListLoading = false
}
})
}
});
}
......
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, } from '@angular/core';
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, ViewChild, } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { ColumnModel } from '@syncfusion/ej2-grids';
import { ToastrService } from 'ngx-toastr';
import { Bu2Model, MyBu2Model } from 'src/app/shared/model/bu2.model';
......@@ -6,6 +7,7 @@ import { Bu3Model, MyBu3Model } from 'src/app/shared/model/bu3.model';
import { Bu2Service } from 'src/app/shared/services/bu2.service';
import { Bu3Service } from 'src/app/shared/services/bu3.service';
import { FileService } from 'src/app/shared/services/file.service';
import Swal from 'sweetalert2';
interface table {
currentPage: number,
page: number[],
......@@ -56,17 +58,38 @@ export class SectionRegistrationComponent implements OnInit {
};
search = ''
selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() };
@ViewChild("sectionRegistrationModal") sectionRegistrationModal: any;
@ViewChild("sectionRegistrationModalBu2") sectionRegistrationModalBu2: any;
dialogRef: any
dialogRefBu2: any
constructor(private bu3Service: Bu3Service,
private bu2Service: Bu2Service,
private toastr: ToastrService,
private cdr: ChangeDetectorRef,
private fileService: FileService
private fileService: FileService,
private dialog: MatDialog
) { }
ngOnInit(): void {
this.getBu3List()
this.getBu2List()
}
openDialog() {
this.dialogRef = this.dialog.open(this.sectionRegistrationModal, {
width: '500px',
})
}
openDialogBu2() {
this.dialogRefBu2 = this.dialog.open(this.sectionRegistrationModalBu2, {
width: '800px',
})
}
closeDialog() {
this.dialogRef.close()
}
closeDialogBu2() {
this.dialogRefBu2.close()
}
onFileSelected(event: any) {
this.selectedFile = event.target.files.length > 0 ? event.target.files[0] : null;
......@@ -154,27 +177,52 @@ export class SectionRegistrationComponent implements OnInit {
}
addBu3() {
this.bu3.loading = true
this.bu3Service.post({ ...this.bu3.select, parent: this.bu2.bu2id }).subscribe({
next: response => {
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการบันทึกข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'บันทึกข้อมูล',
}).then((result) => {
if (result.isConfirmed) {
this.bu3.loading = true
this.bu3Service.post({ ...this.bu3.select, parent: this.bu2.bu2id }).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getBu3List()
this.closeDialog()
} else {
this.showAlert(response.message, 'error')
this.bu3.loading = false
this.closeDialog()
}
}, error: error => {
this.showAlert(error.message, 'error')
this.bu3.loading = false
this.closeDialog()
}
})
}
})
}
deleteBu3() {
this.bu3.loading = true
const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.bu3.dataList.filter(x => selectedKeys.includes(x.bu3id) && this.selectedItems.data.get(x.bu3id)).map(x => new MyBu3Model(x))
this.bu3Service.delete(body).subscribe({
if (this.numSelectItem() == 0) {
this.showAlert('กรุณาเลือกข้อมูลที่จะลบ', 'error')
return
}
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการลบข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ลบข้อมูล',
}).then((result) => {
if (result.isConfirmed) {
this.bu3.loading = true
const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.bu3.dataList.filter(x => selectedKeys.includes(x.bu3id) && this.selectedItems.data.get(x.bu3id)).map(x => new MyBu3Model(x))
this.bu3Service.delete(body).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
......@@ -185,7 +233,9 @@ export class SectionRegistrationComponent implements OnInit {
}
}, error: error => {
this.showAlert(error.message, 'error')
this.bu3.loading = false
this.bu3.loading = false
}
})
}
})
}
......@@ -214,10 +264,12 @@ export class SectionRegistrationComponent implements OnInit {
}
showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', {
timeOut: 3000,
positionClass: 'toast-top-right',
})
Swal.fire({
title: 'แจ้งเตือน',
text: text,
icon: type,
confirmButtonText: 'ตกลง',
});
}
checkPrimary() {
......
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit } from '@angular/core';
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, ViewChild } from '@angular/core';
import { ColumnModel } from '@syncfusion/ej2-grids';
import { MatDialog } from '@angular/material/dialog';
import { ToastrService } from 'ngx-toastr';
import { Bu3Model, MyBu3Model } from 'src/app/shared/model/bu3.model';
import { Bu4Model, MyBu4Model } from 'src/app/shared/model/bu4.model';
import { Bu3Service } from 'src/app/shared/services/bu3.service';
import { Bu4Service } from 'src/app/shared/services/bu4.service';
import { FileService } from 'src/app/shared/services/file.service';
import Swal from 'sweetalert2';
interface table {
currentPage: number,
page: number[],
......@@ -63,16 +65,39 @@ export class SubDepartmentOneComponent implements OnInit {
};
search = ''
selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() };
@ViewChild("subDepartmentOneModal") subDepartmentOneModal: any;
@ViewChild("subDepartmentOneBu3TableModal") subDepartmentOneBu3TableModal: any;
dialogRef: any
dialogRefBu3: any
constructor(private bu4Service: Bu4Service,
private bu3Service: Bu3Service,
private toastr: ToastrService,
private cdr: ChangeDetectorRef,
private fileService: FileService
private fileService: FileService,
private dialog: MatDialog
) { }
ngOnInit(): void {
this.getBu4List()
this.getBu3List()
}
openDialog() {
this.dialogRef = this.dialog.open(this.subDepartmentOneModal, {
width: '500px',
})
}
openDialogBu3() {
this.dialogRefBu3 = this.dialog.open(this.subDepartmentOneBu3TableModal, {
width: '800px',
})
}
closeDialog() {
this.dialogRef.close()
}
closeDialogBu3() {
this.dialogRefBu3.close()
}
onFileSelected(event: any) {
......@@ -160,38 +185,65 @@ export class SubDepartmentOneComponent implements OnInit {
}
addBu4() {
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการบันทึกข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'บันทึกข้อมูล',
}).then((result) => {
if (result.isConfirmed) {
this.bu4.loading = true
this.bu4Service.post({ ...this.bu4.select, parent: this.bu3.bu3id }).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getBu4List()
this.closeDialog()
} else {
this.showAlert(response.message, 'error')
this.bu4.loading = false
this.closeDialog()
}
}, error: error => {
this.showAlert(error.message, 'error')
this.bu4.loading = false
this.closeDialog()
}
})
}
})
}
deleteBu4() {
this.bu4.loading = true
const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.bu4.dataList.filter(x => selectedKeys.includes(x.bu4id) && this.selectedItems.data.get(x.bu4id)).map(x => new MyBu4Model(x))
this.bu4Service.delete(body).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getBu4List()
} else {
this.showAlert(response.message, 'error')
this.bu4.loading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.bu4.loading = false
if (this.numSelectItem() == 0) {
this.showAlert('กรุณาเลือกข้อมูลที่จะลบ', 'error')
return
}
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการลบข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ลบข้อมูล',
}).then((result) => {
if (result.isConfirmed) {
this.bu4.loading = true
const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.bu4.dataList.filter(x => selectedKeys.includes(x.bu4id) && this.selectedItems.data.get(x.bu4id)).map(x => new MyBu4Model(x))
this.bu4Service.delete(body).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getBu4List()
} else {
this.showAlert(response.message, 'error')
this.bu4.loading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.bu4.loading = false
}
})
}
})
}
......@@ -220,10 +272,12 @@ export class SubDepartmentOneComponent implements OnInit {
}
showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', {
timeOut: 3000,
positionClass: 'toast-top-right',
})
Swal.fire({
title: 'แจ้งเตือน',
text: text,
icon: type,
confirmButtonText: 'ตกลง',
});
}
......
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