Commit 29b62b53 by Natthaphat

swal alert

parent fb0cdc2c
...@@ -9,8 +9,6 @@ import { ModuleModel, MyModuleModel } from '../../../../models/module.model'; ...@@ -9,8 +9,6 @@ import { ModuleModel, MyModuleModel } from '../../../../models/module.model';
import { ExcelPortalGroupModel, ExcelPortalModel, ExcelPortalTagsModel, MyExcelPortalGroupModel, MyExcelPortalModel, MyExcelPortalTagsModel } from '../../../../models/excel-portal.model'; import { ExcelPortalGroupModel, ExcelPortalModel, ExcelPortalTagsModel, MyExcelPortalGroupModel, MyExcelPortalModel, MyExcelPortalTagsModel } from '../../../../models/excel-portal.model';
import { ExcelReportService } from '../../../../services/excel-report.service'; import { ExcelReportService } from '../../../../services/excel-report.service';
import { CustomCubeService } from '../../../../services/custom-cube.service'; import { CustomCubeService } from '../../../../services/custom-cube.service';
import { AlertModalComponent } from '../../../../../alert-modal/alert-modal.component';
import { ConfirmModalComponent } from '../../../../../confirm-modal/confirm-modal.component';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { NgSelectModule } from '@ng-select/ng-select'; import { NgSelectModule } from '@ng-select/ng-select';
...@@ -27,6 +25,8 @@ import Swal from 'sweetalert2'; ...@@ -27,6 +25,8 @@ import Swal from 'sweetalert2';
import { DatasourceTableModel, MyDatasourceTableModel } from '../../../../models/datasource-table.model'; import { DatasourceTableModel, MyDatasourceTableModel } from '../../../../models/datasource-table.model';
import { DatasourseTableService } from '../../../../services/datasourse-table.service'; import { DatasourseTableService } from '../../../../services/datasourse-table.service';
import swal from 'sweetalert'; import swal from 'sweetalert';
import { ConfirmModalComponent } from '../../confirm-modal/confirm-modal.component';
import { AlertModalComponent } from '../../alert-modal/alert-modal.component';
export interface ModalDetail { export interface ModalDetail {
text: { cardHead: string, search: string[], tableHead: string[] } text: { cardHead: string, search: string[], tableHead: string[] }
} }
......
...@@ -160,7 +160,7 @@ ...@@ -160,7 +160,7 @@
<a aria-label="anchor" title="Print" <a aria-label="anchor" title="Print"
(mouseenter)="buttonHover.set(item.fileName+'print',!buttonHover.get(item.fileName))" (mouseenter)="buttonHover.set(item.fileName+'print',!buttonHover.get(item.fileName))"
(mouseleave)="buttonHover.clear()" (mouseleave)="buttonHover.clear()"
class="ti-btn ti-btn-wave product-btn !gap-0 !m-0 bg-warning/10 text-warning hover:bg-warning hover:text-white hover:border-warning" class="ti-btn ti-btn-wave product-btn !gap-0 !m-0 bg-warning/10 text-warning hover:bg-warning hover:text-white hover:border-warning cursor-pointer"
(click)="openPrintModal(item);"> (click)="openPrintModal(item);">
<i class="ri-printer-line"></i></a> <i class="ri-printer-line"></i></a>
</td> </td>
...@@ -244,7 +244,7 @@ ...@@ -244,7 +244,7 @@
<i class="ri-close-line"></i> <i class="ri-close-line"></i>
</button> </button>
</div> </div>
<div class="ti-modal-body px-4 mt-3"> <div class="ti-modal-body px-4 mt-3" style="min-height: 9.5rem;">
<div class="row"> <div class="row">
<div class="d-flex col-12 justify-content-center" *ngIf="loading||loadingExcel"> <div class="d-flex col-12 justify-content-center" *ngIf="loading||loadingExcel">
<div *ngFor="let item of [1,2,3]" class="spinner-grow text-info mx-1" role="status"> <div *ngFor="let item of [1,2,3]" class="spinner-grow text-info mx-1" role="status">
......
...@@ -9,8 +9,6 @@ import { MyTemplateFileModel, MyTemplateModel, TemplateFileModel, TemplateModel ...@@ -9,8 +9,6 @@ import { MyTemplateFileModel, MyTemplateModel, TemplateFileModel, TemplateModel
import { ModuleModel } from '../../../../models/module.model'; import { ModuleModel } from '../../../../models/module.model';
import { ExcelReportService } from '../../../../services/excel-report.service'; import { ExcelReportService } from '../../../../services/excel-report.service';
import { CustomCubeService } from '../../../../services/custom-cube.service'; import { CustomCubeService } from '../../../../services/custom-cube.service';
import { ConfirmModalComponent } from '../../../../../confirm-modal/confirm-modal.component';
import { AlertModalComponent } from '../../../../../alert-modal/alert-modal.component';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { SharedModule } from '../../../../../shared/shared.module'; import { SharedModule } from '../../../../../shared/shared.module';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
...@@ -22,6 +20,7 @@ import { MatDialog, MatDialogModule, MatDialogRef } from '@angular/material/dial ...@@ -22,6 +20,7 @@ import { MatDialog, MatDialogModule, MatDialogRef } from '@angular/material/dial
import { DatagridSyncfutionComponent } from '../../../../../datagrid-syncfution/datagrid-syncfution.component'; import { DatagridSyncfutionComponent } from '../../../../../datagrid-syncfution/datagrid-syncfution.component';
import { PivotSyncfutionComponent } from '../../../../../pivot-syncfution/pivot-syncfution.component'; import { PivotSyncfutionComponent } from '../../../../../pivot-syncfution/pivot-syncfution.component';
import { SafeUrlPipe } from '../../../../../../pipe/safe-url.pipe'; import { SafeUrlPipe } from '../../../../../../pipe/safe-url.pipe';
import swal from 'sweetalert';
export interface ModalDetail { export interface ModalDetail {
text: { cardHead: string, search: string[], tableHead: string[] } text: { cardHead: string, search: string[], tableHead: string[] }
} }
...@@ -230,26 +229,30 @@ export class ExcelReportToggleComponent implements OnInit { ...@@ -230,26 +229,30 @@ export class ExcelReportToggleComponent implements OnInit {
} }
menuActiveTemplateFile(templateFile: TemplateFileModel) { menuActiveTemplateFile(templateFile: TemplateFileModel) {
const modalConfirmRef = this.modalService.open(ConfirmModalComponent, { swal({
centered: true, title: "คุณแน่ใจหรือไม่?",
backdrop: 'static', text: "คุณต้องการ" + (templateFile.menuActive == '1' ? 'ปิด' : 'เปิด') + "การใช้งานหรือไม่",
}) icon: "warning",
modalConfirmRef.componentInstance.message = 'คุณต้องการ' + (templateFile.menuActive == '1' ? 'ปิด' : 'เปิด') + 'การใช้งานหรือไม่' buttons: ["ยกเลิก", "ยืนยัน"],
modalConfirmRef.result.then(result => { dangerMode: true,
templateFile.menuActive = templateFile.menuActive == '1' ? '0' : '1' }).then((willChange: any) => {
this.excelReportService.postTemplateFile(templateFile).subscribe(response => { if (willChange) {
if (response.success) { templateFile.menuActive = templateFile.menuActive == '1' ? '0' : '1';
this.openAlertModal(response.message) this.excelReportService.postTemplateFile(templateFile).subscribe(response => {
this.getExcelList() if (response.success) {
} else { this.showAlert(response.message, "success");
this.openAlertModal(response.message) this.getExcelList();
} } else {
}, error => { this.showAlert(response.message, "error");
this.openAlertModal(error.message) }
}) }, error => {
}, reject => { }) this.showAlert(error.message, "error");
});
}
});
} }
formatISOToLocal(isoString: string) { formatISOToLocal(isoString: string) {
const date = new Date(isoString); const date = new Date(isoString);
const day = String(date.getDate()).padStart(2, '0'); const day = String(date.getDate()).padStart(2, '0');
...@@ -261,16 +264,8 @@ export class ExcelReportToggleComponent implements OnInit { ...@@ -261,16 +264,8 @@ export class ExcelReportToggleComponent implements OnInit {
return { date: `${day}-${month}-${year}`, time: `${hours}:${minutes}` }; return { date: `${day}-${month}-${year}`, time: `${hours}:${minutes}` };
} }
showAlert(text: string, type: 'success' | 'error') {
openAlertModal(message?: string) { swal("แจ้งเตือน", text,type);
const modalRef = this.modalService.open(AlertModalComponent, {
centered: true,
backdrop: 'static'
})
modalRef.componentInstance.message = message ? message : ""
modalRef.result.then(result => {
}, reason => {
})
} }
openPrintModal(templateFile: TemplateFileModel) { openPrintModal(templateFile: TemplateFileModel) {
...@@ -285,7 +280,7 @@ export class ExcelReportToggleComponent implements OnInit { ...@@ -285,7 +280,7 @@ export class ExcelReportToggleComponent implements OnInit {
this.getTemplateFileSubscription = this.excelReportService.getTemplateFile(templateFile.templateId, templateFile.fileName).subscribe(response => { this.getTemplateFileSubscription = this.excelReportService.getTemplateFile(templateFile.templateId, templateFile.fileName).subscribe(response => {
this.excelReport = response this.excelReport = response
this.getExcelColumn() this.getExcelColumn()
if (this.excelReport.param) { if (this.excelReport?.param) {
Object.entries(this.excelReport.param.variableSheet).forEach(([key, value]) => { Object.entries(this.excelReport.param.variableSheet).forEach(([key, value]) => {
const data = value as any const data = value as any
if (data.type == 'text') { if (data.type == 'text') {
...@@ -367,7 +362,7 @@ export class ExcelReportToggleComponent implements OnInit { ...@@ -367,7 +362,7 @@ export class ExcelReportToggleComponent implements OnInit {
validateDate(control: NgModel) { validateDate(control: NgModel) {
if (!control.value) { if (!control.value) {
// ว่าง หรือวันที่ไม่ถูกต้อง // ว่าง หรือวันที่ไม่ถูกต้อง
this.openAlertModal('กรุณาเลือกวันที่ให้ถูกต้อง'); this.showAlert('กรุณาเลือกวันที่ให้ถูกต้อง', 'error')
} }
} }
...@@ -395,7 +390,7 @@ export class ExcelReportToggleComponent implements OnInit { ...@@ -395,7 +390,7 @@ export class ExcelReportToggleComponent implements OnInit {
this.cdr.detectChanges() this.cdr.detectChanges()
}, (err) => { }, (err) => {
this.loadingExcel = false this.loadingExcel = false
this.openAlertModal(err.message) this.showAlert(err.message,'error')
this.cdr.detectChanges() this.cdr.detectChanges()
}) })
} }
...@@ -426,39 +421,42 @@ export class ExcelReportToggleComponent implements OnInit { ...@@ -426,39 +421,42 @@ export class ExcelReportToggleComponent implements OnInit {
} }
getExcelColumn() { getExcelColumn() {
const body = { if(this.excelReport){
templateId: this.excelReport.templateId,
fileName: this.excelReport.fileName const body = {
} templateId: this.excelReport.templateId,
this.searchSettings = { fileName: this.excelReport.fileName
fields: [], }
operator: 'contains',
ignoreCase: false
};
this.columns = []
this.pivotColumns = []
this.customCubeService.getExcelColumn(body).subscribe((response: any) => {
this.searchSettings = { this.searchSettings = {
fields: response.map((e: any) => e.split(':')[0]), fields: [],
operator: 'contains', operator: 'contains',
ignoreCase: false ignoreCase: false
}; };
response.forEach((e: any, i: number) => { this.columns = []
const [field, headerText] = e.split(':') this.pivotColumns = []
this.columns.push({ this.customCubeService.getExcelColumn(body).subscribe((response: any) => {
field: field, this.searchSettings = {
headerText: headerText, fields: response.map((e: any) => e.split(':')[0]),
type: "string", operator: 'contains',
isPrimaryKey: i == 0, ignoreCase: false
}) };
this.pivotColumns.push({ response.forEach((e: any, i: number) => {
name: field, const [field, headerText] = e.split(':')
caption: headerText this.columns.push({
}) field: field,
}); headerText: headerText,
}, error => { type: "string",
isPrimaryKey: i == 0,
}) })
this.pivotColumns.push({
name: field,
caption: headerText
})
});
}, error => {
})
}
} }
getExcelData(type: 'grid' | 'pivot') { getExcelData(type: 'grid' | 'pivot') {
this.loadingExcel = true this.loadingExcel = true
...@@ -522,11 +520,15 @@ export class ExcelReportToggleComponent implements OnInit { ...@@ -522,11 +520,15 @@ export class ExcelReportToggleComponent implements OnInit {
pivotStr: "", pivotStr: "",
} }
this.customCubeService.saveExcelPerspective(body).subscribe(response => { this.customCubeService.saveExcelPerspective(body).subscribe(response => {
this.loadingExcel = false if(response.success) {
this.openAlertModal(response.message) this.loadingExcel = false
this.showAlert(response.message, 'success')
} else {
this.showAlert(response.message, 'error')
}
}, error => { }, error => {
this.loadingExcel = false this.loadingExcel = false
this.openAlertModal(error.message) this.showAlert(error.message, 'error')
}) })
this.cdr.detectChanges(); this.cdr.detectChanges();
}, 500); }, 500);
...@@ -540,11 +542,15 @@ export class ExcelReportToggleComponent implements OnInit { ...@@ -540,11 +542,15 @@ export class ExcelReportToggleComponent implements OnInit {
pivotStr: this.pivotLayout.data, pivotStr: this.pivotLayout.data,
} }
this.customCubeService.saveExcelPerspective(body).subscribe(response => { this.customCubeService.saveExcelPerspective(body).subscribe(response => {
this.loadingExcel = false if(response.success) {
this.openAlertModal(response.message) this.loadingExcel = false
this.showAlert(response.message, 'success')
} else {
this.showAlert(response.message, 'error')
}
}, error => { }, error => {
this.loadingExcel = false this.loadingExcel = false
this.openAlertModal(error.message) this.showAlert(error.message, 'error')
}) })
this.cdr.detectChanges(); this.cdr.detectChanges();
}, 500); }, 500);
......
...@@ -41,7 +41,7 @@ export class ExcelReportService { ...@@ -41,7 +41,7 @@ export class ExcelReportService {
edesc: string, edesc: string,
module: string module: string
}) { }) {
return this.http.post(environment.url + "template?companyid=eb2f4f30-edaf-11ee-a69a-c7680edc0e47", body) return this.http.post<AlertModel>(environment.url + "template?companyid=eb2f4f30-edaf-11ee-a69a-c7680edc0e47", body)
} }
deleteTemplate(body: TemplateModel): Observable<AlertModel> { deleteTemplate(body: TemplateModel): Observable<AlertModel> {
let option = { let option = {
......
...@@ -38,7 +38,6 @@ import { ...@@ -38,7 +38,6 @@ import {
import { Query } from '@syncfusion/ej2-data'; import { Query } from '@syncfusion/ej2-data';
import { L10n, setCulture } from '@syncfusion/ej2-base'; import { L10n, setCulture } from '@syncfusion/ej2-base';
import { NgbModal, NgbPaginationModule } from '@ng-bootstrap/ng-bootstrap'; import { NgbModal, NgbPaginationModule } from '@ng-bootstrap/ng-bootstrap';
import { AlertModalComponent } from '../alert-modal/alert-modal.component';
import { ColumnModel, FilterSettingsModel, GroupSettingsModel } from '@syncfusion/ej2-angular-grids'; import { ColumnModel, FilterSettingsModel, GroupSettingsModel } from '@syncfusion/ej2-angular-grids';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { SharedModule } from '../shared/shared.module'; import { SharedModule } from '../shared/shared.module';
......
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