Skip to content

Commit b24911c

Browse files
committed
Updated web dependencies versions.
Simplified JS business code.
1 parent e9b4345 commit b24911c

4 files changed

Lines changed: 28 additions & 23 deletions

File tree

Gruntfile.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ module.exports = function (grunt) {
126126
);
127127

128128
// Task: Build production version ready for deployment
129-
grunt.registerTask('build', [
129+
grunt.registerTask('install', [
130130
'clean:build',
131131
'bower-install-simple',
132132
//'concat:styles',
@@ -140,7 +140,12 @@ module.exports = function (grunt) {
140140
'htmlmin'
141141
]);
142142

143+
grunt.registerTask('process-resources', [
144+
'bower-install-simple',
145+
'wiredep',
146+
]);
147+
143148
grunt.registerTask('default', [
144-
'build'
149+
'install'
145150
]);
146151
};

bower.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
"description": "javaee7-angular JavaScript dependencies.",
99
"private": true,
1010
"dependencies": {
11-
"angular": "1.2.0",
12-
"jquery": "1.9.1",
13-
"angular-bootstrap": "0.10.0",
14-
"angular-grid": "2.0.7"
11+
"angular": "~1.2.20",
12+
"angular-resource": "~1.2.20",
13+
"jquery": "~1.9.1",
14+
"angular-bootstrap": "~0.11.0",
15+
"angular-grid": "~2.0.11"
1516
}
1617
}

src/main/webapp/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<!-- bower:js -->
2121
<script src="lib/bower/jquery/jquery.js"></script>
2222
<script src="lib/bower/angular/angular.js"></script>
23+
<script src="lib/bower/angular-resource/angular-resource.js"></script>
2324
<script src="lib/bower/angular-bootstrap/ui-bootstrap-tpls.js"></script>
2425
<script src="lib/bower/angular-grid/build/ng-grid.js"></script>
2526
<!-- endbower -->
@@ -42,8 +43,8 @@
4243

4344
<!-- Bind the pagination component to be displayed. -->
4445
<pagination direction-links="true" boundary-links="true"
45-
total-items="persons.totalResults" page="persons.currentPage" items-per-page="persons.pageSize"
46-
on-select-page="refreshGrid(page)">
46+
total-items="persons.totalResults" items-per-page="persons.pageSize"
47+
ng-model="persons.currentPage" ng-change="refreshGrid()">
4748
</pagination>
4849
</div>
4950
</div>

src/main/webapp/script/person.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
var app = angular.module('persons', ['ngGrid', 'ui.bootstrap']);
1+
var app = angular.module('persons', ['ngResource', 'ngGrid', 'ui.bootstrap']);
22

33
// Create a controller with name personsList to bind to the html page.
44
app.controller('personsList', function ($scope, personService) {
55
// Refresh the grid, calling the appropriate service method.
6-
$scope.refreshGrid = function (page) {
7-
personService.getAll(page, $scope.sortInfo.fields[0], $scope.sortInfo.directions[0]).success(function (data) {
6+
$scope.refreshGrid = function () {
7+
var listPersonsArgs = {
8+
page: $scope.persons.currentPage,
9+
sortFields: $scope.sortInfo.fields[0],
10+
sortDirections: $scope.sortInfo.directions[0]
11+
};
12+
13+
personService.get(listPersonsArgs, function(data) {
814
$scope.persons = data;
9-
});
15+
})
1016
};
1117

1218
// Do something when the grid is sorted.
@@ -19,7 +25,7 @@ app.controller('personsList', function ($scope, personService) {
1925
// Watch the sortInfo variable. If changes are detected than we need to refresh the grid.
2026
// This also works for the first page access, since we assign the initial sorting in the initialize section.
2127
$scope.$watch('sortInfo.fields[0]', function () {
22-
$scope.refreshGrid($scope.persons.currentPage);
28+
$scope.refreshGrid();
2329
}, true);
2430

2531
// Initialize required information: sorting, the first page to show and the grid options.
@@ -33,14 +39,6 @@ app.controller('personsList', function ($scope, personService) {
3339
});
3440

3541
// Service that provides persons operations
36-
app.service('personService', function ($http) {
37-
// Makes the REST request to get the data to populate the grid.
38-
this.getAll = function (page, sortFields, sortDirections) {
39-
return $http.get('resources/persons', {
40-
params: {
41-
page: page,
42-
sortFields: sortFields,
43-
sortDirections: sortDirections
44-
}});
45-
}
42+
app.factory('personService', function ($resource) {
43+
return $resource('resources/persons');
4644
});

0 commit comments

Comments
 (0)