summaryrefslogtreecommitdiffstats
path: root/cds-ui/client/src/app/feature-modules/blueprint/modify-template/editor/editor.component.ts
diff options
context:
space:
mode:
authorArundathi Patil <arundpil@in.ibm.com>2019-03-25 12:36:31 +0530
committerIBM602-PC0F1E3C\Arundathi <arundpil@in.ibm.com>2019-03-25 12:36:42 +0530
commitb49e0b0491f9521b90d2dff36289e8e3539b992e (patch)
tree23573d4566a5f9b2d89ff8e39c0e924b41fc2784 /cds-ui/client/src/app/feature-modules/blueprint/modify-template/editor/editor.component.ts
parentffb6bdfd6de2afa23d95d0884c9db4059982deed (diff)
File/folder add/delete
Implemented add/delete folder/file feature Issue-ID: CCSDK-1171 Change-Id: Ibbadd3d933291a98cc07f9444962c0ebcbca7d1f 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.ts116
1 files changed, 113 insertions, 3 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 e48177d0a..eaac8cbde 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
@@ -83,6 +83,11 @@ export class EditorComponent implements OnInit {
mode: string;
private zipFile: JSZip = new JSZip();
activeNode: any;
+ selectedFolder: string;
+ activationBlueprint: string;
+ isNameTextboxEnablled : boolean = false;
+ fileAction : string;
+ filetoDelete : string;
private transformer = (node: Node, level: number) => {
return {
@@ -155,14 +160,14 @@ export class EditorComponent implements OnInit {
updateBlueprint() {
console.log(this.blueprint);
this.filesData.forEach(fileNode => {
- if (fileNode.name.includes(this.blueprintName.trim()) && fileNode.name.includes(this.selectedFile.trim())) {
+ if (this.selectedFile && 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 (this.selectedFile && fileNode.name.includes(this.selectedFile.trim())) {
fileNode.data = this.text;
}
});
- if (this.selectedFile == this.blueprintName.trim()) {
+ if (this.selectedFile && this.selectedFile == this.blueprintName.trim()) {
this.blueprint = JSON.parse(this.text);
} else {
this.blueprint = this.blueprintdata;
@@ -180,6 +185,7 @@ export class EditorComponent implements OnInit {
selectFileToView(file) {
this.selectedFile = file.name;
+ this.filetoDelete = file.name;
this.filesData.forEach((fileNode) => {
if (fileNode.name.includes(file.name)) {
this.text = fileNode.data;
@@ -239,4 +245,108 @@ export class EditorComponent implements OnInit {
this.mode = 'json';
}
}
+
+ selectFolder(node) {
+ this.selectedFolder = node.name;
+ this.filetoDelete = node.name;
+ console.log(node);
+ // this.createFolderOrFile(node.name, 'folder');
+ }
+
+ createFolderOrFile(name) {
+ let newFilesData: [any] = this.filesData;
+ let newFileNode = {
+ name: '',
+ data: ''
+ }
+ let newFileNode1 = {
+ name: '',
+ data: ''
+ }
+ for(let i=0; i< this.filesData.length; i++) {
+ if (this.filesData[i].name.includes(this.selectedFolder)) {
+ if(this.fileAction == 'createFolder') {
+ newFileNode.name = this.filesData[i].name + name.srcElement.value + '/';
+ newFileNode.data = '';
+
+ newFileNode1.name = this.filesData[i].name + name.srcElement.value + '/README.md'
+ newFileNode1.data = name.srcElement.value + ' Folder';
+ } else {
+ newFileNode.name = this.filesData[i].name + name.srcElement.value;
+ newFileNode.data = '';
+ }
+ break;
+ }
+ }
+
+ this.filesData.splice(this.findIndexForNewNode()+1, 0, newFileNode);
+ this.filesData.splice(this.findIndexForNewNode()+1, 0, newFileNode1);
+ this.arrangeTreeData(this.filesData);
+ }
+
+ findIndexForNewNode() {
+ let indexForNewNode;
+ for(let i=0; i< this.filesData.length; i++) {
+ if (this.filesData[i].name.includes(this.selectedFolder)) {
+ indexForNewNode = i;
+ }
+ }
+ return indexForNewNode;
+ }
+
+ arrangeTreeData(paths) {
+ const tree = [];
+
+ paths.forEach((path) => {
+
+ const pathParts = path.name.split('/');
+ // pathParts.shift();
+ let currentLevel = tree;
+
+ pathParts.forEach((part) => {
+ const existingPath = currentLevel.filter(level => level.name === part);
+
+ if (existingPath.length > 0) {
+ currentLevel = existingPath[0].children;
+ } else {
+ const newPart = {
+ name: part,
+ children: [],
+ data: path.data,
+ path : path.name
+ };
+ if(part.trim() == this.blueprintName.trim()) {
+ this.activationBlueprint = path.data;
+ newPart.data = JSON.parse(this.activationBlueprint.toString());
+ console.log('newpart', newPart);
+ }
+ if(newPart.name !== '') {
+ currentLevel.push(newPart);
+ currentLevel = newPart.children;
+ }
+ }
+ });
+ });
+ this.dataSource.data = tree;
+ this.filesTree = tree;
+ this.isNameTextboxEnablled = false;
+ this.updateBlueprint();
+ }
+
+ enableNameInputEl(action) {
+ this.fileAction = action;
+ if (action == 'createFolder' || action == 'createFile') {
+ this.isNameTextboxEnablled = true;
+ }
+ }
+
+ deleteFolderOrFile(action) {
+ for(let i=0;i< this.filesData.length ; i++) {
+ if(this.filesData[i].name.includes(this.filetoDelete.trim())) {
+ this.filesData.splice(i, 1);
+ i = i-1;
+ }
+ }
+ this.arrangeTreeData(this.filesData);
+ }
}