Skip to content

Commit

Permalink
initial changes for single-page implementation
Browse files Browse the repository at this point in the history
- separated front-end and backend sources
- front-end is not handled by AngularJS + Thymleaf via HtmlPageController
- backend can now be implemented as RESTful services over Spring
- we will use non-minified versions of angularjs to make debugging easier
  • Loading branch information
gmarintes committed Feb 5, 2016
1 parent 541922f commit 20764c3
Show file tree
Hide file tree
Showing 28 changed files with 33,269 additions and 317 deletions.
4 changes: 2 additions & 2 deletions quick-start/src/main/java/com/marklogic/hub/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.thymeleaf.templateresolver.ITemplateResolver;
import org.thymeleaf.templateresolver.ServletContextTemplateResolver;
import org.thymeleaf.templateresolver.TemplateResolver;

@SpringBootApplication
public class Application extends WebMvcConfigurerAdapter {
Expand All @@ -31,7 +31,7 @@ public static void main(String[] args) {
}

@Bean
public TemplateResolver templateResolver() {
public ITemplateResolver templateResolver() {
ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver();
templateResolver.setPrefix("/WEB-INF/pages/");
templateResolver.setSuffix(".html");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.marklogic.hub.web.controller;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.RequestToViewNameTranslator;
import org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator;

@Controller
@RequestMapping("/**/**.html")
public class HtmlPageController extends BaseController {
private static final Logger LOGGER = LoggerFactory.getLogger(HtmlPageController.class);

@RequestMapping(method = RequestMethod.GET)
public String getPage(HttpServletRequest request) throws Exception {
RequestToViewNameTranslator translator = new DefaultRequestToViewNameTranslator();
String viewName = translator.getViewName(request);

String uri = request.getRequestURI();
LOGGER.debug(uri + " = " + viewName);

return uri.equals("/") ? "index" : viewName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.marklogic.hub.web.controller.api;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
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.RestController;

import com.marklogic.hub.config.EnvironmentConfiguration;
import com.marklogic.hub.exception.DataHubException;
import com.marklogic.hub.service.DataHubService;
import com.marklogic.hub.web.form.LoginForm;

@RestController
@RequestMapping("/api/data-hub")
public class DataHubServerApiController {
private static final Logger LOGGER = LoggerFactory.getLogger(DataHubServerApiController.class);

@Autowired
private EnvironmentConfiguration environmentConfiguration;

@Autowired
private DataHubService dataHubService;

@RequestMapping(value="login", method = RequestMethod.POST, consumes={MediaType.APPLICATION_JSON_UTF8_VALUE}, produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
public LoginForm postLogin(@RequestBody LoginForm loginForm, BindingResult bindingResult, HttpSession session, HttpServletRequest request) throws Exception {
try {
updateEnvironmentConfiguration(loginForm);

loginForm.setInstalled(dataHubService.isInstalled());
loginForm.setServerVersionAccepted(dataHubService.isServerAcceptable());
loginForm.setLoginAccepted(true);

session.setAttribute("loginForm", loginForm);
}
catch (DataHubException e) {
LOGGER.error("Login failed", e);

loginForm.setLoginAccepted(false);
}

return loginForm;
}

@RequestMapping(value="login", method = RequestMethod.GET)
public LoginForm getLoginStatus(HttpSession session) {
return (LoginForm) session.getAttribute("loginForm");
}

@RequestMapping(value="install", method = RequestMethod.POST)
public void install() {
dataHubService.install();
}

@RequestMapping(value="uninstall", method = RequestMethod.POST)
public void uninstall() {
dataHubService.uninstall();
}

@RequestMapping(value="install-user-modules", method = RequestMethod.POST)
public void installUserModules() {
dataHubService.installUserModules();
}

private void updateEnvironmentConfiguration(LoginForm loginForm) {
environmentConfiguration.setMLHost(loginForm.getMlHost());
environmentConfiguration.setMLRestPort(loginForm.getMlRestPort());
environmentConfiguration.setMLUsername(loginForm.getMlUsername());
environmentConfiguration.setMLPassword(loginForm.getMlPassword());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.marklogic.hub.web.form;

public class LoginForm {
private String mlHost;
private String mlRestPort;
private String mlUsername;
private String mlPassword;
private boolean loginAccepted;
private boolean serverVersionAccepted;
private boolean installed;

public String getMlHost() {
return mlHost;
}

public void setMlHost(String mlHost) {
this.mlHost = mlHost;
}

public String getMlRestPort() {
return mlRestPort;
}

public void setMlRestPort(String restPort) {
this.mlRestPort = restPort;
}

public String getMlUsername() {
return mlUsername;
}

public void setMlUsername(String mlUsername) {
this.mlUsername = mlUsername;
}

public String getMlPassword() {
return mlPassword;
}

public void setMlPassword(String mlPassword) {
this.mlPassword = mlPassword;
}

public boolean isLoginAccepted() {
return loginAccepted;
}

public void setLoginAccepted(boolean loginAccepted) {
this.loginAccepted = loginAccepted;
}

public boolean isServerVersionAccepted() {
return serverVersionAccepted;
}

public void setServerVersionAccepted(boolean serverVersionAccepted) {
this.serverVersionAccepted = serverVersionAccepted;
}

public boolean isInstalled() {
return installed;
}

public void setInstalled(boolean installed) {
this.installed = installed;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div id="footer" class="container-fluid">
<span th:utext="#{app.footer}"></span>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div id="header" class="container-fluid">
<div class="row">
<div class="col-xs-8 col-sm-8 col-md-8"><h1 id="sitename" th:text="#{app.title}"></h1></div>
</div>
</div>
43 changes: 35 additions & 8 deletions quick-start/src/main/webapp/WEB-INF/pages/index.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorator="templates/base-template">
<html lang="en" ng-app="quickStartApp">
<head>
<title>Data Hub Quick Start</title>

<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="-1" />
<meta http-equiv="pragma" content="no-cache" />

<!-- Angular -->
<script th:src="@{/static/lib/angular.js/js/angular.js}"></script>
<script th:src="@{/static/lib/angular.js/js/angular-route.js}"></script>

<!-- Angular Dependencies -->
<script th:src="@{/static/lib/jquery/js/jquery.min.js}"></script>

<!-- Bootstrap -->
<script th:src="@{/static/lib/bootstrap-3.3.6-dist/js/bootstrap.min.js}"></script>

<!-- App-Specific JS -->
<script th:src="@{/static/app/quickStartApp.js}"></script>
<script th:src="@{/static/app/services/dataHubService.js}"></script>

<script th:src="@{/static/app/directives/headerDirective.js}"></script>
<script th:src="@{/static/app/directives/footerDirective.js}"></script>

<script th:src="@{/static/app/controllers/loginController.js}"></script>
<script th:src="@{/static/app/controllers/topController.js}"></script>

<!-- Bootstrap CSS -->
<link th:href="@{/static/lib/bootstrap-3.3.6-dist/css/bootstrap.min.css}" rel="stylesheet"></link>

<!-- App-Specific CSS -->
<link th:href="@{/static/css/quick-start.css}" rel="stylesheet"></link>
</head>
<body>
<section layout:fragment="content" class="container-fluid">
<div id="message-div" class="row"></div>
<div th:replace="deployment/deployment :: content">...</div>
</section>
<div layout:fragment="page-script" th:remove="tag">
<div th:replace="deployment/deployment :: page-script" th:remove="tag">...</div>
</div>
<div ng-view=""></div>
</body>
</html>
44 changes: 44 additions & 0 deletions quick-start/src/main/webapp/WEB-INF/pages/login/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<header></header>

<div class="container">
<div class="row spacing-top">
<div class="col-xs-12">
<form ng-submit="login()">
<div class="center-block" style="width: 350px;">
<div class="well">
<div class="row">
<div class="text-center">
<h4 class="no_margin_top"><strong>Login</strong></h4>
</div>
</div>
<div class="row center-block alert alert-danger" ng-if="loginFailedError">
<span>Login failed. Please check your username or password.</span>
</div>
<div class="form-group">
<label th:text="#{label.host}" for="mlHost"></label>
<input class="form-control" name="mlHost" type="text" ng-model="loginForm.mlHost" th:placeHolder="#{placeholder.host}" required="required"/>
</div>
<div class="form-group">
<label th:text="#{label.restPort}" for="restPort"></label>
<input name="mlRestPort" type="text" ng-model="loginForm.mlRestPort" class="form-control" th:placeHolder="#{placeholder.restPort}" required="required"/>
</div>
<div class="form-group">
<label th:text="#{label.username}" for="mlUsername"></label>
<input name="mlUsername" type="text" ng-model="loginForm.mlUsername" class="form-control" th:placeHolder="#{placeholder.username}" required="required"/>
</div>
<div class="form-group">
<label th:text="#{label.password}" for="mlPassword"></label>
<input name="mlPassword" type="password" ng-model="loginForm.mlPassword" class="form-control" th:placeHolder="#{placeholder.password}" required="required"/>
</div>

<div class="row center-block text-center">
<div class="col-md-12">
<button class="btn btn-primary width_100" ng-click="login">Login</button>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
30 changes: 30 additions & 0 deletions quick-start/src/main/webapp/WEB-INF/pages/top/top.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<header></header>

<div class="container">
<div class="row spacing-top">
<div class="col-xs-12">
<ul class="alert alert-info">
<li ng-if="status.serverVersionAccepted" th:text="#{server.is.acceptable}"></li>
<li ng-if="!status.serverVersionAccepted" th:text="#{server.is.unacceptable}"></li>
<li ng-if="status.installed" th:text="#{dhib.is.installed}"></li>
<li ng-if="!status.installed" th:text="#{dhib.is.not.installed}"></li>
</ul>
</div>
</div>

<div class="row">
<div class="col-xs-12">
<div class="form-group" ng-if="!status.installed">
<button type="submit" name="install" class="btn btn-default" ng-click="install())">Install</button>
</div>
<div class="form-group" ng-if="status.installed">
<button type="submit" name="uninstall" class="btn btn-default" ng-click="uninstall()">Uninstall</button>
</div>
<div class="form-group">
<button type="submit" name="installUserModules" class="btn btn-default" ng-click="installUserModules()">Install User Modules</button>
</div>
</div>
</div>
</div>

<footer></footer>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var dependencies = [
'dhib.quickstart.service.data-hub'
];

var module = angular.module('dhib.quickstart.controller.login', dependencies);

module.controller('loginController', [
'$scope'
,'$location'
,'DataHub'
,function(
$scope
,$location
,DataHub
) {
$scope.loginForm = {};

$scope.login = function() {
DataHub.login($scope.loginForm)
.then(function(request) {

if (request.status == 200) {
$location.path('/top');
}
});
};
}
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var dependencies = [
'dhib.quickstart.service.data-hub'
];

var module = angular.module('dhib.quickstart.controller.top', dependencies);

module.controller('topController', [
'$scope'
,'$location'
,'DataHub'
,function(
$scope
,$location
,DataHub
) {
$scope.status = DataHub.status;

console.log('status');
console.log($scope.status);

$scope.install = function () {
DataHub.install();
};

$scope.uninstall = function () {
DataHub.uninstall();
};

$scope.installUserModules = function () {
DataHub.installUserModules();
};
}
]);
Loading

0 comments on commit 20764c3

Please sign in to comment.