From 1874c6a03bdee00485c440506a1adda1e52d0290 Mon Sep 17 00:00:00 2001 From: Benura Abeywardena <43112139+BLasan@users.noreply.github.com> Date: Sun, 2 Aug 2020 11:29:00 +0530 Subject: [PATCH] feat: add create entity data table checks (#788) Fixes: #751 --- ...ate-enity-data-table-checks.component.html | 84 +++++++++++++ ...ate-enity-data-table-checks.component.scss | 3 + ...-enity-data-table-checks.component.spec.ts | 25 ++++ ...reate-enity-data-table-checks.component.ts | 118 ++++++++++++++++++ ...ity-data-table-checks-template.resolver.ts | 30 +++++ .../entity-data-table-checks.component.html | 4 +- .../organization-routing.module.ts | 27 +++- src/app/organization/organization.module.ts | 4 +- src/app/organization/organization.service.ts | 15 +++ 9 files changed, 302 insertions(+), 8 deletions(-) create mode 100644 src/app/organization/entity-data-table-checks/create-enity-data-table-checks/create-enity-data-table-checks.component.html create mode 100644 src/app/organization/entity-data-table-checks/create-enity-data-table-checks/create-enity-data-table-checks.component.scss create mode 100644 src/app/organization/entity-data-table-checks/create-enity-data-table-checks/create-enity-data-table-checks.component.spec.ts create mode 100644 src/app/organization/entity-data-table-checks/create-enity-data-table-checks/create-enity-data-table-checks.component.ts create mode 100644 src/app/organization/entity-data-table-checks/enitity-data-table-checks-template.resolver.ts diff --git a/src/app/organization/entity-data-table-checks/create-enity-data-table-checks/create-enity-data-table-checks.component.html b/src/app/organization/entity-data-table-checks/create-enity-data-table-checks/create-enity-data-table-checks.component.html new file mode 100644 index 000000000..13f821bc2 --- /dev/null +++ b/src/app/organization/entity-data-table-checks/create-enity-data-table-checks/create-enity-data-table-checks.component.html @@ -0,0 +1,84 @@ +
+ + + +
+ + + +
+ + + Entity + + + {{ entity.name }} + + + + Entity is required + + + + + Status + + + {{ status.name }} + + + + Status is required + + + + + Data Table + + + {{ dataTable.dataTableName }} + + + + Data Table is required + + + + + Products + + + {{ loanProducts.name }} + + + + Loan Product is required + + + + + Products + + + {{ savingsProducts.name }} + + + + Loan Product is required + + + +
+ +
+ + + + + + +
+ +
+ +
diff --git a/src/app/organization/entity-data-table-checks/create-enity-data-table-checks/create-enity-data-table-checks.component.scss b/src/app/organization/entity-data-table-checks/create-enity-data-table-checks/create-enity-data-table-checks.component.scss new file mode 100644 index 000000000..1915ad6d3 --- /dev/null +++ b/src/app/organization/entity-data-table-checks/create-enity-data-table-checks/create-enity-data-table-checks.component.scss @@ -0,0 +1,3 @@ +.container { + max-width: 37rem; +} diff --git a/src/app/organization/entity-data-table-checks/create-enity-data-table-checks/create-enity-data-table-checks.component.spec.ts b/src/app/organization/entity-data-table-checks/create-enity-data-table-checks/create-enity-data-table-checks.component.spec.ts new file mode 100644 index 000000000..7eafc9824 --- /dev/null +++ b/src/app/organization/entity-data-table-checks/create-enity-data-table-checks/create-enity-data-table-checks.component.spec.ts @@ -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; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ CreateEnityDataTableChecksComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(CreateEnityDataTableChecksComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/organization/entity-data-table-checks/create-enity-data-table-checks/create-enity-data-table-checks.component.ts b/src/app/organization/entity-data-table-checks/create-enity-data-table-checks/create-enity-data-table-checks.component.ts new file mode 100644 index 000000000..1f62958db --- /dev/null +++ b/src/app/organization/entity-data-table-checks/create-enity-data-table-checks/create-enity-data-table-checks.component.ts @@ -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 }); + }); + } + +} diff --git a/src/app/organization/entity-data-table-checks/enitity-data-table-checks-template.resolver.ts b/src/app/organization/entity-data-table-checks/enitity-data-table-checks-template.resolver.ts new file mode 100644 index 000000000..42377d2f1 --- /dev/null +++ b/src/app/organization/entity-data-table-checks/enitity-data-table-checks-template.resolver.ts @@ -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 { + + /** + * @param {OrganizationService} organizationService Organization service. + */ + constructor(private organizationService: OrganizationService) {} + + /** + * Returns the Entity Data Table Checks data. + * @returns {Observable} + */ + resolve(): Observable { + return this.organizationService.getEntityDataTableChecksTemplate(); + } + +} diff --git a/src/app/organization/entity-data-table-checks/entity-data-table-checks.component.html b/src/app/organization/entity-data-table-checks/entity-data-table-checks.component.html index 245ceca79..38c4dff6f 100644 --- a/src/app/organization/entity-data-table-checks/entity-data-table-checks.component.html +++ b/src/app/organization/entity-data-table-checks/entity-data-table-checks.component.html @@ -1,8 +1,8 @@
-
diff --git a/src/app/organization/organization-routing.module.ts b/src/app/organization/organization-routing.module.ts index cc6f06693..11dd09070 100644 --- a/src/app/organization/organization-routing.module.ts +++ b/src/app/organization/organization-routing.module.ts @@ -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 { } diff --git a/src/app/organization/organization.module.ts b/src/app/organization/organization.module.ts index 22d036c9b..020532dc1 100644 --- a/src/app/organization/organization.module.ts +++ b/src/app/organization/organization.module.ts @@ -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 { } diff --git a/src/app/organization/organization.service.ts b/src/app/organization/organization.service.ts index 757a82cc4..a6e4a9db5 100644 --- a/src/app/organization/organization.service.ts +++ b/src/app/organization/organization.service.ts @@ -495,6 +495,21 @@ export class OrganizationService { return this.http.get('/entityDatatableChecks', { params: httpParams }); } + /** + * Get Entity Data Table Checks Template. + */ + getEntityDataTableChecksTemplate(): Observable { + return this.http.get('/entityDatatableChecks/template'); + } + + /** + * Create Entity Data Table Checks. + * @param entityData Data to be passed. + */ + createEntityDataTableChecks(entityData: any): Observable { + return this.http.post('/entityDatatableChecks', entityData); + } + /** * @param {string} entityDataTableCheckId Entity Data Table Check ID of entity data table to be deleted. * @returns {Observable}