feat: add components for external services (#376)

- Add sms and edit-sms component
- Add notification and edit-notification component
- Add email and edit-email component
- Add amazon-s3 and edit-amazon-s3 component

Fixes: #182 and Fixes: #183
This commit is contained in:
Chirag Gupta
2019-04-21 20:07:24 +05:30
committed by Abhay Chawla
parent cbd8a5a44f
commit fbb7a1583a
40 changed files with 1303 additions and 10 deletions
@@ -0,0 +1,27 @@
<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>
</div>
<div class="container mat-elevation-z8">
<table mat-table [dataSource]="dataSource" matSort>
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Name </th>
<td mat-cell *matCellDef="let configuration"> {{ configuration.name }} </td>
</ng-container>
<ng-container matColumnDef="value">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Value </th>
<td mat-cell *matCellDef="let configuration"> {{ configuration.value }} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
</div>
@@ -0,0 +1,3 @@
table {
width: 100%;
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AmazonS3Component } from './amazon-s3.component';
describe('AmazonS3Component', () => {
let component: AmazonS3Component;
let fixture: ComponentFixture<AmazonS3Component>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AmazonS3Component ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(AmazonS3Component);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,51 @@
/** Angular Imports */
import { Component, OnInit, ViewChild } from '@angular/core';
import { MatTableDataSource, MatSort } from '@angular/material';
import { ActivatedRoute } from '@angular/router';
/**
* Amazon S3 Component.
*/
@Component({
selector: 'mifosx-amazon-s3',
templateUrl: './amazon-s3.component.html',
styleUrls: ['./amazon-s3.component.scss']
})
export class AmazonS3Component implements OnInit {
/** Amazon S3 configuration data. */
amazonS3ConfigurationData: any;
/** Columns to be displayed in Amazon S3 configuration table. */
displayedColumns: string[] = ['name', 'value'];
/** Data source for Amazon S3 configuration table. */
dataSource: MatTableDataSource<any>;
/** Sorter for Amazon S3 configuration table. */
@ViewChild(MatSort) sort: MatSort;
/**
* Retrieves the Amazon S3 configuration data from `resolve`.
* @param {ActivatedRoute} route Activated Route.
*/
constructor(private route: ActivatedRoute) {
this.route.data.subscribe((data: { amazonS3Configuration: any }) => {
this.amazonS3ConfigurationData = data.amazonS3Configuration;
});
}
/**
* Sets the Amazon S3 Configuration table.
*/
ngOnInit() {
this.setAmazonS3Configuration();
}
/**
* Initializes the data source and sorter for Amazon S3 configuration table.
*/
setAmazonS3Configuration() {
this.dataSource = new MatTableDataSource(this.amazonS3ConfigurationData);
this.dataSource.sort = this.sort;
}
}
@@ -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';
/**
* Amazon S3 Configuration data resolver.
*/
@Injectable()
export class AmazonS3ConfigurationResolver implements Resolve<Object> {
/**
* @param {SystemService} systemService System service.
*/
constructor(private systemService: SystemService) {}
/**
* Returns the Amazon S3 Configuration data.
* @returns {Observable<any>}
*/
resolve(): Observable<any> {
return this.systemService.getExternalConfiguration('S3');
}
}
@@ -0,0 +1,48 @@
<div class="container">
<mat-card>
<form [formGroup]="amazonS3ConfigurationForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-label>S3 Access Key</mat-label>
<input matInput required formControlName="s3_access_key">
<mat-error *ngIf="amazonS3ConfigurationForm.controls.s3_access_key.hasError('required')">
S3 Access Key is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>S3 Bucket Name</mat-label>
<input matInput required formControlName="s3_bucket_name">
<mat-error *ngIf="amazonS3ConfigurationForm.controls.s3_bucket_name.hasError('required')">
S3 Bucket Name is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>S3 Secret Key</mat-label>
<input matInput required formControlName="s3_secret_key">
<mat-error *ngIf="amazonS3ConfigurationForm.controls.s3_secret_key.hasError('required')">
S3 Secret Key is <strong>required</strong>
</mat-error>
</mat-form-field>
</div>
</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]="!amazonS3ConfigurationForm.valid || amazonS3ConfigurationForm.pristine">Submit</button>
</mat-card-actions>
</form>
</mat-card>
</div>
@@ -0,0 +1,3 @@
.container {
max-width: 37rem;
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { EditAmazonS3Component } from './edit-amazon-s3.component';
describe('EditAmazonS3Component', () => {
let component: EditAmazonS3Component;
let fixture: ComponentFixture<EditAmazonS3Component>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ EditAmazonS3Component ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(EditAmazonS3Component);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,70 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
/** Custom Services */
import { SystemService } from 'app/system/system.service';
/**
* Edit Amazon S3 Component.
*/
@Component({
selector: 'mifosx-edit-amazon-s3',
templateUrl: './edit-amazon-s3.component.html',
styleUrls: ['./edit-amazon-s3.component.scss']
})
export class EditAmazonS3Component implements OnInit {
/** Amazon S3 Configuration data */
amazonS3ConfigurationData: any;
/** Amazon S3 Configuration Form */
amazonS3ConfigurationForm: FormGroup;
/**
* Retrieves the Amazon S3 configuration data from `resolve`.
* @param {FormBuilder} formBuilder Form Builder.
* @param {SystemService} systemService Accounting Service.
* @param {ActivatedRoute} route Activated Route.
* @param {Router} router Router for navigation.
*/
constructor(private formBuilder: FormBuilder,
private systemService: SystemService,
private route: ActivatedRoute,
private router: Router) {
this.route.data.subscribe((data: { amazonS3Configuration: any }) => {
this.amazonS3ConfigurationData = data.amazonS3Configuration;
});
}
/**
* Creates Amazon S3 configuration form.
*/
ngOnInit() {
this.createAmazonS3ConfigurationForm();
}
/**
* Creates Amazon S3 configuration form.
*/
createAmazonS3ConfigurationForm() {
this.amazonS3ConfigurationForm = this.formBuilder.group({
's3_access_key': [this.amazonS3ConfigurationData[0].value, Validators.required],
's3_bucket_name': [this.amazonS3ConfigurationData[1].value, Validators.required],
's3_secret_key': [this.amazonS3ConfigurationData[2].value, Validators.required]
});
}
/**
* Submits the Amazon S3 configuration and updates the Amazon S3 configuration,
* if successful redirects to view Amazon S3 configuration.
*/
submit() {
this.systemService
.updateExternalConfiguration('S3', this.amazonS3ConfigurationForm.value)
.subscribe((response: any) => {
this.router.navigate(['../'], { relativeTo: this.route });
});
}
}