Merge pull request #7 from sartography/feature/download-search
Feature/download search
This commit is contained in:
commit
082e23a7ec
|
@ -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": {
|
"file-uri-to-path": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
"chart.js": "^2.9.4",
|
"chart.js": "^2.9.4",
|
||||||
"chartjs-plugin-datalabels": "^0.7.0",
|
"chartjs-plugin-datalabels": "^0.7.0",
|
||||||
"code-128-encoder": "^3.1.1",
|
"code-128-encoder": "^3.1.1",
|
||||||
|
"file-saver": "^2.0.5",
|
||||||
"lodash.isequal": "^4.5.0",
|
"lodash.isequal": "^4.5.0",
|
||||||
"ng2-charts": "^2.4.2",
|
"ng2-charts": "^2.4.2",
|
||||||
"ngx-qrcode-svg": "^2.0.0",
|
"ngx-qrcode-svg": "^2.0.0",
|
||||||
|
|
|
@ -112,7 +112,7 @@
|
||||||
|
|
||||||
<mat-card>
|
<mat-card>
|
||||||
<mat-card-header>
|
<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>
|
</mat-card-header>
|
||||||
|
|
||||||
<table mat-table [dataSource]="searchResult" class="mat-elevation-z8">
|
<table mat-table [dataSource]="searchResult" class="mat-elevation-z8">
|
||||||
|
|
|
@ -108,7 +108,6 @@ export class GraphsComponent implements OnInit {
|
||||||
this.graphService.getRawSearchData(this.form, this.currentPage).subscribe(searchResult => this.searchResult = searchResult);
|
this.graphService.getRawSearchData(this.form, this.currentPage).subscribe(searchResult => this.searchResult = searchResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
searchToday(): void {
|
searchToday(): void {
|
||||||
this.startDate = new Date();
|
this.startDate = new Date();
|
||||||
this.endDate = new Date();
|
this.endDate = new Date();
|
||||||
|
@ -121,6 +120,10 @@ export class GraphsComponent implements OnInit {
|
||||||
this.updateGraphData();
|
this.updateGraphData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
downloadSearchResults(): void {
|
||||||
|
this.graphService.downloadSearchResults(this.form);
|
||||||
|
}
|
||||||
|
|
||||||
updateGraphData(): void {
|
updateGraphData(): void {
|
||||||
|
|
||||||
if (this.form.location.trim().split(' ').length === 1) {
|
if (this.form.location.trim().split(' ').length === 1) {
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
import { Injectable, Inject } from '@angular/core';
|
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 { APP_BASE_HREF } from '@angular/common';
|
||||||
import { Observable, throwError } from 'rxjs';
|
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 { ApiError } from '../models/apiError.interface';
|
||||||
import { AppEnvironment } from '../models/appEnvironment.interface';
|
import { AppEnvironment } from '../models/appEnvironment.interface';
|
||||||
import { HttpParams } from '@angular/common/http';
|
import { HttpParams } from '@angular/common/http';
|
||||||
import { Sample } from '../models/sample.interface';
|
import { Sample } from '../models/sample.interface';
|
||||||
|
|
||||||
import { SearchForm } from '../models/search_form';
|
import { SearchForm } from '../models/search_form';
|
||||||
|
import { saveAs } from 'file-saver';
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
|
@ -21,6 +21,17 @@ export class GraphService {
|
||||||
) {
|
) {
|
||||||
this.apiRoot = environment.api;
|
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[]> {
|
getRawSearchData(form: SearchForm, page: number): Observable<Sample[]> {
|
||||||
let params = this.createParams(form);
|
let params = this.createParams(form);
|
||||||
params = params.set('page', String(page));
|
params = params.set('page', String(page));
|
||||||
|
|
Loading…
Reference in New Issue