Bläddra i källkod

Adds Bootstrap and ThymeLeaf managment

fecaille 9 år sedan
förälder
incheckning
918f8fb20f

+ 50 - 7
pom.xml

@@ -17,6 +17,7 @@
 
 	<properties>
 		<java.version>1.8</java.version>
+		
 		<jasmine.version>2.4.1</jasmine.version>
 		<jasmine-ajax.version>3.2.0</jasmine-ajax.version>
 
@@ -38,7 +39,37 @@
 			<groupId>org.springframework.boot</groupId>
 			<artifactId>spring-boot-starter-thymeleaf</artifactId>
 		</dependency>
-		<!-- Testing -->
+		<!-- Security -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-security</artifactId>
+        </dependency>
+		<dependency>
+            <groupId>org.thymeleaf.extras</groupId>
+            <artifactId>thymeleaf-extras-springsecurity4</artifactId>
+        </dependency>
+        <!-- Persistence -->
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-jdbc</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-tx</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-orm</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.hibernate</groupId>
+            <artifactId>hibernate-entitymanager</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.hsqldb</groupId>
+            <artifactId>hsqldb</artifactId>
+        </dependency>
+   		<!-- Testing -->
 		<dependency>
 			<groupId>org.springframework.boot</groupId>
 			<artifactId>spring-boot-starter-test</artifactId>
@@ -118,7 +149,17 @@
 				<configuration>
 					<watches>
 						<watch>
-							<directory>src/main/webapp/js</directory>
+							<excludes>
+								<exclude>src/main/resources/static/js/bundle</exclude>
+								<exclude>src/main/resources/static/js/jsx</exclude>
+							</excludes>
+							<recursive>false</recursive>
+							<directory>src/main/resources/static/js</directory>
+						</watch>
+						<watch>
+							<exclude>src/main/resources/static/css/bundle</exclude>
+							<recursive>false</recursive>
+							<directory>src/main/resources/static/css</directory>
 						</watch>
 						<watch>
 							<directory>src/main/wro</directory>
@@ -141,7 +182,9 @@
 						</goals>
 						<configuration>
 							<target>
-								<delete dir="${project.basedir}/src/main/resources/static" />
+								<delete dir="${project.basedir}/src/main/resources/static/js/bundle" />
+								<delete dir="${project.basedir}/src/main/resources/static/js/jsx" />
+								<delete dir="${project.basedir}/src/main/resources/static/css/bundle" />
 								<delete dir="${project.basedir}/src/test/resources/static/js/compiled" />
 							</target>
 						</configuration>
@@ -185,10 +228,10 @@
 						<configuration>
 							<extension>jsx</extension>
 							<sourcePath>
-								${project.basedir}/src/main/webapp/js
+								${project.basedir}/src/main/resources/static/js
 							</sourcePath>
 							<targetPath>
-								${project.basedir}/src/main/resources/static/js
+								${project.basedir}/src/main/resources/static/js/jsx
 							</targetPath>
 						</configuration>
 					</execution>
@@ -224,8 +267,8 @@
 				</executions>
 				<configuration>
 					<wroManagerFactory>ro.isdc.wro.maven.plugin.manager.factory.ConfigurableWroManagerFactory</wroManagerFactory>
-					<cssDestinationFolder>${project.basedir}/src/main/resources/static/css</cssDestinationFolder>
-					<jsDestinationFolder>${project.basedir}/src/main/resources/static/js</jsDestinationFolder>
+					<cssDestinationFolder>${project.basedir}/src/main/resources/static/css/bundle</cssDestinationFolder>
+					<jsDestinationFolder>${project.basedir}/src/main/resources/static/js/bundle</jsDestinationFolder>
 					<wroFile>${project.build.directory}/wro/wro.xml</wroFile>
 					<extraConfigFile>${project.basedir}/src/main/wro/wro.properties</extraConfigFile>
 				</configuration>

+ 37 - 0
src/main/java/com/opengroupe/cloud/saas/config/WebMvcConfiguration.java

@@ -0,0 +1,37 @@
+package com.opengroupe.cloud.saas.config;
+
+import org.springframework.context.annotation.Bean;
+import org.thymeleaf.extras.springsecurity4.dialect.SpringSecurityDialect;
+import org.thymeleaf.spring4.SpringTemplateEngine;
+import org.thymeleaf.spring4.view.ThymeleafViewResolver;
+import org.thymeleaf.templateresolver.ServletContextTemplateResolver;
+import org.thymeleaf.templateresolver.TemplateResolver;
+import org.thymeleaf.templateresolver.UrlTemplateResolver;
+
+@org.springframework.context.annotation.Configuration
+public class WebMvcConfiguration {
+
+//    @Bean
+//    public TemplateResolver templateResolver() {
+//        TemplateResolver templateResolver = new ThymeleafViewResolver().;
+//        templateResolver.setPrefix("/resources/templates");
+//        templateResolver.setSuffix(".html");
+//        templateResolver.setTemplateMode("HTML5");
+//        templateResolver.setCacheable(false);
+//        return templateResolver;
+//    }
+
+//    @Bean
+//    public UrlTemplateResolver urlTemplateResolver() {
+//        return new UrlTemplateResolver();
+//    }
+    
+//	@Bean
+//	public SpringTemplateEngine templateEngine() {
+//		SpringTemplateEngine templateEngine = new SpringTemplateEngine();
+////		templateEngine.addTemplateResolver(templateResolver());
+//		templateEngine.addTemplateResolver(urlTemplateResolver());
+//		templateEngine.addDialect(new SpringSecurityDialect());
+//		return templateEngine;
+//	}
+}

+ 15 - 0
src/main/java/com/opengroupe/cloud/saas/config/WebSecurityConfig.java

@@ -0,0 +1,15 @@
+package com.opengroupe.cloud.saas.config;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
+import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+
+@Configuration
+@EnableWebSecurity
+public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
+	@Override
+	protected void configure(HttpSecurity http) throws Exception {
+		http.authorizeRequests().anyRequest().permitAll();
+	}
+}

+ 13 - 0
src/main/resources/templates/fragments/footer.html

@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+
+<body>
+	<div class="footer" th:fragment="header">
+		<div class="container">
+			<p>&copy; 2016 Footer</p>
+		</div>
+	</div>
+</body>
+</html>

+ 39 - 0
src/main/resources/templates/fragments/header.html

@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+
+<body>
+	<div class="container" th:fragment="header">
+		<div class="row">
+			<div class="navbar navbar-inverse">
+				<div class="container">
+					<div class="navbar-header">
+						<button type="button" class="navbar-toggle" data-toggle="collapse"
+							data-target=".nav-collapse">
+							<span class="icon-bar"></span> <span class="icon-bar"></span> <span
+								class="icon-bar"></span>
+						</button>
+						<a class="navbar-brand" href="#">My project</a>
+					</div>
+					<div class="navbar-collapse collapse">
+						<ul class="nav navbar-nav">
+							<li class="active"><a href="#" th:href="@{/}">Home</a></li>
+							<li><a href="#" th:href="@{/message}">Messages</a></li>
+							<li><a href="#" th:href="@{/task}">Tasks</a></li>
+						</ul>
+						<ul class="nav navbar-nav navbar-right">
+							<li th:if="${#authorization.expression('!isAuthenticated()')}">
+								<a href="/signin" th:href="@{/signin}">Sign in</a>
+							</li>
+							<li th:if="${#authorization.expression('isAuthenticated()')}">
+								<a href="/logout" th:href="@{/logout}">Logout</a>
+							</li>
+						</ul>
+					</div>
+				</div>
+			</div>
+		</div>
+	</div>
+</body>
+</html>

+ 21 - 14
src/main/resources/templates/index.html

@@ -1,17 +1,24 @@
 <!DOCTYPE html>
 <html xmlns:th="http://www.thymeleaf.org">
-	<head lang="en">
-	    <meta charset="UTF-8"/>
-	    <title>ReactJS</title>
-	    <link rel="stylesheet" href="/css/react-bootstrap.css" />
-	</head>
-	<body>
-	
-	    <div id="content"></div>
-	
-		<script src="/js/react-bootstrap.js"></script>
-	    <script src="/js/bundle.js"></script>
-	    <script src="/js/app.js"></script>
-	    <script src="/js/app.render.js"></script>
-	</body>
+<head lang="en">
+<meta charset="UTF-8" />
+<title>Comments channel</title>
+<link rel="stylesheet" href="/css/bundle/react-bootstrap.css" />
+<link rel="stylesheet" href="/css/bundle/comments.css" />
+</head>
+<body>
+
+	<div th:replace="fragments/header"></div>
+
+	<div class="container">
+		<div id="content"></div>
+	</div>
+
+	<div th:replace="fragments/footer"></div>
+
+	<script src="/js/bundle/react-bootstrap.js"></script>
+	<script src="/js/bundle/comments.js"></script>
+	<script src="/js/jsx/app.js"></script>
+	<script src="/js/jsx/app.render.js"></script>
+</body>
 </html>

+ 7 - 0
src/main/webapp/css/comments.css

@@ -0,0 +1,7 @@
+.footer {
+    position: absolute;
+    bottom: 0;
+    width: 100%;
+    height: 60px;
+    background-color: #f5f5f5;
+}

+ 0 - 0
src/main/webapp/js/app.render.js → src/main/webapp/js/app.render.jsx


+ 4 - 4
src/main/wro/wro.properties

@@ -1,8 +1,8 @@
 debug=true
 # Available processors : http://wro4j.readthedocs.org/en/stable/AvailableProcessors/
-preProcessors=lessCssImport
-postProcessors=less4j,cssMin
+#preProcessors=lessCssImport
+#postProcessors=less4j,cssMin
 # explicitly invalidates the cache each 5 seconds
-cacheUpdatePeriod=5
+cacheUpdatePeriod=1
 # check for changes each 5 seconds and invalidates the cache only when a change is detected
-resourceWatcherUpdatePeriod=5
+resourceWatcherUpdatePeriod=1

+ 4 - 1
src/main/wro/wro.xml

@@ -2,12 +2,15 @@
 <groups xmlns="http://www.isdc.ro/wro">
 	<group name="react-bootstrap">
 		<css>webjar:bootstrap/@bootstrap.version@/css/bootstrap.css</css>
+		
 		<js>webjar:jquery/@jquery.version@/jquery.js</js>
 		<js>webjar:react/@react.version@/react-with-addons.js</js>
 		<js>webjar:react/@react.version@/react-dom.js</js>
 	</group>
 	
-	<group name="bundle">
+	<group name="comments">
+		<css>file:src/main/resources/static/css/comments.css</css>
+		
 		<js>webjar:marked/@marked-lib.version@/marked.js</js>
 	</group>
 </groups>