Commit d6d38cb5 authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch '123-fix-all-crops-list-page' into 'master'

Resolve "Fix all crops list page"

Closes #123

See merge request !83
parents 32f4ce9f ac5ea2e4
......@@ -60,6 +60,9 @@ public interface AccessionRepository extends JpaRepository<Accession, Long>, Acc
@Query("select count(a) from Accession a where a.institute.country = ?1 and a.historic = false")
long countByLocation(Country country);
@Query("select count(a) from Accession a where a.crop = ?1 and a.historic = false")
long countByCrop(Crop crop);
@Query(value = "select a.cropName, count(a.id) from Accession a where a.institute = ?1 and a.historic = false group by a.cropName order by count(a) desc", countQuery = "select count(distinct a.cropName) from Accession a where a.institute = ?1")
Page<Object[]> statisticsCropNameInInstitute(FaoInstitute institute, Pageable pageable);
......
......@@ -183,6 +183,8 @@ public interface GenesysService {
long countAllActive();
long countAllHistoric();
long countByCrop(Crop crop);
/**
* For institutes with {@link FaoInstitute#uniqueAcceNumbs}
......
......@@ -248,7 +248,12 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
return accessionRepository.countByHistoric(true);
}
@Override
@Override
public long countByCrop(final Crop crop) {
return accessionRepository.countByCrop(crop);
}
@Override
public long countByInstitute(FaoInstitute institute) {
return accessionRepository.countByInstitute(institute);
}
......
......@@ -18,7 +18,9 @@ package org.genesys2.server.servlet.controller;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.elasticsearch.common.lang3.StringUtils;
......@@ -29,6 +31,7 @@ import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.FilterConstants;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.StatisticsService;
import org.genesys2.server.service.TraitService;
import org.genesys2.server.service.impl.FilterHandler;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilter;
......@@ -68,10 +71,22 @@ public class CropController extends BaseController {
@Autowired
private TraitService traitService;
@Autowired
private StatisticsService statisticsService;
@RequestMapping(value = "/", method = RequestMethod.GET)
public String index(ModelMap model) {
_logger.debug("Viewing all crops");
model.addAttribute("crops", cropService.list(getLocale()));
List<Crop> cropList = cropService.list(getLocale());
Map<Crop, Long> map = new HashMap<>();
for (Crop crop : cropList) {
map.put(crop, genesysService.countByCrop(crop));
}
model.addAttribute("cropsMap", map);
model.addAttribute("numberOfCountries", statisticsService.numberOfCountries());
model.addAttribute("numberOfInstitutes", statisticsService.numberOfInstitutes());
model.addAttribute("numberOfActiveAccessions", statisticsService.numberOfActiveAccessions());
return "/crop/list";
}
......
......@@ -152,8 +152,10 @@ userprofile.page.ftp-credentials=Your FTP credentials are:
user.page.list.title=Registered user accounts
crop.crops-directory=Genesys crops directory
crop.croplist=Crop list
crop.all-crops=All crops
crop.crops=Crops
crop.taxonomy-rules=Taxonomic rules
crop.view-descriptors=View crop descriptors...
crop.page.edit.title=Edit {0}
......@@ -682,6 +684,8 @@ autocomplete.genus=Find Genus...
stats.number-of-countries={0} Countries
stats.number-of-institutes={0} Institutes
stats.number-of-accessions={0} Accessions
stats.number-of-crops={0} Crops
stats.number-of-datasets={0} Datasets
stats.number-of-historic-accessions={0} Historic accessions
navigate.back=Back
......
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