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">
|
<div class="container m-b-20" fxLayout="row" fxLayoutAlign="end" fxLayoutGap="20px">
|
||||||
<button mat-raised-button color="primary" [routerLink]="['create']">
|
<button mat-raised-button color="primary" [routerLink]="['create']">
|
||||||
<fa-icon icon="plus"></fa-icon>
|
<fa-icon icon="plus"></fa-icon>
|
||||||
Add Code
|
Create Code
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</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 });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import { extract } from '../core/i18n/i18n.service';
|
|||||||
/** Component Imports */
|
/** Component Imports */
|
||||||
import { SystemComponent } from './system.component';
|
import { SystemComponent } from './system.component';
|
||||||
import { CodesComponent } from './codes/codes.component';
|
import { CodesComponent } from './codes/codes.component';
|
||||||
|
import { CreateCodeComponent } from './codes/create-code/create-code.component';
|
||||||
|
|
||||||
/** Custom Resolvers */
|
/** Custom Resolvers */
|
||||||
import { CodesResolver } from './codes/codes.resolver';
|
import { CodesResolver } from './codes/codes.resolver';
|
||||||
@@ -24,11 +25,22 @@ const routes: Routes = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'codes',
|
path: 'codes',
|
||||||
component: CodesComponent,
|
|
||||||
data: { title: extract('View Codes'), breadcrumb: 'Codes' },
|
data: { title: extract('View Codes'), breadcrumb: 'Codes' },
|
||||||
resolve: {
|
children: [
|
||||||
codes: CodesResolver
|
{
|
||||||
}
|
path: '',
|
||||||
|
component: CodesComponent,
|
||||||
|
resolve: {
|
||||||
|
codes: CodesResolver
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'create',
|
||||||
|
component: CreateCodeComponent,
|
||||||
|
data: { title: extract('Create Code'), breadcrumb: 'Create' }
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { SystemRoutingModule } from './system-routing.module';
|
|||||||
/** Component Imports */
|
/** Component Imports */
|
||||||
import { CodesComponent } from './codes/codes.component';
|
import { CodesComponent } from './codes/codes.component';
|
||||||
import { SystemComponent } from './system.component';
|
import { SystemComponent } from './system.component';
|
||||||
|
import { CreateCodeComponent } from './codes/create-code/create-code.component';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -16,7 +17,8 @@ import { SystemComponent } from './system.component';
|
|||||||
],
|
],
|
||||||
declarations: [
|
declarations: [
|
||||||
SystemComponent,
|
SystemComponent,
|
||||||
CodesComponent
|
CodesComponent,
|
||||||
|
CreateCodeComponent
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class SystemModule { }
|
export class SystemModule { }
|
||||||
|
|||||||
@@ -25,4 +25,12 @@ export class SystemService {
|
|||||||
return this.http.get('/codes');
|
return this.http.get('/codes');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {any} code Code to be created.
|
||||||
|
* @returns {Observable<any>}
|
||||||
|
*/
|
||||||
|
createCode(code: any): Observable<any> {
|
||||||
|
return this.http.post('/codes', code);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user