Navigation Menu

Skip to content

Commit

Permalink
Improved the structure of Thymeleaf views. Added Ajax view for signup…
Browse files Browse the repository at this point in the history
…. New AboutController. Jquery now bundled.
  • Loading branch information
kolorobot committed Nov 17, 2016
1 parent 59781c5 commit 1340abf
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 45 deletions.
Expand Up @@ -46,7 +46,7 @@ protected void configure(AuthenticationManagerBuilder auth) throws Exception {
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/", "/favicon.ico", "/resources/**", "/signup").permitAll()
.antMatchers("/", "/favicon.ico", "/resources/**", "/signup", "/about").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
Expand Down
@@ -0,0 +1,19 @@
package ${package}.home;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
class AboutController {

@ModelAttribute("module")
String module() {
return "about";
}

@GetMapping("/about")
String about() {
return "home/about";
}
}
Expand Up @@ -3,13 +3,19 @@
import java.security.Principal;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class HomeController {
class HomeController {

@ModelAttribute("module")
String module() {
return "home";
}

@GetMapping("/")
public String index(Principal principal) {
String index(Principal principal) {
return principal != null ? "home/homeSignedIn" : "home/homeNotSignedIn";
}
}
Expand Up @@ -8,8 +8,9 @@
</head>
<body>
<div class="container">
<div th:replace="fragments/alert :: alert (type='danger', message=${errorMessage})">Error: Error</div>
<div th:include="fragments/footer :: footer">&copy; 2013 The Static Templates</div>
<div th:replace="fragments/layout :: header"></div>
<div th:replace="fragments/components :: alert (type='danger', message=${errorMessage})">Error: Error</div>
<div th:replace="fragments/layout :: footer"></div>
</div>
</body>
</html>

This file was deleted.

@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<link href="../../../resources/css/bootstrap.min.css" rel="stylesheet" media="screen" th:href="@{/resources/css/bootstrap.min.css}"/>
</head>
<body>
<!-- Reusable alert -->
<div th:fragment="alert (type, message)" class="alert alert-dismissable" th:classappend="'alert-' + ${type}">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<span th:text="${message}">Test</span>
</div>
<!-- Reusable modal -->
<div th:fragment="modal (id, title)" class="modal fade" th:id="${id}" tabindex="-1" role="dialog" aria-labelledby="modalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title" id="modalLabel" th:text="${title}">My modal</h4>
</div>
<div class="modal-body" th:id="${id + '-body'}"></div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</body>
</html>

This file was deleted.

Expand Up @@ -4,6 +4,8 @@
<link href="../../../resources/css/bootstrap.min.css" rel="stylesheet" media="screen" th:href="@{/resources/css/bootstrap.min.css}"/>
</head>
<body>

<!-- Header -->
<div class="navbar navbar-inverse navbar-fixed-top" th:fragment="header">
<div class="container">
<div class="navbar-header">
Expand All @@ -16,9 +18,12 @@
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#" th:href="@{/}">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
<li th:classappend="${module == 'home' ? 'active' : ''}">
<a href="#" th:href="@{/}">Home</a>
</li>
<li th:classappend="${module == 'about' ? 'active' : ''}">
<a href="#about" th:href="@{/about}">About</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li th:if="${#authorization.expression('!isAuthenticated()')}">
Expand All @@ -37,5 +42,12 @@
<!--/.nav-collapse -->
</div>
</div>

<!-- Footer -->
<div th:fragment="footer" th:align="center">
&copy;&nbsp;<span th:text="${#temporals.format(#temporals.createNow(), 'yyyy')}">2016</span>
Demo project <span th:text="${@environment.getProperty('app.version')}"></span>
</div>

</body>
</html>
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title th:text="#{view.index.title}">Welcome!</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link href="../../../resources/css/bootstrap.min.css" rel="stylesheet" media="screen" th:href="@{/resources/css/bootstrap.min.css}"/>
<link href="../../../resources/css/core.css" rel="stylesheet" media="screen" th:href="@{/resources/css/core.css}" />
<script src="../../../resources/js/jquery.min.js" th:src="@{/resources/js/jquery.min.js}"></script>
<script src="../../../resources/js/bootstrap.min.js" th:src="@{/resources/js/bootstrap.min.js}"></script>
</head>
<body>
<div th:replace="fragments/layout :: header"></div>
<div class="container">
<p class="lead text-center">
About
</p>
</div>
<div th:replace="fragments/layout :: footer"></div>
</body>
</html>
Expand Up @@ -5,11 +5,11 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link href="../../../resources/css/bootstrap.min.css" rel="stylesheet" media="screen" th:href="@{/resources/css/bootstrap.min.css}"/>
<link href="../../../resources/css/core.css" rel="stylesheet" media="screen" th:href="@{/resources/css/core.css}" />
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="../../../resources/js/jquery.min.js" th:src="@{/resources/js/jquery.min.js}"></script>
<script src="../../../resources/js/bootstrap.min.js" th:src="@{/resources/js/bootstrap.min.js}"></script>
</head>
<body>
<div th:replace="fragments/header :: header">Header</div>
<div th:replace="fragments/layout :: header"></div>
<div class="container">
<div class="text-center">
<h1>Test</h1>
Expand All @@ -18,10 +18,27 @@ <h1>Test</h1>
Get started quickly by signing up.
</p>
<p>
<a href="/signup" th:href="@{/signup}" class="btn btn-success btn-lg">Sign up</a>
<a class="btn btn-success btn-lg" id="signup">Sign up</a>
</p>
</div>
<div th:replace="fragments/footer :: footer">&copy; 2013 The Static Templates</div>
<div th:replace="fragments/layout :: footer">&copy; 2016 The Static Templates</div>
</div>
<script th:inline="javascript" type="text/javascript">
/* Fill in modal with content loaded with Ajax */
$(document).ready(function () {
$('#signup').on('click', function () {
$("#signup-modal").modal();
$("#signup-modal-body").text("");
$.ajax({
url: "signup",
cache: false
}).done(function (html) {
$("#signup-modal-body").append(html);
});
})
});
</script>
<!-- Signup modal -->
<div th:replace="fragments/components :: modal(id='signup-modal', title='Signup')"></div>
</body>
</html>
Expand Up @@ -5,20 +5,21 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link href="../../../resources/css/bootstrap.min.css" rel="stylesheet" media="screen" th:href="@{/resources/css/bootstrap.min.css}"/>
<link href="../../../resources/css/core.css" rel="stylesheet" media="screen" th:href="@{/resources/css/core.css}" />
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="../../../resources/js/jquery.min.js" th:src="@{/resources/js/jquery.min.js}"></script>
<script src="../../../resources/js/bootstrap.min.js" th:src="@{/resources/js/bootstrap.min.js}"></script>
</head>
<body>
<div th:replace="fragments/header :: header">&nbsp;</div>
<div th:replace="fragments/layout :: header"></div>
<div class="container">
<!-- /* Handle the flash message */-->
<th:block th:if="${message != null}">
<!-- /* The message code is returned from the @Controller */ -->
<div th:replace="fragments/alert :: alert (type=${#strings.toLowerCase(message.type)}, message=#{${message.message}(${#authentication.name})})">&nbsp;</div>
<div th:replace="fragments/components :: alert (type=${#strings.toLowerCase(message.type)}, message=#{${message.message}(${#authentication.name})})">&nbsp;</div>
</th:block>
<p>
<p class="lead text-center">
Welcome to the Spring MVC Quickstart application!
</p>
<div th:replace="fragments/layout :: footer"></div>
</div>
</body>
</html>
Expand Up @@ -7,9 +7,10 @@
<link href="../../../resources/css/core.css" rel="stylesheet" media="screen" th:href="@{/resources/css/core.css}" />
</head>
<body>
<div th:replace="fragments/layout :: header"></div>
<form class="form-narrow form-horizontal" action="#" method="post" th:action="@{/authenticate}">
<th:block th:if="${param.error != null}">
<div th:replace="fragments/alert :: alert (type='danger', message='Sign in error. Please try again.')">Alert</div>
<div th:replace="fragments/components :: alert (type='danger', message='Sign in error. Please try again.')">Alert</div>
</th:block>
<fieldset>
<legend>Please Sign In</legend>
Expand Down Expand Up @@ -46,5 +47,6 @@
</div>
</fieldset>
</form>
<div th:replace="fragments/layout :: footer"></div>
</body>
</html>
Expand Up @@ -5,14 +5,15 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link href="../../../resources/css/bootstrap.min.css" rel="stylesheet" media="screen" th:href="@{/resources/css/bootstrap.min.css}"/>
<link href="../../../resources/css/core.css" rel="stylesheet" media="screen" th:href="@{/resources/css/core.css}" />
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="../../../resources/js/jquery.min.js" th:src="@{/resources/js/jquery.min.js}"></script>
<script src="../../../resources/js/bootstrap.min.js" th:src="@{/resources/js/bootstrap.min.js}"></script>
</head>
<body>
<form class="form-narrow form-horizontal" method="post" th:action="@{/signup}" th:object="${signupForm}">
<div th:replace="fragments/layout :: header"></div>
<form class="form-narrow form-horizontal" method="post" th:action="@{/signup}" th:object="${signupForm}" th:fragment="signupForm">
<!--/* Show general error message when form contains errors */-->
<th:block th:if="${#fields.hasErrors('${signupForm.*}')}">
<div th:replace="fragments/alert :: alert (type='danger', message='Form contains errors. Please try again.')">Alert</div>
<div th:replace="fragments/components :: alert (type='danger', message='Form contains errors. Please try again.')">Alert</div>
</th:block>
<fieldset>
<legend>Please Sign Up</legend>
Expand Down Expand Up @@ -42,5 +43,6 @@
</div>
</fieldset>
</form>
<div th:replace="fragments/layout :: footer"></div>
</body>
</html>

Large diffs are not rendered by default.

0 comments on commit 1340abf

Please sign in to comment.