Commit 887f3a67 authored by Jérémy Destin's avatar Jérémy Destin
Browse files

Change name country into Origin Country and add a message when the number of export exced 50 000

parent 7d3fb41b
......@@ -105,14 +105,20 @@ public class GnpISGermplasmController {
@PostMapping(value = "/germplasm-list-csv", produces = "text/csv", consumes = APPLICATION_JSON_VALUE)
public FileSystemResource export(@RequestBody @Valid FaidareGermplasmPOSTShearchCriteria criteria, HttpServletResponse response) {
try {
File exportFile = germplasmService.exportListGermplasmCSV(criteria);
response.setHeader("Content-Disposition", "attachment; filename=germplasm.gnpis.csv");
return new FileSystemResource(exportFile);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("An error occurred when exporting germplasm: " + e.getMessage() + ".", e);
long limitResult = 50000L;
long nbResult = germplasmService.germplasmFind(criteria).getMetadata().getPagination().getTotalCount();
if (!(nbResult > limitResult)) {
try {
File exportFile = germplasmService.exportListGermplasmCSV(criteria);
response.setHeader("Content-Disposition", "attachment; filename=germplasm.gnpis.csv");
return new FileSystemResource(exportFile);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("An error occurred when exporting germplasm: " + e.getMessage() + ".", e);
}
}
return null;
}
@ApiOperation("Search list of germplasm")
......
......@@ -9,7 +9,8 @@ import { GermplasmSearchCriteria } from '../models/gnpis.model';
export const formatFacets: {[key: string]: string} = {
'holdingInstitute': 'holding institute',
'biologicalStatus': 'biological status',
'geneticNature': 'genetic nature'
'geneticNature': 'genetic nature',
'country': 'origin country'
};
@Component({
......
......@@ -19,9 +19,12 @@
</div>
</div>
<div *ngIf="overLimitSizeExport" class="alert alert-warning alert-dismissible fade show" role="alert">
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"
(click)="exportPlantMaterial(localCriteria)">
<span class="iconify" data-icon="fa-solid:file-csv" data-inline="false"></span>
Export Plant Material list
</button>
......
......@@ -39,6 +39,7 @@ export class GermplasmResultPageComponent implements OnInit {
'countryOfOriginCode'];
elementPerPage: number[] = [15, 20, 25];
loading: boolean;
overLimitSizeExport: boolean = false;
fieldSortState: object = {
germplasmName: null,
accessionNumber: null,
......@@ -81,6 +82,7 @@ export class GermplasmResultPageComponent implements OnInit {
this.germplasmSearchCriteria$
.subscribe(criteria => {
this.overLimitSizeExport = false
this.localCriteria = criteria;
this.searchGermplasm(this.localCriteria);
});
......@@ -127,8 +129,13 @@ export class GermplasmResultPageComponent implements OnInit {
this.loading = true;
this.service.plantMaterialExport(criteria).subscribe(
result => {
const blob = new Blob([result], { type: 'text/plain;charset=utf-8' });
saveAs(blob, 'germplasm.gnpis.csv');
if (result) {
const blob = new Blob([result], { type: 'text/plain;charset=utf-8' });
saveAs(blob, 'germplasm.gnpis.csv');
}
else {
this.overLimitSizeExport = true
}
this.loading = false;
},
error => {
......
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