Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Genesys Backend
Commits
25d2c60c
Commit
25d2c60c
authored
Sep 23, 2013
by
Matija Obreza
Browse files
Activity post for admins
parent
258b73a9
Changes
8
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/genesys2/server/model/impl/ActivityPost.java
View file @
25d2c60c
...
...
@@ -38,11 +38,11 @@ public class ActivityPost extends BusinessModel {
private
static
final
long
serialVersionUID
=
8690395020204070378L
;
@Column
(
nullable
=
false
,
length
=
500
)
@Field
(
name
=
"title"
,
store
=
Store
.
NO
)
@Field
(
name
=
"title"
,
store
=
Store
.
NO
)
private
String
title
;
@Lob
@Field
(
name
=
"body"
,
store
=
Store
.
NO
)
@Field
(
name
=
"body"
,
store
=
Store
.
NO
)
private
String
body
;
@Temporal
(
TemporalType
.
TIMESTAMP
)
...
...
@@ -72,4 +72,8 @@ public class ActivityPost extends BusinessModel {
this
.
postDate
=
postDate
;
}
@Override
public
String
toString
()
{
return
"ActivityPost id="
+
id
+
" title="
+
title
;
}
}
src/main/java/org/genesys2/server/service/ContentService.java
View file @
25d2c60c
...
...
@@ -57,4 +57,13 @@ public interface ContentService {
Page
<
Article
>
listArticles
(
Pageable
pageable
);
void
save
(
Iterable
<
Article
>
articles
);
/**
* Create new activity post
*
* @param title
* @param body
* @return
*/
ActivityPost
createActivityPost
(
String
title
,
String
body
);
}
src/main/java/org/genesys2/server/service/impl/ContentServiceImpl.java
View file @
25d2c60c
...
...
@@ -16,6 +16,7 @@
package
org.genesys2.server.service.impl
;
import
java.util.GregorianCalendar
;
import
java.util.List
;
import
java.util.Locale
;
...
...
@@ -29,6 +30,7 @@ import org.genesys2.server.persistence.domain.ActivityPostRepository;
import
org.genesys2.server.persistence.domain.ArticleRepository
;
import
org.genesys2.server.persistence.domain.ClassPKRepository
;
import
org.genesys2.server.service.ContentService
;
import
org.genesys2.server.service.HtmlSanitizer
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageRequest
;
...
...
@@ -51,6 +53,9 @@ public class ContentServiceImpl implements ContentService {
@Autowired
private
ClassPKRepository
classPkRepository
;
@Autowired
private
HtmlSanitizer
htmlSanitizer
;
@Override
public
List
<
ActivityPost
>
lastNews
()
{
PageRequest
page
=
new
PageRequest
(
0
,
10
,
Direction
.
DESC
,
"postDate"
);
...
...
@@ -108,4 +113,21 @@ public class ContentServiceImpl implements ContentService {
}
return
classPk
;
}
/**
* Sanitize content and persist new {@link ActivityPost}
*/
@Override
@Transactional
(
readOnly
=
false
)
public
ActivityPost
createActivityPost
(
String
title
,
String
body
)
{
ActivityPost
newPost
=
new
ActivityPost
();
newPost
.
setTitle
(
htmlSanitizer
.
sanitize
(
title
));
newPost
.
setBody
(
htmlSanitizer
.
sanitize
(
body
));
newPost
.
setPostDate
(
GregorianCalendar
.
getInstance
());
postRepository
.
save
(
newPost
);
LOG
.
info
(
"Added new: "
+
newPost
);
return
newPost
;
}
}
src/main/java/org/genesys2/server/servlet/controller/ActivityPostController.java
0 → 100644
View file @
25d2c60c
package
org.genesys2.server.servlet.controller
;
import
java.util.Calendar
;
import
net.sf.oval.constraint.NotEmpty
;
import
net.sf.oval.constraint.NotNull
;
import
org.genesys2.server.service.ContentService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.ModelMap
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
@Controller
@RequestMapping
(
"/content/activity"
)
public
class
ActivityPostController
extends
BaseController
{
@Autowired
private
ContentService
contentService
;
@RequestMapping
(
value
=
"/add-post-x"
,
method
=
{
RequestMethod
.
POST
})
public
String
postPost
(
ModelMap
model
,
@RequestParam
(
"title"
)
String
title
,
@RequestParam
(
"body"
)
String
body
)
{
contentService
.
createActivityPost
(
title
,
body
);
return
"redirect:/"
;
}
@RequestMapping
(
value
=
"/add-post"
,
method
=
{
RequestMethod
.
PUT
},
consumes
=
{
MediaType
.
APPLICATION_JSON_VALUE
})
@ResponseBody
public
JsonActivityPost
putPost
(
ModelMap
model
,
@RequestBody
@Validated
JsonActivityPost
newPost
)
{
_logger
.
debug
(
"Adding post: "
+
newPost
);
return
null
;
}
public
static
class
JsonActivityPost
{
public
Long
id
;
@NotNull
(
message
=
"sample.error.not.null"
)
@NotEmpty
(
message
=
"sample.error.not.empty"
)
public
String
title
,
body
;
public
Calendar
postDate
;
@Override
public
String
toString
()
{
return
"ActivityPost title="
+
title
+
" id="
+
id
;
}
}
}
src/main/resources/content/language.properties
View file @
25d2c60c
...
...
@@ -219,3 +219,8 @@ filter.organization=Organization
menu.report-an-issue
=
Report an issue
menu.scm
=
Source code
menu.translate
=
Translate Genesys
activitypost.post-title
=
Post title
activitypost.post-body
=
Body
activitypost.add-post
=
Add post
src/main/webapp/WEB-INF/decorator/entry.jsp
View file @
25d2c60c
...
...
@@ -32,6 +32,10 @@
<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>
<!--
--><!-- <script type="text/javascript" src="/html/js/main.js"></script>
...
...
src/main/webapp/WEB-INF/jsp/content/include/activity-post.jsp
0 → 100644
View file @
25d2c60c
<%@include
file=
"/WEB-INF/jsp/init.jsp"
%>
<sec:authorize
access=
"hasRole('ADMINISTRATOR')"
>
<form
class=
"form-vertical"
action=
"
<c:url
value=
"/content/activity/add-post-x"
/>
"
method=
"post"
>
<div
class=
"control-group"
>
<label
for=
"post-title"
class=
"control-label"
><spring:message
code=
"activitypost.post-title"
/></label>
<div
class=
"controls"
>
<input
type=
"text"
id=
"post-title"
name=
"title"
class=
"span9 required html-editor"
/>
</div>
</div>
<div
class=
"control-group"
>
<label
for=
"post-body"
class=
"control-label"
><spring:message
code=
"activitypost.post-body"
/></label>
<div
class=
"controls"
>
<textarea
id=
"post-body"
name=
"body"
class=
"span9 required html-editor"
></textarea>
</div>
</div>
<input
type=
"submit"
value=
"
<spring:message
code=
"activitypost.add-post"
/>
"
class=
"btn btn-primary"
/>
</form>
<script
type=
"text/javascript"
>
jQuery
(
document
).
ready
(
function
()
{
tinyMCE
.
init
({
selector
:
"
#post-title.html-editor
"
,
menubar
:
false
,
statusbar
:
false
,
height
:
50
});
tinyMCE
.
init
({
selector
:
"
#post-body.html-editor
"
,
menubar
:
false
,
statusbar
:
false
,
height
:
200
});
});
</script>
</sec:authorize>
src/main/webapp/WEB-INF/jsp/index.jsp
View file @
25d2c60c
...
...
@@ -28,6 +28,9 @@
<c:if
test=
"
${
lastNews
ne
null
}
"
>
<div
class=
"content-block"
>
<h1><spring:message
code=
"activity.recent-activity"
/></h1>
<%@include
file=
"/WEB-INF/jsp/content/include/activity-post.jsp"
%>
<c:forEach
items=
"
${
lastNews
}
"
var=
"activityPost"
varStatus=
"status"
>
<div
class=
"activity-post"
>
<div
class=
"heading"
>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment