feat: add add-code component (#310)
This commit is contained in:
committed by
Abhay Chawla
parent
04ff1abcc4
commit
dffce8a5e0
@@ -1,7 +1,7 @@
|
||||
<div class="container m-b-20" fxLayout="row" fxLayoutAlign="end" fxLayoutGap="20px">
|
||||
<button mat-raised-button color="primary" [routerLink]="['create']">
|
||||
<fa-icon icon="plus"></fa-icon>
|
||||
Add Code
|
||||
Create Code
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -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">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 { CreateCodeComponent } from './create-code.component';
|
||||
|
||||
describe('CreateCodeComponent', () => {
|
||||
let component: CreateCodeComponent;
|
||||
let fixture: ComponentFixture<CreateCodeComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ CreateCodeComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(CreateCodeComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,57 @@
|
||||
/** Angular Imports */
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
import { Router, ActivatedRoute } from '@angular/router';
|
||||
|
||||
/** Custom Services */
|
||||
import { SystemService } from '../../system.service';
|
||||
|
||||
@Component({
|
||||
selector: 'mifosx-create-code',
|
||||
templateUrl: './create-code.component.html',
|
||||
styleUrls: ['./create-code.component.scss']
|
||||
})
|
||||
export class CreateCodeComponent implements OnInit {
|
||||
|
||||
/** Code form. */
|
||||
codeForm: FormGroup;
|
||||
|
||||
/**
|
||||
* @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) { }
|
||||
|
||||
/**
|
||||
* Creates the code form.
|
||||
*/
|
||||
ngOnInit() {
|
||||
this.createCodeForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the create code form.
|
||||
*/
|
||||
createCodeForm() {
|
||||
this.codeForm = this.formBuilder.group({
|
||||
'name': ['', Validators.required]
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Submits the code form and creates a code,
|
||||
* if successful redirects to view code.
|
||||
*/
|
||||
submit() {
|
||||
this.systemService.createCode(this.codeForm.value)
|
||||
.subscribe((response: any) => {
|
||||
this.router.navigate(['/system/codes'], { relativeTo: this.route });
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user