Merge pull request #7 from sartography/feature/download-search

Feature/download search
This commit is contained in:
Dan Funk 2021-02-28 21:11:59 -05:00 committed by GitHub
commit 082e23a7ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 5 deletions

5
package-lock.json generated
View File

@ -5595,6 +5595,11 @@
}
}
},
"file-saver": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/file-saver/-/file-saver-2.0.5.tgz",
"integrity": "sha512-P9bmyZ3h/PRG+Nzga+rbdI4OEpNDzAVyy74uVO9ATgzLK6VtAsYybF/+TOCvrc0MO793d6+42lLyZTw7/ArVzA=="
},
"file-uri-to-path": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",

View File

@ -39,6 +39,7 @@
"chart.js": "^2.9.4",
"chartjs-plugin-datalabels": "^0.7.0",
"code-128-encoder": "^3.1.1",
"file-saver": "^2.0.5",
"lodash.isequal": "^4.5.0",
"ng2-charts": "^2.4.2",
"ngx-qrcode-svg": "^2.0.0",

View File

@ -112,7 +112,7 @@
<mat-card>
<mat-card-header>
<h3 class="mb-0">Records to be processed </h3>
<h3 class="mb-0">Records to be processed <button mat-raised-button class="btn-sm" color="primary" (click)="downloadSearchResults()">Download Table</button> </h3>
</mat-card-header>
<table mat-table [dataSource]="searchResult" class="mat-elevation-z8">

View File

@ -108,7 +108,6 @@ export class GraphsComponent implements OnInit {
this.graphService.getRawSearchData(this.form, this.currentPage).subscribe(searchResult => this.searchResult = searchResult);
}
searchToday(): void {
this.startDate = new Date();
this.endDate = new Date();
@ -121,6 +120,10 @@ export class GraphsComponent implements OnInit {
this.updateGraphData();
}
downloadSearchResults(): void {
this.graphService.downloadSearchResults(this.form);
}
updateGraphData(): void {
if (this.form.location.trim().split(' ').length === 1) {

View File

@ -1,15 +1,15 @@
import { Injectable, Inject } from '@angular/core';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { HttpClient, HttpErrorResponse, HttpHeaders } from '@angular/common/http';
import { APP_BASE_HREF } from '@angular/common';
import { Observable, throwError } from 'rxjs';
import { catchError, timeout } from 'rxjs/operators';
import { catchError, map, timeout } from 'rxjs/operators';
import { ApiError } from '../models/apiError.interface';
import { AppEnvironment } from '../models/appEnvironment.interface';
import { HttpParams } from '@angular/common/http';
import { Sample } from '../models/sample.interface';
import { SearchForm } from '../models/search_form';
import { saveAs } from 'file-saver';
@Injectable({
providedIn: 'root'
})
@ -21,6 +21,17 @@ export class GraphService {
) {
this.apiRoot = environment.api;
}
downloadSearchResults(form: SearchForm): void {
const params = this.createParams(form);
this.httpClient
.get(this.apiRoot + `/dashboard/download`, {responseType: 'text', params}).subscribe((data: string) => {
const blob = new Blob([data], { type: 'text/csv' });
saveAs(blob, 'data.csv');
});
}
getRawSearchData(form: SearchForm, page: number): Observable<Sample[]> {
let params = this.createParams(form);
params = params.set('page', String(page));