Commit a40766b8 authored by Matija Obreza's avatar Matija Obreza

Blurp editor and layout

parent c6c5c567
......@@ -27,7 +27,7 @@ import org.hibernate.search.annotations.DocumentId;
@SuppressWarnings("serial")
@MappedSuperclass
public abstract class BusinessModel implements HibernateModel {
public abstract class BusinessModel implements EntityId, HibernateModel {
@Id
@DocumentId
......
/**
* Copyright 2013 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.genesys2.server.model;
public interface EntityId {
Long getId();
}
......@@ -59,6 +59,7 @@ public class Article extends BusinessModel {
@Field(name = "title", store = Store.NO)
private String title;
@Column(nullable = false)
@Lob
@Field(name = "body", store = Store.NO)
private String body;
......
......@@ -29,6 +29,7 @@ import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import org.genesys2.server.lucene.genesys.FaoInstituteBridge;
import org.genesys2.server.model.EntityId;
import org.hibernate.annotations.Index;
import org.hibernate.search.annotations.Boost;
import org.hibernate.search.annotations.ClassBridge;
......@@ -42,7 +43,7 @@ import org.hibernate.search.annotations.Store;
@org.hibernate.annotations.Table(appliesTo = "faoinstitute", indexes = { @Index(columnNames = { "code" }, name = "code_FAOINSTITUTE") })
@Indexed
@ClassBridge(name = "body", impl = FaoInstituteBridge.class, boost = @Boost(10))
public class FaoInstitute extends GeoEntity implements java.io.Serializable {
public class FaoInstitute extends GeoEntity implements EntityId, java.io.Serializable {
/**
*
......
......@@ -19,7 +19,7 @@ package org.genesys2.server.service;
import java.util.List;
import java.util.Locale;
import org.genesys2.server.model.BusinessModel;
import org.genesys2.server.model.EntityId;
import org.genesys2.server.model.impl.ActivityPost;
import org.genesys2.server.model.impl.Article;
import org.genesys2.server.model.impl.ClassPK;
......@@ -43,7 +43,7 @@ public interface ContentService {
*/
Article getArticle(Class<?> clazz, Long id, String slug, Locale locale);
Article getArticle(BusinessModel businessEntity, String slug, Locale locale);
Article getArticle(EntityId entity, String slug, Locale locale);
/**
* Global articles have ClassPK of Article.class and targetId of null
......@@ -66,4 +66,12 @@ public interface ContentService {
* @return
*/
ActivityPost createActivityPost(String title, String body);
Article updateArticle(long id, String title, String body);
Article updateArticle(EntityId entity, String slug, String title, String body, Locale locale);
Article updateArticle(Class<?> clazz, Long id, String slug, String title, String body, Locale locale);
}
......@@ -22,7 +22,7 @@ import java.util.Locale;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.model.BusinessModel;
import org.genesys2.server.model.EntityId;
import org.genesys2.server.model.impl.ActivityPost;
import org.genesys2.server.model.impl.Article;
import org.genesys2.server.model.impl.ClassPK;
......@@ -79,8 +79,8 @@ public class ContentServiceImpl implements ContentService {
}
@Override
public Article getArticle(BusinessModel businessEntity, String slug, Locale locale) {
return getArticle(businessEntity.getClass(), businessEntity.getId(), slug, locale);
public Article getArticle(EntityId entity, String slug, Locale locale) {
return getArticle(entity.getClass(), entity.getId(), slug, locale);
}
@Override
......@@ -88,6 +88,52 @@ public class ContentServiceImpl implements ContentService {
return articleRepository.findByClassPkAndTargetIdAndSlugAndLang(getClassPk(clazz), id, slug, locale.getLanguage());
}
/**
* Creates or updates an article
*
* @param entity
* @param body
* @param locale
* @return
*/
@Override
@Transactional(readOnly = false)
public Article updateArticle(EntityId entity, String slug, String title, String body, Locale locale) {
// return
// articleRepository.findByClassPkAndTargetIdAndSlugAndLang(getClassPk(clazz),
// id, slug, locale.getLanguage());
return updateArticle(entity.getClass(), entity.getId(), slug, title, body, locale);
}
@Override
@Transactional(readOnly = false)
public Article updateArticle(Class<?> clazz, Long id, String slug, String title, String body, Locale locale) {
Article article = getArticle(clazz, id, slug, locale);
if (article == null || article.getLang() != locale.getLanguage()) {
article = new Article();
article.setClassPk(ensureClassPK(clazz));
article.setTargetId(id);
article.setLang(locale.getLanguage());
article.setPostDate(GregorianCalendar.getInstance());
article.setSlug(slug);
}
article.setBody(body);
article.setTitle(title);
articleRepository.save(article);
return article;
}
@Override
@Transactional(readOnly=false)
public Article updateArticle(long id, String title, String body) {
Article article = articleRepository.findOne(id);
article.setTitle(title);
article.setBody(body);
articleRepository.save(article);
return article;
}
public ClassPK getClassPk(Class<?> clazz) {
return classPkRepository.findByClassName(clazz.getName());
}
......
......@@ -14,7 +14,6 @@
* limitations under the License.
**/
package org.genesys2.server.servlet.controller;
import org.genesys2.server.model.impl.Article;
......@@ -25,6 +24,8 @@ 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
@RequestMapping("/content")
......@@ -46,4 +47,19 @@ public class ArticleController extends BaseController {
return "/content/article";
}
@RequestMapping(value = "/blurp/update-blurp", method = { RequestMethod.POST })
public String updateBlurp(ModelMap model, @RequestParam("id") long id, @RequestParam(required = false, value = "title") String title,
@RequestParam("body") String body) {
contentService.updateArticle(id, title, body);
return "redirect:/";
}
@RequestMapping(value = "/blurp/create-blurp", method = { RequestMethod.POST })
public String createBlurp(ModelMap model, @RequestParam("clazz") String clazz, @RequestParam("entityId") long entityId,
@RequestParam(required = false, value = "title") String title, @RequestParam("body") String body) throws ClassNotFoundException {
contentService.updateArticle(Class.forName(clazz), entityId, "blurp", title, body, getLocale());
return "redirect:/";
}
}
......@@ -21,6 +21,7 @@ import java.util.HashMap;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.Taxonomy;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.TaxonomyService;
......@@ -53,6 +54,10 @@ public class WiewsController extends BaseController {
@Autowired
private TaxonomyService taxonomyService;
@Autowired
private ContentService contentService;
@RequestMapping("/")
public String view(ModelMap model, @RequestParam(value = "page", required = false, defaultValue = "1") int page) {
model.addAttribute("pagedData", instituteService.list(new PageRequest(page - 1, 50, new Sort("code"))));
......@@ -75,8 +80,9 @@ public class WiewsController extends BaseController {
}
model.addAttribute("faoInstitute", faoInstitute);
model.addAttribute("blurp", contentService.getArticle(faoInstitute, "blurp", getLocale()));
model.addAttribute("countByInstitute", genesysService.countByInstitute(faoInstitute));
model.addAttribute("statisticsGenus", genesysService.statisticsGenusByInstitute(faoInstitute, new PageRequest(0, 30)));
model.addAttribute("statisticsTaxonomy", genesysService.statisticsTaxonomyByInstitute(faoInstitute, new PageRequest(0, 30)));
......
......@@ -122,6 +122,11 @@ faoInstitute.accessions.at=Accessions at {0}
faoInstitutes.viewAll=View all registered institutes
faoInstitutes.viewActiveOnly=View institutes with accessions in Genesys
faoInstitute.no-accessions-registered=Please get in touch with us if you can facilitate in providing data from this institiute.
faoInstitute.country=Country
faoInstitute.code=WIEWS Code
faoInstitute.email=Contact email
faoInstitute.acronym=Acronym
faoInstitute.url=Web link
view.accessions=View accessions...
paged.pageOfPages=Page {0} of {1}
......@@ -224,3 +229,8 @@ menu.translate=Translate Genesys
activitypost.post-title=Post title
activitypost.post-body=Body
activitypost.add-post=Add post
blurp.admin-no-blurp-here=No blurp here.
blurp.blurp-title=Blurp title
blurp.blurp-body=Blurp contents
blurp.update-blurp=Save blurp
......@@ -80,6 +80,8 @@
<bean name="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:content/language"/>
<property name="defaultEncoding" value="UTF-8"/>
<!-- Ease development -->
<property name="useCodeAsDefaultMessage" value="true" />
</bean>
<!--Interceptors-->
......
......@@ -46,75 +46,77 @@
<body>
<sec:authentication var="user" property="principal" />
<div class="container">
<div id="header">
<div class="clearfix">
<div class="pull-left">
<a href="<c:url value="/" />"><img style="height: 40px;" src="<c:url value="/html/images/logo2.png" />" /></a>
</div>
<!-- <h4 class="pull-left"><spring:message code="sample.message.welcome"/></h4> -->
<div class="pull-right searcher" style="margin-top: 5px;">
<form class="form-inline" method="get" action="<c:url value="/search" />">
<div class="input-group">
<input type="text" name="q" class="form-control" placeholder="<spring:message code="search.input.placeholder" />"/>
<span class="input-group-btn">
<button type="submit" class="btn notimportant"><spring:message code="search.button.label" /></button>
</span>
<div id="wrap">
<div class="container">
<div id="header">
<div class="clearfix">
<div class="pull-left">
<a href="<c:url value="/" />"><img style="height: 40px;" src="<c:url value="/html/images/logo2.png" />" /></a>
</div>
<!-- <h4 class="pull-left"><spring:message code="sample.message.welcome"/></h4> -->
<div class="pull-right searcher" style="margin-top: 5px;">
<form class="form-inline" method="get" action="<c:url value="/search" />">
<div class="input-group">
<input type="text" name="q" class="form-control" placeholder="<spring:message code="search.input.placeholder" />"/>
<span class="input-group-btn">
<button type="submit" class="btn notimportant"><spring:message code="search.button.label" /></button>
</span>
</div>
</form>
</div>
<div class="navbar pull-right">
<div class="nav-collapse">
<ul class="nav">
<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown"> <spring:message code="sample.message.locale.${pageContext.response.locale}" /> <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><a href="?lang=en"><spring:message code="sample.message.locale.en" /></a></li>
<li><a href="?lang=sl"><spring:message code="sample.message.locale.sl" /></a></li>
</ul></li>
</ul>
</div>
</form>
</div>
<div class="navbar pull-right">
<div class="nav-collapse">
<ul class="nav">
<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown"> <spring:message code="sample.message.locale.${pageContext.response.locale}" /> <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><a href="?lang=en"><spring:message code="sample.message.locale.en" /></a></li>
<li><a href="?lang=sl"><spring:message code="sample.message.locale.sl" /></a></li>
</ul></li>
</ul>
</div>
<div class="navbar pull-right">
<sec:authorize access="isAnonymous()">
<ul class="nav">
<li>
<a href="<c:url value="/login" />">Login</a><%-- or <a href="<c:url value="/registration" />"><spring:message code="user.create-new-account" /></a> --%>
</li>
</ul>
</sec:authorize>
<sec:authorize access="isAuthenticated()">
<ul class="nav">
<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" title="<spring:message code="sample.message.change.locale"/>"> You are <b>${user.username}</b> <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<sec:authorize access="hasRole('ADMINISTRATOR')">
<li><a href="<c:url value="/admin/" />">Administation</a></li>
</sec:authorize>
<li><a href="<c:url value="/profile" />"><spring:message code="user.pulldown.profile" /></a></li>
<li><a href="<c:url value="/logout" />"><spring:message code="user.pulldown.logout" /></a></li>
</ul></li>
</ul>
</sec:authorize>
</div>
</div>
<div class="navbar pull-right">
<sec:authorize access="isAnonymous()">
<ul class="nav">
<li>
<a href="<c:url value="/login" />">Login</a><%-- or <a href="<c:url value="/registration" />"><spring:message code="user.create-new-account" /></a> --%>
</li>
</ul>
</sec:authorize>
<sec:authorize access="isAuthenticated()">
<ul class="nav">
<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" title="<spring:message code="sample.message.change.locale"/>"> You are <b>${user.username}</b> <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<sec:authorize access="hasRole('ADMINISTRATOR')">
<li><a href="<c:url value="/admin/" />">Administation</a></li>
</sec:authorize>
<li><a href="<c:url value="/profile" />"><spring:message code="user.pulldown.profile" /></a></li>
<li><a href="<c:url value="/logout" />"><spring:message code="user.pulldown.logout" /></a></li>
</ul></li>
</ul>
</sec:authorize>
</div>
</div>
</div>
<%@include file="menu.jsp" %>
<div id="content" class="clearfix">
<div id="dialog"></div>
<div class="clearfix">
<sitemesh:write property="body" />
<%@include file="menu.jsp" %>
<div id="content" class="clearfix">
<div id="dialog"></div>
<div class="clearfix">
<sitemesh:write property="body" />
</div>
</div>
</div>
<%@include file="footer.jsp" %>
</div>
<%@include file="footer.jsp" %>
</body>
</html>
<%@include file="/WEB-INF/jsp/init.jsp"%>
<div id="footer" class="clearfix">
<div class="container">
<div id="footer">
<div id="nav-foot" class="clearfix">
<div class="pull-left">
<ul>
<li><a href="<c:url value="/content/about" />"><spring:message code="menu.about" /></a></li>
<li><a href="<c:url value="/content/contact" />"><spring:message code="menu.contact" /></a></li>
<li><a href="<c:url value="/content/disclaimer" />"><spring:message code="menu.disclaimer" /></a></li>
<li><a href="https://bitbucket.org/genesys2/genesys2-server/issues/new"><spring:message code="menu.report-an-issue" /></a></li>
<li class="notimportant"><a href="https://bitbucket.org/genesys2/genesys2-server.git"><spring:message code="menu.scm" /></a></li>
<li class="notimportant"><a href="https://www.transifex.com/projects/p/genesys/"><spring:message code="menu.translate" /></a></li>
<li><a target="_blank" href="https://bitbucket.org/genesys2/genesys2-server/issues/new"><spring:message code="menu.report-an-issue" /></a></li>
<li class="notimportant"><a target="_blank" href="https://bitbucket.org/genesys2/genesys2-server.git"><spring:message code="menu.scm" /></a></li>
<li class="notimportant"><a target="_blank" href="https://www.transifex.com/projects/p/genesys/"><spring:message code="menu.translate" /></a></li>
</ul>
</div>
<div class="pull-right">
......@@ -32,3 +33,4 @@
<!-- Processing time:
<div class="footer clearfix" style="font-size: 80%"><spring:message code="page.rendertime" arguments="${springExecuteTime}" /></div>
-->
</div>
\ No newline at end of file
......@@ -32,6 +32,9 @@
<script type="text/javascript" src="/html/js/jquery.dataTables.js"></script>
<script type="text/javascript" src="/html/js/handlebars.js"></script> -->
<script type="text/javascript" src="/html/js/bootstrap.min.js"></script>
<sec:authorize access="! isAnonymous()">
<script type="text/javascript" src="/html/js/tinymce/tinymce.min.js"></script>
</sec:authorize>
<script type="text/javascript" src="/html/js/crophub.js"></script>
<!--
-->
......@@ -43,37 +46,39 @@
<body>
<sec:authentication var="user" property="principal" />
<div class="container">
<div id="header">
<div class="clearfix">
<div class="pull-left">
<a href="<c:url value="/" />"><img style="height: 30px" src="<c:url value="/html/images/logo2.png" />" /></a>
</div>
<div class="pull-right" id="header-searcher">
<form class="form-inline" method="get" action="<c:url value="/search" />">
<div class="input-group">
<input type="text" name="q" class="form-control" placeholder="<spring:message code="search.input.placeholder" />"/>
<span class="input-group-btn">
<button type="submit" class="btn"><spring:message code="search.button.label" /></button>
</span>
</div>
</form>
<div id="wrap">
<div class="container">
<div id="header">
<div class="clearfix">
<div class="pull-left">
<a href="<c:url value="/" />"><img style="height: 30px" src="<c:url value="/html/images/logo2.png" />" /></a>
</div>
<div class="pull-right" id="header-searcher">
<form class="form-inline" method="get" action="<c:url value="/search" />">
<div class="input-group">
<input type="text" name="q" class="form-control" placeholder="<spring:message code="search.input.placeholder" />"/>
<span class="input-group-btn">
<button type="submit" class="btn"><spring:message code="search.button.label" /></button>
</span>
</div>
</form>
</div>
</div>
</div>
</div>
<%@include file="menu.jsp" %>
<div id="content" class="clearfix">
<div id="dialog"></div>
<div class="content-block clearfix">
<sitemesh:write property="body" />
<%@include file="menu.jsp" %>
<div id="content" class="clearfix">
<div id="dialog"></div>
<div class="content-block clearfix">
<sitemesh:write property="body" />
</div>
</div>
</div>
<%@include file="footer.jsp" %>
</div>
<%@include file="footer.jsp" %>
</body>
</html>
......@@ -11,4 +11,4 @@
<li><a href="<c:url value="/sel/" />"><spring:message code="menu.my-list" />
<span class="badge" id="selcounter">${selection.size() gt 0 ? selection.size() : ''}</span></a></li>
</ul>
</div>
\ No newline at end of file
</div>
<%@include file="/WEB-INF/jsp/init.jsp"%>
<div class="form-behind" id="blurper">
<div class="display">
<security:authorize access="hasRole('ADMINISTRATOR')">
<button type="button" class="close">Edit</button>
<c:if test="${blurp eq null}">
<spring:message code="blurp.admin-no-blurp-here" />
</c:if>
</security:authorize>
<c:out value="${blurp.body}" escapeXml="false" />
</div>
<security:authorize access="hasRole('ADMINISTRATOR')">
<div class="editor">
<button type="button" class="close" aria-hidden="true">Close</button>
<form role="form" class="" action="<c:url value="/content/blurp/${blurp.id ne null ? 'update' : 'create'}-blurp" />" method="post">
<c:if test="${clazz ne null and entityId ne null}">
<input type="hidden" name="clazz" value="${clazz}" />
<input type="hidden" name="entityId" value="${entityId}" />
</c:if>
<c:if test="${blurp ne null}">
<input type="hidden" name="id" value="${blurp.id}" />
</c:if>
<div class="form-group">
<label for="post-body" class="control-label"><spring:message code="blurp.blurp-body" /></label>
<div class="controls">
<textarea id="post-body" name="body" class="span9 required html-editor"><c:out value="${blurp.body}" /></textarea>
</div>
</div>
<input type="submit" value="<spring:message code="blurp.update-blurp"/>" class="btn btn-primary" />
</form>
<script type="text/javascript">
jQuery(document).ready(function() {
$("#blurper .display button").on("click", function(event) {
tinyMCE.init({
selector : "#post-body.html-editor",
menubar : false,
statusbar : false,
height: 200
});
$("#blurper").addClass("editing");
});
$("#blurper .editor button.close").on("click", function(event) {
$("#blurper").removeClass("editing");
});
});
</script>
</div>
</security:authorize>
</div>
......@@ -19,16 +19,17 @@
</c:if>
<div class="jumbotron">
<c:if test="${blurp ne null}">
<c:out value="${blurp.body}" escapeXml="false" />
<spring:message code="country.stat.countByOrigin" arguments="${countByOrigin}" />
<c:if test="${countByOrigin gt 0}">
<a href="<c:url value="/geo/${country.code3.toLowerCase()}/data" />"><spring:message code="view.accessions" /></a>
</c:if>
<div>
<spring:message code="country.stat.countByOrigin" arguments="${countByOrigin}" />
<c:if test="${countByOrigin gt 0}">
<a href="<c:url value="/geo/${country.code3.toLowerCase()}/data" />"><spring:message code="view.accessions" /></a>
</c:if>
</div>
</div>