diff options
Diffstat (limited to 'cds-ui/designer-client/src/app/modules')
8 files changed, 105 insertions, 137 deletions
diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/creationModes/PackageCreation.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/creationModes/PackageCreation.ts new file mode 100644 index 000000000..e1d28105f --- /dev/null +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/creationModes/PackageCreation.ts @@ -0,0 +1,13 @@ +import {CBAPackage} from '../mapping-models/CBAPacakge.model'; + +export abstract class PackageCreation { + + abstract setModeType(cbaPackage: CBAPackage); + + abstract setEntryPoint(cbaPackage: CBAPackage); + + createToscaMetaData(cbaPackage: CBAPackage) { + + } + +} diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/imports-tab/imports-tab.component.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/imports-tab/imports-tab.component.ts index 4db67b8dc..a8ba164f3 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/imports-tab/imports-tab.component.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/imports-tab/imports-tab.component.ts @@ -1,7 +1,7 @@ -import { Component, OnInit } from '@angular/core'; -import { NgxFileDropEntry, FileSystemFileEntry, FileSystemDirectoryEntry } from 'ngx-file-drop'; -import { PackageCreationStore } from '../package-creation.store'; -import { PackageCreationUtils } from '../package-creation.utils'; +import {Component, OnInit} from '@angular/core'; +import {FileSystemFileEntry, NgxFileDropEntry} from 'ngx-file-drop'; +import {PackageCreationStore} from '../package-creation.store'; +import {PackageCreationUtils} from '../package-creation.utils'; @Component({ @@ -19,8 +19,8 @@ export class ImportsTabComponent implements OnInit { constructor(private packageCreationStore: PackageCreationStore, private packageCreationUtils: PackageCreationUtils) { this.packageCreationStore.state$.subscribe(cbaPackage => { - if (cbaPackage.definitions && cbaPackage.definitions.files && cbaPackage.definitions.files.size > 0) { - this.definitionFiles = cbaPackage.definitions.files; + if (cbaPackage.definitions && cbaPackage.definitions.imports && cbaPackage.definitions.imports.size > 0) { + this.definitionFiles = cbaPackage.definitions.imports; } }); } @@ -65,7 +65,7 @@ export class ImportsTabComponent implements OnInit { removeFile(fileIndex: number) { console.log(this.uploadedFiles[fileIndex]); console.log(this.uploadedFiles); - this.packageCreationStore.removeFromState(this.uploadedFiles[fileIndex].name, 'definitions'); + this.packageCreationStore.removeFileFromDefinition(this.uploadedFiles[fileIndex].name); this.uploadedFiles.splice(fileIndex, 1); } @@ -76,6 +76,7 @@ export class ImportsTabComponent implements OnInit { public fileLeave(event) { console.log(event); } + /* readFileContent(file: File): string | ArrayBuffer { const fileReader = new FileReader(); // let content: string | ArrayBuffer = ''; diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/CBAPacakge.model.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/CBAPacakge.model.ts index cbb82f118..a5f5ec70a 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/CBAPacakge.model.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/CBAPacakge.model.ts @@ -1,19 +1,39 @@ - import {MetaDataTabModel} from './metadata/MetaDataTab.model'; export class Definition { - public files: Map<string, string> = new Map<string, string>(); - constructor(files: Map<string, string>) { - this.files = files; + public metaDataTab: MetaDataTabModel; + public imports: Map<string, string>; + + // public dslDefinition: + + constructor() { + this.imports = new Map<string, string>(); + this.metaDataTab = new MetaDataTabModel(); + } + + public setImports(key: string, value: string) { + this.imports.set(key, value); + return this; + } + + public setMetaData(metaDataTab: MetaDataTabModel) { + this.metaDataTab = metaDataTab; + return this; } + } export class Scripts { - public files: Map<string, string> = new Map<string, string>(); + public files: Map<string, string>; - constructor(files: Map<string, string>) { - this.files = files; + constructor() { + this.files = new Map<string, string>(); + } + + public setScripts(key: string, value: string) { + this.files.set(key, value); + return this; } } @@ -23,12 +43,14 @@ export class CBAPackage { public definitions: Definition; public scripts: Scripts; + constructor() { - this.definitions = new Definition(new Map<string, string>()); - this.scripts = new Scripts(new Map<string, string>()); + this.definitions = new Definition(); + this.scripts = new Scripts(); this.metaData = new MetaDataTabModel(); } + } diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/metadata/MetaDataTab.model.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/metadata/MetaDataTab.model.ts index c62694213..194e660c7 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/metadata/MetaDataTab.model.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/metadata/MetaDataTab.model.ts @@ -45,7 +45,7 @@ Content-Type: application/vnd.oasis.bpmn*/ export class MetaDataFile { - static getObjectInstance(metaDataTab: MetaDataTabModel): string { + static getValueOfMetaData(metaDataTab: MetaDataTabModel): string { return 'TOSCA-Meta-File-Version: 1.0.0\n' + 'CSAR-Version: 1.0\n' + 'Created-By: Shaaban Ebrahim <shaaban.eltanany.ext@orange.con>\n' + @@ -109,7 +109,7 @@ export class FolderNodeElement { export class FilesContent { - public static mapOfFilesNamesAndContent: Map<string, string> = new Map<string, string>(); + private static mapOfFilesNamesAndContent: Map<string, string> = new Map<string, string>(); public static getMapOfFilesNamesAndContent(): Map<string, string> { return FilesContent.mapOfFilesNamesAndContent; diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/metadata-tab/metadata-tab.component.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/metadata-tab/metadata-tab.component.ts index 894716711..710ca924a 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/metadata-tab/metadata-tab.component.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/metadata-tab/metadata-tab.component.ts @@ -1,9 +1,6 @@ import {Component, OnInit} from '@angular/core'; import {PackageCreationService} from '../package-creation.service'; -import {PackageCreationUtils} from '../package-creation.utils'; -import {Router} from '@angular/router'; -import {FilesContent, FolderNodeElement, MetaDataFile, MetaDataTabModel} from '../mapping-models/metadata/MetaDataTab.model'; -import * as JSZip from 'jszip'; +import {MetaDataTabModel} from '../mapping-models/metadata/MetaDataTab.model'; import {PackageCreationStore} from '../package-creation.store'; @@ -19,14 +16,9 @@ export class MetadataTabComponent implements OnInit { {name: 'Designer Mode', style: 'mode-icon icon-designer-mode'}, {name: 'Scripting Mode', style: 'mode-icon icon-scripting-mode'}]; private metaDataTab: MetaDataTabModel = new MetaDataTabModel(); - - private folder: FolderNodeElement = new FolderNodeElement(); - private zipFile: JSZip = new JSZip(); - private filesData: any = []; private errorMessage: string; - constructor(private packageCreationService: PackageCreationService, private packageCreationUtils: PackageCreationUtils, - private router: Router, private packageCreationStore: PackageCreationStore) { + constructor(private packageCreationService: PackageCreationService, private packageCreationStore: PackageCreationStore) { } @@ -34,94 +26,6 @@ export class MetadataTabComponent implements OnInit { this.packageCreationStore.changeMetaData(this.metaDataTab); } - saveMetaData() { - this.setModeType(this.metaDataTab); - this.setEntryPoint(this.metaDataTab); - - this.addToscaMetaDataFile(this.metaDataTab); - - // const vlbDefinition: VlbDefinition = new VlbDefinition(); - // this.fillVLBDefinition(vlbDefinition, this.metaDataTab); - - this.filesData.push(this.folder.TREE_DATA); - this.saveBluePrint(); - this.packageCreationService.refreshPackages(); - this.router.navigate(['/packages']); - - } - - addToscaMetaDataFile(metaDataTab: MetaDataTabModel) { - const filename = 'TOSCA.meta'; - FilesContent.putData(filename, MetaDataFile.getObjectInstance(this.metaDataTab)); - } - - private setModeType(metaDataTab: MetaDataTabModel) { - if (metaDataTab.mode.startsWith('Scripting')) { - metaDataTab.mode = 'KOTLIN_SCRIPT'; - } else if (metaDataTab.mode.startsWith('Designer')) { - metaDataTab.mode = 'DEFAULT'; - } else { - metaDataTab.mode = 'GENERIC_SCRIPT'; - } - } - - saveBluePrint() { - this.create(); - this.zipFile.generateAsync({type: 'blob'}) - .then(blob => { - this.packageCreationService.savePackage(blob); - - }); - } - - - create() { - this.folder.TREE_DATA.forEach((path) => { - - const name = path.name; - if (path.children) { - this.zipFile.folder(name); - path.children.forEach(children => { - const name2 = children.name; - if (FilesContent.getMapOfFilesNamesAndContent().has(name2)) { - this.zipFile.file(name + '/' + name2, FilesContent.getMapOfFilesNamesAndContent().get(name2)); - } else { - } - - }); - - } - }); - } - - private setEntryPoint(metaDataTab: MetaDataTabModel) { - if (metaDataTab.mode.startsWith('DEFAULT')) { - metaDataTab.entryFileName = 'Definitions/vLB_CDS.json'; - } else { - metaDataTab.entryFileName = ''; - } - - - } - - /* private fillVLBDefinition(vlbDefinition: VlbDefinition, metaDataTab: MetaDataTabModel) { - - const metadata: Metadata = new Metadata(); - metadata.template_author = 'Shaaban'; - metadata.template_name = metaDataTab.templateName; - metadata.template_tags = metaDataTab.tags; - - metadata.dictionary_group = 'default'; - metadata.template_version = metaDataTab.version; - metadata['author-email'] = 'shaaban.altanany.ext@orange.com'; - metadata['user-groups'] = 'ADMIN'; - vlbDefinition.tosca_definitions_version = metaDataTab.version; - vlbDefinition.metadata = metadata; - const value = this.packageCreationUtils.transformToJson(vlbDefinition); - console.log(value); - FilesContent.putData('vLB_CDS.json', value); - }*/ - validatePackageNameAndVersion() { if (this.metaDataTab.name && this.metaDataTab.version) { this.packageCreationService.checkBluePrintNameAndVersion(this.metaDataTab.name, this.metaDataTab.version).then(element => { diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.component.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.component.ts index aa44cdf7c..cdf8cf38b 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.component.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.component.ts @@ -24,6 +24,7 @@ import {FilesContent, FolderNodeElement, MetaDataFile, MetaDataTabModel} from '. // import {saveAs} from 'file-saver/dist/FileSaver'; import * as JSZip from 'jszip'; import {PackageCreationStore} from './package-creation.store'; +import {Definition} from './mapping-models/CBAPacakge.model'; @Component({ selector: 'app-package-creation', @@ -39,6 +40,7 @@ export class PackageCreationComponent implements OnInit { private folder: FolderNodeElement = new FolderNodeElement(); private zipFile: JSZip = new JSZip(); private filesData: any = []; + private definition: Definition = new Definition(); constructor(private packageCreationStore: PackageCreationStore) { } @@ -50,28 +52,31 @@ export class PackageCreationComponent implements OnInit { saveBluePrint() { this.packageCreationStore.state$.subscribe( cbaPackage => { + console.log(cbaPackage); this.metaDataTab = cbaPackage.metaData; this.setModeType(this.metaDataTab); this.setEntryPoint(this.metaDataTab); - this.addToscaMetaDataFile(this.metaDataTab); + this.definition = cbaPackage.definitions; + this.definition.metaDataTab = cbaPackage.metaData; + this.createDefinitionsFolder(this.definition); // const vlbDefinition: VlbDefinition = new VlbDefinition(); // this.fillVLBDefinition(vlbDefinition, this.metaDataTab); this.filesData.push(this.folder.TREE_DATA); - console.log(FilesContent.getMapOfFilesNamesAndContent()); this.saveBluePrintToDataBase(); }); } - addToscaMetaDataFile(metaDataTab: MetaDataTabModel) { - const filename = 'TOSCA.meta'; - FilesContent.putData(filename, MetaDataFile.getObjectInstance(this.metaDataTab)); + private addToscaMetaDataFile(metaDataTab: MetaDataTabModel) { + const filename = 'TOSCA-Metadata/TOSCA.meta'; + FilesContent.putData(filename, MetaDataFile.getValueOfMetaData(metaDataTab)); } +// TODO use enumerator private setModeType(metaDataTab: MetaDataTabModel) { if (metaDataTab.mode.startsWith('Scripting')) { metaDataTab.mode = 'KOTLIN_SCRIPT'; @@ -82,6 +87,14 @@ export class PackageCreationComponent implements OnInit { } } + private setEntryPoint(metaDataTab: MetaDataTabModel) { + if (metaDataTab.mode.startsWith('DEFAULT')) { + metaDataTab.entryFileName = 'Definitions/vLB_CDS.json'; + } else { + metaDataTab.entryFileName = ''; + } + } + saveBluePrintToDataBase() { this.create(); this.zipFile.generateAsync({type: 'blob'}) @@ -93,7 +106,6 @@ export class PackageCreationComponent implements OnInit { create() { this.folder.TREE_DATA.forEach((path) => { - const name = path.name; if (path.children) { this.zipFile.folder(name); @@ -110,15 +122,29 @@ export class PackageCreationComponent implements OnInit { }); } - private setEntryPoint(metaDataTab: MetaDataTabModel) { - if (metaDataTab.mode.startsWith('DEFAULT')) { - metaDataTab.entryFileName = 'Definitions/vLB_CDS.json'; - } else { - metaDataTab.entryFileName = ''; - } + private createDefinitionsFolder(definition: Definition) { + this.definition.imports.forEach((key, value) => { + FilesContent.putData(key, value); + }); + /*const filenameEntry = 'vLB_CDS.json'; + const vlbDefinition: VlbDefinition = new VlbDefinition(); + const metadata: MetaDataTabModel = new MetaDataTabModel(); - } + metadata.templateAuthor = ' lldkslds'; + metadata.templateName = ' lldkslds'; + metadata.templateTags = ' lldkslds'; + metadata.templateVersion = ' lldkslds'; + metadata['author-email'] = ' lldkslds'; + metadata['user-groups'] = ' lldkslds'; + vlbDefinition.metadata = metadata; + vlbDefinition.imports = [{ + file: 'Definitions/data_types.json' + }]; + + const value = this.packageCreationUtils.transformToJson(vlbDefinition); + FilesContent.putData(filenameEntry, value);*/ + } } diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.store.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.store.ts index f19ada820..93998e8a9 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.store.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.store.ts @@ -23,7 +23,7 @@ import {Injectable} from '@angular/core'; import {Store} from '../../../../common/core/stores/Store'; -import {CBAPackage, Definition, Scripts} from './mapping-models/CBAPacakge.model'; +import {CBAPackage} from './mapping-models/CBAPacakge.model'; import {PackageCreationService} from './package-creation.service'; import {FolderNodeElement, MetaDataTabModel} from './mapping-models/metadata/MetaDataTab.model'; import * as JSZip from 'jszip'; @@ -53,7 +53,7 @@ export class PackageCreationStore extends Store<CBAPackage> { this.setState({ ...this.state, - definitions: new Definition(this.state.definitions.files.set(name, content)) + definitions: this.state.definitions.setImports(name, content) }); } @@ -61,15 +61,17 @@ export class PackageCreationStore extends Store<CBAPackage> { this.setState({ ...this.state, - scripts: new Scripts(this.state.scripts.files.set(name, content)) + scripts: this.state.scripts.setScripts(name, content) }); } - // type => refer to scripts || definitions - // from Files from scripts or imports - removeFromState(name: string, type: string) { - this.state[type].files.delete(name); + removeFileFromState(name: string) { + this.state.scripts.files.delete(name); + } + + removeFileFromDefinition(filename) { + this.state.definitions.imports.delete(filename); } saveBluePrint(blob) { diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/scripts-tab/scripts-tab.component.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/scripts-tab/scripts-tab.component.ts index d4d2b20d0..43b9b503c 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/scripts-tab/scripts-tab.component.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/scripts-tab/scripts-tab.component.ts @@ -43,7 +43,7 @@ export class ScriptsTabComponent implements OnInit { removeFile(fileIndex: number) { console.log(this.uploadedFiles[fileIndex]); - this.packageCreationStore.removeFromState(this.uploadedFiles[fileIndex].name, 'scripts'); + this.packageCreationStore.removeFileFromState(this.uploadedFiles[fileIndex].name); this.uploadedFiles.splice(fileIndex, 1); } |