X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cds-ui%2Fdesigner-client%2Fsrc%2Fapp%2Fmodules%2Ffeature-modules%2Fpackages%2Fconfiguration-dashboard%2Fconfiguration-dashboard.component.ts;h=47e89b39a0fef7732306490484755e9df209eea4;hb=6afbfc0e71798f21b8b70ad34a468aacc63d03ab;hp=19c10c5fd2ef8b7d8f329eceacb55cda9b2f8581;hpb=d7fffebc00a236147e67ffa877016c5e6d1d911f;p=ccsdk%2Fcds.git diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/configuration-dashboard/configuration-dashboard.component.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/configuration-dashboard/configuration-dashboard.component.ts index 19c10c5fd..47e89b39a 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/configuration-dashboard/configuration-dashboard.component.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/configuration-dashboard/configuration-dashboard.component.ts @@ -6,14 +6,15 @@ import {FilesContent, FolderNodeElement, MetaDataTabModel} from '../package-crea import {MetadataTabComponent} from '../package-creation/metadata-tab/metadata-tab.component'; import * as JSZip from 'jszip'; import {ConfigurationDashboardService} from './configuration-dashboard.service'; -import {VlbDefinition} from '../package-creation/mapping-models/definitions/VlbDefinition'; +import {TemplateTopology, VlbDefinition} from '../package-creation/mapping-models/definitions/VlbDefinition'; import {DslDefinition} from '../package-creation/mapping-models/CBAPacakge.model'; import {PackageCreationUtils} from '../package-creation/package-creation.utils'; import {PackageCreationModes} from '../package-creation/creationModes/PackageCreationModes'; import {PackageCreationBuilder} from '../package-creation/creationModes/PackageCreationBuilder'; import {saveAs} from 'file-saver'; import {DesignerStore} from '../designer/designer.store'; -import { DesignerService } from '../designer/designer.service'; +import {ToastrService} from 'ngx-toastr'; +import {NgxFileDropEntry} from 'ngx-file-drop'; @Component({ selector: 'app-configuration-dashboard', @@ -23,41 +24,69 @@ import { DesignerService } from '../designer/designer.service'; export class ConfigurationDashboardComponent implements OnInit { viewedPackage: BluePrintDetailModel = new BluePrintDetailModel(); @ViewChild(MetadataTabComponent, {static: false}) - private metadataTabComponent: MetadataTabComponent; - public customActionName: string; + metadataTabComponent: MetadataTabComponent; + public customActionName = ''; entryDefinitionKeys: string[] = ['template_tags', 'user-groups', - 'author-email', 'template_version', 'template_name', 'template_author']; + 'author-email', 'template_version', 'template_name', 'template_author', 'template_description']; @ViewChild('nameit', {static: true}) - private elementRef: ElementRef; + elementRef: ElementRef; + uploadedFiles = []; + zipFile: JSZip = new JSZip(); + filesData: any = []; + folder: FolderNodeElement = new FolderNodeElement(); + id: any; - private zipFile: JSZip = new JSZip(); - private filesData: any = []; - private folder: FolderNodeElement = new FolderNodeElement(); + currentBlob = new Blob(); + vlbDefinition: VlbDefinition = new VlbDefinition(); + isSaveEnabled = false; + versionPattern = '^(\\d+\\.)?(\\d+\\.)?(\\*|\\d+)$'; + metadataClasses = 'nav-item nav-link active'; - private currentBlob = new Blob(); - - constructor(private route: ActivatedRoute, private configurationDashboardService: ConfigurationDashboardService, - private packageCreationStore: PackageCreationStore, - private packageCreationUtils: PackageCreationUtils, - private router: Router, - private designerStore: DesignerStore, - private designerService: DesignerService) { + constructor( + private route: ActivatedRoute, + private configurationDashboardService: ConfigurationDashboardService, + private packageCreationStore: PackageCreationStore, + private packageCreationUtils: PackageCreationUtils, + private router: Router, + private designerStore: DesignerStore, + private toastService: ToastrService + ) { } ngOnInit() { + this.vlbDefinition.topology_template = new TemplateTopology(); + this.elementRef.nativeElement.focus(); - const id = this.route.snapshot.paramMap.get('id'); - this.configurationDashboardService.getPagedPackages(id).subscribe( + this.refreshCurrentPackage(); + const regexp = RegExp(this.versionPattern); + this.packageCreationStore.state$.subscribe( + cbaPackage => { + if (cbaPackage && cbaPackage.metaData && cbaPackage.metaData.description + && cbaPackage.metaData.name && cbaPackage.metaData.version && + regexp.test(cbaPackage.metaData.version)) { + if (!this.metadataClasses.includes('complete')) { + this.metadataClasses += ' complete'; + } + } else { + this.metadataClasses = this.metadataClasses.replace('complete', ''); + } + + }); + } + + private refreshCurrentPackage() { + this.id = this.route.snapshot.paramMap.get('id'); + this.configurationDashboardService.getPagedPackages(this.id).subscribe( (bluePrintDetailModels) => { if (bluePrintDetailModels) { this.viewedPackage = bluePrintDetailModels[0]; this.downloadCBAPackage(bluePrintDetailModels); + this.packageCreationStore.clear(); } }); } - private downloadCBAPackage(bluePrintDetailModels: BluePrintDetailModel) { this.configurationDashboardService.downloadResource( bluePrintDetailModels[0].artifactName + '/' + bluePrintDetailModels[0].artifactVersion).subscribe(response => { @@ -65,7 +94,6 @@ export class ConfigurationDashboardComponent implements OnInit { this.currentBlob = blob; this.zipFile.loadAsync(blob).then((zip) => { Object.keys(zip.files).forEach((filename) => { - console.log(filename); zip.files[filename].async('string').then((fileData) => { if (fileData) { if (filename.includes('Scripts/')) { @@ -76,11 +104,11 @@ export class ConfigurationDashboardComponent implements OnInit { } else if (filename.includes('-template.')) { this.setTemplates(filename, fileData); } + } else if (filename.includes('Definitions/')) { - this.setImports(filename, fileData); + this.setImports(filename, fileData, bluePrintDetailModels); } else if (filename.includes('TOSCA-Metadata/')) { const metaDataTabInfo: MetaDataTabModel = this.getMetaDataTabInfo(fileData); - // console.log(metaDataTabInfo); this.setMetaData(metaDataTabInfo, bluePrintDetailModels[0]); } } @@ -90,12 +118,12 @@ export class ConfigurationDashboardComponent implements OnInit { }); } - private setScripts(filename: string, fileData: any) { + setScripts(filename: string, fileData: any) { this.packageCreationStore.addScripts(filename, fileData); } - private setImports(filename: string, fileData: any) { - if (filename.includes('blueprint.json') || filename.includes('vLB_CDS.json')) { + setImports(filename: string, fileData: any, bluePrintDetailModels: BluePrintDetailModel) { + if (filename.includes(bluePrintDetailModels[0].artifactName)) { let definition = new VlbDefinition(); definition = fileData as VlbDefinition; definition = JSON.parse(fileData); @@ -109,28 +137,26 @@ export class ConfigurationDashboardComponent implements OnInit { } this.packageCreationStore.changeDslDefinition(dslDefinition); this.packageCreationStore.setCustomKeys(mapOfCustomKeys); - // console.log(definition.topology_template.content); - if (definition.topology_template.content) { + if (definition.topology_template && definition.topology_template.content) { this.designerStore.saveSourceContent(definition.topology_template.content); } - } else { - this.packageCreationStore.addDefinition(filename, fileData); } + this.packageCreationStore.addDefinition(filename, fileData); + } - private setTemplates(filename: string, fileData: any) { + setTemplates(filename: string, fileData: any) { this.packageCreationStore.addTemplate(filename, fileData); } - private setMapping(fileName: string, fileData: string) { + setMapping(fileName: string, fileData: string) { this.packageCreationStore.addMapping(fileName, fileData); } editBluePrint() { this.packageCreationStore.state$.subscribe( cbaPackage => { - console.log(cbaPackage); FilesContent.clear(); let packageCreationModes: PackageCreationModes; cbaPackage = PackageCreationModes.mapModeType(cbaPackage); @@ -142,7 +168,7 @@ export class ConfigurationDashboardComponent implements OnInit { }); } - private setMetaData(metaDataObject: MetaDataTabModel, bluePrintDetailModel: BluePrintDetailModel) { + setMetaData(metaDataObject: MetaDataTabModel, bluePrintDetailModel: BluePrintDetailModel) { metaDataObject.description = bluePrintDetailModel.artifactDescription; this.packageCreationStore.changeMetaData(metaDataObject); @@ -150,6 +176,7 @@ export class ConfigurationDashboardComponent implements OnInit { saveMetaData() { this.metadataTabComponent.saveMetaDataToStore(); + } getMetaDataTabInfo(fileData: string) { @@ -160,7 +187,6 @@ export class ConfigurationDashboardComponent implements OnInit { metaDataTabModel.version = arrayOfLines[5].split(':')[1]; metaDataTabModel.mode = arrayOfLines[6].split(':')[1]; metaDataTabModel.templateTags = new Set(arrayOfLines[7].split(':')[1].split(',')); - console.log(metaDataTabModel.mode); return metaDataTabModel; } @@ -168,13 +194,32 @@ export class ConfigurationDashboardComponent implements OnInit { this.create(); this.zipFile.generateAsync({type: 'blob'}) .then(blob => { - this.packageCreationStore.saveBluePrint(blob); - this.router.navigate(['/packages']); + this.packageCreationStore.saveBluePrint(blob).subscribe( + bluePrintDetailModels => { + if (bluePrintDetailModels) { + const id = bluePrintDetailModels.toString().split('id')[1].split(':')[1].split('"')[1]; + this.toastService.info('package updated successfully '); + this.router.navigate(['/packages/package/' + id]); + } + }, error => { + this.toastService.error('error happened when editing ' + error.message); + console.log('Error -' + error.message); + }); }); } + deletePackage() { + this.configurationDashboardService.deletePackage(this.id).subscribe(res => { + console.log('Deleted'); + console.log(res); + this.router.navigate(['/packages']); + }, err => { + console.log(err); + }); + } create() { + this.zipFile = new JSZip(); FilesContent.getMapOfFilesNamesAndContent().forEach((value, key) => { this.zipFile.folder(key.split('/')[0]); this.zipFile.file(key, value); @@ -182,8 +227,8 @@ export class ConfigurationDashboardComponent implements OnInit { } - goBacktoDashboard() { - this.router.navigate(['/packages']); + discardChanges() { + this.refreshCurrentPackage(); } downloadPackage(artifactName: string, artifactVersion: string) { @@ -195,22 +240,65 @@ export class ConfigurationDashboardComponent implements OnInit { deployCurrentPackage() { console.log('happened'); - /* this.zipFile.generateAsync({type: 'blob'}) - .then(blob => { - const formData = new FormData(); - formData.append('file', this.currentBlob); - this.configurationDashboardService.deployPost(formData) - .subscribe(data => { - }, error => { - }); - this.router.navigate(['/packages']); - }); - */ this.router.navigate(['/packages']); } goToDesignerMode(id) { - // this.designerService.setActionName(this.customActionName); + // this.designerService.setActionName(this.customActionName); this.router.navigate(['/packages/designer', id, {actionName: this.customActionName}]); - } + } + + public dropped(files: NgxFileDropEntry[]) { + + } + + public fileOver(event) { + console.log(event); + } + + public fileLeave(event) { + console.log(event); + } + + textChanged($event: {}) { + this.packageCreationStore.addTopologyTemplate(this.vlbDefinition.topology_template); + } + + enrichBluePrint() { + + this.packageCreationStore.state$.subscribe( + cbaPackage => { + FilesContent.clear(); + console.log(cbaPackage); + + let packageCreationModes: PackageCreationModes; + cbaPackage = PackageCreationModes.mapModeType(cbaPackage); + cbaPackage.metaData = PackageCreationModes.setEntryPoint(cbaPackage.metaData); + packageCreationModes = PackageCreationBuilder.getCreationMode(cbaPackage); + packageCreationModes.execute(cbaPackage, this.packageCreationUtils); + this.filesData.push(this.folder.TREE_DATA); + this.enrichPackage(); + + }); + } + + private enrichPackage() { + this.create(); + this.zipFile.generateAsync({type: 'blob'}) + .then(blob => { + this.packageCreationStore.enrichBluePrint(blob).subscribe(response => { + console.log('success'); + const blobInfo = new Blob([response], {type: 'application/octet-stream'}); + saveAs(blobInfo, 'test' + '-' + '1.0.0' + '-CBA.zip'); + this.toastService.info('enriched successfully '); + }); + }, error => { + this.toastService.error('error happened when editing ' + error.message); + console.log('Error -' + error.message); + }); + } + + clickEvent() { + this.isSaveEnabled = true; + } }