2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2019 Orange. All rights reserved.
5 ===================================================================
7 Unless otherwise specified, all software contained herein is licensed
8 under the Apache License, Version 2.0 (the License);
9 you may not use this software except in compliance with the License.
10 You may obtain a copy of the License at
12 http://www.apache.org/licenses/LICENSE-2.0
14 Unless required by applicable law or agreed to in writing, software
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
19 ============LICENSE_END============================================
22 import {Component, OnInit} from '@angular/core';
23 import {FilesContent, FolderNodeElement, MetaDataFile, MetaDataTab} from './mapping-models/metadata/MetaDataTab.model';
24 // import {saveAs} from 'file-saver/dist/FileSaver';
25 import * as JSZip from 'jszip';
26 import {Observable} from 'rxjs';
27 import {ApiService} from '../../../../common/core/services/api.service';
28 import {BlueprintURLs} from '../../../../common/constants/app-constants';
29 import {Import, Metadata, VlbDefinition} from './mapping-models/definitions/VlbDefinition';
30 import {JsonConvert} from 'json2typescript';
31 import {JsonPipe} from '@angular/common';
32 import {PackageCreationService} from './package-creation.service';
33 import {PackageCreationUtils} from './package-creation.utils';
36 selector: 'app-package-creation',
37 templateUrl: './package-creation.component.html',
38 styleUrls: ['./package-creation.component.css']
40 export class PackageCreationComponent implements OnInit {
42 modes: string[] = ['Designer Mode', 'Scripting Mode'];
43 dictionaryLibraryInstances: string[] = ['x', 'y'];
44 private target: HTMLElement;
45 private newElement: HTMLElement;
46 private metaDataTab: MetaDataTab = new MetaDataTab();
48 private result: string;
50 private folder: FolderNodeElement = new FolderNodeElement();
51 private zipFile: JSZip = new JSZip();
52 private filesData: any = [];
55 constructor(private packageCreationService: PackageCreationService, private packageCreationUtils: PackageCreationUtils) {
62 createAnotherCustomKeyDiv() {
63 console.log(this.metaDataTab);
64 this.newElement = document.createElement('div');
65 this.newElement.setAttribute('class', 'alert-dark');
66 this.target = document.getElementById('target');
67 this.target.appendChild(this.newElement);
68 this.metaDataTab = new MetaDataTab();
69 this.metaDataTab.name = 'klfdj';
70 this.metaDataTab.entryFileName = 'Definitions/vLB_CDS.json';
71 this.metaDataTab.description = 'rere';
72 this.metaDataTab.tags = 'ffsssssss';
73 this.metaDataTab.version = '1.01.10';
74 this.metaDataTab.templateName = 'test';
77 this.saveToFileSystem(MetaDataFile.getObjectInstance(this.metaDataTab));
80 validatePacakgeName() {
84 getDictionaryLibraryInstances() {
93 private saveToFileSystem(response) {
95 const filename = 'TOSCA.meta';
96 FilesContent.putData(filename, response);
98 const filenameEntry = 'vLB_CDS.json';
99 const vlbDefinition: VlbDefinition = new VlbDefinition();
100 const metadata: Metadata = new Metadata();
102 metadata.templateAuthor = ' lldkslds';
103 metadata.templateName = ' lldkslds';
104 metadata.templateTags = ' lldkslds';
105 metadata.templateVersion = ' lldkslds';
106 metadata['author-email'] = ' lldkslds';
107 metadata['user-groups'] = ' lldkslds';
108 vlbDefinition.metadata = metadata;
110 vlbDefinition.imports = [{
111 file: 'Definitions/data_types.json'
114 const value = this.packageCreationUtils.transformToJson(vlbDefinition);
115 FilesContent.putData(filenameEntry, value);
117 this.filesData.push(this.folder.TREE_DATA);
118 this.saveToBackend();
124 this.zipFile.generateAsync({type: 'blob'})
126 const formData = new FormData();
127 formData.append('file', blob);
128 this.packageCreationService.saveBlueprint(formData)
131 console.log('Success:' + JSON.stringify(data));
133 console.log('Error -' + error.message);
141 this.folder.TREE_DATA.forEach((path) => {
143 const name = path.name;
145 this.zipFile.folder(name);
146 path.children.forEach(children => {
147 const name2 = children.name;
148 console.log(FilesContent.getMapOfFilesNamesAndContent());
150 if (FilesContent.getMapOfFilesNamesAndContent().has(name2)) {
151 this.zipFile.file(name + '/' + name2, FilesContent.getMapOfFilesNamesAndContent().get(name2));
162 searchPackages($event: Event) {
163 const searchQuery = event.target.value;
164 searchQuery = searchQuery.trim();
165 this.packagesStore.search(searchQuery);