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 @@
+
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