From e767206483553cab2127e5094fb5e430e62598ca Mon Sep 17 00:00:00 2001 From: Ezhilarasi Date: Mon, 11 Mar 2019 20:11:56 +0530 Subject: Editor mode for all type files Change-Id: I51f478f8a6b042d5137dae15d197a60f6ea35822 Issue-ID: CCSDK-1135 Signed-off-by: Ezhilarasi --- .../modify-template/editor/editor.component.ts | 45 ++++++++++++++++++---- 1 file changed, 37 insertions(+), 8 deletions(-) (limited to 'cds-ui/client/src/app/feature-modules/blueprint/modify-template/editor/editor.component.ts') 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 ac701806e..5092a698e 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 @@ -79,6 +79,8 @@ export class EditorComponent implements OnInit { selectedFile: string; zipFolder: any; blueprintName: string; + fileExtension: string; + mode: string; private zipFile: JSZip = new JSZip(); private transformer = (node: Node, level: number) => { @@ -145,22 +147,21 @@ export class EditorComponent implements OnInit { // this.editor.getEditor().getSession().setMode("ace/mode/json"); this.editor.getEditor().getSession().setTabSize(2); this.editor.getEditor().getSession().setUseWrapMode(true); - // this.editor.getEditor().setValue(JSON.stringify(this.blueprintdata, null, '\t')); - // console.log(this.text); + this.setEditorMode(); }) } updateBlueprint() { console.log(this.blueprint); - this.filesData.forEach(fileNode=>{ - if(fileNode.name.includes(this.blueprintName.trim()) && fileNode.name.includes(this.selectedFile.trim())) { + this.filesData.forEach(fileNode => { + if (fileNode.name.includes(this.blueprintName.trim()) && fileNode.name.includes(this.selectedFile.trim())) { fileNode.data = this.text; - } else if(fileNode.name.includes(this.selectedFile.trim())) { + } else if (fileNode.name.includes(this.selectedFile.trim())) { fileNode.data = this.text; } }); - if(this.selectedFile == this.blueprintName) { + if (this.selectedFile == this.blueprintName) { this.blueprint = JSON.parse(this.text); } else { this.blueprint = this.blueprintdata; @@ -183,12 +184,15 @@ export class EditorComponent implements OnInit { this.text = fileNode.data; } }) + this.fileExtension = this.selectedFile.substr(this.selectedFile.lastIndexOf('.') + 1); + // console.log(this.fileExtension); + this.setEditorMode(); } SaveToBackend() { this.zipFile.generateAsync({ type: "blob" }) .then(blob => { - + }); } @@ -196,7 +200,7 @@ export class EditorComponent implements OnInit { // to do } - create() { + create() { this.filesData.forEach((path) => { this.zipFile.file(path.name, path.data); }); @@ -210,4 +214,29 @@ export class EditorComponent implements OnInit { saveAs(blob, zipFilename); }); } + setEditorMode() { + switch (this.fileExtension) { + case "xml": + // console.log("xml mode set"); + this.mode = 'xml'; + break; + case "py": + console.log("python mode set"); + this.mode = 'python'; + break; + case "kts": + // console.log("kotlin mode set"); + this.mode = 'kotlin'; + break; + case "txt": + this.mode = 'text'; + break; + case "meta": + this.mode = 'text'; + break; + default: + this.mode = 'json'; + console.log("json mode set"); + } + } } -- cgit 1.2.3-korg