This is an automated email from the ASF dual-hosted git repository.
bossenti pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/streampipes.git
The following commit(s) were added to refs/heads/dev by this push:
new 7dbf50650 2074 Add download button for files in streampipes (#2185)
7dbf50650 is described below
commit 7dbf50650a8e9695f186a1c64924d654da8df9e1
Author: Isaak Krut <[email protected]>
AuthorDate: Thu Nov 16 01:48:01 2023 -0500
2074 Add download button for files in streampipes (#2185)
* Added File Download button
* Updated import on file-saver
---
ui/cypress/support/utils/FileManagementUtils.ts | 14 ++++++++++++++
.../tests/fileManagement/testFileManagement.smoke.spec.ts | 1 +
.../platform-services/src/lib/apis/files.service.ts | 9 +++++++++
.../components/file-overview/file-overview.component.html | 10 ++++++++++
.../components/file-overview/file-overview.component.ts | 9 +++++++++
5 files changed, 43 insertions(+)
diff --git a/ui/cypress/support/utils/FileManagementUtils.ts
b/ui/cypress/support/utils/FileManagementUtils.ts
index 6149bcb4a..fab66c927 100644
--- a/ui/cypress/support/utils/FileManagementUtils.ts
+++ b/ui/cypress/support/utils/FileManagementUtils.ts
@@ -39,4 +39,18 @@ export class FileManagementUtils {
cy.dataCy('confirm-delete').click();
cy.dataCy('delete').should('have.length', 0);
}
+
+ public static downloadFile(expectedFilename: string) {
+ const downloadsFolder = Cypress.config('downloadsFolder');
+
+ // Go to StreamPipes file management
+ cy.visit('#/files');
+ // Check if file was uploaded
+ cy.dataCy('download').should('have.length', 1);
+
+ // Download file and verify it was downloaded
+ cy.dataCy('download').click();
+ cy.dataCy('download').should('have.length', 1);
+ cy.readFile(downloadsFolder + '/' + expectedFilename);
+ }
}
diff --git a/ui/cypress/tests/fileManagement/testFileManagement.smoke.spec.ts
b/ui/cypress/tests/fileManagement/testFileManagement.smoke.spec.ts
index b8bde110a..2308b52af 100644
--- a/ui/cypress/tests/fileManagement/testFileManagement.smoke.spec.ts
+++ b/ui/cypress/tests/fileManagement/testFileManagement.smoke.spec.ts
@@ -25,6 +25,7 @@ describe('Test File Management', () => {
it('Perform Test', () => {
FileManagementUtils.addFile('fileTest/test.csv');
+ FileManagementUtils.downloadFile('test.csv');
FileManagementUtils.deleteFile();
});
});
diff --git
a/ui/projects/streampipes/platform-services/src/lib/apis/files.service.ts
b/ui/projects/streampipes/platform-services/src/lib/apis/files.service.ts
index db0206210..1439093ad 100644
--- a/ui/projects/streampipes/platform-services/src/lib/apis/files.service.ts
+++ b/ui/projects/streampipes/platform-services/src/lib/apis/files.service.ts
@@ -81,4 +81,13 @@ export class FilesService {
this.platformServicesCommons.apiBasePath + '/files/' + fileId,
);
}
+
+ getFile(filename: string): Observable<Blob> {
+ return this.http.get(
+ this.platformServicesCommons.apiBasePath + '/files/' + filename,
+ {
+ responseType: 'blob',
+ },
+ );
+ }
}
diff --git
a/ui/src/app/files/components/file-overview/file-overview.component.html
b/ui/src/app/files/components/file-overview/file-overview.component.html
index 6e08d53f4..d221556f8 100644
--- a/ui/src/app/files/components/file-overview/file-overview.component.html
+++ b/ui/src/app/files/components/file-overview/file-overview.component.html
@@ -60,6 +60,16 @@
>
<i class="material-icons">delete</i>
</button>
+ <button
+ color="accent"
+ mat-icon-button
+ matTooltip="Download File"
+ matTooltipPosition="above"
+ (click)="downloadFile(fileMetadata)"
+ data-cy="download"
+ >
+ <i class="material-icons">download</i>
+ </button>
</td>
</ng-container>
diff --git
a/ui/src/app/files/components/file-overview/file-overview.component.ts
b/ui/src/app/files/components/file-overview/file-overview.component.ts
index 22865f21a..5479b5110 100644
--- a/ui/src/app/files/components/file-overview/file-overview.component.ts
+++ b/ui/src/app/files/components/file-overview/file-overview.component.ts
@@ -22,6 +22,7 @@ import { MatTableDataSource } from '@angular/material/table';
import { MatPaginator } from '@angular/material/paginator';
import { ConfirmDialogComponent } from '@streampipes/shared-ui';
import { MatDialog } from '@angular/material/dialog';
+import { saveAs } from 'file-saver';
@Component({
selector: 'sp-file-overview',
@@ -80,6 +81,14 @@ export class FileOverviewComponent implements OnInit {
});
}
+ downloadFile(fileMetadata: FileMetadata) {
+ this.filesService
+ .getFile(fileMetadata.internalFilename)
+ .subscribe(response => {
+ saveAs(response, fileMetadata.originalFilename);
+ });
+ }
+
@ViewChild(MatPaginator) set content(paginator: MatPaginator) {
this.paginator = paginator;
}