Commit 2f918b56 authored by Jeremy Destin's avatar Jeremy Destin Committed by Célia Michotey
Browse files

Feat: Add mcpd export on front.

parent f0ec1550
......@@ -23,12 +23,18 @@
You must filter your results to have less than <strong>50,000 results</strong> before exporting the data.
</div>
<button type="button" class="btn btn-outline-success mb-2"
<button type="button" class="btn btn-outline-success btn-sm mb-2"
(click)="exportPlantMaterial(localCriteria)">
<span class="iconify" data-icon="fa-solid:file-csv" data-inline="false"></span>
Export Plant Material list
</button>
<button type="button" class="btn btn-outline-info btn-sm ml-3 mb-2"
(click)="exportMcpd(localCriteria)">
<span class="iconify" data-icon="fa-solid:file-csv" data-inline="false"></span>
Export MCPD list
</button>
<!-- Loading spinner-->
<div class="text-center">
<faidare-loading-spinner [loading]="loading"></faidare-loading-spinner>
......
import { Component, Input, OnInit } from '@angular/core';
import { GnpisService } from '../gnpis.service';
import { Germplasm, GermplasmSearchCriteria } from '../models/gnpis.model';
import {Component, Input, OnInit} from '@angular/core';
import {GnpisService} from '../gnpis.service';
import {Germplasm, GermplasmSearchCriteria} from '../models/gnpis.model';
import { saveAs } from 'file-saver';
import { ActivatedRoute } from '@angular/router';
import {saveAs} from 'file-saver';
import {ActivatedRoute} from '@angular/router';
import {
DataDiscoveryCriteria,
DataDiscoveryCriteriaUtils,
......@@ -12,8 +12,8 @@ import {
DEFAULT_PAGE_SIZE,
MAX_RESULTS
} from '../models/data-discovery.model';
import { asArray } from '../utils';
import { BehaviorSubject } from 'rxjs';
import {asArray} from '../utils';
import {BehaviorSubject} from 'rxjs';
@Component({
selector: 'faidare-germplasm-result-page',
......@@ -131,7 +131,24 @@ export class GermplasmResultPageComponent implements OnInit {
result => {
if (result) {
const blob = new Blob([result], { type: 'text/plain;charset=utf-8' });
saveAs(blob, 'germplasm.gnpis.csv');
saveAs(blob, 'germplasm_gnpis.csv');
} else {
this.overLimitSizeExport = true;
}
this.loading = false;
},
error => {
console.log(error);
});
}
exportMcpd(criteria: GermplasmSearchCriteria) {
this.loading = true;
this.service.mcpdExport(criteria).subscribe(
result => {
if (result) {
const blob = new Blob([result], { type: 'text/plain;charset=utf-8' });
saveAs(blob, 'germplasm_mcpd.csv');
} else {
this.overLimitSizeExport = true;
}
......
import { Injectable } from '@angular/core';
import { Observable, ReplaySubject, zip } from 'rxjs';
import { HttpClient } from '@angular/common/http';
import {Injectable} from '@angular/core';
import {Observable, ReplaySubject, zip} from 'rxjs';
import {HttpClient} from '@angular/common/http';
import {
DataDiscoveryCriteria,
DataDiscoveryFacet,
......@@ -12,10 +12,10 @@ import {
GermplasmCriteria,
GermplasmResults
} from './models/brapi.model';
import { map } from 'rxjs/operators';
import { Germplasm, GermplasmSearchCriteria } from './models/gnpis.model';
import { XrefResponse } from './models/xref.model';
import { removeNullUndefined } from './utils';
import {map} from 'rxjs/operators';
import {Germplasm, GermplasmSearchCriteria} from './models/gnpis.model';
import {XrefResponse} from './models/xref.model';
import {removeNullUndefined} from './utils';
export const BASE_URL = 'faidare/v1';
......@@ -152,6 +152,19 @@ export class GnpisService {
);
}
// TODO Change the service's response to return an object with the number of results and handle here if the number is over the limit
mcpdExport(criteria: GermplasmSearchCriteria): Observable<any> {
const requestOptions: Object = {
/* other options here */
responseType: 'text'
};
return this.http.post<any>(
`${BASE_URL}/germplasm/germplasm-mcpd-csv`,
criteria,
requestOptions
);
}
getSourcesName(sourceByURI, response) {
response.facets = response.facets.map((facet: DataDiscoveryFacet) => {
facet.terms = facet.terms.map(term => {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment