diff options
author | ShaabanEltanany <shaaban.eltanany.ext@orange.com> | 2020-09-22 11:56:38 +0200 |
---|---|---|
committer | ShaabanEltanany <shaaban.eltanany.ext@orange.com> | 2020-09-22 22:29:23 +0200 |
commit | 81d82489f5592770a9e5f9ee137bfc1558b48153 (patch) | |
tree | 0cb464ad59e1477462faa4c0f2e409431b5821eb /cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation | |
parent | 2c2fa8779bc21dabbe8b5367eca5dec55afae3c2 (diff) |
adding saving simple function at designer
Issue-ID: CCSDK-2298
Signed-off-by: ShaabanEltanany <shaaban.eltanany.ext@orange.com>
Change-Id: Id4ebd3413103d6433e84b3513c4f651176a9833f
Diffstat (limited to 'cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation')
9 files changed, 73 insertions, 46 deletions
diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/creationModes/DesignerCreationMode.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/creationModes/DesignerCreationMode.ts index b8938043c..e9dd667d2 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/creationModes/DesignerCreationMode.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/creationModes/DesignerCreationMode.ts @@ -87,6 +87,7 @@ export class DesignerCreationMode extends PackageCreationModes { if (cbaPackage.definitions.dslDefinition.content) { vlbDefinition.dsl_definitions = JSON.parse(cbaPackage.definitions.dslDefinition.content); } + if (cbaPackage.templateTopology.content) { vlbDefinition.topology_template = JSON.parse(cbaPackage.templateTopology.content); } diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/imports-tab/imports-tab.component.html b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/imports-tab/imports-tab.component.html index 8f2b554d9..641caf2ad 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/imports-tab/imports-tab.component.html +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/imports-tab/imports-tab.component.html @@ -74,7 +74,7 @@ <div [id]="'id-'+mapIndex" class="collapse" [attr.aria-labelledby]="'head-'+mapIndex" data-parent="#accordion"> <div class="card-body"> - <ace-editor [(text)]="file.value" (textChange)="textChanges($event,file.key)" [mode]="'json'" + <ace-editor [(text)]="file.value" readOnly="true" (textChange)="textChanges($event,file.key)" [mode]="'json'" [autoUpdateContent]="true" [durationBeforeCallback]="1000" [theme]="'eclipse'" #editor style="height:300px;"> </ace-editor> diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/definitions/VlbDefinition.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/definitions/VlbDefinition.ts index f82310872..7a029fb3f 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/definitions/VlbDefinition.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/definitions/VlbDefinition.ts @@ -1,8 +1,11 @@ -import { Any, JsonObject, JsonProperty } from 'json2typescript'; +import {JsonObject, JsonProperty} from 'json2typescript'; @JsonObject('topology_template') export class TemplateTopology { - public content: string; + // tslint:disable-next-line:variable-name + public node_templates: object; + public workflows: object; + public content: string ; } @JsonObject @@ -22,26 +25,27 @@ export class VlbDefinition { export class DslContent { } + // Refactor varaibles name and use JsonConverteri @JsonObject('metadata') export class Metadata { @JsonProperty('template_author') - // tslint:disable-next-line:variable-name + // tslint:disable-next-line:variable-name template_author: string; 'author-email': string; 'user-groups': string; @JsonProperty('template_name') - // tslint:disable-next-line:variable-name + // tslint:disable-next-line:variable-name template_name: string; @JsonProperty('template_version') - // tslint:disable-next-line:variable-name + // tslint:disable-next-line:variable-name template_version: string; @JsonProperty('template_tag') - // tslint:disable-next-line:variable-name + // tslint:disable-next-line:variable-name template_tags: string; @JsonProperty('dictionary_group') - // tslint:disable-next-line:variable-name + // tslint:disable-next-line:variable-name dictionary_group: string; @JsonProperty('template_tags') templateTags: string; 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 20cee7340..a46d2a3ec 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 @@ -55,9 +55,9 @@ export class MetadataTabComponent implements OnInit { this.customKeysMap = element.metaData.mapOfCustomKey; this.metaDataTab.mapOfCustomKey = this.customKeysMap; - if (this.isNameEditable) { - this.validatePackageNameAndVersion(); - } + /* if (this.isNameEditable) { + this.validatePackageNameAndVersion(); + }*/ // this.tags = element.metaData.templateTags; diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation-extraction.service.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation-extraction.service.ts index 31a5c3c35..b1dcded1c 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation-extraction.service.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation-extraction.service.ts @@ -13,18 +13,23 @@ import {DesignerStore} from '../designer/designer.store'; }) export class PackageCreationExtractionService { - zipFile: JSZip = new JSZip(); - entryDefinitionKeys: string[] = ['template_tags', 'user-groups', + private zipFile: JSZip = new JSZip(); + private entryDefinitionKeys: string[] = ['template_tags', 'user-groups', 'author-email', 'template_version', 'template_name', 'template_author', 'template_description']; + + private toscaMetaDataKeys: string[] = ['TOSCA-Meta-File-Version', 'CSAR-Version', + 'Created-By', 'Entry-Definitions', 'Template-Name', 'Template-Version', 'Template-Type', 'Template-Tags']; @ViewChild(MetadataTabComponent, {static: false}) - metadataTabComponent: MetadataTabComponent; + private metadataTabComponent: MetadataTabComponent; constructor(private packageCreationStore: PackageCreationStore, private packageCreationUtils: PackageCreationUtils, private designerStore: DesignerStore) { + } public extractBlobToStore(blob) { + let packageName = null; this.zipFile.loadAsync(blob).then((zip) => { Object.keys(zip.files).filter(fileName => fileName.includes('TOSCA-Metadata/')) @@ -32,6 +37,7 @@ export class PackageCreationExtractionService { zip.files[filename].async('string').then((fileData) => { if (fileData) { if (filename.includes('TOSCA-Metadata/')) { + const metaDataTabInfo: MetaDataTabModel = this.getMetaDataTabInfo(fileData); packageName = metaDataTabInfo.name; this.setMetaData(metaDataTabInfo); @@ -65,11 +71,11 @@ export class PackageCreationExtractionService { }); } - setScripts(filename: string, fileData: any) { + private setScripts(filename: string, fileData: any) { this.packageCreationStore.addScripts(filename, fileData); } - setImports(filename: string, fileData: any, packageName: string) { + private setImports(filename: string, fileData: any, packageName: string) { console.log(filename); if (filename.includes(packageName)) { let definition = new VlbDefinition(); @@ -86,37 +92,48 @@ export class PackageCreationExtractionService { this.packageCreationStore.changeDslDefinition(dslDefinition); this.packageCreationStore.setCustomKeys(mapOfCustomKeys); this.setPackageDescription(definition.metadata.template_description); - if (definition.topology_template && definition.topology_template.content) { - this.designerStore.saveSourceContent(definition.topology_template.content); - } + console.log(definition); + console.log(definition.topology_template); + const content = {}; + const workflow = 'workflows'; + content[workflow] = definition.topology_template.workflows; + const nodeTemplates = 'node_templates'; + content[nodeTemplates] = definition.topology_template.node_templates; + this.designerStore.saveSourceContent(JSON.stringify(content)); } this.packageCreationStore.addDefinition(filename, fileData); } - setTemplates(filename: string, fileData: any) { + private setTemplates(filename: string, fileData: any) { this.packageCreationStore.addTemplate(filename, fileData); } - setMapping(fileName: string, fileData: string) { + private setMapping(fileName: string, fileData: string) { this.packageCreationStore.addMapping(fileName, fileData); } - setMetaData(metaDataObject: MetaDataTabModel) { + private setMetaData(metaDataObject: MetaDataTabModel) { this.packageCreationStore.changeMetaData(metaDataObject); } - getMetaDataTabInfo(fileData: string) { + private getMetaDataTabInfo(fileData: string) { const metaDataTabModel = new MetaDataTabModel(); + const arrayOfLines = fileData.split('\n'); - metaDataTabModel.entryFileName = arrayOfLines[3].split(':')[1]; - metaDataTabModel.name = arrayOfLines[4].split(':')[1]; - metaDataTabModel.version = arrayOfLines[5].split(':')[1]; - metaDataTabModel.mode = arrayOfLines[6].split(':')[1]; - console.log(arrayOfLines[7]); - if (arrayOfLines[7].split(':')) { - metaDataTabModel.templateTags = new Set<string>(arrayOfLines[7].split(':')[1].split(',')); + const map = new Map<string, string>(); + for (const currentLine of arrayOfLines) { + const currentKey = currentLine.split(':')[0]; + const currentValue = currentLine.split(':')[1]; + map.set(currentKey, currentValue); + } + metaDataTabModel.entryFileName = map.get(this.toscaMetaDataKeys[3]); + metaDataTabModel.name = map.get(this.toscaMetaDataKeys[4]); + metaDataTabModel.version = map.get(this.toscaMetaDataKeys[5]).trim(); + metaDataTabModel.mode = map.get(this.toscaMetaDataKeys[6]); + if (map.get(this.toscaMetaDataKeys[7])) { + metaDataTabModel.templateTags = new Set<string>(map.get(this.toscaMetaDataKeys[7]).split(',')); } return metaDataTabModel; } 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 f74015956..25f5c5996 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,7 +24,7 @@ import {FilesContent, FolderNodeElement, MetaDataTabModel} from './mapping-model import * as JSZip from 'jszip'; import {PackageCreationStore} from './package-creation.store'; -import {Definition} from './mapping-models/CBAPacakge.model'; +import {CBAPackage, Definition} from './mapping-models/CBAPacakge.model'; import {PackageCreationModes} from './creationModes/PackageCreationModes'; import {PackageCreationBuilder} from './creationModes/PackageCreationBuilder'; import {PackageCreationUtils} from './package-creation.utils'; @@ -78,11 +78,13 @@ export class PackageCreationComponent extends ComponentCanDeactivate implements elementRef: ElementRef; versionPattern = '^(\\d+\\.)?(\\d+\\.)?(\\*|\\d+)$'; metadataClasses = 'nav-item nav-link active complete'; + private cbaPackage: CBAPackage; ngOnInit() { this.elementRef.nativeElement.focus(); const regexp = RegExp(this.versionPattern); this.packageCreationStore.state$.subscribe(cbaPackage => { + this.cbaPackage = cbaPackage; if (cbaPackage && cbaPackage.metaData && cbaPackage.metaData.description && cbaPackage.metaData.name && cbaPackage.metaData.version && regexp.test(cbaPackage.metaData.version)) { @@ -104,19 +106,17 @@ export class PackageCreationComponent extends ComponentCanDeactivate implements } saveBluePrint() { - this.packageCreationStore.state$.subscribe( - cbaPackage => { - console.log(cbaPackage); - FilesContent.clear(); - let packageCreationModes: PackageCreationModes; - cbaPackage = PackageCreationModes.mapModeType(cbaPackage); - cbaPackage.metaData = PackageCreationModes.setEntryPoint(cbaPackage.metaData); - packageCreationModes = PackageCreationBuilder.getCreationMode(cbaPackage); - cbaPackage.templateTopology.content = this.designerStore.state.sourceContent; - packageCreationModes.execute(cbaPackage, this.packageCreationUtils); - this.filesData.push(this.folder.TREE_DATA); - this.saveBluePrintToDataBase(); - }); + console.log(this.cbaPackage); + FilesContent.clear(); + let packageCreationModes: PackageCreationModes; + this.cbaPackage = PackageCreationModes.mapModeType(this.cbaPackage); + this.cbaPackage.metaData = PackageCreationModes.setEntryPoint(this.cbaPackage.metaData); + packageCreationModes = PackageCreationBuilder.getCreationMode(this.cbaPackage); + + // this.cbaPackage.templateTopology.content = this.designerStore.state.sourceContent; + packageCreationModes.execute(this.cbaPackage, this.packageCreationUtils); + this.filesData.push(this.folder.TREE_DATA); + this.saveBluePrintToDataBase(); } diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.service.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.service.ts index bd0944146..94ab9ed02 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.service.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.service.ts @@ -42,7 +42,7 @@ export class PackageCreationService { } private enrichBlueprint(body: any | null, options?: any): Observable<any> { - return this.api.post(BlueprintURLs.enrich, body, { responseType: 'blob' }); + return this.api.post(BlueprintURLs.enrich, body, {responseType: 'blob'}); } private deployBluePrint(body: any | null, options?: any): Observable<any> { @@ -83,7 +83,9 @@ export class PackageCreationService { return this.api.post(ResourceDictionaryURLs.searchResourceDictionaryByNames, variables); } - + downloadPackage(id) { + return this.api.getCustomized(BlueprintURLs.download + id, {responseType: 'blob'}); + } } 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 bca6903f6..77867e55e 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 @@ -110,7 +110,9 @@ export class PackageCreationStore extends Store<CBAPackage> { } clear() { + console.log('clearing the store'); this.setState(new CBAPackage()); + console.log('it should be empty'); } setEntryDefinition(data: string) { 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 c3704365c..2653d739c 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 @@ -24,6 +24,7 @@ export class ScriptsTabComponent implements OnInit { ngOnInit() { + this.packageCreationStore.state$.subscribe(cbaPackage => { if (cbaPackage.scripts && cbaPackage.scripts.files && cbaPackage.scripts.files.size > 0) { this.scriptsFiles = cbaPackage.scripts.files; |