Enhacement to management funds (#1735)
Co-authored-by: Jose Alberto Hernandez <alberto@MacBook-Pro.local>
This commit is contained in:
co-authored by
Jose Alberto Hernandez
parent
452a1adc17
commit
bf700cc100
@@ -0,0 +1,37 @@
|
||||
<div class="container">
|
||||
|
||||
<mat-card>
|
||||
|
||||
<form [formGroup]="fundForm" (ngSubmit)="submit()">
|
||||
|
||||
<mat-card-content>
|
||||
|
||||
<div fxLayout="column">
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Name</mat-label>
|
||||
<input matInput required autofocus formControlName="name">
|
||||
<mat-error *ngIf="fundForm.controls.name.hasError('required')">
|
||||
Name <strong>is required</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>External Id</mat-label>
|
||||
<input matInput autofocus formControlName="externalId">
|
||||
</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]="!fundForm.valid" *mifosxHasPermission="'UPDATE_FUND'">Submit</button>
|
||||
</mat-card-actions>
|
||||
|
||||
</form>
|
||||
|
||||
</mat-card>
|
||||
|
||||
</div>
|
||||
@@ -0,0 +1,3 @@
|
||||
.container {
|
||||
max-width: 37rem;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { EditFundComponent } from './edit-fund.component';
|
||||
|
||||
describe('EditFundComponent', () => {
|
||||
let component: EditFundComponent;
|
||||
let fixture: ComponentFixture<EditFundComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ EditFundComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(EditFundComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,56 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { OrganizationService } from 'app/organization/organization.service';
|
||||
|
||||
@Component({
|
||||
selector: 'mifosx-edit-fund',
|
||||
templateUrl: './edit-fund.component.html',
|
||||
styleUrls: ['./edit-fund.component.scss']
|
||||
})
|
||||
export class EditFundComponent implements OnInit {
|
||||
|
||||
/** Selected Data. */
|
||||
fundData: any;
|
||||
/** Charge form. */
|
||||
fundForm: FormGroup;
|
||||
|
||||
/**
|
||||
* Retrieves the charge data from `resolve`.
|
||||
* @param {ProductsService} productsService Products Service.
|
||||
* @param {FormBuilder} formBuilder Form Builder.
|
||||
* @param {ActivatedRoute} route Activated Route.
|
||||
* @param {Router} router Router for navigation.
|
||||
*/
|
||||
constructor(private organizationService: OrganizationService,
|
||||
private formBuilder: FormBuilder,
|
||||
private router: Router,
|
||||
private route: ActivatedRoute) {
|
||||
this.route.data.subscribe((data: { fundData: any }) => {
|
||||
this.fundData = data.fundData;
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.createFundForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit Fund form.
|
||||
*/
|
||||
createFundForm() {
|
||||
this.fundForm = this.formBuilder.group({
|
||||
'name': [this.fundData.name, Validators.required],
|
||||
'externalId': [this.fundData.externalId]
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
submit() {
|
||||
const payload = this.fundForm.getRawValue();
|
||||
this.organizationService.editFund(this.fundData.id.toString(), payload)
|
||||
.subscribe((response: any) => {
|
||||
this.router.navigate(['../'], { relativeTo: this.route });
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user