External events management view

This commit is contained in:
Jose Alberto Hernandez
2022-10-27 15:50:01 +02:00
committed by Arnold Gálovics
parent 11b1e6793b
commit eaa58a7caf
10 changed files with 236 additions and 2 deletions
@@ -0,0 +1,46 @@
<div class="container">
<div #filter fxLayout="row">
<mat-form-field fxFlex>
<mat-label>Filter</mat-label>
<input matInput (keyup)="applyFilter($event.target.value)">
</mat-form-field>
<div class="action-button" fxLayoutGap="25px">
<button mat-raised-button color="primary" (click)="applyChanges()"
[disabled]="!existAnyUpdate" *mifosxHasPermission="'UPDATE_EXTERNAL_EVENT_CONFIGURATION'">
Apply Changes
</button>
</div>
</div>
<div #eventsTable class="mat-elevation-z8">
<table mat-table [dataSource]="dataSource" matSort>
<ng-container matColumnDef="eventType">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Event Type </th>
<td mat-cell *matCellDef="let event"> {{ event.type }} </td>
</ng-container>
<ng-container matColumnDef="status">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Status </th>
<td mat-cell *matCellDef="let event">
<mat-slide-toggle [(ngModel)]="event.enabled" name="{{event.type}}" (click)="toggleStatus(event)">
<div [className]="event.enabled ? 'enabled' : 'disabled'">
<span *ngIf="event.enabled">Enabled</span>
<span *ngIf="!event.enabled">Disabled</span>
</div>
</mat-slide-toggle>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;" class="select-row"></tr>
</table>
<mat-paginator [pageSizeOptions]="[10, 25, 50, 100]" showFirstLastButtons></mat-paginator>
</div>
</div>
@@ -0,0 +1,5 @@
.container {
.action-button {
margin-left: auto;
}
}
@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ManageExternalEventsComponent } from './manage-external-events.component';
describe('ManageExternalEventsComponent', () => {
let component: ManageExternalEventsComponent;
let fixture: ComponentFixture<ManageExternalEventsComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ ManageExternalEventsComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(ManageExternalEventsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,78 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { MatPaginator } from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort';
import { MatTableDataSource } from '@angular/material/table';
import { ActivatedRoute } from '@angular/router';
import { SystemService } from '../system.service';
@Component({
selector: 'mifosx-manage-external-events',
templateUrl: './manage-external-events.component.html',
styleUrls: ['./manage-external-events.component.scss']
})
export class ManageExternalEventsComponent implements OnInit {
/** Events Data. */
eventsData: any;
externalEventConfigurations: any = {};
existAnyUpdate = false;
/** Columns to be displayed in events table. */
displayedColumns: string[] = ['eventType', 'status'];
/** 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;
constructor(private route: ActivatedRoute,
private systemService: SystemService) {
this.route.data.subscribe((data: { events: any }) => {
this.eventsData = data.events.externalEventConfiguration;
});
}
ngOnInit() {
this.setEventDatasource();
}
/**
* Initializes the data source, paginator and sorter for events table.
*/
setEventDatasource() {
this.dataSource = new MatTableDataSource(this.eventsData);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
/**
* Enables/Disables respective event
*/
toggleStatus(event: any) {
this.externalEventConfigurations[event.type] = !event.enabled;
this.existAnyUpdate = true;
}
/**
* Filter using the event type value
*/
applyFilter(filterValue: string) {
this.dataSource.filter = filterValue.trim().toLowerCase();
}
/**
* send the changes to the backend
*/
applyChanges() {
const payload = {
externalEventConfigurations: this.externalEventConfigurations
};
this.systemService.putExternalEventConfiguration(payload).subscribe(() => {
this.existAnyUpdate = false;
});
}
}
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { ManageExternalEventsResolver } from './manage-external-events.resolver';
describe('ManageExternalEventsResolver', () => {
let resolver: ManageExternalEventsResolver;
beforeEach(() => {
TestBed.configureTestingModule({});
resolver = TestBed.inject(ManageExternalEventsResolver);
});
it('should be created', () => {
expect(resolver).toBeTruthy();
});
});
@@ -0,0 +1,27 @@
import { Injectable } from '@angular/core';
import {
Router, Resolve,
RouterStateSnapshot,
ActivatedRouteSnapshot
} from '@angular/router';
import { Observable, of } from 'rxjs';
import { SystemService } from '../system.service';
@Injectable({
providedIn: 'root'
})
export class ManageExternalEventsResolver implements Resolve<boolean> {
/**
* @param {SystemService} systemService System service.
*/
constructor(private systemService: SystemService) {}
/**
* Returns the Configuration data.
* @returns {Observable<any>}
*/
resolve(route: ActivatedRouteSnapshot): Observable<any> {
return this.systemService.getExternalEventConfiguration();
}
}