From 3f87894a91a64d53c1509bb5f48c91cdb6e9fc2c Mon Sep 17 00:00:00 2001 From: Arundathi Patil Date: Thu, 25 Jul 2019 21:57:31 +0530 Subject: Source option- avoiding duplicates Implemented code to prevent adding duplicate resources in source list Issue-ID: CCSDK-707 Change-Id: I56caa3a248a2e2a611dceec0982820ea13c438a6 Signed-off-by: Arundathi Patil --- .../sources-template.component.html | 2 +- .../sources-template/sources-template.component.ts | 66 +++++++++++++++++----- 2 files changed, 54 insertions(+), 14 deletions(-) diff --git a/cds-ui/client/src/app/feature-modules/resource-definition/resource-edit/sources-template/sources-template.component.html b/cds-ui/client/src/app/feature-modules/resource-definition/resource-edit/sources-template/sources-template.component.html index b179f011d..a5f367de0 100644 --- a/cds-ui/client/src/app/feature-modules/resource-definition/resource-edit/sources-template/sources-template.component.html +++ b/cds-ui/client/src/app/feature-modules/resource-definition/resource-edit/sources-template/sources-template.component.html @@ -27,7 +27,7 @@ class="sources-list" (cdkDropListDropped)="drop($event)">
- + {{item.name}} diff --git a/cds-ui/client/src/app/feature-modules/resource-definition/resource-edit/sources-template/sources-template.component.ts b/cds-ui/client/src/app/feature-modules/resource-definition/resource-edit/sources-template/sources-template.component.ts index 42f990a24..3c76b8506 100644 --- a/cds-ui/client/src/app/feature-modules/resource-definition/resource-edit/sources-template/sources-template.component.ts +++ b/cds-ui/client/src/app/feature-modules/resource-definition/resource-edit/sources-template/sources-template.component.ts @@ -48,7 +48,8 @@ export class SourcesTemplateComponent implements OnInit { sources:ISourcesData; sourcesOptions = []; sourcesData = {}; - @Output() resourcesData = new EventEmitter(); + @Output() resourcesData = new EventEmitter(); + tempOption = []; constructor(private store: Store, private apiService: ResourceEditService) { this.rdState = this.store.select('resources'); @@ -62,12 +63,10 @@ export class SourcesTemplateComponent implements OnInit { resourcesdata => { var resourcesState: IResourcesState = { resources: resourcesdata.resources, isLoadSuccess: resourcesdata.isLoadSuccess, isSaveSuccess: resourcesdata.isSaveSuccess, isUpdateSuccess: resourcesdata.isUpdateSuccess }; this.resources=resourcesState.resources; - // this.sources = resourcesState.resources.sources; if(resourcesState.resources.definition && resourcesState.resources.definition.sources) { this.sources = resourcesState.resources.definition.sources; } for (let key in this.sources) { - // this.sourcesOptions.push(key); let source = { name : key, data: this.sources[key] @@ -136,14 +135,45 @@ export class SourcesTemplateComponent implements OnInit { } drop(event: CdkDragDrop) { - if (event.previousContainer === event.container) { - moveItemInArray(event.container.data, event.previousIndex, event.currentIndex); - } else { - transferArrayItem(event.previousContainer.data, - event.container.data, - event.previousIndex, - event.currentIndex); - } + if (!this.checkIfSourceExists(event.item.element.nativeElement.innerText)) { + if (event.previousContainer === event.container) { + moveItemInArray(event.container.data, event.previousIndex, event.currentIndex); + } else { + transferArrayItem(event.previousContainer.data, + event.container.data, + event.previousIndex, + event.currentIndex); + } + this.tempOption.forEach((item) => { + if (item.name == event.item.element.nativeElement.innerText) { + this.apiService.getModelType(item.value) + .subscribe(data => { + console.log(data); + data.forEach(dataitem => { + if (typeof (dataitem) == "object") { + for (let key1 in dataitem) { + if (key1 == 'properties') { + let newPropOnj = {} + for (let key2 in dataitem[key1]) { + console.log(dataitem[key1][key2]); + let varType = dataitem[key1][key2].type + // let property : varType = + newPropOnj[key2] = dataitem[key1][key2]; + } + } + } + } + }); + this.sourcesData = data; + this.sourcesOptions.forEach(sourcesOptionsitem => { + if (sourcesOptionsitem.name == item.name) { + sourcesOptionsitem.data = data; + } + }) + }) + } + }); + } } getResources() { @@ -152,11 +182,21 @@ export class SourcesTemplateComponent implements OnInit { console.log(data); for (let key in data[0]) { let sourceObj = { name: key, value: data[0][key] } - this.option.push(sourceObj); + this.option.push(sourceObj); + this.tempOption.push(sourceObj); } - // this.sourcesOptions = data; }, error=>{ console.log(error); }) } + + checkIfSourceExists(sourceName) { + let sourceExists: boolean = false; + this.sourcesOptions.forEach(item => { + if (item.name == sourceName) { + sourceExists = true; + } + }); + return sourceExists; +} } -- cgit 1.2.3-korg