From 8cc76f50e0aa662f5c4e64008e56f36eea618ad2 Mon Sep 17 00:00:00 2001
From: Muskan Khedia <36980003+muskankhedia@users.noreply.github.com>
Date: Sun, 31 May 2020 19:58:59 +0530
Subject: [PATCH] feat: add view entity to entity mapping (#613)
- adds entity to entity mapping list
- displays the data as per user selection
Fixes: #485
---
.../entity-to-entity-mapping.component.html | 135 +++++++++++++
.../entity-to-entity-mapping.component.scss | 0
...entity-to-entity-mapping.component.spec.ts | 25 +++
.../entity-to-entity-mapping.component.ts | 186 ++++++++++++++++++
.../entity-to-entity-mapping.resolver.ts | 30 +++
src/app/system/system-routing.module.ts | 13 +-
src/app/system/system.component.html | 2 +-
src/app/system/system.module.ts | 4 +-
src/app/system/system.service.ts | 46 +++++
9 files changed, 438 insertions(+), 3 deletions(-)
create mode 100644 src/app/system/entity-to-entity-mapping/entity-to-entity-mapping.component.html
create mode 100644 src/app/system/entity-to-entity-mapping/entity-to-entity-mapping.component.scss
create mode 100644 src/app/system/entity-to-entity-mapping/entity-to-entity-mapping.component.spec.ts
create mode 100644 src/app/system/entity-to-entity-mapping/entity-to-entity-mapping.component.ts
create mode 100644 src/app/system/entity-to-entity-mapping/entity-to-entity-mapping.resolver.ts
diff --git a/src/app/system/entity-to-entity-mapping/entity-to-entity-mapping.component.html b/src/app/system/entity-to-entity-mapping/entity-to-entity-mapping.component.html
new file mode 100644
index 000000000..aaad01d3b
--- /dev/null
+++ b/src/app/system/entity-to-entity-mapping/entity-to-entity-mapping.component.html
@@ -0,0 +1,135 @@
+
+
+
+
+
+ | Mapping Between Entities |
+
+
+ Offices --> Loan Products
+
+
+ Offices --> Savings Products
+
+
+ Offices --> Charges/Fees
+
+
+ Roles --> Loan Products
+
+
+ Roles --> Savings Products
+
+ |
+
+
+
+
+
+
+
+
0">
+
+
+
+
+
+
+
+
+
+
+ | {{firstMappingEntity}} |
+ {{ listdata.fromEntity }} |
+
+
+
+ {{secondMappingEntity}} |
+ {{ listdata.toEntity }} |
+
+
+
+ Start Date |
+ {{ listdata.startData }} |
+
+
+
+ End Date |
+ {{ listdata.endDate }} |
+
+
+
+ |
+
+
+ |
+
+
+
+ |
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/app/system/entity-to-entity-mapping/entity-to-entity-mapping.component.scss b/src/app/system/entity-to-entity-mapping/entity-to-entity-mapping.component.scss
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/app/system/entity-to-entity-mapping/entity-to-entity-mapping.component.spec.ts b/src/app/system/entity-to-entity-mapping/entity-to-entity-mapping.component.spec.ts
new file mode 100644
index 000000000..169414902
--- /dev/null
+++ b/src/app/system/entity-to-entity-mapping/entity-to-entity-mapping.component.spec.ts
@@ -0,0 +1,25 @@
+import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+
+import { EntityToEntityMappingComponent } from './entity-to-entity-mapping.component';
+
+describe('EntityToEntityMappingComponent', () => {
+ let component: EntityToEntityMappingComponent;
+ let fixture: ComponentFixture;
+
+ beforeEach(async(() => {
+ TestBed.configureTestingModule({
+ declarations: [ EntityToEntityMappingComponent ]
+ })
+ .compileComponents();
+ }));
+
+ beforeEach(() => {
+ fixture = TestBed.createComponent(EntityToEntityMappingComponent);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+ });
+
+ it('should create', () => {
+ expect(component).toBeTruthy();
+ });
+});
diff --git a/src/app/system/entity-to-entity-mapping/entity-to-entity-mapping.component.ts b/src/app/system/entity-to-entity-mapping/entity-to-entity-mapping.component.ts
new file mode 100644
index 000000000..8d75498b2
--- /dev/null
+++ b/src/app/system/entity-to-entity-mapping/entity-to-entity-mapping.component.ts
@@ -0,0 +1,186 @@
+/** Angular Imports */
+import { Component, OnInit, ViewChild } from '@angular/core';
+import { MatPaginator, MatSort, MatTableDataSource } from '@angular/material';
+import { ActivatedRoute } from '@angular/router';
+
+/** Custom Services */
+import { SystemService } from 'app/system/system.service';
+import { FormGroup, FormBuilder, Validators } from '@angular/forms';
+
+/**
+ * Entity to Entity Mapping Component
+ */
+@Component({
+ selector: 'mifosx-entity-to-entity-mapping',
+ templateUrl: './entity-to-entity-mapping.component.html',
+ styleUrls: ['./entity-to-entity-mapping.component.scss']
+})
+export class EntityToEntityMappingComponent implements OnInit {
+
+ /** Stores entity to entity mapping data */
+ entityMappings: string[] = [];
+ /** Stores Id of selected mapping type */
+ selectedMappingType = 0;
+ /** Stores Id of first Entity filter */
+ selectedFromId = 0;
+ /** Stores Id of second Entity filter */
+ selectedToId = 0;
+ /** Checks wheter the filter is default or customized */
+ hasClickedFilters = false;
+ /** Selected Entity Id */
+ retrieveById = 0;
+ /** Stores filtered data */
+ filterPreference: any;
+
+ /**
+ * stores the data for clicked mapType
+ */
+ firstEntityData: string[] = [];
+ secondEntityData: string[] = [];
+ firstMappingEntity: string;
+ secondMappingEntity: string;
+ /** Data source for entity table. */
+ datasource: MatTableDataSource;
+ /** Data source for entity to entity list data. */
+ entityMappingsListData: MatTableDataSource;
+ /** Filter Preference Form */
+ filterPreferenceForm: FormGroup;
+ /** List of Entity to Entity Mapping */
+ displayedColumns: string[] = ['entitymapping'];
+ /** Columns for details of a chosen mapping */
+ entityMappingListColumns: string[] = ['fromentity', 'toentity', 'startdate', 'enddate', 'edit', 'delete'];
+
+ /** Paginator for entity table. */
+ @ViewChild(MatPaginator) paginator: MatPaginator;
+ /** Sorter for entity table. */
+ @ViewChild(MatSort) sort: MatSort;
+
+ /**
+ * Retrieves the codes data from `resolve`.
+ * @param {ActivatedRoute} route Activated Route.
+ */
+ constructor(private route: ActivatedRoute,
+ private formBuilder: FormBuilder,
+ private systemService: SystemService) {
+ this.route.data.subscribe((data: { entityMappings: any }) => {
+ this.entityMappings = data.entityMappings;
+ });
+ }
+
+ /**
+ * Creates the filter preference form.
+ */
+ createFilterPreferenceForm() {
+ this.filterPreferenceForm = this.formBuilder.group({
+ 'mappingFirstParamId': ['', Validators.required],
+ 'mappingSecondParamId': ['', Validators.required]
+ });
+ }
+
+ /**
+ * Sets the mapping table.
+ */
+ ngOnInit() {
+ this.setMapping();
+ }
+
+ setMapping() {
+ this.datasource = new MatTableDataSource(this.entityMappings);
+ this.datasource.paginator = this.paginator;
+ this.datasource.sort = this.sort;
+ }
+
+ /**
+ * Displays filter based on mapping id
+ * @param id Entity Mapping Id
+ */
+ showFilters(id: number) {
+ this.selectedMappingType = id;
+ this.hasClickedFilters = false;
+ this.fetchRelatedData(this.selectedMappingType);
+ this.selectedFromId = 0;
+ this.selectedToId = 0;
+ }
+
+ /** Fetches data based on the selected mapping type */
+ fetchRelatedData(id: number) {
+ this.retrieveById = id;
+ this.createFilterPreferenceForm();
+ switch (this.retrieveById) {
+
+ case 1:
+ this.systemService.getOffices().subscribe((response: any) => {
+ this.firstEntityData = response;
+ this.firstMappingEntity = 'Office';
+ });
+ this.systemService.getLoanProducts().subscribe((response: any) => {
+ this.secondEntityData = response;
+ this.secondMappingEntity = 'Loan Products';
+ });
+ break;
+ case 2:
+ this.systemService.getOffices().subscribe((response: any) => {
+ this.firstEntityData = response;
+ this.firstMappingEntity = 'Office';
+ });
+ this.systemService.getSavingProducts().subscribe((response: any) => {
+ this.secondEntityData = response;
+ this.secondMappingEntity = 'Saving Products';
+ });
+ break;
+ case 3:
+ this.systemService.getOffices().subscribe((response: any) => {
+ this.firstEntityData = response;
+ this.firstMappingEntity = 'Office';
+ });
+ this.systemService.getCharges().subscribe((response: any) => {
+ this.secondEntityData = response;
+ this.secondMappingEntity = 'Charges';
+ });
+ break;
+ case 4:
+ this.systemService.getRoles().subscribe((response: any) => {
+ this.firstEntityData = response;
+ this.firstMappingEntity = 'Role';
+ });
+ this.systemService.getLoanProducts().subscribe((response: any) => {
+ this.secondEntityData = response;
+ this.secondMappingEntity = 'Loan Products';
+ });
+ break;
+ case 5:
+ this.systemService.getRoles().subscribe((response: any) => {
+ this.firstEntityData = response;
+ this.firstMappingEntity = 'Role';
+ });
+ this.systemService.getSavingProducts().subscribe((response: any) => {
+ this.secondEntityData = response;
+ this.secondMappingEntity = 'Saving Products';
+ });
+ break;
+ }
+
+ }
+
+ /**
+ * Submits the filter preference form and creates a entityMappingList data
+ */
+ showFilteredData() {
+ this.filterPreference = this.filterPreferenceForm.value;
+ if (this.filterPreference.mappingFirstParamId === '') {
+ this.filterPreference.mappingFirstParamId = undefined;
+ }
+ if (this.filterPreference.mappingSecondParamId === '') {
+ this.filterPreference.mappingSecondParamId = undefined;
+ }
+ this.hasClickedFilters = true;
+ this.selectedFromId = this.filterPreference.mappingFirstParamId;
+ this.selectedToId = this.filterPreference.mappingSecondParamId;
+ this.systemService.getEntitytoEntityData(this.retrieveById, this.selectedFromId, this.selectedToId).subscribe((response: any) => {
+ this.entityMappingsListData = new MatTableDataSource(response);
+ this.entityMappingsListData.paginator = this.paginator;
+ this.entityMappingsListData.sort = this.sort;
+ });
+ }
+
+}
diff --git a/src/app/system/entity-to-entity-mapping/entity-to-entity-mapping.resolver.ts b/src/app/system/entity-to-entity-mapping/entity-to-entity-mapping.resolver.ts
new file mode 100644
index 000000000..6d64f765b
--- /dev/null
+++ b/src/app/system/entity-to-entity-mapping/entity-to-entity-mapping.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 { SystemService } from '../system.service';
+
+/**
+ * Entity to entity mapping data resolver.
+ */
+@Injectable()
+export class EntityToEntityMappingResolver implements Resolve