Commit 6f28c7db by Natthaphat

แก้ layout หน้าเพิ่มรายงาน Excel

parent e8b711e4
.ti-modal-header {
display: flex;
align-items: center;
justify-content: space-between;
border-bottom-width: 1px;
padding-top: 0.75rem;
padding-bottom: 0.75rem;
padding-left: 1rem;
padding-right: 1rem;
}
\ No newline at end of file
...@@ -17,7 +17,7 @@ import { NgSelectModule } from '@ng-select/ng-select'; ...@@ -17,7 +17,7 @@ import { NgSelectModule } from '@ng-select/ng-select';
import { SharedModule } from '../../../../../shared/shared.module'; import { SharedModule } from '../../../../../shared/shared.module';
import { MatPaginator } from '@angular/material/paginator'; import { MatPaginator } from '@angular/material/paginator';
import { QuillModule } from 'ngx-quill'; import { QuillModule } from 'ngx-quill';
import { MatDialogModule } from '@angular/material/dialog'; import { MatDialog, MatDialogModule } from '@angular/material/dialog';
import { FileUploadModule } from 'ng2-file-upload'; import { FileUploadModule } from 'ng2-file-upload';
import { FormsModule, NgModel } from '@angular/forms'; import { FormsModule, NgModel } from '@angular/forms';
import { DatagridSyncfutionComponent } from '../../../../../datagrid-syncfution/datagrid-syncfution.component'; import { DatagridSyncfutionComponent } from '../../../../../datagrid-syncfution/datagrid-syncfution.component';
...@@ -57,6 +57,8 @@ export class ExcelListComponent implements OnInit { ...@@ -57,6 +57,8 @@ export class ExcelListComponent implements OnInit {
template: { data: TemplateModel[], filter: TemplateModel[], loading: boolean } = { data: [], filter: [], loading: false } template: { data: TemplateModel[], filter: TemplateModel[], loading: boolean } = { data: [], filter: [], loading: false }
templateFile: TemplateFileModel = new MyTemplateFileModel() templateFile: TemplateFileModel = new MyTemplateFileModel()
module: { data: ModuleModel[], loading: boolean } = { data: [], loading: false } module: { data: ModuleModel[], loading: boolean } = { data: [], loading: false }
pageIndex: number = 0;
itemsPerPage: number = 10;
page = 1 page = 1
pageSize = 10 pageSize = 10
pageModal = 1 pageModal = 1
...@@ -140,10 +142,18 @@ export class ExcelListComponent implements OnInit { ...@@ -140,10 +142,18 @@ export class ExcelListComponent implements OnInit {
gridLayout: { stimulate: boolean, data: string } = { stimulate: false, data: '' } gridLayout: { stimulate: boolean, data: string } = { stimulate: false, data: '' }
pivotLayout: { stimulate: boolean, data: string } = { stimulate: false, data: '' } pivotLayout: { stimulate: boolean, data: string } = { stimulate: false, data: '' }
setPerspective = "" setPerspective = ""
isSearching = false;
modalRef: any;
modalRefaddChild: any;
searchText: string = '';
@ViewChild('addGroupModal') addGroupModal!: TemplateRef<any>;
@ViewChild('addChildModal') addChildModal!: TemplateRef<any>;
constructor(private excelReportService: ExcelReportService, constructor(private excelReportService: ExcelReportService,
private modalService: NgbModal, private modalService: NgbModal,
private customCubeService: CustomCubeService, private customCubeService: CustomCubeService,
private cdr: ChangeDetectorRef) { private cdr: ChangeDetectorRef,
private modal: MatDialog) {
} }
ngOnInit(): void { ngOnInit(): void {
...@@ -153,6 +163,31 @@ export class ExcelListComponent implements OnInit { ...@@ -153,6 +163,31 @@ export class ExcelListComponent implements OnInit {
this.getExcelPortalgGroupList() this.getExcelPortalgGroupList()
this.getExcelPortalTagsList() this.getExcelPortalTagsList()
} }
get totalItems(): number {
return this.searchText == ''
? this.template.data.length
: this.template.filter.length;
}
get totalPages(): number {
return Math.ceil(this.totalItems / this.itemsPerPage);
}
get totalPagesArray(): number[] {
return Array(this.totalPages).fill(0);
}
goToPage(index: number): void {
if (index < 0 || index >= this.totalPages) return;
this.pageIndex = index;
this.updatePagedItems();
}
updatePagedItems(): void {
const start = this.pageIndex * this.itemsPerPage;
const end = start + this.itemsPerPage;
const source = this.searchText == '' ? this.template.data : this.template.filter;
this.template.filter = source.slice(start, end);
}
getExcelPortalList() { getExcelPortalList() {
this.excelPortal.loading = true this.excelPortal.loading = true
this.excelReportService.getExcelPortalList().subscribe(response => { this.excelReportService.getExcelPortalList().subscribe(response => {
...@@ -235,9 +270,9 @@ export class ExcelListComponent implements OnInit { ...@@ -235,9 +270,9 @@ export class ExcelListComponent implements OnInit {
}, reason => { }, reason => {
}) })
} }
openAddGroupModal(targetModal: TemplateRef<any>, data?: TemplateModel) { openAddGroupModal(data?: TemplateModel) {
if (data) { if (data) {
this.bodyTemplate.status = 'edit' this.bodyTemplate.status = 'edit';
this.bodyTemplate.data = { this.bodyTemplate.data = {
templateId: data.templateId, templateId: data.templateId,
tname: data.tname, tname: data.tname,
...@@ -245,9 +280,9 @@ export class ExcelListComponent implements OnInit { ...@@ -245,9 +280,9 @@ export class ExcelListComponent implements OnInit {
tdesc: data.tdesc, tdesc: data.tdesc,
edesc: data.edesc, edesc: data.edesc,
module: data.module module: data.module
} };
} else { } else {
this.bodyTemplate.status = 'add' this.bodyTemplate.status = 'add';
this.bodyTemplate.data = { this.bodyTemplate.data = {
templateId: '', templateId: '',
tname: '', tname: '',
...@@ -255,32 +290,10 @@ export class ExcelListComponent implements OnInit { ...@@ -255,32 +290,10 @@ export class ExcelListComponent implements OnInit {
tdesc: '', tdesc: '',
edesc: '', edesc: '',
module: '' module: ''
} };
} }
const modalRef = this.modalService.open(targetModal, { this.openModalAddGroup()
centered: true,
backdrop: 'static',
size: 'lg'
})
modalRef.result.then(result => {
const modalConfirmRef = this.modalService.open(ConfirmModalComponent, {
centered: true,
backdrop: 'static',
})
modalConfirmRef.componentInstance.message = 'คุณต้องการบันทึกข้อมูลหรือไม่'
modalConfirmRef.result.then(result => {
this.excelReportService.postTemplate(this.bodyTemplate.data).subscribe((response: any) => {
this.openAlertModal(response.message)
if (response.success) {
this.getExcelList()
this.getModuleList()
}
}, error => { this.openAlertModal(error.message) })
}, reject => { })
}, reject => { })
} }
deleteTemplate(template: TemplateModel) { deleteTemplate(template: TemplateModel) {
...@@ -302,7 +315,7 @@ export class ExcelListComponent implements OnInit { ...@@ -302,7 +315,7 @@ export class ExcelListComponent implements OnInit {
}) })
}, reject => { }) }, reject => { })
} }
openAddChildModal(targetModal: TemplateRef<any>, data: TemplateModel | TemplateFileModel, status: 'add' | 'edit') { openAddChildModal(data: TemplateModel | TemplateFileModel, status: 'add' | 'edit') {
if (status == 'add') { if (status == 'add') {
this.templateFile = new MyTemplateFileModel({ templateId: data.templateId, module: data.module }) this.templateFile = new MyTemplateFileModel({ templateId: data.templateId, module: data.module })
this.templateFileType = 'portal' this.templateFileType = 'portal'
...@@ -313,11 +326,7 @@ export class ExcelListComponent implements OnInit { ...@@ -313,11 +326,7 @@ export class ExcelListComponent implements OnInit {
this.templateFileName = this.templateFile.portalId ? '' : this.templateFile.fileName this.templateFileName = this.templateFile.portalId ? '' : this.templateFile.fileName
this.templateFile.realFileNameOld = this.templateFile.fileName this.templateFile.realFileNameOld = this.templateFile.fileName
} }
this.addChildModalRef = this.modalService.open(targetModal, { this.openModaladdChild()
centered: true,
backdrop: 'static',
size: 'lg'
})
} }
openExcelPortalModal(targetModal: TemplateRef<any>) { openExcelPortalModal(targetModal: TemplateRef<any>) {
...@@ -362,29 +371,42 @@ export class ExcelListComponent implements OnInit { ...@@ -362,29 +371,42 @@ export class ExcelListComponent implements OnInit {
} }
templateListSearch() { templateListSearch() {
if (!this.searchBy || !this.condition || !this.searchValue) { this.isSearching = true;
this.template.filter = this.template.data.map(e => new MyTemplateModel(e))
}
const conditionMap: { [key: string]: (a: any, b: any) => boolean } = {
includes: (a, b) => (a || '').toString().toLowerCase().includes((b || '').toString().toLowerCase()),
lt: (a, b) => parseFloat(a) < parseFloat(b),
gt: (a, b) => parseFloat(a) > parseFloat(b),
eq: (a, b) => a == b,
lte: (a, b) => parseFloat(a) <= parseFloat(b),
gte: (a, b) => parseFloat(a) >= parseFloat(b),
neq: (a, b) => a != b,
};
const compareFn = conditionMap[this.condition];
if (!compareFn) {
this.template.filter = this.template.data.map(e => new MyTemplateModel(e))
}
setTimeout(() => {
if (!this.searchBy || !this.condition || !this.searchValue) {
this.template.filter = this.template.data.map(e => new MyTemplateModel(e));
this.isSearching = false;
return;
}
const conditionMap: { [key: string]: (a: any, b: any) => boolean } = {
includes: (a, b) => (a || '').toString().toLowerCase().includes((b || '').toString().toLowerCase()),
lt: (a, b) => parseFloat(a) < parseFloat(b),
gt: (a, b) => parseFloat(a) > parseFloat(b),
eq: (a, b) => a == b,
lte: (a, b) => parseFloat(a) <= parseFloat(b),
gte: (a, b) => parseFloat(a) >= parseFloat(b),
neq: (a, b) => a != b,
};
const compareFn = conditionMap[this.condition];
if (!compareFn) {
this.template.filter = this.template.data.map(e => new MyTemplateModel(e));
this.isSearching = false;
return;
}
this.template.filter = this.template.data
.filter(item => {
const value = (item as any)[this.searchBy];
return compareFn(value, this.searchValue);
})
.map(e => new MyTemplateModel(e));
this.template.filter = this.template.data.filter(item => { this.isSearching = false;
const value = (item as any)[this.searchBy]; }, 1000); // delay mock loading
return compareFn(value, this.searchValue);
}).map(e => new MyTemplateModel(e));
} }
onFileSelected(event: any) { onFileSelected(event: any) {
...@@ -802,4 +824,27 @@ export class ExcelListComponent implements OnInit { ...@@ -802,4 +824,27 @@ export class ExcelListComponent implements OnInit {
}, 500); }, 500);
} }
} }
openModalAddGroup() {
this.modalRef = this.modal.open(this.addGroupModal, {
width: '1000px',
height: '500px'
})
}
closeModalAddGroup() {
this.modalRef?.close()
}
openModaladdChild() {
this.modalRefaddChild = this.modal.open(this.addChildModal, {
width: '1000px',
height: '500px'
})
}
closeModaladdChild() {
this.modalRefaddChild?.close()
}
} }
\ No newline at end of file
...@@ -29,11 +29,10 @@ import { MyPdpaModel, PdpaModel } from "../../models/pdpa.model"; ...@@ -29,11 +29,10 @@ import { MyPdpaModel, PdpaModel } from "../../models/pdpa.model";
TranslateModule, TranslateModule,
NgSelectModule, NgSelectModule,
FormsModule, FormsModule,
MatPaginator,
FileUploadModule, FileUploadModule,
PdpaConfigComponent, PdpaConfigComponent,
QuillModule QuillModule
], ],
templateUrl: './pdpa-manage.component.html', templateUrl: './pdpa-manage.component.html',
styleUrl: './pdpa-manage.component.css' styleUrl: './pdpa-manage.component.css'
}) })
......
...@@ -23,9 +23,8 @@ import { TokenService } from "../../../../shared/services/token.service"; ...@@ -23,9 +23,8 @@ import { TokenService } from "../../../../shared/services/token.service";
TranslateModule, TranslateModule,
NgSelectModule, NgSelectModule,
FormsModule, FormsModule,
MatPaginator,
FileUploadModule FileUploadModule
], ],
templateUrl: './user-setting.component.html', templateUrl: './user-setting.component.html',
styleUrl: './user-setting.component.css' styleUrl: './user-setting.component.css'
}) })
......
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