Skip to content

Commit

Permalink
feat(#2192): add download button in asset management overview (#2224)
Browse files Browse the repository at this point in the history
* Added Asset Download button

* Updated to use FileSaver
  • Loading branch information
IsaakKrut authored Nov 27, 2023
1 parent 2762997 commit 3ba4f77
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
27 changes: 27 additions & 0 deletions ui/cypress/tests/assetManagement/createAsset.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,36 @@ describe('Creates a new adapter, add to assets and export assets', () => {
cy.dataCy('import-button').click();

// Check if import was successful
cy.visit('#/connect');
cy.dataCy('adapters-table').children().should('have.length', 1);
cy.visit('#/assets');
cy.dataCy('assets-table').should('have.length', 1);

// Export Asset via Assets page
cy.dataCy('download').click();

// Delete Adapter and Asset
cy.visit('#/connect');
cy.dataCy('delete-adapter').click();
cy.dataCy('delete-adapter-confirmation').click();

cy.visit('#/assets');
cy.dataCy('delete').click();

// Import downloaded Asset
cy.visit('#/configuration/export');
cy.dataCy('import-application-data-button').click();
cy.get('input[type="file"]').selectFile(
'cypress/downloads/assetExport.zip',
{ force: true },
);
cy.dataCy('next-import-button').click();
cy.dataCy('import-button').click();

// Check if import was successful
cy.visit('#/connect');
cy.dataCy('adapters-table').children().should('have.length', 1);
cy.visit('#/assets');
cy.dataCy('assets-table').should('have.length', 1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,18 @@ <h5>
>delete</i
>
</button>
<button
color="accent"
mat-icon-button
matTooltip="Download asset"
data-cy="download"
matTooltipPosition="above"
(click)="downloadAsset(asset)"
>
<i class="material-icons"
>download</i
>
</button>
</span>
</div>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ import { SpAssetRoutes } from '../../assets.routes';
import { AssetUploadDialogComponent } from '../../dialog/asset-upload/asset-upload-dialog.component';
import { Router } from '@angular/router';
import { SpCreateAssetDialogComponent } from '../../dialog/create-asset/create-asset-dialog.component';
import { DataExportService } from '../../../configuration/export/data-export.service';
import { mergeMap } from 'rxjs/operators';
import { saveAs } from 'file-saver';

@Component({
selector: 'sp-asset-overview-component',
Expand All @@ -50,6 +53,7 @@ export class SpAssetOverviewComponent implements OnInit {
private breadcrumbService: SpBreadcrumbService,
private dialogService: DialogService,
private router: Router,
private dataExportService: DataExportService,
) {}

ngOnInit(): void {
Expand Down Expand Up @@ -147,4 +151,18 @@ export class SpAssetOverviewComponent implements OnInit {
this.loadAssets();
});
}

downloadAsset(asset: SpAssetModel) {
this.dataExportService
.getExportPreview([asset._id])
.pipe(
mergeMap(preview =>
this.dataExportService.triggerExport(preview),
),
)
.subscribe((data: Blob) => {
const blob = new Blob([data], { type: 'application/zip' });
saveAs(blob, 'assetExport');
});
}
}

0 comments on commit 3ba4f77

Please sign in to comment.