Commit 75dfcf2d authored by Matija Obreza's avatar Matija Obreza
Browse files

News archive

parent 46e8563e
/**
* Copyright 2014 Global Crop Diversity Trust
* Copyright 2015 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.
......@@ -37,15 +37,24 @@ import com.fasterxml.jackson.databind.ObjectMapper;
@Component
public class JspHelper {
@Autowired
private static final String regExpr="[^\\w]+";
private static final String delimiter="-";
@Autowired
private UserService userService;
@Autowired
@Autowired
private GeoService geoService;
@Autowired
@Autowired
private CropService cropService;
@Autowired
@Autowired
private ObjectMapper objectMapper;
@Autowired
@Autowired
private HtmlConverter htmlConverter;
public String userFullName(Long userId) {
......@@ -104,4 +113,8 @@ public class JspHelper {
public int randomInt(int min, int max) {
return min + RandomUtils.nextInt(max - min + 1);
}
public String suggestUrlForText(String text) {
return htmlToText(text, 60).replaceAll(regExpr, delimiter).toLowerCase().replaceAll("\\-+$", "");
}
}
/**
* Copyright 2015 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.servlet.controller;
import java.util.ArrayList;
import java.util.List;
import org.genesys2.server.model.impl.ActivityPost;
import org.genesys2.server.model.impl.Menu;
import org.genesys2.server.model.impl.MenuItem;
......@@ -16,23 +35,12 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
@Controller
public class NewsController extends BaseController {
@Value("${news.title.url.reg.expr}")
private String regExpr;
@Value("${news.title.url.delimiter}")
private String delimiter;
@Value("${news.menu.abbreviate.lenght}")
private int abrLenght;
@Value("${news.menu.abbreviate.length}")
private int abrLength;
@Autowired
private ContentService contentService;
......@@ -44,17 +52,10 @@ public class NewsController extends BaseController {
public String getAllNews(ModelMap model, @RequestParam(value = "page", defaultValue = "1") int page) {
Page<ActivityPost> allNews = contentService.allNews(page);
Map<Long, String> titlesRef = new HashMap<>();
for (ActivityPost post : allNews.getContent()) {
titlesRef.put(post.getId(), normaliseTitle(post.getTitle()));
post.getLastModifiedBy();
}
model.addAttribute("pagedData", allNews);
model.addAttribute("titlesRef", titlesRef);
return "/content/news-all";
return "/content/news-index";
}
......@@ -63,7 +64,7 @@ public class NewsController extends BaseController {
ActivityPost activityPost = contentService.getActivityPost(id);
List menuItems = new ArrayList<>();
List<MenuItem> menuItems = new ArrayList<MenuItem>();
MenuItem archiveItem = new MenuItem();
archiveItem.setText(messageSource.getMessage("news.archive.title", new Object[]{}, LocaleContextHolder.getLocale()));
......@@ -77,8 +78,8 @@ public class NewsController extends BaseController {
if (post.getId().equals(id)) continue;
MenuItem item = new MenuItem();
item.setText(jspHelper.htmlToText(post.getTitle(), abrLenght));
item.setUrl("/content/news/" + post.getId() + "/" + normaliseTitle(post.getTitle()));
item.setText(jspHelper.htmlToText(post.getTitle(), abrLength));
item.setUrl("/content/news/" + post.getId() + "/" + jspHelper.suggestUrlForText(post.getTitle()));
menuItems.add(item);
}
......@@ -100,9 +101,5 @@ public class NewsController extends BaseController {
return "/content/news";
}
private String normaliseTitle(String title) {
return jspHelper.htmlToText(title).replaceAll(regExpr, delimiter);
}
}
......@@ -628,10 +628,6 @@ menu.admin.loggers=Loggers
menu.admin.caches=Caches
menu.admin.ds2=DS2 Datasets
news.share=Share this news
news.title=News
news.author=Author
news.last.modified.date=Updating date
news.content.page.all.title=News list
news.archive.title=News Archive
......
......@@ -34,9 +34,7 @@ hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
google.api.key=AIzaSyBEvPuc8j5ps5GDQ3tdnTJaffKhfOdxFVc
google.url.shortener=https://www.googleapis.com/urlshortener/v1/url
news.title.url.reg.expr=[^\\w]+
news.title.url.delimiter=-
news.menu.abbreviate.lenght=22
news.menu.abbreviate.length=22
c3p0.acquireIncrement=1
c3p0.minPoolSize=1
......
......@@ -75,6 +75,11 @@ html[dir="rtl"] {
}
}
.list-unstyled {
padding-left: inherit;
padding-right: 0;
}
@media (min-width: $screen-md-min) {
.col-md-offset-2 {
margin-right: 16.6666666667%;
......
......@@ -396,6 +396,10 @@ html[dir="rtl"] .navbar#nav-main ul li a{
margin-top: 0px;
margin-bottom: 0px;
padding: 10px 30px;
p {
margin: 0px;
}
}
}
......@@ -2448,4 +2452,14 @@ div[x-href] {
color: inherit;
display: inline;
}
}
\ No newline at end of file
}
#show-moar-news {
width: 100%;
display: block;
color: White;
background-color: #BBB;
border: solid 1px #999;
text-align: center;
padding: 10px;
}
<!DOCTYPE html>
<%@include file="/WEB-INF/jsp/init.jsp" %>
<html>
<head>
<title><spring:message code="news.content.page.all.title"/></title>
</head>
<body>
<div class="main-col clearfix">
<h1>
<spring:message code="news.content.page.all.title"/>
</h1>
<div class="main-col-header clearfix">
<div class="nav-header">
<div class="results"><spring:message code="paged.totalElements"
arguments="${pagedData.totalElements}"/></div>
<div class="pagination pull-left">
<spring:message code="paged.pageOfPages" arguments="${pagedData.number+1},${pagedData.totalPages}"/>
<a class="${pagedData.number eq 0 ? 'disabled' :''}"
href="?page=${pagedData.number eq 0 ? 1 : pagedData.number}"><spring:message
code="pagination.previous-page"/></a> <a href="?page=${pagedData.number + 2}"><spring:message
code="pagination.next-page"/></a>
</div>
</div>
</div>
<table class="">
<thead>
<tr>
<td></td>
<td><spring:message code="news.title"/></td>
<td><spring:message code="news.last.modified.date"/></td>
<td><spring:message code="news.author"/></td>
</tr>
</thead>
<tbody>
<c:forEach items="${pagedData.content}" var="news" varStatus="status">
<tr class="${status.count % 2 == 0 ? 'even' : 'odd'}">
<td>${status.count}</td>
<td>
<a href="<c:url value="/content/news/${news.id}/${titlesRef[news.id]}" />">${jspHelper.htmlToText(news.title)}</a>
</td>
<td>${news.lastModifiedDate}</td>
<td>${jspHelper.userFullName(news.lastModifiedBy)}</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</body>
</html>
<!DOCTYPE html>
<%@include file="/WEB-INF/jsp/init.jsp" %>
<html>
<head>
<title><spring:message code="news.content.page.all.title"/></title>
</head>
<body>
<div class="main-col clearfix">
<cms:informative-h1 title="news.content.page.all.title" fancy="true" />
<div class="main-col-header clearfix">
<div class="nav-header">
<div class="results"><spring:message code="paged.totalElements"
arguments="${pagedData.totalElements}"/></div>
<div class="pagination pull-left">
<spring:message code="paged.pageOfPages" arguments="${pagedData.number+1},${pagedData.totalPages}"/>
<a class="${pagedData.number eq 0 ? 'disabled' :''}"
href="?page=${pagedData.number eq 0 ? 1 : pagedData.number}"><spring:message
code="pagination.previous-page"/></a> <a href="?page=${pagedData.number + 2}"><spring:message
code="pagination.next-page"/></a>
</div>
</div>
</div>
<ul class="funny-list" dir="ltr">
<c:forEach items="${pagedData.content}" var="news" varStatus="status">
<li class="clearfix ${status.count % 2 == 0 ? 'even' : 'odd'}">
<a class="pull-left"
href="<c:url value="/content/news/${news.id}/${jspHelper.suggestUrlForText(news.title)}" />"><c:out
value="${jspHelper.htmlToText(news.title)}" /></a>
<div class="pull-right"><local:prettyTime date="${news.postDate.time}" locale="${pageContext.response.locale}" /></div>
</li>
</c:forEach>
</ul>
</div>
</body>
</html>
......@@ -34,7 +34,7 @@
<div class="article">
<div class="right-side main-col col-md-9">
<div class="free-text">
<div class="free-text" dir="ltr">
<c:out value="${news.body}" escapeXml="false" />
</div>
......@@ -44,7 +44,7 @@
<div class="share-article">
<p>
<spring:message code="news.share" />
<spring:message code="article.share" />
</p>
<ul class="list-inline">
<li class="twitter">
......@@ -57,7 +57,7 @@
</div>
</div>
<div class="col-md-3 sidebar-nav col-xs-12">
<div class="col-md-3 sidebar-nav col-xs-12" dir="ltr">
<cms:menu key="${menu.key}" items="${menu.items}" />
</div>
</div>
......
......@@ -132,6 +132,8 @@
<cms:activitypost activityPost="${activityPost}" />
</c:forEach>
</div>
<a id="show-moar-news" href="<c:url value="/content/news" />"><spring:message code="news.content.page.all.title" /></a>
</div>
</div>
</div>
......
......@@ -8,7 +8,7 @@
<%@ attribute name="activityPost" required="true" type="org.genesys2.server.model.impl.ActivityPost" %>
<div class="post type-article">
<div class="post-head clearfix">
<div class="post-head clearfix" x-href="<c:url value="/content/news/${activityPost.id}/${jspHelper.suggestUrlForText(activityPost.title)}" />">
<div class="user-icon">
<img src="<c:url value="/html/images/icon_user_genesys.png" />" alt="" />
</div>
......
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