Skip to content

Commit 7338a80

Browse files
committed
various changes
1 parent 8a8c0ac commit 7338a80

File tree

16 files changed

+307
-126
lines changed

16 files changed

+307
-126
lines changed

src/main/java/ru/mrchebik/web/BlogController.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ public class BlogController {
3434
@Resource
3535
private CommentService commentService;
3636

37-
@RequestMapping(value = "/", method = GET)
38-
public String notes(@RequestParam(value = "hide", defaultValue = "1") int page,
37+
@RequestMapping(value = { "/", "/{username}" }, method = GET)
38+
public String notes(@PathVariable(required = false) String username,
39+
@RequestParam(value = "hide", defaultValue = "1") int page,
3940
@RequestParam(value = "hideId", defaultValue = "0") long id,
4041
Principal principal,
4142
Model model) {
@@ -68,26 +69,22 @@ public String notes(@RequestParam(value = "hide", defaultValue = "1") int page,
6869
posts = posts.subList((page - 1) * UserSession.getCount(), page * UserSession.getCount());
6970
}
7071
}
72+
model.addAttribute("userBlog", username);
7173
model.addAttribute("username", principal.getName());
74+
for (Post post : posts) {
75+
if (post.getText().length() > 500) {
76+
post.setText(post.getText().substring(0, 500) + "...");
77+
}
78+
}
7279
model.addAttribute("posts", posts);
7380
model.addAttribute("page", page);
7481
model.addAttribute("pages", UserSession.getPages());
7582

76-
return "Blog";
77-
}
78-
79-
@RequestMapping(value = "/add", method = GET)
80-
public String addPage() {
81-
return "AddPost";
82-
}
83-
84-
@RequestMapping(value = "/add", method = POST)
85-
public String addPost(@RequestParam String title,
86-
@RequestParam String text,
87-
Principal principal) {
88-
postService.add(new Post(userService.findUser(principal.getName()), title, text, new Date()));
89-
90-
return "redirect:/blog/";
83+
if (username != null) {
84+
return "BlogGlobal";
85+
} else {
86+
return "Blog";
87+
}
9188
}
9289

9390
@RequestMapping(value = "/{username}/post/{id}", method = GET)
@@ -146,9 +143,10 @@ public String postPage(@PathVariable String id,
146143
public String addComment(@PathVariable String id,
147144
@PathVariable String username,
148145
@RequestParam String text,
146+
@RequestParam(value = "hide") int page,
149147
Principal principal) {
150148
commentService.addComment(new Comment(userService.findUser(principal.getName()), postService.findPost(Integer.parseInt(id)), text, new Date()));
151149

152-
return "redirect:/blog/" + username + "/post/" + id;
150+
return "redirect:/blog/" + username + "/post/" + id + "?hide=" + page;
153151
}
154152
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,41 @@
11
package ru.mrchebik.web;
22

3+
import org.springframework.stereotype.Controller;
4+
import org.springframework.web.bind.annotation.RequestMapping;
5+
import org.springframework.web.bind.annotation.RequestParam;
6+
import ru.mrchebik.model.Post;
7+
import ru.mrchebik.service.PostService;
8+
import ru.mrchebik.service.UserService;
9+
10+
import javax.annotation.Resource;
11+
import java.security.Principal;
12+
import java.util.Date;
13+
14+
import static org.springframework.web.bind.annotation.RequestMethod.GET;
15+
import static org.springframework.web.bind.annotation.RequestMethod.POST;
16+
317
/**
418
* Created by mrchebik on 14.01.17.
519
*/
20+
@Controller
21+
@RequestMapping("/blog/post")
622
public class PostController {
23+
@Resource
24+
private PostService postService;
25+
@Resource
26+
private UserService userService;
27+
28+
@RequestMapping(value = "/add", method = GET)
29+
public String addPage() {
30+
return "AddPost";
31+
}
32+
33+
@RequestMapping(value = "/add", method = POST)
34+
public String addPost(@RequestParam String title,
35+
@RequestParam String text,
36+
Principal principal) {
37+
postService.add(new Post(userService.findUser(principal.getName()), title, text, new Date()));
38+
39+
return "redirect:/blog/";
40+
}
741
}

src/main/webapp/WEB-INF/views/AddPost.jsp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<link type="text/css" rel="stylesheet" href="<c:url value="/resources/css/Boxes.css"/>"/>
1515
<link type="text/css" rel="stylesheet" href="<c:url value="/resources/css/Blog.css"/>"/>
1616
<link type="text/css" rel="stylesheet" href="<c:url value="/resources/css/Add.css"/>"/>
17+
<script type="text/javascript" src="<c:url value="/resources/js/Title.js"/>"></script>
1718
</head>
1819
<body>
1920
<div class="top">
@@ -31,20 +32,23 @@
3132
</div>
3233
</div>
3334
<div class="center">
34-
<div class="postCreateBox">
35-
<form id="form1" method="post">
36-
<input id="title" type="text" name="title" required placeholder="Title">
37-
<textarea id="text" name="text" required placeholder="Text"></textarea>
38-
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}">
39-
</form>
40-
</div>
41-
<div class="menu">
42-
<div class="addButton" onclick="document.getElementById('form1').submit()">
43-
Add post
35+
<div class="postsBox">
36+
<div class="postCreateBox">
37+
<form id="form1" method="post">
38+
<input id="title" type="text" name="title" oninput="check(this.id)" placeholder="Title">
39+
<textarea id="text" name="text" placeholder="Text"></textarea>
40+
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}">
41+
</form>
42+
</div>
43+
<div class="menu">
44+
<div class="addButton" onclick="checkError()">
45+
Add post
46+
</div>
4447
</div>
4548
</div>
4649
</div>
4750
<div class="footer">
51+
<hr class="footer">
4852
© 2017 Blog
4953
</div>
5054
</body>

src/main/webapp/WEB-INF/views/Blog.jsp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
</div>
3838
<div class="center">
3939
<div class="menu">
40-
<div class="addButton" onclick="window.location.href='/blog/add'">
40+
<div class="addButton" onclick="window.location.href='/blog/post/add'">
4141
Add post
4242
</div>
4343
</div>
@@ -97,6 +97,7 @@
9797
</div>
9898
</div>
9999
<div class="footer">
100+
<hr class="footer">
100101
© 2017 Blog
101102
</div>
102103
</body>

src/main/webapp/WEB-INF/views/BlogGlobal.jsp

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
12
<%--
23
Created by IntelliJ IDEA.
34
User: mrchebik
@@ -8,9 +9,89 @@
89
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
910
<html>
1011
<head>
11-
<title>Title</title>
12+
<title>Blog - ${userBlog}</title>
13+
<link type="text/css" rel="stylesheet" href="<c:url value="/resources/css/default.css"/>"/>
14+
<link type="text/css" rel="stylesheet" href="<c:url value="/resources/css/Boxes.css"/>"/>
15+
<link type="text/css" rel="stylesheet" href="<c:url value="/resources/css/Blog.css"/>"/>
1216
</head>
1317
<body>
14-
18+
<div class="top">
19+
<div class="blog">
20+
Blog
21+
</div>
22+
<c:if test="${username != null}">
23+
<div class="bar">
24+
<ul id="navbar">
25+
<li onclick="window.location.href='/blog/';"><span>Home</span></li>
26+
<li onclick="window.location.href='/blog/{username}/';"><span>View</span></li>
27+
<li onclick="window.location.href='/blog/news';"><span>News</span></li>
28+
<li onclick="window.location.href='/blog/setting/';"><span>Setting</span></li>
29+
<li onclick="window.location.href='/blog/logout/';"><span>Logout</span></li>
30+
</ul>
31+
</div>
32+
</c:if>
33+
</div>
34+
<div class="center">
35+
<div class="postsBox">
36+
<c:choose>
37+
<c:when test="${posts.size() == 0}" >
38+
<b>This user do not have any posts.</b>
39+
</c:when>
40+
<c:otherwise>
41+
<form id="form1" method="get">
42+
<c:forEach items="${posts}" var="post" >
43+
<div class="postBox">
44+
<div class="categoryBox"></div>
45+
<div class="titleBox fake-link" onclick="window.location.href='/blog/${username}/post/${post.postId}'">
46+
${post.title}
47+
</div>
48+
<hr>
49+
<div class="textBox">
50+
${post.text}
51+
</div>
52+
<hr class="date">
53+
<div class="dateBox">
54+
${post.date}
55+
</div>
56+
<hr class="date">
57+
</div>
58+
</c:forEach>
59+
</table>
60+
<input id="0071" type="hidden" name="hideId">
61+
<c:choose>
62+
<c:when test="${pages > 1}">
63+
<br>
64+
<input id="007" type="hidden" name="hide" value="${page}">
65+
<c:choose>
66+
<c:when test="${page > 4}">
67+
<span class="fake-link" id="${1}" onclick="submitData(this.id, '007')">${1}</span> ...
68+
</c:when>
69+
</c:choose>
70+
<c:forEach begin="${page > 4 ? page - 2 : 1}" end="${page + 4 > pages ? pages : page + 2}" var="pageId">
71+
<c:choose>
72+
<c:when test="${page == pageId}">
73+
<span class="fake-link currentPage" id="${pageId}" onclick="submitData(this.id, '007')">${pageId}</span>
74+
</c:when>
75+
<c:otherwise>
76+
<span class="fake-link" id="${pageId}" onclick="submitData(this.id, '007')">${pageId}</span>
77+
</c:otherwise>
78+
</c:choose>
79+
</c:forEach>
80+
<c:choose>
81+
<c:when test="${page + 4 <= pages}">
82+
... <span class="fake-link" id="${pages}" onclick="submitData(this.id, '007')">${pages}</span>
83+
</c:when>
84+
</c:choose>
85+
</c:when>
86+
</c:choose>
87+
</form>
88+
</c:otherwise>
89+
</c:choose>
90+
</div>
91+
</div>
92+
<div class="footer">
93+
<hr class="footer">
94+
© 2017 Blog
95+
</div>
1596
</body>
1697
</html>

src/main/webapp/WEB-INF/views/CheckCode.jsp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
</div>
3232
</div>
3333
<div class="footer">
34+
<hr class="footer">
3435
© 2017 Blog
3536
</div>
3637
</body>

src/main/webapp/WEB-INF/views/Forgot.jsp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
</div>
3434
</div>
3535
<div class="footer">
36+
<hr class="footer">
3637
© 2017 Blog
3738
</div>
3839
</body>

src/main/webapp/WEB-INF/views/NewPassword.jsp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
</div>
3333
</div>
3434
<div class="footer">
35+
<hr class="footer">
3536
© 2017 Blog
3637
</div>
3738
</body>

src/main/webapp/WEB-INF/views/News.jsp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
<span class="news">News</span>
6060
<hr>
6161
<p>
62+
24.01.17 -- Added the ability to add comments.<br>
6263
21.01.17 -- Added the ability to add posts.<br>
6364
17.01.17 -- Added a password recovery by email.<br>
6465
16.01.17 -- Added an authorization.<br>
@@ -85,6 +86,7 @@
8586
</div>
8687
</div>
8788
<div class="footer">
89+
<hr class="footer">
8890
© 2017 Blog
8991
</div>
9092
</body>

0 commit comments

Comments
 (0)