feat: create, view, edit, delete for hooks (#403)
- Add create-hook - Add view-hook - Add edit-hook #180
This commit is contained in:
@@ -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>
|
||||
Edit
|
||||
</button>
|
||||
|
||||
<button mat-raised-button color="warn" (click)="delete()">
|
||||
<fa-icon icon="trash"></fa-icon>
|
||||
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']);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user