diff options
author | 2019-03-07 21:34:43 +0530 | |
---|---|---|
committer | 2019-03-07 21:34:56 +0530 | |
commit | c2ac1e52d88e4d590e2fa0e29b9af1431afef0dc (patch) | |
tree | 24c855e2a14a42cab9bf2194c5edcf7d34526a5b /cds-ui/client/src/app/feature-modules/blueprint/modify-template/editor/editor.component.ts | |
parent | 7e06008a45d6767919fccdffb6d95e591a78a680 (diff) |
File Download
Added file download functionality
Issue-ID: CCSDK-759
Change-Id: I9106ce4f6229c7d848e5bef9a1842444ca828934
Signed-off-by: Arundathi Patil <arundpil@in.ibm.com>
Diffstat (limited to 'cds-ui/client/src/app/feature-modules/blueprint/modify-template/editor/editor.component.ts')
-rw-r--r-- | cds-ui/client/src/app/feature-modules/blueprint/modify-template/editor/editor.component.ts | 131 |
1 files changed, 98 insertions, 33 deletions
diff --git a/cds-ui/client/src/app/feature-modules/blueprint/modify-template/editor/editor.component.ts b/cds-ui/client/src/app/feature-modules/blueprint/modify-template/editor/editor.component.ts index 46dca73dd..96aececcf 100644 --- a/cds-ui/client/src/app/feature-modules/blueprint/modify-template/editor/editor.component.ts +++ b/cds-ui/client/src/app/feature-modules/blueprint/modify-template/editor/editor.component.ts @@ -27,18 +27,61 @@ import "ace-builds/webpack-resolver"; import 'brace'; import 'brace/ext/language_tools'; import 'ace-builds/src-min-noconflict/snippets/html'; +import * as JSZip from 'jszip'; +import { saveAs } from 'file-saver'; + import { IAppState } from '../../../../common/core/store/state/app.state'; import { Store } from '@ngrx/store'; import { Observable } from 'rxjs'; import { IBlueprintState } from 'src/app/common/core/store/models/blueprintState.model'; -import { LoadBlueprintSuccess } from '../../../../common/core/store/actions/blueprint.action'; +import { LoadBlueprintSuccess } from '../../../../common/core/store/actions/blueprint.action' interface FoodNode { name: string; children?: FoodNode[]; + data?: any } +// const TREE_DATA: FoodNode[] = [ +// { +// name: 'Definitions', +// children: [ +// { name: 'activation-blueprint.json' }, +// { name: 'artifacts_types.json' }, +// { name: 'data_types.json' }, +// ] +// }, +// { +// name: 'Scripts', +// children: [ +// { +// name: 'kotlin', +// children: [ +// { name: 'ScriptComponent.cba.kts' }, +// { name: 'ResourceAssignmentProcessor.cba.kts' }, +// ] +// } +// ] +// }, +// { +// name: 'Templates', +// children: [ +// { +// name: 'baseconfig-template' +// } +// ] +// }, +// { +// name: 'TOSCA-Metada', +// children: [ +// { +// name: 'TOSCA.meta' +// } +// ] +// }, +// ]; + const TREE_DATA: FoodNode[] = [ { name: 'Definitions', @@ -47,35 +90,7 @@ const TREE_DATA: FoodNode[] = [ { name: 'artifacts_types.json' }, { name: 'data_types.json' }, ] - }, - { - name: 'Scripts', - children: [ - { - name: 'kotlin', - children: [ - { name: 'ScriptComponent.cba.kts' }, - { name: 'ResourceAssignmentProcessor.cba.kts' }, - ] - } - ] - }, - { - name: 'Templates', - children: [ - { - name: 'baseconfig-template' - } - ] - }, - { - name: 'TOSCA-Metada', - children: [ - { - name: 'TOSCA.meta' - } - ] - }, + } ]; /** Flat node with expandable and level information */ @@ -98,6 +113,11 @@ export class EditorComponent implements OnInit { blueprint: IBlueprint; bpState: Observable<IBlueprintState>; text: string; + filesTree: any = []; + filesData: any = []; + selectedFile: string; + zipFolder: any; + private zipFile: JSZip = new JSZip(); private transformer = (node: FoodNode, level: number) => { return { @@ -118,12 +138,14 @@ export class EditorComponent implements OnInit { constructor(private store: Store<IAppState>) { this.dataSource.data = TREE_DATA; this.bpState = this.store.select('blueprint'); + // this.dataSource.data = TREE_DATA; } hasChild = (_: number, node: ExampleFlatNode) => node.expandable; ngOnInit() { this.editorContent(); + this.dataSource.data = this.filesTree; } fileClicked(file) { @@ -147,6 +169,9 @@ export class EditorComponent implements OnInit { blueprintdata => { var blueprintState: IBlueprintState = { blueprint: blueprintdata.blueprint, isLoadSuccess: blueprintdata.isLoadSuccess, isSaveSuccess: blueprintdata.isSaveSuccess, isUpdateSuccess: blueprintdata.isUpdateSuccess }; this.blueprintdata = blueprintState.blueprint; + this.filesTree = blueprintdata.files; + this.filesData = blueprintdata.filesData; + this.dataSource.data = this.filesTree; let blueprint = []; for (let key in this.blueprintdata) { if (this.blueprintdata.hasOwnProperty(key)) { @@ -161,10 +186,50 @@ export class EditorComponent implements OnInit { // console.log(this.text); }) } - - updateBlueprint(){ + + updateBlueprint() { + if (this.selectedFile == 'activation-blueprint.json') { + // to do + } else { + // to do + } this.blueprint = JSON.parse(this.text); this.store.dispatch(new LoadBlueprintSuccess(this.blueprint)); // console.log(this.text); - } + } + + selectFileToView(file) { + this.selectedFile = file.name; + this.filesData.forEach((fileNode) => { + if (fileNode.name.includes(file.name)) { + this.text = fileNode.data; + } + }) + } + + SaveToBackend() { + this.zipFile.generateAsync({ type: "blob" }) + .then(blob => { + + }); + } + + deploy() { + // to do + } + + create() { + this.filesData.forEach((path) => { + this.zipFile.file(path.name, path.data); + }); + } + + download() { + this.create(); + var zipFilename = "baseconfiguration.zip"; + this.zipFile.generateAsync({ type: "blob" }) + .then(blob => { + saveAs(blob, zipFilename); + }); + } } |