Commit 00ae3464 authored by Alexander Basov's avatar Alexander Basov Committed by Matija Obreza
Browse files

Done --> Feature #25054

Enhancing crop pages with text blurb
parent 2a45f047
......@@ -36,6 +36,8 @@ public interface CropService {
List<Crop> getCrops(Taxonomy2 taxonomy2);
void updateBlurp(Crop crop, String textBody, String summary, Locale locale);
void rebuildTaxonomies();
void rebuildTaxonomies(Crop crop);
......
......@@ -16,14 +16,6 @@
package org.genesys2.server.service.impl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.Predicate;
import org.apache.commons.lang.StringUtils;
......@@ -37,6 +29,7 @@ import org.genesys2.server.persistence.domain.CropRepository;
import org.genesys2.server.persistence.domain.CropRuleRepository;
import org.genesys2.server.persistence.domain.CropTaxonomyRepository;
import org.genesys2.server.persistence.domain.Taxonomy2Repository;
import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.HtmlSanitizer;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -49,6 +42,8 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
@Service
@Transactional(readOnly = true)
public class CropServiceImpl implements CropService {
......@@ -69,6 +64,9 @@ public class CropServiceImpl implements CropService {
@Autowired
private HtmlSanitizer htmlSanitizer;
@Autowired
private ContentService contentService;
@Autowired
private Taxonomy2Repository taxonomy2Repository;
......@@ -86,6 +84,13 @@ public class CropServiceImpl implements CropService {
return crop;
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#faoInstitute, 'ADMINISTRATION')")
@Transactional(readOnly = false)
public void updateBlurp(Crop crop, String textBody, String summary, Locale locale) {
contentService.updateArticle(crop, "blurp", null, textBody, summary, locale);
}
@Override
public List<Crop> listCrops() {
return cropRepository.findAll();
......
......@@ -18,11 +18,7 @@ package org.genesys2.server.servlet.controller;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.CropTaxonomy;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.FilterConstants;
import org.genesys2.server.service.GenesysFilterService;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.TraitService;
import org.genesys2.server.service.*;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
......@@ -42,6 +38,9 @@ public class CropController extends BaseController {
@Autowired
private CropService cropService;
@Autowired
private ContentService contentService;
@Autowired
private GenesysService genesysService;
......@@ -61,10 +60,31 @@ public class CropController extends BaseController {
model.addAttribute("crop", crop);
model.addAttribute("cropRules", cropService.getCropRules(crop));
model.addAttribute("cropTaxonomies", cropService.getCropTaxonomies(crop, new PageRequest(0, 20, new Sort("taxonomy.genus", "taxonomy.species"))));
model.addAttribute("blurp", contentService.getArticle(crop, "blurp", getLocale()));
return "/crop/index";
}
@RequestMapping("/{shortName}/edit")
public String edit(ModelMap model, @PathVariable(value = "shortName") String shortName) {
view(model, shortName);
return "/crop/edit";
}
@RequestMapping("/{shortName}/update")
public String update(ModelMap model, @PathVariable(value = "shortName") String shortName, @RequestParam("blurp") String aboutBody,
@RequestParam(value = "summary", required = false) String summary) {
_logger.debug("Updating crop " + shortName);
final Crop crop = cropService.getCrop(shortName);
if (crop == null) {
throw new ResourceNotFoundException();
}
cropService.updateBlurp(crop, aboutBody, summary, getLocale());
return "redirect:/c/" + shortName;
}
@RequestMapping("/{shortName}/ajax/taxonomies")
public String ajaxTaxonomies(ModelMap model, @PathVariable(value = "shortName") String shortName,
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
......
......@@ -138,6 +138,8 @@ crop.all-crops=All crops
crop.page.profile.title={0} profile
crop.taxonomy-rules=Taxonomic rules
crop.view-descriptors=View crop descriptors...
crop.page.profile.title=Edit {0}
crop.summary=Summary (HTML metadata)
activity.recent-activity=Recent activity
......@@ -219,12 +221,12 @@ accession.mlsStatus=MLS Status
accession.duplSite=Safety duplication institute
accession.inSvalbard=Safety duplicated in Svalbard
accession.inTrust.true=This accession is under Article 15 of the International Treaty on Plant Genetic Resources for Food and Agriculture.
accession.mlsStatus.true=This accession is in the Multilateral System of the ITPGRFA.
accession.mlsStatus.true=This accession is in the Multilateral System of the ITPGRFA.
accession.inSvalbard.true=Safety duplicated in Svalbard Global Seed Vault.
accession.not-available-for-distribution=The accession is NOT available for distribution.
accession.this-is-a-historic-entry=This is a historic record of an accession.
accession.historic=Historic entry
accession.available-for-distribution=The accession is available for distribution.
accession.available-for-distribution=The accession is available for distribution.
accession.elevation=Elevation
accession.geolocation=Geolocation (lat, long)
......@@ -325,7 +327,7 @@ accession.acceUrl=Additional accession URL
accession.page.profile.title=Accession profile: {0}
accession.page.resolve.title=Multiple accessions found
accession.resolve=Multiple accessions with the name ''{0}'' found in Genesys. Select one from the list.
accession.resolve=Multiple accessions with the name ''{0}'' found in Genesys. Select one from the list.
accession.page.data.title=Accession browser
accession.page.data.intro=Explore the accession data with Genesys. To refine your search, add filters such as country of origin, crop, species, or the latitude and longitude of the collecting site.
accession.taxonomy-at-institute=View {0} at {1}
......@@ -398,7 +400,7 @@ filter.apply=Apply
filter.close=Close
filter.remove=Remove filter
filter.autocomplete-placeholder=Type more than 3 characters...
filter.coll.collMissId=Collecting mission ID
filter.coll.collMissId=Collecting mission ID
filter.storage=Type of Germplasm storage
filter.string.equals=Equals
filter.string.like=Starts with
......@@ -468,7 +470,7 @@ oauth2.button-approve=Yes, allow access
oauth2.button-deny=No, deny access
oauth2.authorization-code=Authorization code
oauth2.authorization-code-instructions=Copy this authorization code:
oauth2.authorization-code-instructions=Copy this authorization code:
oauth2.access-denied=Access denied
oauth2.access-denied-text=You have denied access to your resources.
......@@ -667,7 +669,7 @@ accession.donorNumb=Donor institute code
accession.acqDate=Acquisition date
accession.svalbard-data.url=Svalbard database URL
accession.svalbard-data.url-title=Deposit information in SGSV database
accession.svalbard-data.url-title=Deposit information in SGSV database
accession.svalbard-data.url-text=View SGSV deposit information for {0}
filter.download-pdci=Download PDCI data
......
<!DOCTYPE html>
<%@include file="/WEB-INF/jsp/init.jsp"%>
<html>
<head>
<title><spring:message code="crop.page.profile.title" arguments="${crop.name}" argumentSeparator="|" /></title>
</head>
<body>
<h1>
<img class="country-flag bigger" src="<c:url value="${cdnFlagsUrl}" />/${faoInstitute.country.code3.toUpperCase()}.svg" />
<c:out value="${crop.name}" />
<small><c:out value="${crop.shortName}" /></small>
</h1>
<form role="form" class="form-horizontal" action="<c:url value="/c/${crop.shortName}/update" />" method="post">
<div class="form-group">
<label for="blurp-body" class="col-lg-12 control-label"><spring:message code="blurp.blurp-body" /></label>
<div class="controls col-lg-12">
<textarea id="blurp-body" name="blurp" class="span9 required html-editor">
<c:out value="${blurp.body}" />
</textarea>
</div>
</div>
<div class="form-group">
<label for="crop-summary" class="col-lg-12 control-label"><spring:message code="crop.summary" /></label>
<div class="controls col-lg-12">
<textarea id="crop-summary" name="summary" class="span9 required html-editor">
<c:out value="${blurp.summary}" />
</textarea>
</div>
</div>
<%--<div class="form-group">--%>
<%--<label class="col-lg-3 control-label"><spring:message code="ga.tracker-code" /></label>--%>
<%--<div class="controls col-lg-9">--%>
<%--<input type="text" name="gaTracker" class="form-control required" value="${faoInstitute.settings['googleAnalytics.tracker'].value}" />--%>
<%--</div>--%>
<%--</div>--%>
<%--<div class="form-group">--%>
<%--<label class="col-lg-3 control-label"><spring:message code="faoInstitute.requests.mailto" /></label>--%>
<%--<div class="controls col-lg-9">--%>
<%--<input type="text" name="mailto" class="form-control required" value="${faoInstitute.settings['requests.mailto'].value}" />--%>
<%--</div>--%>
<%--</div>--%>
<%--<div class="form-group">--%>
<%--<label class="col-lg-3 control-label"><spring:message code="faoInstitute.sgsv" /></label>--%>
<%--<div class="controls col-lg-9">--%>
<%--<input type="text" name="codeSVGS" class="form-control required" value="${faoInstitute.codeSGSV}" />--%>
<%--</div>--%>
<%--</div>--%>
<%--<div class="form-group">--%>
<%--<div class="controls col-lg-offset-3 col-lg-9">--%>
<%--<label><input type="radio" name="uniqueAcceNumbs" class="" value="true" ${faoInstitute.uniqueAcceNumbs==true ? 'checked' : ''} /> <spring:message code="faoInstitute.uniqueAcceNumbs.true" /></label>--%>
<%--<label><input type="radio" name="uniqueAcceNumbs" class="" value="false" ${faoInstitute.uniqueAcceNumbs==false ? 'checked' : ''} /> <spring:message code="faoInstitute.uniqueAcceNumbs.false" /></label>--%>
<%--</div>--%>
<%--<div class="controls col-lg-offset-3 col-lg-9">--%>
<%--<label><input type="checkbox" name="allowMaterialRequests" class="" ${faoInstitute.allowMaterialRequests==true ? 'checked' : ''} /> <spring:message code="faoInstitute.allow.requests" /></label>--%>
<%--</div>--%>
<%--</div>--%>
<input type="submit" value="<spring:message code="save"/>" class="btn btn-primary" /> <a href="<c:url value="/c/${crop.shortName}" />" class="btn btn-default"> <spring:message code="cancel" />
</a>
<!-- CSRF protection -->
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
</form>
<content tag="javascript">
<script type="text/javascript">
<local:tinyMCE selector=".html-editor" />
</script>
</content>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<%@include file="/WEB-INF/jsp/init.jsp"%>
<%@include file="/WEB-INF/jsp/init.jsp" %>
<html>
<head>
<title><spring:message code="crop.page.profile.title" arguments="${crop.getName(pageContext.response.locale)}" /></title>
<title><spring:message code="crop.page.profile.title"
arguments="${crop.getName(pageContext.response.locale)}"/></title>
</head>
<body>
<c:if test="${crop eq null}">
<div class="alert alert-error">
<spring:message code="data.error.404" />
</div>
</c:if>
<c:if test="${crop eq null}">
<div class="alert alert-error">
<spring:message code="data.error.404"/>
</div>
</c:if>
<h1>
<c:out value="${crop.getName(pageContext.response.locale)}" />
</h1>
<h1>
<c:out value="${crop.getName(pageContext.response.locale)}"/>
</h1>
<security:authorize access="hasRole('ADMINISTRATOR') or hasPermission(#crop, 'ADMINISTRATION')">
<a href="<c:url value="/acl/${crop.getClass().name}/${crop.id}/permissions"><c:param name="back">/c/${crop.shortName}</c:param></c:url>" class="close"> <spring:message code="edit-acl" /></a>
</security:authorize>
<security:authorize access="hasRole('ADMINISTRATOR') or hasPermission(#faoInstitute, 'ADMINISTRATION')">
<a href="<c:url value="/acl/${crop.getClass().name}/${crop.id}/permissions"><c:param name="back">/wiews/${crop.shortName}</c:param></c:url>"
class="close">
<spring:message code="edit-acl"/>
</a>
<a href="<c:url value="/c/${crop.shortName}/edit" />" class="close">
<spring:message code="edit"/>
</a>
</security:authorize>
<div class="free-text">
<c:out value="${crop.getDescription(pageContext.response.locale)}" />
</div>
<div>
<a href="<c:url value="/c/${crop.shortName}/data" />"><spring:message code="view.accessions" /></a>
</div>
<div>
<a href="<c:url value="/c/${crop.shortName}/descriptors" />"><spring:message code="crop.view-descriptors" /></a>
</div>
<c:if test="${blurp ne null}">
<span property="schema:Organization#description">
<%@include file="/WEB-INF/jsp/content/include/blurp-display.jsp" %>
</span>
</c:if>
<div>
<a href="<c:url value="/c/${crop.shortName}/data" />"><spring:message code="view.accessions"/></a>
</div>
<div>
<a href="<c:url value="/c/${crop.shortName}/descriptors" />"><spring:message code="crop.view-descriptors"/></a>
</div>
<h4><spring:message code="crop.taxonomy-rules" /></h4>
<ul class="funny-list">
<c:forEach items="${cropRules}" var="rule">
<li class="${rule.included ? '' : 'excluded'}" /><b>${rule.included ? '+' : '-'}</b> <c:out value="${rule.genus}" /> <c:out value="${rule.species eq null ? '*' : rule.species}" /></li>
</c:forEach>
</ul>
<h4><spring:message code="crop.taxonomy-rules"/></h4>
<ul class="funny-list">
<c:forEach items="${cropRules}" var="rule">
<li class="${rule.included ? '' : 'excluded'}"/>
<b>${rule.included ? '+' : '-'}</b> <c:out value="${rule.genus}"/> <c:out
value="${rule.species eq null ? '*' : rule.species}"/></li>
</c:forEach>
</ul>
<%--
<div class="free-text">
<c:out value="${crop.language}" />
</div>
--%>
<h3><spring:message code="taxonomy-list" /></h3>
<ul class="funny-list">
<c:forEach items="${cropTaxonomies.content}" var="cropTaxonomy" varStatus="status">
<li class="${status.count % 2 == 0 ? 'even' : 'odd'}"><a href="<c:url value="/acn/t/${cropTaxonomy.taxonomy.genus}/${cropTaxonomy.taxonomy.species}" />"><c:out value="${cropTaxonomy.taxonomy.taxonName}" /></a></li>
</c:forEach>
<c:if test="${cropTaxonomies.hasNext()}">
<li id="loadMoreTaxonomies"><button class="btn">Load more...</button></li>
</c:if>
</ul>
<h3><spring:message code="taxonomy-list"/></h3>
<ul class="funny-list">
<c:forEach items="${cropTaxonomies.content}" var="cropTaxonomy" varStatus="status">
<li class="${status.count % 2 == 0 ? 'even' : 'odd'}"><a
href="<c:url value="/acn/t/${cropTaxonomy.taxonomy.genus}/${cropTaxonomy.taxonomy.species}" />"><c:out
value="${cropTaxonomy.taxonomy.taxonName}"/></a></li>
</c:forEach>
<c:if test="${cropTaxonomies.hasNext()}">
<li id="loadMoreTaxonomies">
<button class="btn">Load more...</button>
</li>
</c:if>
</ul>
<content tag="javascript">
<content tag="javascript">
<script type="text/javascript">
jQuery(document).ready(function() {
$("body").on("click", "#loadMoreTaxonomies", function(event) {
jQuery(document).ready(function () {
$("body").on("click", "#loadMoreTaxonomies", function (event) {
event.preventDefault();
var loader=$(this);
var page=loader.attr("page") || 2;
var loader = $(this);
var page = loader.attr("page") || 2;
$.ajax({
url : "<c:url value="/c/${crop.shortName}/ajax/taxonomies" />",
type : "GET",
data : {
"page" : page
url: "<c:url value="/c/${crop.shortName}/ajax/taxonomies" />",
type: "GET",
data: {
"page": page
},
success : function(data) {
success: function (data) {
loader.before(data);
loader.attr("page", parseInt(page)+1);
loader.attr("page", parseInt(page) + 1);
},
error: function(err) {
error: function (err) {
loader.remove();
}
});
......
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