feat: create, view, edit, delete for hooks (#403)

- Add create-hook
- Add view-hook
- Add edit-hook

#180
This commit is contained in:
Chirag Gupta
2020-03-22 18:45:36 +05:30
committed by GitHub
parent 85b8e907f8
commit 17197056bb
24 changed files with 1264 additions and 13 deletions
@@ -0,0 +1,55 @@
<h1 mat-dialog-title>Add Event</h1>
<mat-dialog-content>
<form [formGroup]="eventForm">
<div fxLayout="column">
<mat-form-field>
<mat-label>Select Grouping</mat-label>
<mat-select required formControlName="grouping">
<mat-option *ngFor="let grouping of data.groupings" [value]="grouping.name">
{{ grouping.name }}
</mat-option>
</mat-select>
<mat-error *ngIf="eventForm.controls.grouping.hasError('required')">
Grouping is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Select Entity</mat-label>
<mat-select required formControlName="entity">
<mat-option *ngFor="let entity of entityData" [value]="entity.name">
{{ entity.name }}
</mat-option>
</mat-select>
<mat-error *ngIf="eventForm.controls.entity.hasError('required')">
Entity is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Select Action</mat-label>
<mat-select required formControlName="action">
<mat-option *ngFor="let action of actionData" [value]="action">
{{ action }}
</mat-option>
</mat-select>
<mat-error *ngIf="eventForm.controls.action.hasError('required')">
Action is <strong>required</strong>
</mat-error>
</mat-form-field>
</div>
</form>
</mat-dialog-content>
<mat-dialog-actions align="end">
<button mat-button mat-dialog-close>Cancel</button>
<button mat-raised-button color="primary"
[disabled]="!eventForm.valid || eventForm.pristine" (click)="submit()">Submit</button>
</mat-dialog-actions>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AddEventDialogComponent } from './add-event-dialog.component';
describe('AddEventDialogComponent', () => {
let component: AddEventDialogComponent;
let fixture: ComponentFixture<AddEventDialogComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AddEventDialogComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(AddEventDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,73 @@
/** Angular Imports */
import { Component, OnInit, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
/**
* Add Event Dialog Component.
*/
@Component({
selector: 'mifosx-add-event-dialog',
templateUrl: './add-event-dialog.component.html',
styleUrls: ['./add-event-dialog.component.scss']
})
export class AddEventDialogComponent implements OnInit {
/** Event Form. */
eventForm: FormGroup;
/** Entity Data. */
entityData: Array<any> = new Array<any>();
/** Action Data. */
actionData: Array<any> = new Array<any>();
/**
* @param {MatDialogRef} dialogRef Component reference to dialog.
* @param {FormBuilder} formBuilder Form Builder.
* @param {any} data Provides grouping, entities and actions data to fill dropdowns.
*/
constructor(public dialogRef: MatDialogRef<AddEventDialogComponent>,
public formBuilder: FormBuilder,
@Inject(MAT_DIALOG_DATA) public data: any) {
}
/**
* Creates add event form.
*/
ngOnInit() {
this.eventForm = this.formBuilder.group({
'grouping': ['', Validators.required],
'entity': ['', Validators.required],
'action': ['', Validators.required]
});
this.setGroupingListener();
this.setEntityListener();
}
/**
* Subscribes to the grouping dropdown to set entity data for that row accordingly.
*/
setGroupingListener() {
this.eventForm.get('grouping').valueChanges
.subscribe(changedGrouping => {
this.entityData = this.data.groupings.find((grouping: any) => grouping.name === changedGrouping).entities;
});
}
/**
* Subscribes to the entity dropdown to set entity data for that row accordingly.
*/
setEntityListener() {
this.eventForm.get('entity').valueChanges
.subscribe(changedEntity => {
this.actionData = this.entityData[0].actions;
});
}
/**
* Closes the dialog and returns value of the form.
*/
submit() {
this.dialogRef.close(this.eventForm.value);
}
}
@@ -0,0 +1,159 @@
<div class="container">
<mat-card>
<form [formGroup]="hookForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="row wrap" fxLayout.lt-md="column" fxLayoutGap="4%">
<mat-form-field fxFlex="40%">
<mat-label>Hook Template</mat-label>
<mat-select required formControlName="name">
<mat-option *ngFor="let hookTemplate of hooksTemplateData.templates" [value]="hookTemplate.name">
{{ hookTemplate.name }}
</mat-option>
</mat-select>
<mat-error *ngIf="hookForm.controls.name.hasError('required')">
Hook Template is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field fxFlex="40%">
<mat-label>Display Name</mat-label>
<input matInput required formControlName="displayName">
<mat-error *ngIf="hookForm.controls.displayName.hasError('required')">
Display Name is <strong>required</strong>
</mat-error>
</mat-form-field>
<div class="is-active-wrapper">
<mat-checkbox class="is-active" fxFlex="10%" labelPosition="before" formControlName="isActive">
Is Active?
</mat-checkbox>
</div>
</div>
<div fxLayout="row wrap" fxLayout.lt-md="column" fxLayoutGap="4%">
<mat-form-field fxFlex="48%" *ngIf="hookForm.controls.name.value === 'Web'">
<mat-label>Content Type</mat-label>
<mat-select required formControlName="contentType">
<mat-option [value]="'json'">
json
</mat-option>
<mat-option [value]="'form'">
form
</mat-option>
</mat-select>
<mat-error *ngIf="hookForm.controls.contentType.hasError('required')">
Content Type is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field fxFlex="48%" *ngIf="hookForm.controls.name.value === 'SMS Bridge'">
<mat-label>Phone Number</mat-label>
<input matInput type="tel" #input maxlength="10" required formControlName="phoneNumber">
<mat-hint align="end">{{input.value?.length || 0}}/10</mat-hint>
<mat-error *ngIf="hookForm.controls.phoneNumber.hasError('required')">
Payload URL is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field fxFlex="48%">
<mat-label>Payload URL</mat-label>
<input matInput required formControlName="payloadUrl">
<mat-error *ngIf="hookForm.controls.payloadUrl.hasError('required')">
Payload URL is <strong>required</strong>
</mat-error>
</mat-form-field>
</div>
<div fxLayout="row wrap" fxLayout.lt-md="column" fxLayoutGap="4%"
*ngIf="hookForm.controls.name.value === 'SMS Bridge'">
<mat-form-field fxFlex="30%">
<mat-label>SMS Provider</mat-label>
<input matInput required formControlName="smsProvider">
<mat-error *ngIf="hookForm.controls.smsProvider.hasError('required')">
SMS Provider is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field fxFlex="30%">
<mat-label>SMS Provider Account ID</mat-label>
<input matInput required formControlName="smsProviderAccountId">
<mat-error *ngIf="hookForm.controls.smsProviderAccountId.hasError('required')">
SMS Provider Account ID is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field fxFlex="30%">
<mat-label>SMS Provider Token</mat-label>
<input matInput required formControlName="smsProviderToken">
<mat-error *ngIf="hookForm.controls.smsProviderToken.hasError('required')">
SMS Provider Token is <strong>required</strong>
</mat-error>
</mat-form-field>
</div>
<br>
<mat-divider [inset]="true"></mat-divider>
<br>
<div fxLayout="row wrap" fxLayoutGap="60%" fxLayout.lt-md="column">
<p fxFlex="20%" class="mat-title">Events</p>
<button mat-raised-button fxFlex="20%" type="button" color="primary" (click)="addEvent()">
<fa-icon icon="plus"></fa-icon>&nbsp;&nbsp;
Add Event
</button>
</div>
<table mat-table [dataSource]="dataSource" matSort>
<ng-container matColumnDef="entityName">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Entity Name </th>
<td mat-cell *matCellDef="let event"> {{ event.entityName }} </td>
</ng-container>
<ng-container matColumnDef="actionName">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Action Name </th>
<td mat-cell *matCellDef="let event"> {{ event.actionName }} </td>
</ng-container>
<ng-container matColumnDef="actions">
<th mat-header-cell *matHeaderCellDef> Actions </th>
<td mat-cell *matCellDef="let i = index" fxLayoutGap="15%">
<button type="button" fxFlex="8%" color="warn" mat-icon-button
(click)="deleteEvent(i)">
<fa-icon icon="trash" size="lg"></fa-icon>
</button>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
</mat-card-content>
<mat-card-actions fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center" fxLayoutGap="5px">
<button type="button" mat-raised-button [routerLink]="['../']">Cancel</button>
<button mat-raised-button color="primary" [disabled]="!hookForm.valid">Submit</button>
</mat-card-actions>
</form>
</mat-card>
</div>
@@ -0,0 +1,17 @@
@media (min-width: 992px) {
.is-active-wrapper {
position: relative;
.is-active {
padding: 0 0 17.5px 0;
position: absolute;
bottom: 0;
right: 0;
}
}
}
table {
width: 100%;
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { CreateHookComponent } from './create-hook.component';
describe('CreateHookComponent', () => {
let component: CreateHookComponent;
let fixture: ComponentFixture<CreateHookComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CreateHookComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(CreateHookComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,164 @@
/** Angular Imports */
import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { MatTableDataSource, MatPaginator, MatSort, MatDialog } from '@angular/material';
/** Custom Services */
import { SystemService } from '../../system.service';
/** Custom Components */
import { AddEventDialogComponent } from '../add-event-dialog/add-event-dialog.component';
import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component';
/**
* Create Hook Component.
*/
@Component({
selector: 'mifosx-create-hook',
templateUrl: './create-hook.component.html',
styleUrls: ['./create-hook.component.scss']
})
export class CreateHookComponent implements OnInit {
/** Hooks Template Data. */
hooksTemplateData: any;
/** Hook Form. */
hookForm: FormGroup;
/** Columns to be displayed in events table. */
displayedColumns: string[] = ['entityName', 'actionName', 'actions'];
/** Data source for events table. */
dataSource: MatTableDataSource<any>;
/** Events Data. */
eventsData: any[] = [];
/** Sorter for events table. */
@ViewChild(MatSort) sort: MatSort;
/**
* Retrieves the hooks template data from `resolve`.
* @param {ActivatedRoute} route Activated Route.
* @param {SystemService} systemService System Service.
* @param {Router} router Router for navigation.
* @param {FormBuilder} formBuilder Form Builder.
* @param {MatDialog} dialog Dialog Reference.
*/
constructor(private route: ActivatedRoute,
private systemService: SystemService,
private router: Router,
private formBuilder: FormBuilder,
private dialog: MatDialog) {
this.route.data.subscribe((data: { hooksTemplate: any }) => {
this.hooksTemplateData = data.hooksTemplate;
});
}
/**
* Creates the hook form.
*/
ngOnInit() {
this.createHookForm();
this.hookForm.get('name').valueChanges.subscribe(name => {
if (name === 'Web') {
this.hookForm.get('contentType').enable();
this.hookForm.get('phoneNumber').disable();
this.hookForm.get('smsProvider').disable();
this.hookForm.get('smsProviderAccountId').disable();
this.hookForm.get('smsProviderToken').disable();
} else {
this.hookForm.get('contentType').disable();
this.hookForm.get('phoneNumber').enable();
this.hookForm.get('smsProvider').enable();
this.hookForm.get('smsProviderAccountId').enable();
this.hookForm.get('smsProviderToken').enable();
}
});
this.setEvents();
}
/**
* Initializes the data source, paginator and sorter for events table.
*/
setEvents() {
this.dataSource = new MatTableDataSource(this.eventsData);
this.dataSource.sort = this.sort;
}
/**
* Creates the hook form.
*/
createHookForm() {
this.hookForm = this.formBuilder.group({
'name': ['Web', Validators.required],
'displayName': ['', Validators.required],
'isActive': [''],
'phoneNumber': [{ value: '', disabled: true }, Validators.required],
'smsProvider': [{ value: '', disabled: true }, Validators.required],
'smsProviderAccountId': [{ value: '', disabled: true }, Validators.required],
'smsProviderToken': [{ value: '', disabled: true }, Validators.required],
'contentType': ['', Validators.required],
'payloadUrl': ['', Validators.required]
});
}
/**
* Adds the event form to given events form array.
*/
addEvent() {
const addEventDialogRef = this.dialog.open(AddEventDialogComponent, {
data: this.hooksTemplateData
});
addEventDialogRef.afterClosed().subscribe((response: any) => {
if (response) {
this.eventsData.push({ entityName: response.entity,
actionName: response.action });
this.dataSource.connect().next(this.eventsData);
}
});
}
/**
* Removes the event form from given events form array at given index.
* @param {number} index Array index from where event form needs to be removed.
*/
deleteEvent(index: number) {
const deleteEventDialogRef = this.dialog.open(DeleteDialogComponent, {
data: { deleteContext: `event with entity name of ${this.eventsData[index].entityName}` }
});
deleteEventDialogRef.afterClosed().subscribe((response: any) => {
if (response.delete) {
this.eventsData.splice(index, 1);
this.dataSource.connect().next(this.eventsData);
}
});
}
/**
* Submits the hook form and creates hook,
* if successful redirects to view created hook.
*/
submit() {
const hook: {
name: string, isActive: boolean, displayName: string, events: any,
config: {
'Payload URL': string, 'Content Type'?: string, 'SMS Provider'?: string,
'SMS Provider Account Id'?: string, 'SMS Provider Token'?: string
}
} = {
name: this.hookForm.get('name').value,
isActive: this.hookForm.get('isActive').value,
displayName: this.hookForm.get('displayName').value,
events: this.eventsData,
config: {
'Payload URL': this.hookForm.get('payloadUrl').value,
'Content Type': this.hookForm.get('contentType').enabled ? this.hookForm.get('contentType').value : undefined,
'SMS Provider': this.hookForm.get('smsProvider').enabled ? this.hookForm.get('smsProvider').value : undefined,
'SMS Provider Account Id': this.hookForm.get('smsProviderAccountId').enabled ? this.hookForm.get('smsProviderAccountId').value : undefined,
'SMS Provider Token': this.hookForm.get('smsProviderToken').enabled ? this.hookForm.get('smsProviderToken').value : undefined
}
};
this.systemService.createHook(hook)
.subscribe((response: any) => {
this.router.navigate(['../', response.resourceId], {relativeTo: this.route});
});
}
}
@@ -0,0 +1,159 @@
<div class="container">
<mat-card>
<form [formGroup]="hookForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="row wrap" fxLayout.lt-md="column" fxLayoutGap="4%">
<mat-form-field fxFlex="40%">
<mat-label>Hook Template</mat-label>
<mat-select required formControlName="name">
<mat-option *ngFor="let hookTemplate of hooksTemplateData.templates" [value]="hookTemplate.name">
{{ hookTemplate.name }}
</mat-option>
</mat-select>
<mat-error *ngIf="hookForm.controls.name.hasError('required')">
Hook Template is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field fxFlex="40%">
<mat-label>Display Name</mat-label>
<input matInput required formControlName="displayName">
<mat-error *ngIf="hookForm.controls.displayName.hasError('required')">
Display Name is <strong>required</strong>
</mat-error>
</mat-form-field>
<div class="is-active-wrapper">
<mat-checkbox class="is-active" fxFlex="10%" labelPosition="before" formControlName="isActive">
Is Active?
</mat-checkbox>
</div>
</div>
<div fxLayout="row wrap" fxLayout.lt-md="column" fxLayoutGap="4%">
<mat-form-field fxFlex="48%" *ngIf="hookForm.controls.name.value === 'Web'">
<mat-label>Content Type</mat-label>
<mat-select required formControlName="contentType">
<mat-option [value]="'json'">
json
</mat-option>
<mat-option [value]="'form'">
form
</mat-option>
</mat-select>
<mat-error *ngIf="hookForm.controls.contentType.hasError('required')">
Content Type is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field fxFlex="48%" *ngIf="hookForm.controls.name.value === 'SMS Bridge'">
<mat-label>Phone Number</mat-label>
<input matInput type="tel" #input maxlength="10" required formControlName="phoneNumber">
<mat-hint align="end">{{input.value?.length || 0}}/10</mat-hint>
<mat-error *ngIf="hookForm.controls.phoneNumber.hasError('required')">
Payload URL is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field fxFlex="48%">
<mat-label>Payload URL</mat-label>
<input matInput required formControlName="payloadUrl">
<mat-error *ngIf="hookForm.controls.payloadUrl.hasError('required')">
Payload URL is <strong>required</strong>
</mat-error>
</mat-form-field>
</div>
<div fxLayout="row wrap" fxLayout.lt-md="column" fxLayoutGap="4%"
*ngIf="hookForm.controls.name.value === 'SMS Bridge'">
<mat-form-field fxFlex="30%">
<mat-label>SMS Provider</mat-label>
<input matInput required formControlName="smsProvider">
<mat-error *ngIf="hookForm.controls.smsProvider.hasError('required')">
SMS Provider is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field fxFlex="30%">
<mat-label>SMS Provider Account ID</mat-label>
<input matInput required formControlName="smsProviderAccountId">
<mat-error *ngIf="hookForm.controls.smsProviderAccountId.hasError('required')">
SMS Provider Account ID is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field fxFlex="30%">
<mat-label>SMS Provider Token</mat-label>
<input matInput required formControlName="smsProviderToken">
<mat-error *ngIf="hookForm.controls.smsProviderToken.hasError('required')">
SMS Provider Token is <strong>required</strong>
</mat-error>
</mat-form-field>
</div>
<br>
<mat-divider [inset]="true"></mat-divider>
<br>
<div fxLayout="row wrap" fxLayoutGap="60%" fxLayout.lt-md="column">
<p fxFlex="20%" class="mat-title">Events</p>
<button mat-raised-button fxFlex="20%" type="button" color="primary" (click)="addEvent()">
<fa-icon icon="plus"></fa-icon>&nbsp;&nbsp;
Add Event
</button>
</div>
<table mat-table [dataSource]="dataSource" matSort>
<ng-container matColumnDef="entityName">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Entity Name </th>
<td mat-cell *matCellDef="let event"> {{ event.entityName }} </td>
</ng-container>
<ng-container matColumnDef="actionName">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Action Name </th>
<td mat-cell *matCellDef="let event"> {{ event.actionName }} </td>
</ng-container>
<ng-container matColumnDef="actions">
<th mat-header-cell *matHeaderCellDef> Actions </th>
<td mat-cell *matCellDef="let i = index">
<button type="button" color="warn" mat-icon-button
(click)="deleteEvent(i)">
<fa-icon icon="trash" size="lg"></fa-icon>
</button>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
</mat-card-content>
<mat-card-actions fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center" fxLayoutGap="5px">
<button type="button" mat-raised-button [routerLink]="['../']">Cancel</button>
<button mat-raised-button color="primary" [disabled]="(!hookForm.valid || hookForm.pristine) && !eventsDataChanged">Submit</button>
</mat-card-actions>
</form>
</mat-card>
</div>
@@ -0,0 +1,17 @@
@media (min-width: 992px) {
.is-active-wrapper {
position: relative;
.is-active {
padding: 0 0 17.5px 0;
position: absolute;
bottom: 0;
right: 0;
}
}
}
table {
width: 100%;
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { EditHookComponent } from './edit-hook.component';
describe('EditHookComponent', () => {
let component: EditHookComponent;
let fixture: ComponentFixture<EditHookComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ EditHookComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(EditHookComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,158 @@
/** Angular Imports */
import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { MatTableDataSource, MatPaginator, MatSort, MatDialog } from '@angular/material';
/** Custom Services */
import { SystemService } from '../../system.service';
/** Custom Components */
import { AddEventDialogComponent } from '../add-event-dialog/add-event-dialog.component';
import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component';
/**
* Edit Hook Component.
*/
@Component({
selector: 'mifosx-edit-hook',
templateUrl: './edit-hook.component.html',
styleUrls: ['./edit-hook.component.scss']
})
export class EditHookComponent implements OnInit {
/** Hooks Template Data. */
hooksTemplateData: any;
/** Hook Data. */
hookData: any;
/** Hook Form. */
hookForm: FormGroup;
/** Columns to be displayed in events table. */
displayedColumns: string[] = ['entityName', 'actionName', 'actions'];
/** Data source for events table. */
dataSource: MatTableDataSource<any>;
/** Events Data. */
eventsData: any[] = [];
/** Boolean to check if events data is changed or not. */
eventsDataChanged: Boolean = false;
/** Sorter for events table. */
@ViewChild(MatSort) sort: MatSort;
/**
* Retrieves the hooks template data from `resolve`.
* @param {ActivatedRoute} route Activated Route.
* @param {SystemService} systemService System Service.
* @param {Router} router Router for navigation.
* @param {FormBuilder} formBuilder Form Builder.
* @param {MatDialog} dialog Dialog Reference.
*/
constructor(private route: ActivatedRoute,
private systemService: SystemService,
private router: Router,
private formBuilder: FormBuilder,
private dialog: MatDialog) {
this.route.data.subscribe(( data: { hooksTemplate: any, hook: any }) => {
this.hooksTemplateData = data.hooksTemplate;
this.hookData = data.hook;
this.eventsData = data.hook.events ? data.hook.events : [];
});
}
/**
* Creates the hook form.
*/
ngOnInit() {
this.createHookForm();
this.setEvents();
}
/**
* Initializes the data source, paginator and sorter for events table.
*/
setEvents() {
this.dataSource = new MatTableDataSource(this.eventsData);
this.dataSource.sort = this.sort;
}
/**
* Creates the hook form.
*/
createHookForm() {
this.hookForm = this.formBuilder.group({
'name': [{ value: this.hookData.name, disabled: true }, Validators.required],
'displayName': [this.hookData.displayName, Validators.required],
'isActive': [this.hookData.isActive],
'phoneNumber': [{ value: this.hookData.name === 'SMS Bridge' ? this.hookData.config[1].fieldValue : '', disabled: this.hookData.name !== 'SMS Bridge' }, Validators.required],
'smsProvider': [{ value: this.hookData.name === 'SMS Bridge' ? this.hookData.config[2].fieldValue : '', disabled: this.hookData.name !== 'SMS Bridge' }, Validators.required],
'smsProviderAccountId': [{ value: this.hookData.name === 'SMS Bridge' ? this.hookData.config[3].fieldValue : '', disabled: this.hookData.name !== 'SMS Bridge' }, Validators.required],
'smsProviderToken': [{ value: this.hookData.name === 'SMS Bridge' ? this.hookData.config[4].fieldValue : '', disabled: this.hookData.name !== 'SMS Bridge' }, Validators.required],
'contentType': [{ value: this.hookData.name === 'Web' ? this.hookData.config[0].fieldValue : '', disabled: this.hookData.name !== 'Web' }, Validators.required],
'payloadUrl': [this.hookData.name === 'Web' ? this.hookData.config[1].fieldValue : this.hookData.config[0].fieldValue, Validators.required]
});
}
/**
* Adds the event form to given events form array.
*/
addEvent() {
const addEventDialogRef = this.dialog.open(AddEventDialogComponent, {
data: this.hooksTemplateData
});
addEventDialogRef.afterClosed().subscribe((response: any) => {
if (response) {
this.eventsData.push({ entityName: response.entity,
actionName: response.action });
this.dataSource.connect().next(this.eventsData);
this.eventsDataChanged = true;
}
});
}
/**
* Removes the event form from given events form array at given index.
* @param {number} index Array index from where event form needs to be removed.
*/
deleteEvent(index: number) {
const deleteEventDialogRef = this.dialog.open(DeleteDialogComponent, {
data: { deleteContext: `event with entity name of ${this.eventsData[index].entityName}` }
});
deleteEventDialogRef.afterClosed().subscribe((response: any) => {
if (response.delete) {
this.eventsData.splice(index, 1);
this.dataSource.connect().next(this.eventsData);
this.eventsDataChanged = true;
}
});
}
/**
* Submits the hook form and updates hook,
* if successful redirects to view updated hook.
*/
submit() {
const hook: {
name: string, isActive: boolean, displayName: string, events: any,
config: {
'Payload URL': string, 'Content Type'?: string, 'SMS Provider'?: string,
'SMS Provider Account Id'?: string, 'SMS Provider Token'?: string
}
} = {
name: this.hookForm.get('name').value,
isActive: this.hookForm.get('isActive').value,
displayName: this.hookForm.get('displayName').value,
events: this.eventsData,
config: {
'Payload URL': this.hookForm.get('payloadUrl').value,
'Content Type': this.hookForm.get('contentType').enabled ? this.hookForm.get('contentType').value : undefined,
'SMS Provider': this.hookForm.get('smsProvider').enabled ? this.hookForm.get('smsProvider').value : undefined,
'SMS Provider Account Id': this.hookForm.get('smsProviderAccountId').enabled ? this.hookForm.get('smsProviderAccountId').value : undefined,
'SMS Provider Token': this.hookForm.get('smsProviderToken').enabled ? this.hookForm.get('smsProviderToken').value : undefined
}
};
this.systemService.updateHook(this.hookData.id, hook)
.subscribe((response: any) => {
this.router.navigate(['../'], {relativeTo: this.route});
});
}
}
@@ -0,0 +1,30 @@
/** Angular Imports */
import { Injectable } from '@angular/core';
import { Resolve } from '@angular/router';
/** rxjs Imports */
import { Observable } from 'rxjs';
/** Custom Services */
import { SystemService } from '../system.service';
/**
* Hooks template data resolver.
*/
@Injectable()
export class HooksTemplateResolver implements Resolve<Object> {
/**
* @param {SystemService} systemService System service.
*/
constructor(private systemService: SystemService) {}
/**
* Returns the hooks template data.
* @returns {Observable<any>}
*/
resolve(): Observable<any> {
return this.systemService.getHooksTemplate();
}
}
@@ -1,5 +1,5 @@
<div class="container m-b-20" fxLayout="row" fxLayoutAlign="end" fxLayoutGap="20px">
<button mat-raised-button color="primary">
<button mat-raised-button color="primary" [routerLink]="['create']">
<fa-icon icon="plus"></fa-icon>&nbsp;&nbsp;
Create Hook
</button>
@@ -38,7 +38,7 @@
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;" class="select-row"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;" [routerLink]="[row.id]" class="select-row"></tr>
</table>
@@ -3,11 +3,8 @@ import { Component, OnInit, ViewChild } from '@angular/core';
import { MatTableDataSource, MatPaginator, MatSort } from '@angular/material';
import { ActivatedRoute } from '@angular/router';
/** rxjs Imports */
import { of } from 'rxjs';
/**
* Manage Hooks component.
* Manage Hooks Component.
*/
@Component({
selector: 'mifosx-manage-hooks',
@@ -20,7 +20,7 @@ export class ManageHooksResolver implements Resolve<Object> {
constructor(private systemService: SystemService) {}
/**
* Returns the manage hooks data.
* Returns the hooks data.
* @returns {Observable<any>}
*/
resolve(): Observable<any> {
@@ -0,0 +1,31 @@
/** Angular Imports */
import { Injectable } from '@angular/core';
import {ActivatedRouteSnapshot, Resolve} from '@angular/router';
/** rxjs Imports */
import { Observable } from 'rxjs';
/** Custom Services */
import { SystemService } from '../../system.service';
/**
* Hook data resolver.
*/
@Injectable()
export class HookResolver implements Resolve<Object> {
/**
* @param {SystemService} systemService System service.
*/
constructor(private systemService: SystemService) {}
/**
* Returns the manage hooks data.
* @returns {Observable<any>}
*/
resolve(route: ActivatedRouteSnapshot): Observable<any> {
const hookId = route.paramMap.get('id');
return this.systemService.getHook(hookId);
}
}
@@ -0,0 +1,129 @@
<div class="container m-b-20" fxLayout="row" fxLayoutAlign="end" fxLayoutGap="20px">
<button mat-raised-button color="primary" [routerLink]="['edit']">
<fa-icon icon="edit"></fa-icon>&nbsp;&nbsp;
Edit
</button>
<button mat-raised-button color="warn" (click)="delete()">
<fa-icon icon="trash"></fa-icon>&nbsp;&nbsp;
Delete
</button>
</div>
<div class="container">
<mat-card>
<mat-card-content>
<div fxLayout="row wrap" class="content">
<div fxFlex="50%" class="mat-body-strong">
Hook Name:
</div>
<div fxFlex="50%">
{{ hookData.displayName }}
</div>
<div fxFlex="50%" class="mat-body-strong">
Status:
</div>
<div fxFlex="50%">
{{ hookData.isActive ? 'Active' : 'Inactive' }}
</div>
<div fxFlex="50%" class="mat-body-strong">
Activation Date:
</div>
<div fxFlex="50%">
{{ hookData.createdAt | date }}
</div>
<div fxFlex="50%" class="mat-body-strong">
Updated on:
</div>
<div fxFlex="50%">
{{ hookData.updatedAt | date }}
</div>
<div fxFlex="50%" class="mat-body-strong">
Events:
</div>
<div fxFlex="50%">
<mat-label *ngFor="let event of hookData.events">
{{ event.actionName + ' - ' + event.entityName }}
<br>
</mat-label>
</div>
<div fxFlex="50%" class="mat-body-strong" *ngIf="hookData.name === 'Web'">
Content Type:
</div>
<div fxFlex="50%" *ngIf="hookData.name === 'Web'">
{{ hookData.config[0].fieldValue }}
</div>
<div fxFlex="50%" class="mat-body-strong">
Payload URL:
</div>
<div fxFlex="50%" *ngIf="hookData.name === 'Web'">
{{ hookData.config[1].fieldValue }}
</div>
<div fxFlex="50%" *ngIf="hookData.name === 'SMS Bridge'">
{{ hookData.config[0].fieldValue }}
</div>
<div fxFlex="50%" class="mat-body-strong" *ngIf="hookData.name === 'SMS Bridge'">
Phone Number:
</div>
<div fxFlex="50%" *ngIf="hookData.name === 'SMS Bridge'">
{{ hookData.config[1].fieldValue }}
</div>
<div fxFlex="50%" class="mat-body-strong" *ngIf="hookData.name === 'SMS Bridge'">
SMS Provider:
</div>
<div fxFlex="50%" *ngIf="hookData.name === 'SMS Bridge'">
{{ hookData.config[2].fieldValue }}
</div>
<div fxFlex="50%" class="mat-body-strong" *ngIf="hookData.name === 'SMS Bridge'">
SMS Provider Account ID:
</div>
<div fxFlex="50%" *ngIf="hookData.name === 'SMS Bridge'">
{{ hookData.config[3].fieldValue }}
</div>
<div fxFlex="50%" class="mat-body-strong" *ngIf="hookData.name === 'SMS Bridge'">
SMS Provider Token:
</div>
<div fxFlex="50%" *ngIf="hookData.name === 'SMS Bridge'">
{{ hookData.config[4].fieldValue }}
</div>
</div>
</mat-card-content>
</mat-card>
</div>
@@ -0,0 +1,10 @@
.container {
max-width: 37rem;
.content {
div {
margin: 1rem 0;
word-wrap: break-word;
}
}
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ViewHookComponent } from './view-hook.component';
describe('ViewHookComponent', () => {
let component: ViewHookComponent;
let fixture: ComponentFixture<ViewHookComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ViewHookComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ViewHookComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,61 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { MatDialog } from '@angular/material';
/** Custom Components */
import { DeleteDialogComponent } from '../../../shared/delete-dialog/delete-dialog.component';
/** Custom Services */
import { SystemService } from '../../system.service';
/**
* View Hook Component.
*/
@Component({
selector: 'mifosx-view-hook',
templateUrl: './view-hook.component.html',
styleUrls: ['./view-hook.component.scss']
})
export class ViewHookComponent implements OnInit {
/** Hook Data. */
hookData: any;
/**
* Retrieves the hook data from `resolve`.
* @param {ActivatedRoute} route Activated Route.
* @param {MatDialog} dialog Dialog Reference.
* @param {SystemService} systemService System Service.
* @param {Router} router Router for navigation.
*/
constructor(private route: ActivatedRoute,
private dialog: MatDialog,
private systemService: SystemService,
private router: Router) {
this.route.data.subscribe((data: { hook: any }) => {
this.hookData = data.hook;
});
}
ngOnInit() {
}
/**
* Deletes the current hook.
*/
delete() {
const deleteHookDialogRef = this.dialog.open(DeleteDialogComponent, {
data: { deleteContext: `hook ${this.hookData.id}` }
});
deleteHookDialogRef.afterClosed().subscribe((response: any) => {
if (response.delete) {
this.systemService.deleteHook(this.hookData.id)
.subscribe(() => {
this.router.navigate(['/system/hooks']);
});
}
});
}
}
+46 -4
View File
@@ -14,6 +14,9 @@ import { EditCodeComponent } from './codes/edit-code/edit-code.component';
import { ExternalServicesComponent } from './external-services/external-services.component';
import { ManageDataTablesComponent } from './manage-data-tables/manage-data-tables.component';
import { ManageHooksComponent } from './manage-hooks/manage-hooks.component';
import { ViewHookComponent } from './manage-hooks/view-hook/view-hook.component';
import { CreateHookComponent } from './manage-hooks/create-hook/create-hook.component';
import { EditHookComponent } from './manage-hooks/edit-hook/edit-hook.component';
import { RolesAndPermissionsComponent } from './roles-and-permissions/roles-and-permissions.component';
import { AddRoleComponent } from './roles-and-permissions/add-role/add-role.component';
import { ManageSurveysComponent } from './manage-surveys/manage-surveys.component';
@@ -43,6 +46,8 @@ import { CodeResolver } from './codes/code.resolver';
import { CodeValuesResolver } from './codes/view-code/code-values.resolver';
import { ManageDataTablesResolver } from './manage-data-tables/manage-data-tables.resolver';
import { ManageHooksResolver } from './manage-hooks/manage-hooks.resolver';
import { HookResolver } from './manage-hooks/view-hook/hook.resolver';
import { HooksTemplateResolver } from './manage-hooks/hooks-template.resolver';
import { RolesAndPermissionsResolver } from './roles-and-permissions/roles-and-permissions.resolver';
import { ManageSurveysResolver } from './manage-surveys/manage-surveys.resolver';
import { ManageSchedulerJobsResolver } from './manage-scheduler-jobs/manage-scheduler-jobs.resolver';
@@ -214,11 +219,46 @@ const routes: Routes = [
},
{
path: 'hooks',
component: ManageHooksComponent,
resolve: {
hooks: ManageHooksResolver
},
data: { title: extract('Manage Hooks'), breadcrumb: 'Manage Hooks' },
children: [
{
path: '',
component: ManageHooksComponent,
resolve: {
hooks: ManageHooksResolver
}
},
{
path: 'create',
component: CreateHookComponent,
data: { title: extract('Create Hook'), breadcrumb: 'Create' },
resolve: {
hooksTemplate: HooksTemplateResolver
}
},
{
path: ':id',
data: { title: extract('View Hook'), routeParamBreadcrumb: 'id' },
children: [
{
path: '',
component: ViewHookComponent,
resolve: {
hook: HookResolver
}
},
{
path: 'edit',
component: EditHookComponent,
data: { title: extract('Edit Hook'), breadcrumb: 'Edit', routeParamBreadcrumb: false },
resolve: {
hooksTemplate: HooksTemplateResolver,
hook: HookResolver
}
}
]
}
]
},
{
path: 'roles-and-permissions',
@@ -375,6 +415,8 @@ const routes: Routes = [
CodeValuesResolver,
ManageDataTablesResolver,
ManageHooksResolver,
HookResolver,
HooksTemplateResolver,
RolesAndPermissionsResolver,
ManageSurveysResolver,
ManageSchedulerJobsResolver,
+11 -2
View File
@@ -36,9 +36,13 @@ import { ManageReportsComponent } from './manage-reports/manage-reports.componen
import { ViewReportComponent } from './manage-reports/view-report/view-report.component';
import { CreateReportComponent } from './manage-reports/create-report/create-report.component';
import { EditReportComponent } from './manage-reports/edit-report/edit-report.component';
import { EditHookComponent } from './manage-hooks/edit-hook/edit-hook.component';
import { ViewHookComponent } from './manage-hooks/view-hook/view-hook.component';
import { CreateHookComponent } from './manage-hooks/create-hook/create-hook.component';
/** Dialog Component Imports */
import { ReportParameterDialogComponent } from './manage-reports/report-parameter-dialog/report-parameter-dialog.component';
import { AddEventDialogComponent } from './manage-hooks/add-event-dialog/add-event-dialog.component';
@NgModule({
imports: [
@@ -76,10 +80,15 @@ import { ReportParameterDialogComponent } from './manage-reports/report-paramete
CreateReportComponent,
EditReportComponent,
ReportParameterDialogComponent,
AddRoleComponent
AddRoleComponent,
EditHookComponent,
ViewHookComponent,
CreateHookComponent,
AddEventDialogComponent
],
entryComponents: [
ReportParameterDialogComponent
ReportParameterDialogComponent,
AddEventDialogComponent
]
})
export class SystemModule { }
+40
View File
@@ -32,6 +32,46 @@ export class SystemService {
return this.http.get('/hooks');
}
/**
* @param {string} hookId Hook ID of Hook.
* @returns {Observable<any>}
*/
getHook(hookId: string): Observable<any> {
return this.http.get(`/hooks/${hookId}`);
}
/**
* @returns {Observable<any>} Hooks Template.
*/
getHooksTemplate(): Observable<any> {
return this.http.get('/hooks/template');
}
/**
* @param {any} hook Hook to be created.
* @returns {Observable<any>}
*/
createHook(hook: any): Observable<any> {
return this.http.post('/hooks', hook);
}
/**
* @param {string} hookId Hook ID of Hook to be updated.
* @param {any} hook Hook to be updated.
* @returns {Observable<any>}
*/
updateHook(hookId: string, hook: any): Observable<any> {
return this.http.put(`/hooks/${hookId}`, hook);
}
/**
* @param {string} hookId Hook ID of Hook to be deleted.
* @returns {Observable<any>}
*/
deleteHook(hookId: string): Observable<any> {
return this.http.delete(`/hooks/${hookId}`);
}
/**
* @returns {Observable<any>} Fetches Roles and Permissions
*/