Skip to content

Commit

Permalink
Better filename when exporting training snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
polterguy committed Oct 13, 2023
1 parent 0109b7c commit 70e0381
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ 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' +
this.queryArgService.getQueryArgs(filter)).subscribe({
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);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 70e0381

Please sign in to comment.