From fc4ed6b21257e94137c3b96a9771ab2ba0844560 Mon Sep 17 00:00:00 2001 From: Muskan Khedia <36980003+muskankhedia@users.noreply.github.com> Date: Sun, 31 May 2020 20:42:34 +0530 Subject: [PATCH] feat: add new entity to entity mapping (#822) Fixes: #767 --- .../entity-to-entity-mapping.component.html | 84 ++++++++++++++++--- .../entity-to-entity-mapping.component.scss | 5 ++ .../entity-to-entity-mapping.component.ts | 83 ++++++++++++++++-- src/app/system/system.module.ts | 4 +- src/app/system/system.service.ts | 10 +++ 5 files changed, 167 insertions(+), 19 deletions(-) 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 index aaad01d3b..7ec5ce3e1 100644 --- 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 @@ -68,11 +68,9 @@ - - - + @@ -81,30 +79,30 @@ -
- +
+
- + - + - - + + - + - + +
{{firstMappingEntity}} {{firstMappingEntity}} {{ listdata.fromEntity }} {{secondMappingEntity}} {{secondMappingEntity}} {{ listdata.toEntity }} Start Date {{ listdata.startData }} Start Date {{ listdata.startDate }} End Date End Date {{ listdata.endDate }}
- +
+ + + + Add new entity mapping +
+ + +
+ + + {{firstMappingEntity}} + + + + {{ firstEntity.name }} + + + + {{firstMappingEntity}} is required + + + + + {{secondMappingEntity}} + + + + {{ secondEntity.name }} + + + + {{secondMappingEntity}} is required + + + + + + Start Date + + + + + + + End Date + + + + + +
+
+ + + + +
+
+
+ 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 index e69de29bb..898678c69 100644 --- 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 @@ -0,0 +1,5 @@ +table { + .select-row { + cursor: pointer; + } +} 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 index 8d75498b2..e1cc8c270 100644 --- 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 @@ -2,6 +2,7 @@ import { Component, OnInit, ViewChild } from '@angular/core'; import { MatPaginator, MatSort, MatTableDataSource } from '@angular/material'; import { ActivatedRoute } from '@angular/router'; +import { DatePipe } from '@angular/common'; /** Custom Services */ import { SystemService } from 'app/system/system.service'; @@ -29,8 +30,12 @@ export class EntityToEntityMappingComponent implements OnInit { hasClickedFilters = false; /** Selected Entity Id */ retrieveById = 0; + /** relative Id */ + relId: number; /** Stores filtered data */ filterPreference: any; + /** Checks where add form is to be displayed */ + addScreenFilter = false; /** * stores the data for clicked mapType @@ -45,6 +50,8 @@ export class EntityToEntityMappingComponent implements OnInit { entityMappingsListData: MatTableDataSource; /** Filter Preference Form */ filterPreferenceForm: FormGroup; + /** Add entity Form */ + addMappingForm: FormGroup; /** List of Entity to Entity Mapping */ displayedColumns: string[] = ['entitymapping']; /** Columns for details of a chosen mapping */ @@ -61,7 +68,8 @@ export class EntityToEntityMappingComponent implements OnInit { */ constructor(private route: ActivatedRoute, private formBuilder: FormBuilder, - private systemService: SystemService) { + private systemService: SystemService, + private datePipe: DatePipe) { this.route.data.subscribe((data: { entityMappings: any }) => { this.entityMappings = data.entityMappings; }); @@ -168,19 +176,84 @@ export class EntityToEntityMappingComponent implements OnInit { showFilteredData() { this.filterPreference = this.filterPreferenceForm.value; if (this.filterPreference.mappingFirstParamId === '') { - this.filterPreference.mappingFirstParamId = undefined; + this.filterPreference.mappingFirstParamId = 0; } if (this.filterPreference.mappingSecondParamId === '') { - this.filterPreference.mappingSecondParamId = undefined; + this.filterPreference.mappingSecondParamId = 0; } this.hasClickedFilters = true; + this.addScreenFilter = false; + 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; + // this.entityMappingsListData.paginator = this.paginator; + // this.entityMappingsListData.sort = this.sort; }); } + /** + * Creates the add mapping form + */ + createAddMappingForm() { + this.addMappingForm = this.formBuilder.group({ + 'fromId': ['', Validators.required], + 'toId': ['', Validators.required], + 'startDate': [''], + 'endDate': [''] + }); + } + + /** + * Shows the add entity screen + * @param selectedType selected Map Type + */ + showAddScreen(selectedType: number) { + this.createAddMappingForm(); + this.relId = selectedType; + this.hasClickedFilters = false; + this.addScreenFilter = true; + this.fetchRelatedData(this.relId); + } + + + /** + * Submits the new mapping + * @param id Map type id + */ + submitNew(id: number) { + + if (this.addMappingForm.value.fromId === '') { + this.addMappingForm.value.fromId = undefined; + } + if (this.addMappingForm.value.toId === '') { + this.addMappingForm.value.toId = undefined; + } + this.relId = id; + const dateFormat = 'dd MMMM yyyy'; + + const startDate: Date = this.addMappingForm.value.startDate; + const endDate: Date = this.addMappingForm.value.endDate; + + this.addMappingForm.patchValue({ + startDate: this.datePipe.transform(startDate, dateFormat), + endDate: this.datePipe.transform(endDate, dateFormat) + }); + const newMappingData = this.addMappingForm.value; + newMappingData.dateFormat = dateFormat; + newMappingData.locale = 'en'; + this.systemService.createMapping(this.relId, newMappingData).subscribe((response: any) => { + this.showFilteredData(); + }); + } + + /** + * Cancels the add entity operation + */ + cancelOperation() { + this.hasClickedFilters = true; + this.addScreenFilter = false; + } + } diff --git a/src/app/system/system.module.ts b/src/app/system/system.module.ts index adfee6af1..cca274d62 100644 --- a/src/app/system/system.module.ts +++ b/src/app/system/system.module.ts @@ -4,6 +4,7 @@ import { NgModule } from '@angular/core'; /** Module Imports */ import { SharedModule } from '../shared/shared.module'; import { SystemRoutingModule } from './system-routing.module'; +import { PipesModule } from '../pipes/pipes.module'; /** Component Imports */ import { CodesComponent } from './codes/codes.component'; @@ -58,7 +59,8 @@ import { EditSchedulerJobComponent } from './manage-scheduler-jobs/edit-schedule @NgModule({ imports: [ SystemRoutingModule, - SharedModule + SharedModule, + PipesModule ], declarations: [ SystemComponent, diff --git a/src/app/system/system.service.ts b/src/app/system/system.service.ts index 36a211ff4..a201c3647 100644 --- a/src/app/system/system.service.ts +++ b/src/app/system/system.service.ts @@ -476,6 +476,16 @@ export class SystemService { return this.http.get(`/entitytoentitymapping/${mappingId}/${fromId}/${toId}`); } + /** + * Creates a new mapping + * @param {any} mapType Map id to be created. + * @param {any} mapData Map data to be added + * @returns {Observable} resolved data + */ + createMapping(mapType: any, mapData: any): Observable { + return this.http.post(`/entitytoentitymapping/${mapType}`, mapData); + } + /** * @returns {Observable} Offices data */