diff options
author | Swapnali Shadanan Pode <sp00501638@techmahindra.com> | 2019-03-07 15:43:32 +0530 |
---|---|---|
committer | Swapnali Shadanan Pode <sp00501638@techmahindra.com> | 2019-03-07 15:43:32 +0530 |
commit | 3a5ecdcf6129611e1f8a016bd4e5260c1096af88 (patch) | |
tree | dc1cb3f24ae8d4c097808b506dfd1ca2ceab95c8 /cds-ui/client | |
parent | ab1ed5de2918c7f199433e3853b1a19b673ba24b (diff) |
Upload file
Change-Id: Icaab7e8800fac9a82ebe38709aacc550da9f43fa
Issue-ID: CCSDK-808
Signed-off-by: sp00501638 <sp00501638@techmahindra.com>
Diffstat (limited to 'cds-ui/client')
4 files changed, 45 insertions, 15 deletions
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 @@ </mat-step> <mat-step [stepControl]="step2FormGroup"> <ng-template matStepLabel>Browse or Search Resources</ng-template> - <app-upload-resource (change)="fileChange(fileupload.files)"></app-upload-resource><br><br> + <app-upload-resource (fileData)=upload($event)></app-upload-resource><br><br> <app-existing-model></app-existing-model> <div> - <button mat-button matStepperNext class="matStepNextBtn">Upload</button> + <button mat-button matStepperNext (click)="updateResourcesState()" class="matStepNextBtn">Upload</button> </div> </mat-step> </mat-vertical-stepper> 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<IAppState>) { } 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 @@ */--> -<input type="file" accept=".json"> +<div> + <input #myInput type="file" accept=".json" (change)="fileChanged($event)"> +</div>
\ 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<IResourcesState>; + + constructor(private store: Store<IAppState>) { } ngOnInit() { } + fileChanged(e: any) { + this.file = e.target.files[0]; + this.fileData.emit(this.file); + } + } |