-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial changes for single-page implementation
- 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
Showing
28 changed files
with
33,269 additions
and
317 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
quick-start/src/main/java/com/marklogic/hub/web/controller/HtmlPageController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
...-start/src/main/java/com/marklogic/hub/web/controller/api/DataHubServerApiController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
quick-start/src/main/java/com/marklogic/hub/web/form/LoginForm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
quick-start/src/main/webapp/WEB-INF/pages/directives/footer.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
5 changes: 5 additions & 0 deletions
5
quick-start/src/main/webapp/WEB-INF/pages/directives/header.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
44
quick-start/src/main/webapp/WEB-INF/pages/login/login.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
28 changes: 28 additions & 0 deletions
28
quick-start/src/main/webapp/WEB-INF/static/app/controllers/loginController.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
}); | ||
}; | ||
} | ||
]); |
33 changes: 33 additions & 0 deletions
33
quick-start/src/main/webapp/WEB-INF/static/app/controllers/topController.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}; | ||
} | ||
]); |
Oops, something went wrong.