From 3a5ecdcf6129611e1f8a016bd4e5260c1096af88 Mon Sep 17 00:00:00 2001 From: Swapnali Shadanan Pode Date: Thu, 7 Mar 2019 15:43:32 +0530 Subject: Upload file Change-Id: Icaab7e8800fac9a82ebe38709aacc550da9f43fa Issue-ID: CCSDK-808 Signed-off-by: sp00501638 --- .../resource-creation.component.html | 4 +-- .../resource-creation.component.ts | 30 ++++++++++++++-------- .../upload-resource/upload-resource.component.html | 4 ++- .../upload-resource/upload-resource.component.ts | 22 ++++++++++++++-- 4 files changed, 45 insertions(+), 15 deletions(-) (limited to 'cds-ui/client/src/app') diff --git a/cds-ui/client/src/app/feature-modules/resource-definition/resource-creation/resource-creation.component.html b/cds-ui/client/src/app/feature-modules/resource-definition/resource-creation/resource-creation.component.html index c488dfdd7..8ace910b1 100644 --- a/cds-ui/client/src/app/feature-modules/resource-definition/resource-creation/resource-creation.component.html +++ b/cds-ui/client/src/app/feature-modules/resource-definition/resource-creation/resource-creation.component.html @@ -34,10 +34,10 @@ Browse or Search Resources -

+

- +
diff --git a/cds-ui/client/src/app/feature-modules/resource-definition/resource-creation/resource-creation.component.ts b/cds-ui/client/src/app/feature-modules/resource-definition/resource-creation/resource-creation.component.ts index bb8ceea51..c751e0ee8 100644 --- a/cds-ui/client/src/app/feature-modules/resource-definition/resource-creation/resource-creation.component.ts +++ b/cds-ui/client/src/app/feature-modules/resource-definition/resource-creation/resource-creation.component.ts @@ -21,6 +21,9 @@ import { Component, OnInit } from '@angular/core'; import { Observable } from 'rxjs'; import { Store } from '@ngrx/store'; +import { IResources } from 'src/app/common/core/store/models/resources.model'; +import { IAppState } from '../../../common/core/store/state/app.state'; +import { LoadResourcesSuccess } from 'src/app/common/core/store/actions/resources.action'; @Component({ selector: 'app-resource-creation', @@ -29,25 +32,32 @@ import { Store } from '@ngrx/store'; }) export class ResourceCreationComponent implements OnInit { - myFile: File; /* property of File type */ + myFile: any; selectedValue: any; - constructor() { + constructor(private store: Store) { } ngOnInit() { } - fileChange(files: any) { - console.log(files); - this.myFile = files[0].nativeElement; - } - upload(){ + upload(value){ + this.myFile=value; + } - } + updateResourcesState() { + let fileReader = new FileReader(); + fileReader.readAsText(this.myFile); + var me = this; + fileReader.onload = function () { + var data: IResources = JSON.parse(fileReader.result.toString()); + me.store.dispatch(new LoadResourcesSuccess(data)); + console.log(data); + } + } - selectedOption(value){ + selectedOption(value){ this.selectedValue=value; console.log(this.selectedValue); -} + } } diff --git a/cds-ui/client/src/app/feature-modules/resource-definition/resource-creation/upload-resource/upload-resource.component.html b/cds-ui/client/src/app/feature-modules/resource-definition/resource-creation/upload-resource/upload-resource.component.html index 97859cb37..3d60dabb8 100644 --- a/cds-ui/client/src/app/feature-modules/resource-definition/resource-creation/upload-resource/upload-resource.component.html +++ b/cds-ui/client/src/app/feature-modules/resource-definition/resource-creation/upload-resource/upload-resource.component.html @@ -19,4 +19,6 @@ */--> - +
+ +
\ No newline at end of file diff --git a/cds-ui/client/src/app/feature-modules/resource-definition/resource-creation/upload-resource/upload-resource.component.ts b/cds-ui/client/src/app/feature-modules/resource-definition/resource-creation/upload-resource/upload-resource.component.ts index f408c7ac4..ac3561a21 100644 --- a/cds-ui/client/src/app/feature-modules/resource-definition/resource-creation/upload-resource/upload-resource.component.ts +++ b/cds-ui/client/src/app/feature-modules/resource-definition/resource-creation/upload-resource/upload-resource.component.ts @@ -18,7 +18,13 @@ * ============LICENSE_END========================================================= */ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, EventEmitter, Output } from '@angular/core'; +import { IResources } from 'src/app/common/core/store/models/resources.model'; +import { IResourcesState } from 'src/app/common/core/store/models/resourcesState.model'; +import { LoadResourcesSuccess } from 'src/app/common/core/store/actions/resources.action'; +import { IAppState } from '../../../../common/core/store/state/app.state'; +import { Observable } from 'rxjs'; +import { Store } from '@ngrx/store'; @Component({ selector: 'app-upload-resource', @@ -27,9 +33,21 @@ import { Component, OnInit } from '@angular/core'; }) export class UploadResourceComponent implements OnInit { - constructor() { } + @Output() fileData = new EventEmitter(); + file: File; + localResourcesData: IResources; + fileText: object[]; + blueprintState: IResourcesState; + bpState: Observable; + + constructor(private store: Store) { } ngOnInit() { } + fileChanged(e: any) { + this.file = e.target.files[0]; + this.fileData.emit(this.file); + } + } -- cgit 1.2.3-korg