From 1539180a3a68d650e76d90ff78ac5cd6c424db73 Mon Sep 17 00:00:00 2001 From: Muskan Khedia <36980003+muskankhedia@users.noreply.github.com> Date: Sun, 31 May 2020 21:14:56 +0530 Subject: [PATCH] feat: add edit entity to entity mapping (#823) - add edit entity to entity mapping - add delete entity to entity mapping Fixes: #767 --- .../entity-to-entity-mapping.component.html | 66 ++++++++++++- .../entity-to-entity-mapping.component.ts | 97 ++++++++++++++++++- src/app/system/system.service.ts | 27 ++++++ 3 files changed, 185 insertions(+), 5 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 7ec5ce3e1..61d30dbca 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 @@ -104,7 +104,8 @@ - @@ -113,7 +114,8 @@ - @@ -186,6 +188,66 @@ + + + + Edit 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.ts b/src/app/system/entity-to-entity-mapping/entity-to-entity-mapping.component.ts index e1cc8c270..e937aa26f 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 @@ -1,6 +1,6 @@ /** Angular Imports */ import { Component, OnInit, ViewChild } from '@angular/core'; -import { MatPaginator, MatSort, MatTableDataSource } from '@angular/material'; +import { MatPaginator, MatSort, MatTableDataSource, MatDialog } from '@angular/material'; import { ActivatedRoute } from '@angular/router'; import { DatePipe } from '@angular/common'; @@ -8,6 +8,9 @@ import { DatePipe } from '@angular/common'; import { SystemService } from 'app/system/system.service'; import { FormGroup, FormBuilder, Validators } from '@angular/forms'; +/** Custom Components */ +import { DeleteDialogComponent } from '../../shared/delete-dialog/delete-dialog.component'; + /** * Entity to Entity Mapping Component */ @@ -36,7 +39,12 @@ export class EntityToEntityMappingComponent implements OnInit { filterPreference: any; /** Checks where add form is to be displayed */ addScreenFilter = false; - + /** Checks where edit form is to be displayed */ + editScreenFilter = false; + /** details of particular map id */ + entityMap: any; + /** Map Id to ID */ + mapIdToEdit: any; /** * stores the data for clicked mapType */ @@ -44,14 +52,18 @@ export class EntityToEntityMappingComponent implements OnInit { 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; /** Add entity Form */ addMappingForm: FormGroup; + /** Edit entity Form */ + editMappingForm: FormGroup; /** List of Entity to Entity Mapping */ displayedColumns: string[] = ['entitymapping']; /** Columns for details of a chosen mapping */ @@ -62,6 +74,7 @@ export class EntityToEntityMappingComponent implements OnInit { /** Sorter for entity table. */ @ViewChild(MatSort) sort: MatSort; + /** * Retrieves the codes data from `resolve`. * @param {ActivatedRoute} route Activated Route. @@ -69,7 +82,8 @@ export class EntityToEntityMappingComponent implements OnInit { constructor(private route: ActivatedRoute, private formBuilder: FormBuilder, private systemService: SystemService, - private datePipe: DatePipe) { + private datePipe: DatePipe, + private dialog: MatDialog) { this.route.data.subscribe((data: { entityMappings: any }) => { this.entityMappings = data.entityMappings; }); @@ -183,6 +197,7 @@ export class EntityToEntityMappingComponent implements OnInit { } this.hasClickedFilters = true; this.addScreenFilter = false; + this.editScreenFilter = false; this.selectedFromId = this.filterPreference.mappingFirstParamId; this.selectedToId = this.filterPreference.mappingSecondParamId; @@ -205,6 +220,21 @@ export class EntityToEntityMappingComponent implements OnInit { }); } + /** + * Edits the mapping data + */ + createEditMappingForm(data: any) { + const dateFormat = 'dd MMMM yyyy'; + const startDate = new Date(data[0].startDate); + const endDate = new Date(data[0].endDate); + this.editMappingForm = this.formBuilder.group({ + 'fromId': [data[0].fromId, Validators.required], + 'toId': [data[0].toId, Validators.required], + 'startDate': [startDate, Validators.required], + 'endDate': [endDate, Validators.required] + }); + } + /** * Shows the add entity screen * @param selectedType selected Map Type @@ -214,9 +244,28 @@ export class EntityToEntityMappingComponent implements OnInit { this.relId = selectedType; this.hasClickedFilters = false; this.addScreenFilter = true; + this.editScreenFilter = false; this.fetchRelatedData(this.relId); } + /** + * Shows the edit entity screen + * @param selectedMap selected Map Number + * @param selectedType selected Map Type + */ + showEditScreen(selectedMap: number, selectedType: number) { + this.relId = selectedType; + this.mapIdToEdit = selectedMap; + this.fetchRelatedData(this.relId); + this.systemService.getMapIdData(selectedMap).subscribe((response: any) => { + this.entityMap = response; + this.createEditMappingForm(this.entityMap); + this.hasClickedFilters = false; + this.addScreenFilter = false; + this.editScreenFilter = true; + }); + } + /** * Submits the new mapping @@ -248,12 +297,54 @@ export class EntityToEntityMappingComponent implements OnInit { }); } + /** + * Submits the edited data + * @param id Map Id + */ + submitEdit(id: number) { + this.relId = id; + const dateFormat = 'dd MMMM yyyy'; + + const startDate: Date = this.editMappingForm.value.startDate; + const endDate: Date = this.editMappingForm.value.endDate; + + this.editMappingForm.patchValue({ + startDate: this.datePipe.transform(startDate, dateFormat), + endDate: this.datePipe.transform(endDate, dateFormat) + }); + const newMappingData = this.editMappingForm.value; + newMappingData.dateFormat = dateFormat; + newMappingData.locale = 'en'; + this.systemService.editMapping(this.relId, newMappingData).subscribe((response: any) => { + this.showFilteredData(); + }); + } + + /** + * Deletes the selected Map Id + * @param id Map Id + */ + delete(id: number) { + const deleteNoteDialogRef = this.dialog.open(DeleteDialogComponent, { + data: { deleteContext: `Mapping id: ${id}` } + }); + deleteNoteDialogRef.afterClosed().subscribe((response: any) => { + if (response.delete) { + this.systemService.deleteMapping(id) + .subscribe(() => { + this.showFilteredData(); + }); + } + }); + } + /** * Cancels the add entity operation */ cancelOperation() { this.hasClickedFilters = true; this.addScreenFilter = false; + this.editScreenFilter = false; } } diff --git a/src/app/system/system.service.ts b/src/app/system/system.service.ts index a201c3647..768731935 100644 --- a/src/app/system/system.service.ts +++ b/src/app/system/system.service.ts @@ -476,6 +476,15 @@ export class SystemService { return this.http.get(`/entitytoentitymapping/${mappingId}/${fromId}/${toId}`); } + /** + * Get particular Map Data + * @param mapId Mapping Id + */ + getMapIdData(mapId: number): Observable { + return this.http.get(`/entitytoentitymapping/${mapId}`); + } + + /** * Creates a new mapping * @param {any} mapType Map id to be created. @@ -486,6 +495,24 @@ export class SystemService { return this.http.post(`/entitytoentitymapping/${mapType}`, mapData); } + /** + * Edit a mapping + * @param {any} mapType Map id to be edited. + * @param {any} mapData Map data to be added + * @returns {Observable} resolved data + */ + editMapping(mapId: any, mapData: any): Observable { + return this.http.put(`/entitytoentitymapping/${mapId}`, mapData); + } + + /** + * Delete the Map Id + * @param mapId Map Id + */ + deleteMapping(mapId: any): Observable { + return this.http.delete(`/entitytoentitymapping/${mapId}`); + } + /** * @returns {Observable} Offices data */