From 70e0381657ecce050974c2c478fa316b89216288 Mon Sep 17 00:00:00 2001
From: Thomas Hansen
Date: Fri, 13 Oct 2023 14:28:17 +0300
Subject: [PATCH] Better filename when exporting training snippets
---
.../_general/services/machine-learning-training.service.ts | 4 ++--
.../machine-learning-training-data.component.ts | 4 +++-
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/frontend/src/app/_general/services/machine-learning-training.service.ts b/frontend/src/app/_general/services/machine-learning-training.service.ts
index f061e08f81..6732cde06d 100644
--- a/frontend/src/app/_general/services/machine-learning-training.service.ts
+++ b/frontend/src/app/_general/services/machine-learning-training.service.ts
@@ -63,7 +63,7 @@ export class MachineLearningTrainingService {
/**
* Exports all training snippet matching filter.
*/
- ml_training_snippets_export(filter: any) {
+ ml_training_snippets_export(filter: any, filename: string) {
this.httpService.download(
'/magic/system/magic/ml_training_snippets_export' +
@@ -71,7 +71,7 @@ export class MachineLearningTrainingService {
next: (res) => {
const disp = res.headers.get('Content-Disposition');
- let filename = disp.split(';')[1].trim().split('=')[1].replace(/"/g, '');
+ filename = filename ?? disp.split(';')[1].trim().split('=')[1].replace(/"/g, '');
const file = new Blob([res.body]);
saveAs(file, filename);
},
diff --git a/frontend/src/app/_protected/pages/manage/machine-learning/machine-learning-training-data/machine-learning-training-data.component.ts b/frontend/src/app/_protected/pages/manage/machine-learning/machine-learning-training-data/machine-learning-training-data.component.ts
index b840636c58..9858a7bbc5 100644
--- a/frontend/src/app/_protected/pages/manage/machine-learning/machine-learning-training-data/machine-learning-training-data.component.ts
+++ b/frontend/src/app/_protected/pages/manage/machine-learning/machine-learning-training-data/machine-learning-training-data.component.ts
@@ -376,10 +376,12 @@ export class MachineLearningTrainingDataComponent implements OnInit {
if (this.filter['ml_training_snippets.uri.like']) {
filter['ml_training_snippets.uri.like'] = this.filter['ml_training_snippets.uri.like'];
}
+ let filename = 'training-snippets.csv';
if (this.filter['ml_training_snippets.type.eq']) {
filter['ml_training_snippets.type.eq'] = this.filter['ml_training_snippets.type.eq'];
+ filename = this.filter['ml_training_snippets.type.eq'] + '.csv';
}
- this.machineLearningTrainingService.ml_training_snippets_export(filter);
+ this.machineLearningTrainingService.ml_training_snippets_export(filter, filename);
}
page(event: PageEvent) {
|