diff options
author | KAPIL SINGAL <ks220y@att.com> | 2020-09-30 13:11:27 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-09-30 13:11:27 +0000 |
commit | 485036607caf467042e8b85db6a0930beea12656 (patch) | |
tree | 954c5ec2907f96e902c167cdd14790729d03f574 | |
parent | 27a3982c04d4f81ffa7549d051a6cbc990404972 (diff) | |
parent | 586217be2b0fdd4af68c551bca91b6d83cb63991 (diff) |
Merge "adding save automatic with import"
2 files changed, 39 insertions, 2 deletions
diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/packages-dashboard/import-package/import-package.component.html b/cds-ui/designer-client/src/app/modules/feature-modules/packages/packages-dashboard/import-package/import-package.component.html index 274435cd4..d578582fd 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/packages-dashboard/import-package/import-package.component.html +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/packages-dashboard/import-package/import-package.component.html @@ -45,9 +45,14 @@ (click)="resetTheUploadedFiles()">Cancel </button> <button type="button" class="btn btn-sm btn-primary" [disabled]="uploadedFiles?.length<=0" - data-dismiss="modal" (click)="openFilesInCreationPackage();saveFileToStore()"> + data-dismiss="modal" (click)="importAndSave()"> + Import&Save + </button> + <button type="button" class="btn btn-sm btn-primary" [disabled]="uploadedFiles?.length<=0" + data-dismiss="modal" (click)="importPackageAndViewIt()"> Import </button> + </div> </div> </div> diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/packages-dashboard/import-package/import-package.component.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/packages-dashboard/import-package/import-package.component.ts index dae58a493..7496338d6 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/packages-dashboard/import-package/import-package.component.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/packages-dashboard/import-package/import-package.component.ts @@ -3,6 +3,10 @@ import {FileSystemFileEntry, NgxFileDropEntry} from 'ngx-file-drop'; import {PackageCreationExtractionService} from '../../package-creation/package-creation-extraction.service'; import {Router} from '@angular/router'; import {PackageCreationStore} from '../../package-creation/package-creation.store'; +import * as JSZip from 'jszip'; +import {PackageCreationService} from '../../package-creation/package-creation.service'; +import {ToastrService} from 'ngx-toastr'; +import {PackagesStore} from '../../packages.store'; @Component({ selector: 'app-import-package', @@ -14,10 +18,14 @@ export class ImportPackageComponent implements OnInit { public uploadedFiles: FileSystemFileEntry[] = []; private fileNames: Set<string> = new Set(); fileToDelete: any = {}; + zipFile: JSZip = new JSZip(); public files: NgxFileDropEntry[] = []; constructor(private packageCreationExtractionService: PackageCreationExtractionService, private packageCreationStore: PackageCreationStore, + private packageCreationService: PackageCreationService, + private toastService: ToastrService, + private packagesStore: PackagesStore, private router: Router) { } @@ -72,7 +80,12 @@ export class ImportPackageComponent implements OnInit { public fileLeave(event) { console.log(event); } -// TODO mix two function in ond bigger one + + importPackageAndViewIt() { + this.openFilesInCreationPackage(); + this.saveFileToStore(); + } + saveFileToStore() { console.log(this.uploadedFiles.length); const file = this.getFile(this.uploadedFiles[this.uploadedFiles.length - 1]); @@ -91,4 +104,23 @@ export class ImportPackageComponent implements OnInit { console.log(err); } } + + importAndSave() { + const file = this.getFile(this.uploadedFiles[this.uploadedFiles.length - 1]); + this.zipFile = new JSZip(); + this.zipFile.loadAsync(file).then(zip => { + this.zipFile = zip; + console.log(this.zipFile); + this.resetTheUploadedFiles(); + this.zipFile.generateAsync({type: 'blob'}).then(blob => { + this.packageCreationService.savePackage(blob).subscribe( + bluePrintDetailModels => { + this.toastService.info('package is imported and saved successfully '); + this.router.navigate(['/packages']); + this.packagesStore.getAll(); + }, error => + this.toastService.error('there is an error happened ' + error)); + }); + }); + } } |