feat(system): view, edit, delete code (#380)

- Add view code component
- Add edit code component

Fixes: #379
This commit is contained in:
Chirag Gupta
2019-05-21 20:19:41 +05:30
committed by Abhay Chawla
parent fbb7a1583a
commit e766a91ecf
16 changed files with 625 additions and 3 deletions
@@ -0,0 +1,32 @@
<div class="container">
<mat-card>
<form [formGroup]="codeForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-label>Code Name</mat-label>
<input matInput required formControlName="name">
<mat-error *ngIf="codeForm.controls.name.hasError('required')">
Code Name 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]="!codeForm.valid || codeForm.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 { EditCodeComponent } from './edit-code.component';
describe('EditCodeComponent', () => {
let component: EditCodeComponent;
let fixture: ComponentFixture<EditCodeComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ EditCodeComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(EditCodeComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,67 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */
import { SystemService } from '../../system.service';
/**
* Edit Code Component.
*/
@Component({
selector: 'mifosx-edit-code',
templateUrl: './edit-code.component.html',
styleUrls: ['./edit-code.component.scss']
})
export class EditCodeComponent implements OnInit {
/** Code Form */
codeForm: FormGroup;
/** Code Data */
codeData: any;
/**
* Retrieves the code data from `resolve`.
* @param {FormBuilder} formBuilder Form Builder.
* @param {SystemService} systemService System 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: { code: any }) => {
this.codeData = data.code;
});
}
/**
* Creates and sets the code form.
*/
ngOnInit() {
this.createCodeForm();
}
/**
* Creates and sets code form.
*/
createCodeForm() {
this.codeForm = this.formBuilder.group({
'name': [this.codeData.name, Validators.required]
});
}
/**
* Submits the code form and updates code,
* if successful redirects to view updated code.
*/
submit() {
this.systemService.updateCode(this.codeForm.value, this.codeData.id)
.subscribe((response: any) => {
this.router.navigate(['../../', response.resourceId], { relativeTo: this.route });
});
}
}