feat: add create entity data table checks (#788)

Fixes: #751
This commit is contained in:
Benura Abeywardena
2020-08-02 11:29:00 +05:30
committed by GitHub
parent 26ce041855
commit 1874c6a03b
9 changed files with 302 additions and 8 deletions
@@ -0,0 +1,84 @@
<div class="container">
<mat-card>
<form [formGroup]="createEntityForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-label>Entity</mat-label>
<mat-select required formControlName="entity">
<mat-option *ngFor="let entity of entityTypes" [value]="entity.value">
{{ entity.name }}
</mat-option>
</mat-select>
<mat-error *ngIf="createEntityForm.controls.entity.hasError('required')">
Entity is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Status</mat-label>
<mat-select required formControlName="status">
<mat-option *ngFor="let status of statusList" [value]="status.code">
{{ status.name }}
</mat-option>
</mat-select>
<mat-error *ngIf="createEntityForm.controls.status.hasError('required')">
Status is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Data Table</mat-label>
<mat-select required formControlName="datatableName">
<mat-option *ngFor="let dataTable of dataTableList" [value]="dataTable.dataTableName">
{{ dataTable.dataTableName }}
</mat-option>
</mat-select>
<mat-error *ngIf="createEntityForm.controls.datatableName.hasError('required')">
Data Table is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field *ngIf="entityType === 'm_loan'">
<mat-label>Products</mat-label>
<mat-select required formControlName="productId">
<mat-option *ngFor="let loanProducts of createEntityData.loanProductDatas" [value]="loanProducts.id">
{{ loanProducts.name }}
</mat-option>
</mat-select>
<mat-error *ngIf="createEntityForm.controls.productId.hasError('required')">
Loan Product is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field *ngIf="entityType === 'm_savings_account'">
<mat-label>Products</mat-label>
<mat-select required formControlName="productId">
<mat-option *ngFor="let savingsProducts of createEntityData.savingsProductDatas" [value]="savingsProducts.id">
{{ savingsProducts.name }}
</mat-option>
</mat-select>
<mat-error *ngIf="createEntityForm.controls.productId.hasError('required')">
Loan Product 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]="!createEntityForm.valid">Submit</button>
</mat-card-actions>
</form>
</mat-card>
</div>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { CreateEnityDataTableChecksComponent } from './create-enity-data-table-checks.component';
describe('CreateEnityDataTableChecksComponent', () => {
let component: CreateEnityDataTableChecksComponent;
let fixture: ComponentFixture<CreateEnityDataTableChecksComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CreateEnityDataTableChecksComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(CreateEnityDataTableChecksComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,118 @@
/** Angular Imports. */
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services. */
import { OrganizationService } from 'app/organization/organization.service';
/**
* Create Entity Data Table Checks component.
*/
@Component({
selector: 'mifosx-create-enity-data-table-checks',
templateUrl: './create-enity-data-table-checks.component.html',
styleUrls: ['./create-enity-data-table-checks.component.scss']
})
export class CreateEnityDataTableChecksComponent implements OnInit {
/** Create Entity Datatable Checks form. */
createEntityForm: FormGroup;
/** Entity Datatable Checks data. */
createEntityData: any;
/** Selected entity type. */
entityType: string;
/** Entity types object array. */
entityTypes: any[];
/** Datatable Checks list. */
dataTableList: any[];
/** Loan and Savings status list. */
statusList: any[];
/**
* Retrieves Entity Datatable Checks data from `resolve`.
* @param {FormBuilder} formBuilder Form Builder.
* @param {ActivatedRoute} route Activated Route.
* @param {OrganizationService} organizationService Organization Service.
* @param {Router} router Router.
*/
constructor(private formBuilder: FormBuilder,
private route: ActivatedRoute,
private organizationService: OrganizationService,
private router: Router) {
this.route.data.subscribe((data: {dataTableEntity: any}) => {
this.createEntityData = data.dataTableEntity;
this.entityTypes = [
{ name: 'Client', value: this.createEntityData.entities[0] },
{ name: 'Loan', value: this.createEntityData.entities[1] },
{ name: 'Group', value: this.createEntityData.entities[2] },
{ name: 'Savings Account', value: this.createEntityData.entities[3] }
];
});
}
ngOnInit() {
this.setCreateEntityDataTableForm();
this.getEntityType();
}
/**
* Sets Entity Data Table Form.
*/
setCreateEntityDataTableForm() {
this.createEntityForm = this.formBuilder.group({
'entity': ['', Validators.required],
'status': ['', Validators.required],
'datatableName': ['', Validators.required]
});
}
/**
* Get Entity on selection.
* @param entity Selected Entity.
*/
getEntityType() {
this.createEntityForm.get('entity').valueChanges.subscribe((option: any) => {
switch (option) {
case 'm_client': {
this.entityType = 'm_client';
this.dataTableList = this.createEntityData.datatables.filter((data: any) => data.entity === 'm_client');
this.statusList = this.createEntityData.statusClient;
this.createEntityForm.removeControl('productId');
break;
}
case 'm_loan': {
this.entityType = 'm_loan';
this.dataTableList = this.createEntityData.datatables.filter((data: any) => data.entity === 'm_loan');
this.statusList = this.createEntityData.statusLoans;
this.createEntityForm.addControl('productId', new FormControl('', Validators.required));
break;
}
case 'm_group': {
this.entityType = 'm_group';
this.dataTableList = this.createEntityData.datatables.filter((data: any) => data.entity === 'm_group');
this.statusList = this.createEntityData.statusGroup;
this.createEntityForm.removeControl('productId');
break;
}
default : {
this.entityType = 'm_savings_account';
this.dataTableList = this.createEntityData.datatables.filter((data: any) => data.entity === 'm_savings_account');
this.statusList = this.createEntityData.statusSavings;
this.createEntityForm.addControl('productId', new FormControl('', Validators.required));
break;
}
}
});
}
/**
* Submits Entity Datble Form.
*/
submit() {
this.organizationService.createEntityDataTableChecks(this.createEntityForm.value).subscribe((response: any) => {
this.router.navigate(['../'], { relativeTo: this.route });
});
}
}
@@ -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 { OrganizationService } from '../organization.service';
/**
* Entity Data Table Checks data resolver.
*/
@Injectable()
export class EntityDataTableChecksTemplateResolver implements Resolve<Object> {
/**
* @param {OrganizationService} organizationService Organization service.
*/
constructor(private organizationService: OrganizationService) {}
/**
* Returns the Entity Data Table Checks data.
* @returns {Observable<any>}
*/
resolve(): Observable<any> {
return this.organizationService.getEntityDataTableChecksTemplate();
}
}
@@ -1,8 +1,8 @@
<div class="container m-b-20" fxLayout="row" fxLayoutAlign="end" fxLayoutGap="20px">
<button mat-raised-button color="primary">
<button mat-raised-button color="primary" [routerLink]="['create']">
<fa-icon icon="plus"></fa-icon>&nbsp;&nbsp;
Create Entity Data Table Check
Create
</button>
</div>
@@ -55,6 +55,7 @@ import { ViewBulkImportComponent } from './bulk-import/view-bulk-import/view-bul
import { ViewLoanProvisioningCriteriaComponent } from './loan-provisioning-criteria/view-loan-provisioning-criteria/view-loan-provisioning-criteria.component';
import { CreateCampaignComponent } from './sms-campaigns/create-campaign/create-campaign.component';
import { EditCampaignComponent } from './sms-campaigns/edit-campaign/edit-campaign.component';
import { CreateEnityDataTableChecksComponent } from './entity-data-table-checks/create-enity-data-table-checks/create-enity-data-table-checks.component';
/** Custom Resolvers */
import { LoanProvisioningCriteriaResolver } from './loan-provisioning-criteria/loan-provisioning-criteria.resolver';
@@ -90,6 +91,7 @@ import { HolidayTemplateResolver } from './holidays/holiday-template.resolver';
import { AdhocQueryAndTemplateResolver } from './adhoc-query/common-resolvers/adhoc-query-and-template.resolver';
import { BulkImportResolver } from './bulk-import/bulk-import.resolver';
import { SmsCampaignTemplateResolver } from './sms-campaigns/common-resolvers/sms-campaign-template.resolver';
import { EntityDataTableChecksTemplateResolver } from './entity-data-table-checks/enitity-data-table-checks-template.resolver';
/** Organization Routes */
const routes: Routes = [
@@ -491,11 +493,24 @@ const routes: Routes = [
},
{
path: 'entity-data-table-checks',
component: EntityDataTableChecksComponent,
data: { title: extract('Entity Data Table Checks'), breadcrumb: 'Entity Data Table Checks' },
resolve: {
entityDataTableChecks: EntityDataTableChecksResolver
}
children: [
{
path: '',
component: EntityDataTableChecksComponent,
resolve: {
entityDataTableChecks: EntityDataTableChecksResolver
},
},
{
path: 'create',
component: CreateEnityDataTableChecksComponent,
data: { title: extract('Create Entity Data Table Checks'), breadcrumb: 'Create' },
resolve: {
dataTableEntity: EntityDataTableChecksTemplateResolver
}
}
]
},
{
path: 'working-days',
@@ -614,7 +629,9 @@ const routes: Routes = [
EditCashierResolver,
HolidayResolver,
HolidayTemplateResolver,
BulkImportResolver
BulkImportResolver,
HolidayResolver,
EntityDataTableChecksTemplateResolver
]
})
export class OrganizationRoutingModule { }
+3 -1
View File
@@ -62,6 +62,7 @@ import { BusinessRuleParametersComponent } from './sms-campaigns/sms-campaign-st
import { EditCampaignComponent } from './sms-campaigns/edit-campaign/edit-campaign.component';
import { EditSmsCampaignStepComponent } from './sms-campaigns/sms-campaign-stepper/edit-sms-campaign-step/edit-sms-campaign-step.component';
import { EditBusinessRuleParametersComponent } from './sms-campaigns/sms-campaign-stepper/edit-sms-campaign-step/edit-business-rule-parameters/edit-business-rule-parameters.component';
import { CreateEnityDataTableChecksComponent } from './entity-data-table-checks/create-enity-data-table-checks/create-enity-data-table-checks.component';
/**
* Organization Module
@@ -129,7 +130,8 @@ import { EditBusinessRuleParametersComponent } from './sms-campaigns/sms-campaig
BusinessRuleParametersComponent,
EditCampaignComponent,
EditSmsCampaignStepComponent,
EditBusinessRuleParametersComponent
EditBusinessRuleParametersComponent,
CreateEnityDataTableChecksComponent,
]
})
export class OrganizationModule { }
@@ -495,6 +495,21 @@ export class OrganizationService {
return this.http.get('/entityDatatableChecks', { params: httpParams });
}
/**
* Get Entity Data Table Checks Template.
*/
getEntityDataTableChecksTemplate(): Observable<any> {
return this.http.get('/entityDatatableChecks/template');
}
/**
* Create Entity Data Table Checks.
* @param entityData Data to be passed.
*/
createEntityDataTableChecks(entityData: any): Observable<any> {
return this.http.post('/entityDatatableChecks', entityData);
}
/**
* @param {string} entityDataTableCheckId Entity Data Table Check ID of entity data table to be deleted.
* @returns {Observable<any>}