-
Notifications
You must be signed in to change notification settings - Fork 888
Expand file tree
/
Copy pathmanage-reports.component.ts
More file actions
192 lines (175 loc) · 5.56 KB
/
manage-reports.component.ts
File metadata and controls
192 lines (175 loc) · 5.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/**
* Copyright since 2025 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/** Angular Imports */
import { Component, OnInit, TemplateRef, ElementRef, ViewChild, AfterViewInit, inject } from '@angular/core';
import { MatPaginator } from '@angular/material/paginator';
import { MatSort, MatSortHeader } from '@angular/material/sort';
import {
MatTableDataSource,
MatTable,
MatColumnDef,
MatHeaderCellDef,
MatHeaderCell,
MatCellDef,
MatCell,
MatHeaderRowDef,
MatHeaderRow,
MatRowDef,
MatRow
} from '@angular/material/table';
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
import { MatDialog } from '@angular/material/dialog';
/* Custom Services */
import { PopoverService } from '../../configuration-wizard/popover/popover.service';
import { ConfigurationWizardService } from '../../configuration-wizard/configuration-wizard.service';
/** Custom Dialog Component */
import { CompletionDialogComponent } from '../../configuration-wizard/completion-dialog/completion-dialog.component';
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
import { MatTooltip } from '@angular/material/tooltip';
import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
/**
* Manage Reports Component.
*/
@Component({
selector: 'mifosx-manage-reports',
templateUrl: './manage-reports.component.html',
styleUrls: ['./manage-reports.component.scss'],
imports: [
...STANDALONE_SHARED_IMPORTS,
FaIconComponent,
MatTable,
MatSort,
MatColumnDef,
MatHeaderCellDef,
MatHeaderCell,
MatSortHeader,
MatCellDef,
MatCell,
MatTooltip,
MatHeaderRowDef,
MatHeaderRow,
MatRowDef,
MatRow,
MatPaginator
]
})
export class ManageReportsComponent implements OnInit, AfterViewInit {
private route = inject(ActivatedRoute);
private router = inject(Router);
private configurationWizardService = inject(ConfigurationWizardService);
private popoverService = inject(PopoverService);
private dialog = inject(MatDialog);
/** Reports Data. */
reportsData: any;
/** Columns to be displayed in reports table. */
displayedColumns: string[] = [
'reportName',
'reportType',
'reportSubType',
'reportCategory',
'coreReport',
'userReport'
];
/** Data source for reports table. */
dataSource: MatTableDataSource<any>;
/** Paginator for reports table. */
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
/** Sorter for reports table. */
@ViewChild(MatSort, { static: true }) sort: MatSort;
/* Reference of Create Report Button */
@ViewChild('buttonCreateReport') buttonCreateReport: ElementRef<any>;
/* Template for popover on Create Report Button */
@ViewChild('templateButtonCreateReport') templateButtonCreateReport: TemplateRef<any>;
/**
* Retrieves the reports data from `resolve`.
* @param {ActivatedRoute} route Activated Route.
* @param {Router} router Router for navigation.
* @param {ConfigurationWizardService} configurationWizardService ConfigurationWizard Service.
* @param {PopoverService} popoverService PopoverService.
* @param {Matdialog} matdialog Matdialog.
*/
constructor() {
this.route.data.subscribe((data: { reports: any }) => {
this.reportsData = data.reports;
});
}
/**
* Sets the reports table.
*/
ngOnInit() {
this.setReports();
}
/**
* Initializes the data source, paginator and sorter for reports table.
*/
setReports() {
// Transform data to replace "(NULL)" strings with null
const transformedData = this.reportsData.map((report: any) => ({
...report,
reportCategory: report.reportCategory === '(NULL)' ? null : report.reportCategory,
description: report.description === '(NULL)' ? null : report.description
}));
this.dataSource = new MatTableDataSource(transformedData);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
/**
* Filters data in reports table based on passed value.
* @param {string} filterValue Value to filter data.
*/
applyFilter(filterValue: string) {
this.dataSource.filter = filterValue.trim().toLowerCase();
}
/**
* To show popover.
*/
ngAfterViewInit() {
if (this.configurationWizardService.showManageReports) {
setTimeout(() => {
this.showPopover(this.templateButtonCreateReport, this.buttonCreateReport.nativeElement, 'bottom', true);
});
}
}
/**
* Popover function
* @param template TemplateRef<any>.
* @param target HTMLElement | ElementRef<any>.
* @param position String.
* @param backdrop Boolean.
*/
showPopover(
template: TemplateRef<any>,
target: HTMLElement | ElementRef<any>,
position: string,
backdrop: boolean
): void {
setTimeout(() => this.popoverService.open(template, target, position, backdrop, {}), 200);
}
/**
* Next Step (Home) Configuration Wizard Tour Complete.
*/
nextStep() {
this.configurationWizardService.showManageReports = false;
this.openNextStepDialog();
}
/**
* Previous Step (Manage Reports System Page) Configuration Wizard.
*/
previousStep() {
this.router.navigate(['/system']);
}
/**
* Completed Configuration Wizard Tour Dialog.
*/
openNextStepDialog() {
const completionDialogRef = this.dialog.open(CompletionDialogComponent);
completionDialogRef.afterClosed().subscribe(() => {
this.router.navigate(['/home']);
});
}
}