Commit 416caa35 authored by Matija Obreza's avatar Matija Obreza
Browse files

Accession selection

parent bb51bc98
......@@ -4,6 +4,7 @@ encoding//src/main/webapp/WEB-INF/jsp/country/data.jsp=UTF-8
encoding//src/main/webapp/WEB-INF/jsp/login.jsp=UTF-8
encoding//src/main/webapp/WEB-INF/jsp/metadata/index.jsp=UTF-8
encoding//src/main/webapp/WEB-INF/jsp/metadata/view.jsp=UTF-8
encoding//src/main/webapp/WEB-INF/jsp/selection/index.jsp=UTF-8
encoding//src/main/webapp/WEB-INF/jsp/wiews/data.jsp=UTF-8
encoding//src/main/webapp/WEB-INF/jsp/wiews/index.jsp=UTF-8
encoding//src/test/resources=UTF-8
......
......@@ -16,6 +16,7 @@
package org.crophub.rest.common.persistence.domain;
import java.util.Collection;
import java.util.List;
import org.crophub.rest.common.model.genesys.Accession;
......@@ -35,7 +36,7 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
@Query("select count(a) from Accession a where a.institute = ?1")
long countByInstitute(FaoInstitute institute);
@Query("select count(a) from Accession a where a.origin = ?1")
long countByOrigin(String isoCode3);
......@@ -43,8 +44,7 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
long countByLocation(String isoCode3);
@Query("select a from Accession a where a.institute in ( ?1 )")
Page<Accession> findByInstitute(List<FaoInstitute> institutes,
Pageable pageable);
Page<Accession> findByInstitute(List<FaoInstitute> institutes, Pageable pageable);
@Query("select a from Accession a where a.genus in ( ?1 )")
Page<Accession> findByGenus(List<String> genus, Pageable pageable);
......@@ -58,9 +58,12 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
@Query("select a.taxonomy, count(a) as total from Accession a where a.genus in ( ?1 ) group by a.taxonomy order by total desc")
List<Object[]> statisticsTaxonomy(List<String> genus);
// List<Accession> findByOrigin(String origin);
// List<Accession> findByOrigin(String origin);
Page<Accession> findByOrigin(String isoCode3, Pageable pageable);
List<Accession> findByInstituteAndAccessionName(FaoInstitute faoInstitute, String accessionName);
@Query("from Accession a where a.id in ( ?1 )")
Page<Accession> findById(Collection<Long> accessionIds, Pageable pageable);
}
package org.crophub.rest.common.service;
import java.util.Collection;
import java.util.List;
import java.util.Map;
......@@ -57,4 +58,6 @@ public interface GenesysService {
Map<Long, Map<Long, Object>> getMetadataTraitValues(Metadata metadata, List<Accession> content);
Page<Accession> listAccessions(Collection<Long> accessionIds, Pageable pageable);
}
package org.crophub.rest.common.service.impl;
import java.util.Collection;
import java.util.List;
import java.util.Map;
......@@ -84,6 +85,14 @@ public class GenesysServiceImpl implements GenesysService {
return accessionRepository.findByInstitute(faoInstitute, pageable);
}
@Override
public Page<Accession> listAccessions(Collection<Long> accessionIds, Pageable pageable) {
if (accessionIds == null || accessionIds.size() == 0) {
return null;
}
return accessionRepository.findById(accessionIds, pageable);
}
@Override
public Accession getAccession(long accessionId) {
return accessionRepository.findOne(accessionId);
......
package org.crophub.rest.servlet.controller;
import java.util.HashSet;
import java.util.Set;
import org.crophub.rest.common.model.genesys.Accession;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@Component
@Scope("session")
public class SelectionBean {
private Set<Long> accessionIds = new HashSet<Long>();
public Set<Long> getAccessionIds() {
return accessionIds;
}
public void add(long id) {
accessionIds.add(id);
}
public void remove(long id) {
accessionIds.remove(id);
}
public void clear() {
accessionIds.clear();
}
public boolean contains(Accession accession) {
return accessionIds.contains(accession.getId());
}
public Set<Long> copy() {
return new HashSet<>(accessionIds);
}
}
package org.crophub.rest.servlet.controller;
import org.crophub.rest.common.model.genesys.Accession;
import org.crophub.rest.common.service.GenesysService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
@Scope("request")
@RequestMapping("/sel/")
public class SelectionController extends BaseController {
@Autowired
private SelectionBean selectionBean;
@Autowired
private GenesysService genesysService;
@RequestMapping
public String view(ModelMap model, @RequestParam(value = "page", required = false, defaultValue = "1") int page) {
model.addAttribute("accessions", genesysService.listAccessions(selectionBean.copy(), new PageRequest(page - 1, 50, new Sort("accessionName"))));
return "/selection/index";
}
@RequestMapping("add/{id}")
public String add(ModelMap model, @PathVariable("id") long accessionId) {
selectionBean.add(accessionId);
return "redirect:/sel/#a" + accessionId;
}
@RequestMapping(method = RequestMethod.POST, value = "add-many")
public String add(ModelMap model, @RequestParam(required = true, value = "accessionIds") String accessionIds) {
String[] splits = accessionIds.split("\\s");
for (String s : splits) {
try {
long accessionId = Long.parseLong(s);
Accession accession = genesysService.getAccession(accessionId);
if (accession != null) {
selectionBean.add(accessionId);
}
} catch (NumberFormatException e) {
}
}
return "redirect:/sel/";
}
@RequestMapping("remove/{id}")
public String remove(ModelMap model, @PathVariable("id") long accessionId) {
selectionBean.remove(accessionId);
return "redirect:/sel/";
}
@RequestMapping("clear")
public String remove(ModelMap model) {
selectionBean.clear();
return "redirect:/sel/";
}
}
......@@ -142,3 +142,10 @@ taxonomy.genus=Genus
taxonomy.species=Species
taxonomy.taxonName=Taxonomy
selection.page.title=Selected accessions
selection.add=Add {0} to list
selection.remove=Remove {0} from list
selection.clear=Clear the list
selection.empty-list-warning=You have not added any accessions to the list.
selection.add-many=Check and add
selection.add-many.accessionIds=List accession IDs as used in Genesys separated by space or new line.
......@@ -87,6 +87,7 @@
<li><a href="<c:url value="/data/" />">Datasets</a></li>
<li><a href="<c:url value="/geo/" />">Countries</a></li>
<li><a href="<c:url value="/wiews/active" />">Institutes</a></li>
<li><a href="<c:url value="/sel/" />">My List</a></li>
</ul>
</div>
......
......@@ -11,6 +11,10 @@
<c:out value="${accession.accessionName}" />
<small><c:out value="${accession.instituteCode}" /></small>
</h1>
<div class="page-header">
<a href="<c:url value="/sel/add/${accession.id}" />"><spring:message code="selection.add" arguments="${accession.accessionName}" /></a>
</div>
<c:if test="${accession.inTrust eq true}">
<div class="alert"><spring:message code="accession.inTrust.true" /></div>
......
<!DOCTYPE html>
<%@include file="/WEB-INF/jsp/init.jsp"%>
<html>
<head>
<title><spring:message code="selection.page.title" /></title>
</head>
<body>
<h1>
<spring:message code="selection.page.title" />
</h1>
<c:if test="${accessions == null}">
<div class="alert">
<spring:message code="selection.empty-list-warning" />
</div>
</c:if>
<c:if test="${accessions != null}">
<div class="page-header">
<a href="<c:url value="/sel/clear" />">Clear list</a>
</div>
<div class="nav-header">
<spring:message code="accessions.number" arguments="${accessions.totalElements}" />
<br />
<spring:message code="paged.pageOfPages" arguments="${accessions.number+1},${accessions.totalPages}" />
<a href="?page=${accessions.number}">⇇ Previous</a> <a href="?page=${accessions.number + 2}">Next ⇉</a>
</div>
<table>
<thead>
<tr>
<td class="idx-col"></td>
<td><spring:message code="accession.accessionName" /></td>
<td><spring:message code="accession.origin" /></td>
<td><spring:message code="accession.taxonomy" /></td>
<td><spring:message code="accession.holdingInstitute" /></td>
<td><spring:message code="accession.holdingCountry" /></td>
<td></td>
</tr>
</thead>
<tbody>
<c:forEach items="${accessions.content}" var="accession" varStatus="status">
<tr id="a${accession.id}" class="targeted ${status.count % 2 == 0 ? 'even' : 'odd'}">
<td class="idx-col">${status.count + accessions.size * accessions.number}</td>
<td><a href="<c:url value="/acn/id/${accession.id}" />"><b><c:out value="${accession.accessionName}" /></b></a></td>
<td><c:out value="${accession.countryOfOrigin.name}" /></td>
<td><c:out value="${accession.taxonomy.taxonName}" /></td>
<td><a href="<c:url value="/wiews/${accession.institute.code.toLowerCase()}" />"><c:out value="${accession.institute.code}" /></a></td>
<td><a href="<c:url value="/geo/${accession.institute.country.code3.toLowerCase()}" />"><c:out value="${accession.institute.country.name}" /></a></td>
<td class="idx-col"><a href="<c:url value="/sel/remove/${accession.id}" />">Remove</a></td>
</tr>
</c:forEach>
</tbody>
</table>
</c:if>
<c:if test="${accessions eq null or accessions.number eq 0}">
<h4 style="margin-top: 3em">Add multiple accessions</h4>
<form method="post" action="<c:url value="/sel/add-many" />" class="form-horizontal">
<div class="control-group">
<label for="accessionIds" class="control-label"><spring:message code="selection.add-many.accessionIds" /></label>
<div class="controls">
<textarea class="form-control" placeholder="12345 123545 423231" name="accessionIds"></textarea>
</div>
</div>
<div class="form-actions clearfix">
<input type="submit" value="<spring:message code="selection.add-many" />" />
</div>
</form>
</c:if>
<script type="text/javascript">
/* jQuery(document).ready(function(){
if(document.location.hash != '') {
setTimeout(function() { document.location.hash=''; }, 2000);
}
}); */
</script>
</body>
</html>
\ No newline at end of file
......@@ -7,7 +7,11 @@
<title><spring:message code="faoInstitutes.page.profile.title" arguments="${faoInstitute.fullName}" argumentSeparator="|" /></title>
</head>
<body>
<h1><c:out value="${faoInstitute.fullName}" /></h1>
<h1>
<img class="country-flag bigger" src="http://genesys-pgr.org/images/flags/${faoInstitute.country.code3.toUpperCase()}.png" />
<c:out value="${faoInstitute.fullName}" />
<small><c:out value="${faoInstitute.code}" /></small>
</h1>
<c:if test="${countByInstitute eq 0}">
<div class="alert"><spring:message code="faoInstitute.no-accessions-registered" /></div>
......@@ -18,7 +22,7 @@
</c:if> --%>
<div>
<img src="http://genesys-pgr.org/images/flags/${faoInstitute.country.code3.toUpperCase()}.png" />
<%-- <img src="http://genesys-pgr.org/images/flags/${faoInstitute.country.code3.toUpperCase()}.png" /> --%>
<a href="<c:url value="/geo/${faoInstitute.country.code3.toLowerCase()}" />"><c:out value="${faoInstitute.country.name}" /></a>
</div>
......
......@@ -12,10 +12,10 @@
</h1>
<c:if test="${activeOnly eq true}">
<div><a href="<c:url value="/wiews/" />"><spring:message code="faoInstitutes.viewAll" /></a></div>
<div class="page-header"><a href="<c:url value="/wiews/" />"><spring:message code="faoInstitutes.viewAll" /></a></div>
</c:if>
<c:if test="${activeOnly ne true}">
<div><a href="<c:url value="/wiews/active" />"><spring:message code="faoInstitutes.viewActiveOnly" /></a></div>
<div class="page-header"><a href="<c:url value="/wiews/active" />"><spring:message code="faoInstitutes.viewActiveOnly" /></a></div>
</c:if>
<div class="nav-header">
......
......@@ -16,6 +16,10 @@
font-size: 15px;
}
.form-actions {
padding: 1em 1em;
}
.nav-header {
padding: 1em 0;
}
......@@ -112,7 +116,7 @@ li.hoofdleter small {
margin-left: 1em;
}
div.targeted:target {
.targeted:target {
background-color: #dfd0c0;
}
......
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