Commit 46e8563e authored by Alexander Dolzhenko's avatar Alexander Dolzhenko
Browse files

News_archive

parent b22f2c15
......@@ -34,6 +34,8 @@ public interface ContentService {
List<ActivityPost> lastNews();
Page<ActivityPost> allNews(int page);
ClassPK ensureClassPK(Class<?> clazz);
/**
......
......@@ -92,6 +92,13 @@ public class ContentServiceImpl implements ContentService {
return postRepository.findAll(page).getContent();
}
@Override
@Cacheable(value = "contentcache")
public Page<ActivityPost> allNews(int page) {
final PageRequest pageRequest = new PageRequest(page-1, 50, Direction.DESC, "postDate");
return postRepository.findAll(pageRequest);
}
@Override
public Page<Article> listArticles(Pageable pageable) {
return articleRepository.findAll(pageable);
......
package org.genesys2.server.servlet.controller;
import org.genesys2.server.model.impl.ActivityPost;
import org.genesys2.server.model.impl.Menu;
import org.genesys2.server.model.impl.MenuItem;
import org.genesys2.server.service.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
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;
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;
@Autowired
private ContentService contentService;
@Autowired
private JspHelper jspHelper;
@RequestMapping(value = "/content/news", method = RequestMethod.GET)
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";
}
@RequestMapping(value = "/content/news/{id:.+}/{title:.+} ", method = RequestMethod.GET)
public String getNewsById(@PathVariable("id") Long id, Model model) throws Exception {
ActivityPost activityPost = contentService.getActivityPost(id);
List menuItems = new ArrayList<>();
MenuItem archiveItem = new MenuItem();
archiveItem.setText(messageSource.getMessage("news.archive.title", new Object[]{}, LocaleContextHolder.getLocale()));
archiveItem.setUrl("/content/news");
menuItems.add(archiveItem);
List<ActivityPost> posts = contentService.lastNews();
for (ActivityPost post : posts) {
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()));
menuItems.add(item);
}
Menu menu = new Menu();
menu.setKey("temp menu");
menu.setItems(menuItems);
model.addAttribute("news", activityPost);
model.addAttribute("menu", menu);
return "/content/news";
}
@RequestMapping(value = "/content/news/edit/{id:.+}", method = RequestMethod.GET)
public String editNews(@PathVariable("id") Long id, Model model) throws Exception {
ActivityPost activityPost = contentService.getActivityPost(id);
model.addAttribute("news", activityPost);
return "/content/news";
}
private String normaliseTitle(String title) {
return jspHelper.htmlToText(title).replaceAll(regExpr, delimiter);
}
}
......@@ -628,6 +628,13 @@ 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
worldclim.monthly.title=Climate at collecting site
worldclim.monthly.precipitation.title=Monthly precipitation
worldclim.monthly.temperatures.title=Monthly temperatures
......
......@@ -50,7 +50,6 @@ registration.full-name=Ваше полное имя
registration.create-account=Создать учетную запись
captcha.text=Текст капчи
id=ID
name=Название
......@@ -107,7 +106,12 @@ menu.how-to-use-genesys=Как пользоваться проектом Genesys
menu.history-of-genesys=История проекта Genesys
menu.about-genesys-data=О данных в проекте Genesys
news.share=Поделиться новостью
news.title=Новости
news.author=Автор
news.last.modified.date=Дата обновления
news.content.page.all.title=Список новостей
news.archive.title =Архив новостей
page.home.title=PGR Genesys
......
......@@ -34,6 +34,9 @@ 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
c3p0.acquireIncrement=1
c3p0.minPoolSize=1
......
<!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>${jspHelper.htmlToText(news.title)}</title>
</head>
<body>
<content tag="header">
<div class="hidden-xs top-image">
<img src="<c:url value="/html/images/aim/banner-${jspHelper.randomInt(1, 4)}.jpg" />" title="${title}" />
</div>
<div class="top-title">
<div class="container">
<security:authorize access="hasRole('ADMINISTRATOR') or hasRole('CONTENTMANAGER')">
<form class="inline-form pull-right" >
<a href="<c:url value="/content/activitypost/${news.id}/edit"/>" class="btn btn-default">
<spring:message code="edit" />
</a>
<a href="<c:url value="/content/activitypost/new"/>" class="btn btn-default">
<spring:message code="activitypost.add-new-post" />
</a>
</form>
</security:authorize>
<h1>
<c:out value="${news.title}" escapeXml="false" />
</h1>
</div>
</div>
</content>
<div class="article">
<div class="right-side main-col col-md-9">
<div class="free-text">
<c:out value="${news.body}" escapeXml="false" />
</div>
<div class="article-timestamp">
<local:prettyTime date="${news.postDate.time}" locale="${pageContext.response.locale}" />
</div>
<div class="share-article">
<p>
<spring:message code="news.share" />
</p>
<ul class="list-inline">
<li class="twitter">
<local:tweet text="${news.title}" hashTags="GenesysPGR" />
</li>
<li class="linkedin">
<local:linkedin-share text="${news.title}" summary="${news.body}" />
</li>
</ul>
</div>
</div>
<div class="col-md-3 sidebar-nav col-xs-12">
<cms:menu key="${menu.key}" items="${menu.items}" />
</div>
</div>
</body>
</html>
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