Commit 521f04e0 authored by Matija Obreza's avatar Matija Obreza
Browse files

Posts

parent 630d0982
package org.crophub.rest.common.model.impl;
import java.util.Calendar;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.crophub.rest.common.model.BusinessModel;
@Entity
@Table(name = "activitypost")
public class ActivityPost extends BusinessModel {
private static final long serialVersionUID = 8690395020204070378L;
@Column(nullable = false, length = 500)
private String title;
@Lob
private String body;
@Temporal(TemporalType.TIMESTAMP)
private Calendar postDate;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public Calendar getPostDate() {
return postDate;
}
public void setPostDate(Calendar postDate) {
this.postDate = postDate;
}
}
/**
* 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.crophub.rest.common.persistence.domain;
import org.crophub.rest.common.model.impl.ActivityPost;
import org.springframework.data.jpa.repository.JpaRepository;
public interface ActivityPostRepository extends JpaRepository<ActivityPost, Long> {
}
package org.crophub.rest.common.service;
import java.util.List;
import org.crophub.rest.common.model.impl.ActivityPost;
public interface ActivityPostService {
List<ActivityPost> lastNews();
}
package org.crophub.rest.common.service.impl;
import java.util.List;
import org.crophub.rest.common.model.impl.ActivityPost;
import org.crophub.rest.common.persistence.domain.ActivityPostRepository;
import org.crophub.rest.common.service.ActivityPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional(readOnly = true)
public class ActivityPostServiceImpl implements ActivityPostService {
@Autowired
private ActivityPostRepository postRepository;
@Override
public List<ActivityPost> lastNews() {
PageRequest page = new PageRequest(0, 10, Direction.DESC, "postDate");
return postRepository.findAll(page).getContent();
}
}
...@@ -28,6 +28,7 @@ import org.crophub.rest.common.aspect.AsAdmin; ...@@ -28,6 +28,7 @@ import org.crophub.rest.common.aspect.AsAdmin;
import org.crophub.rest.common.model.Permissions; import org.crophub.rest.common.model.Permissions;
import org.crophub.rest.common.model.UserRole; import org.crophub.rest.common.model.UserRole;
import org.crophub.rest.common.model.impl.User; import org.crophub.rest.common.model.impl.User;
import org.crophub.rest.common.service.ActivityPostService;
import org.crophub.rest.common.service.CropService; import org.crophub.rest.common.service.CropService;
import org.crophub.rest.common.service.UserService; import org.crophub.rest.common.service.UserService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -54,6 +55,9 @@ public class HtmlController extends BaseController { ...@@ -54,6 +55,9 @@ public class HtmlController extends BaseController {
@Autowired @Autowired
private CropService cropService; private CropService cropService;
@Autowired
private ActivityPostService activityPostService;
@Autowired @Autowired
private Validator validator; private Validator validator;
...@@ -74,6 +78,7 @@ public class HtmlController extends BaseController { ...@@ -74,6 +78,7 @@ public class HtmlController extends BaseController {
List<Permissions> permissionsList = Arrays.asList(Permissions.values()); List<Permissions> permissionsList = Arrays.asList(Permissions.values());
model.addAttribute("permissionsList", permissionsList); model.addAttribute("permissionsList", permissionsList);
model.addAttribute("cropList", cropService.list()); model.addAttribute("cropList", cropService.list());
model.addAttribute("lastNews", activityPostService.lastNews());
return "/index"; return "/index";
} }
......
...@@ -73,6 +73,7 @@ data.error.404=The data you requested was not found in the system. ...@@ -73,6 +73,7 @@ data.error.404=The data you requested was not found in the system.
user.pulldown.logout=Logout user.pulldown.logout=Logout
user.pulldown.profile=View profile user.pulldown.profile=View profile
crop.croplist=Crop list crop.croplist=Crop list
crop.page.profile.title=Crop profile crop.page.profile.title=Crop profile
activity.recent-activity=Recent activity
...@@ -9,12 +9,36 @@ ...@@ -9,12 +9,36 @@
<body> <body>
<c:if test="${cropList ne null and cropList.size() gt 0}"> <c:if test="${cropList ne null and cropList.size() gt 0}">
<div class="pull-left" style="margin-right: 5%;">
<h3><spring:message code="crop.croplist"/></h3> <h3><spring:message code="crop.croplist"/></h3>
<ul> <ul>
<c:forEach items="${cropList}" var="crop" varStatus="status"> <c:forEach items="${cropList}" var="crop" varStatus="status">
<li><a href="/c/${crop.shortName}"><c:out value="${crop.name}" /></a></li> <li><a href="/c/${crop.shortName}"><c:out value="${crop.name}" /></a></li>
</c:forEach> </c:forEach>
</ul> </ul>
</div>
</c:if> </c:if>
<c:if test="${lastNews ne null}">
<div class="pull-left" style="width: 60%; margin-left: 5%">
<h3><spring:message code="activity.recent-activity"/></h3>
<c:forEach items="${lastNews}" var="activityPost" varStatus="status">
<div class="activity-post">
<div class="heading">
<c:out value="${activityPost.title}" escapeXml="false" />
</div>
<c:if test="${activityPost.body ne null and activityPost.body.length() gt 0}">
<div class="post-body">
<c:out value="${activityPost.body}" escapeXml="false" />
</div>
</c:if>
<div class="foot">
<fmt:formatDate value="${activityPost.postDate.time}" />
</div>
</div>
</c:forEach>
</div>
</c:if>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -30,4 +30,20 @@ h1, h2, h3, h4 { ...@@ -30,4 +30,20 @@ h1, h2, h3, h4 {
td { td {
vertical-align: top; vertical-align: top;
padding: 0.2em 0.5em; padding: 0.2em 0.5em;
} }
\ No newline at end of file
.activity-post {
padding: 1em 0em;
}
.activity-post .post-body {
background-color: #e0e0e0;
padding: 0.3em;
margin: 1em;
margin-left: 10%;
}
.activity-post .foot {
margin-left: 10%;
font-size: 80%;
}
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