From 586217be2b0fdd4af68c551bca91b6d83cb63991 Mon Sep 17 00:00:00 2001 From: ShaabanEltanany Date: Wed, 30 Sep 2020 14:15:33 +0200 Subject: adding save automatic with import Issue-ID: CCSDK-2842 Signed-off-by: ShaabanEltanany Change-Id: I8b87cf0472b2ddd3e05558fe46b8265200eb8f28 --- .../import-package/import-package.component.html | 7 ++++- .../import-package/import-package.component.ts | 34 +++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) (limited to 'cds-ui') 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 + + 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 = 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)); + }); + }); + } } -- cgit 1.2.3-korg