WW-4522 Support latest stable AngularJS version in maven angularjs archetype

- Follow angular style guide and use one file for each controller and service
This commit is contained in:
Johannes Geppert
2015-07-10 17:09:58 +02:00
parent 8312ed14ba
commit 19a55a8857
10 changed files with 185 additions and 93 deletions
@@ -75,6 +75,15 @@
<scope>provided</scope>
</dependency>
<!-- The Servlet API mocks in Spring Framework 4.x only supports Servlet 3.0 and higher.
This is only necessary in tests-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
@@ -1,13 +1,12 @@
<!DOCTYPE html>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html lang="en" ng-app="angularStrutsApp">
<html lang="en" ng-app="app">
<head>
<meta charset="utf-8">
<title>My AngularJS Struts2 App</title>
<s:url var="ctxUrl" forceAddSchemeHostAndPort="true" includeContext="true" value="/" namespace="/" ></s:url>
<base href="<s:property value="ctxUrl"/>">
<base href="<s:url forceAddSchemeHostAndPort="true" includeContext="true" value="/" namespace="/" />">
</head>
<body>
@@ -23,9 +22,11 @@
<script src="<s:url value="js/lib/angular/angular.min.js" />"></script>
<script src="<s:url value="js/lib/angular/angular-route.min.js" />"></script>
<script src="<s:url value="js/bootstrap.js" />"></script>
<script src="<s:url value="js/directives.js" />"></script>
<script src="<s:url value="js/services.js" />"></script>
<script src="<s:url value="js/controllers.js" />"></script>
<script src="<s:url value="js/app.js" />"></script>
<script src="<s:url value="js/config.js" />"></script>
<script src="<s:url value="js/services/DataService.js" />"></script>
<script src="<s:url value="js/controllers/AppController.js" />"></script>
<script src="<s:url value="js/controllers/HomeController.js" />"></script>
<script src="<s:url value="js/controllers/ApacheProjectsController.js" />"></script>
</body>
</html>
@@ -18,3 +18,9 @@
* specific language governing permissions and limitations
* under the License.
*/
(function() {
'use strict';
angular
.module('app', ['ngRoute']);
})();
@@ -0,0 +1,40 @@
/*
* $Id$
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
(function() {
'use strict';
angular
.module('app')
.config(['$routeProvider', '$locationProvider',
function($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true).hashPrefix('!');
$routeProvider.when('/projects', {
templateUrl: 'partials/projects.html',
controller: 'ApacheProjectsController'
}).when('/home', {
templateUrl: 'partials/home.html',
controller: 'HomeController'
}).otherwise({ redirectTo: '/home' });
}
]);
})();
@@ -18,20 +18,22 @@
* specific language governing permissions and limitations
* under the License.
*/
angularStrutsApp.controller('AppController', function ($scope) { });
(function() {
'use strict';
angularStrutsApp.controller('HomeController', function ($scope) {
$scope.name = "Sunshine";
});
angular
.module('app')
.controller('ApacheProjectsController', ApacheProjectsController);
angularStrutsApp.controller('ApacheProjectsController', function ($scope, $log, DataService) {
this.init = function() {
DataService.getProjects().then(function(data) {
$scope.projects = data.projectNames;
}, function() {
$log.error('Could not receive project names.')
});
};
function ApacheProjectsController($scope, $log, DataService) {
this.init = function() {
DataService.getProjects().then(function(data) {
$scope.projects = data.projectNames;
}, function() {
$log.error('Could not receive project names.')
});
};
this.init();
});
this.init();
}
})();
@@ -18,20 +18,14 @@
* specific language governing permissions and limitations
* under the License.
*/
(function() {
'use strict';
var angularStrutsApp = angular.module('angularStrutsApp', ['ngRoute']);
angular
.module('app')
.controller('AppController', AppController);
angularStrutsApp.config(['$routeProvider', '$locationProvider',
function($routeProvider, $locationProvider) {
function AppController() {
$locationProvider.html5Mode(true).hashPrefix('!');
$routeProvider.when('/projects', {
templateUrl: 'partials/projects.html',
controller: 'ApacheProjectsController'
}).when('/home', {
templateUrl: 'partials/home.html',
controller: 'HomeController'
}).otherwise({ redirectTo: '/home' });
}
]);
})();
@@ -0,0 +1,31 @@
/*
* $Id$
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
(function() {
'use strict';
angular
.module('app')
.controller('HomeController', HomeController);
function HomeController($scope) {
$scope.name = "Sunshine";
}
})();
@@ -1,58 +0,0 @@
/*
* $Id$
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
angularStrutsApp.factory('DataService', ['$http', '$log', '$q', function($http, $log, $q) {
var DataService = {
urls : {
projects : "data/projects"
}
};
DataService._request = function(url, method, model){
if(!method) {
method = 'GET';
}
var def = $q.defer();
if(method === 'GET') {
$http.get(url).success(function(data) {
def.resolve(data);
}).error(function(data, code) {
def.reject(data);
$log.error(data, code);
});
} else if(method === 'POST'){
$http.post(url, model).success(function(data) {
DataService.data = data;
def.resolve(data);
}).error(function(data, code) {
def.reject(data);
$log.error(data, code);
});
}
return def.promise;
};
DataService.getProjects = function () {
return this._request(this.urls.projects);
};
return DataService;
}]);
@@ -0,0 +1,67 @@
/*
* $Id$
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
(function() {
'use strict';
angular
.module('app')
.factory('DataService', DataService);
function DataService($http, $log, $q) {
var DataService = {
urls : {
projects : "data/projects"
}
};
DataService._request = function(url, method, model){
if(!method) {
method = 'GET';
}
var def = $q.defer();
if(method === 'GET') {
$http.get(url).success(function(data) {
def.resolve(data);
}).error(function(data, code) {
def.reject(data);
$log.error(data, code);
});
} else if(method === 'POST'){
$http.post(url, model).success(function(data) {
DataService.data = data;
def.resolve(data);
}).error(function(data, code) {
def.reject(data);
$log.error(data, code);
});
}
return def.promise;
};
DataService.getProjects = function () {
return this._request(this.urls.projects);
};
return DataService;
}
})();
@@ -29,6 +29,6 @@ public class IndexTest extends StrutsTestCase {
Index index = new Index();
String result = index.execute();
assertTrue("Expected a success result!", ActionSupport.SUCCESS.equals(result));
assertTrue("Expected the 'hello' action name!!", "hello".equals(index.getRedirectName()));
assertTrue("Expected the 'hello' action name!!", "application".equals(index.getRedirectName()));
}
}