163 lines
4.8 KiB
TypeScript
163 lines
4.8 KiB
TypeScript
/**
|
|
* 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, ViewChild, inject } from '@angular/core';
|
|
import { MatDialog } from '@angular/material/dialog';
|
|
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';
|
|
|
|
/** Custom Services */
|
|
import { SystemService } from 'app/system/system.service';
|
|
import { Datatables } from 'app/core/utils/datatables';
|
|
|
|
/** Custom Components */
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component';
|
|
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
|
|
import { MatTooltip } from '@angular/material/tooltip';
|
|
import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
|
|
import { AlertService } from 'app/core/alert/alert.service';
|
|
|
|
/**
|
|
* View Data Table Component
|
|
*/
|
|
@Component({
|
|
selector: 'mifosx-view-data-table',
|
|
templateUrl: './view-data-table.component.html',
|
|
styleUrls: ['./view-data-table.component.scss'],
|
|
imports: [
|
|
...STANDALONE_SHARED_IMPORTS,
|
|
FaIconComponent,
|
|
MatTable,
|
|
MatSort,
|
|
MatColumnDef,
|
|
MatHeaderCellDef,
|
|
MatHeaderCell,
|
|
MatSortHeader,
|
|
MatCellDef,
|
|
MatCell,
|
|
MatTooltip,
|
|
MatHeaderRowDef,
|
|
MatHeaderRow,
|
|
MatRowDef,
|
|
MatRow,
|
|
MatPaginator
|
|
]
|
|
})
|
|
export class ViewDataTableComponent implements OnInit {
|
|
private route = inject(ActivatedRoute);
|
|
private systemService = inject(SystemService);
|
|
private router = inject(Router);
|
|
private dialog = inject(MatDialog);
|
|
private translateService = inject(TranslateService);
|
|
private alertService = inject(AlertService);
|
|
public datatables = inject(Datatables);
|
|
|
|
/** Data Table Data */
|
|
dataTableData: any;
|
|
/** Column Data */
|
|
columnsData: any;
|
|
/** Columns to be displayed in columns table. */
|
|
displayedColumns: string[] = [
|
|
'columnName',
|
|
'columnDisplayType',
|
|
'columnLength',
|
|
'columnCode',
|
|
'isColumnNullable',
|
|
'isColumnUnique',
|
|
'isColumnIndexed'
|
|
];
|
|
/** Data source for columns table. */
|
|
dataSource: MatTableDataSource<any>;
|
|
|
|
/** Paginator for columns table. */
|
|
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
|
|
/** Sorter for columns table. */
|
|
@ViewChild(MatSort, { static: true }) sort: MatSort;
|
|
|
|
/**
|
|
* Retrieves the data table data from `resolve`.
|
|
* @param {ActivatedRoute} route Activated Route.
|
|
* @param {SystemService} systemService System Service.
|
|
* @param {Router} router Router for navigation.
|
|
* @param {MatDialog} dialog Dialog reference.
|
|
* @param {TranslateService} translateService Translate Service.
|
|
*/
|
|
constructor() {
|
|
this.route.data.subscribe((data: { dataTable: any }) => {
|
|
this.dataTableData = data.dataTable;
|
|
this.columnsData = this.dataTableData.columnHeaderData;
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Sets the columns table.
|
|
*/
|
|
ngOnInit() {
|
|
this.setColumnsTable();
|
|
}
|
|
|
|
/**
|
|
* Get display name for field (e.g., "Actividad" from "ADDRESS_TYPE_cd_ACTIVIDAD")
|
|
*/
|
|
getFieldDisplayName(columnName: string): string {
|
|
return this.datatables.toDisplayLabel(columnName);
|
|
}
|
|
|
|
/**
|
|
* Initializes the data source, paginator and sorter for columns table.
|
|
*/
|
|
setColumnsTable() {
|
|
this.columnsData.shift();
|
|
// TODO: Figure out a better approach in order to pass only updated parameters instead of all of them.
|
|
this.dataSource = new MatTableDataSource(this.columnsData);
|
|
this.dataSource.paginator = this.paginator;
|
|
this.dataSource.sort = this.sort;
|
|
}
|
|
|
|
/**
|
|
* Deletes the current data table.
|
|
*/
|
|
delete() {
|
|
const deleteDataTableDialogRef = this.dialog.open(DeleteDialogComponent, {
|
|
data: {
|
|
deleteContext:
|
|
this.translateService.instant('labels.inputs.Data Table') + ' ' + this.dataTableData.registeredTableName
|
|
}
|
|
});
|
|
deleteDataTableDialogRef.afterClosed().subscribe((response: any) => {
|
|
if (response.delete) {
|
|
this.systemService.deleteDataTable(this.dataTableData.registeredTableName).subscribe((deleteResponse: any) => {
|
|
if (deleteResponse?.rollbackTransaction) {
|
|
this.alertService.alert({
|
|
type: 'Success',
|
|
message: 'Data table deletion has been submitted for approval.'
|
|
});
|
|
}
|
|
this.router.navigate(['/system/data-tables'], { relativeTo: this.route });
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|