aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2013-01-04 10:18:56 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2013-01-04 10:18:56 +0100
commit4a6c9c52d006ecb717bae7d9b502d9b661a08ccd (patch)
tree2b31f40d854f137a960933f5e2d99ebb98f48935
parent5c8c3467906d996c04210cc8350edbd027ccc32a (diff)
downloadesper-testing-4a6c9c52d006ecb717bae7d9b502d9b661a08ccd.tar.gz
esper-testing-4a6c9c52d006ecb717bae7d9b502d9b661a08ccd.tar.bz2
esper-testing-4a6c9c52d006ecb717bae7d9b502d9b661a08ccd.tar.xz
esper-testing-4a6c9c52d006ecb717bae7d9b502d9b661a08ccd.zip
o Using the PagingTableService on the front page and person apps.
-rwxr-xr-x[-rw-r--r--]src/main/java/io/trygvis/esper/testing/web/JerseyApplication.java4
-rwxr-xr-x[-rw-r--r--]src/main/webapp/WEB-INF/tags/common/head.tagx5
-rwxr-xr-x[-rw-r--r--]src/main/webapp/apps/core/PagingTableService.js1
-rwxr-xr-x[-rw-r--r--]src/main/webapp/apps/frontPageApp/frontPage.html36
-rwxr-xr-x[-rw-r--r--]src/main/webapp/apps/frontPageApp/frontPageApp.js67
-rwxr-xr-x[-rw-r--r--]src/main/webapp/apps/personApp/personApp.js33
6 files changed, 44 insertions, 102 deletions
diff --git a/src/main/java/io/trygvis/esper/testing/web/JerseyApplication.java b/src/main/java/io/trygvis/esper/testing/web/JerseyApplication.java
index 46964a0..a02bb5c 100644..100755
--- a/src/main/java/io/trygvis/esper/testing/web/JerseyApplication.java
+++ b/src/main/java/io/trygvis/esper/testing/web/JerseyApplication.java
@@ -86,6 +86,10 @@ public class JerseyApplication extends Application {
}
private UUID parse(String s) {
+ if(s == null) {
+ return null;
+ }
+
try {
return UUID.fromString(s);
} catch (IllegalArgumentException e) {
diff --git a/src/main/webapp/WEB-INF/tags/common/head.tagx b/src/main/webapp/WEB-INF/tags/common/head.tagx
index f5b27a4..0ad2ba2 100644..100755
--- a/src/main/webapp/WEB-INF/tags/common/head.tagx
+++ b/src/main/webapp/WEB-INF/tags/common/head.tagx
@@ -16,11 +16,12 @@
<script type="text/javascript" src="/external/headjs-0.99/head.min.js"><!-- --></script>
<script type="text/javascript">
head.js(
- {app: "/apps/app.js"},
{jquery: "/external/jquery-1.8.3/jquery-1.8.3.js"},
{angularjs: "/external/angular-1.0.3/angular.js"},
{angularjsResource: "/external/angular-1.0.3/angular-resource.js"},
- {angularUiNgGrid: "/external/angular-ui/ng-grid-1.6.0/ng-grid-1.6.0.debug.js"}
+ {angularUiNgGrid: "/external/angular-ui/ng-grid-1.6.0/ng-grid-1.6.0.debug.js"},
+ {app: "/apps/app.js"},
+ {PagingTableService: "/apps/core/PagingTableService.js"}
);
</script>
<script>var noCache = new Date().getTime();</script>
diff --git a/src/main/webapp/apps/core/PagingTableService.js b/src/main/webapp/apps/core/PagingTableService.js
index 689a225..d65e7f3 100644..100755
--- a/src/main/webapp/apps/core/PagingTableService.js
+++ b/src/main/webapp/apps/core/PagingTableService.js
@@ -37,6 +37,7 @@ function PagingTableService() {
};
var defaultCallback = function(Resource, args) {
+ args = args || {};
return function(startIndex, count, cb) {
console.log("fetching", arguments);
args.startIndex = startIndex;
diff --git a/src/main/webapp/apps/frontPageApp/frontPage.html b/src/main/webapp/apps/frontPageApp/frontPage.html
index 4523e6f..5cdea9a 100644..100755
--- a/src/main/webapp/apps/frontPageApp/frontPage.html
+++ b/src/main/webapp/apps/frontPageApp/frontPage.html
@@ -3,13 +3,33 @@
<div class="page-header">
<h1>Newcomers</h1>
</div>
-
- <style>
- .personsGrid {
- height: 400px;
- }
- </style>
-
- <div class="personsGrid" ng-grid="personsGridOptions"><!-- --></div>
+ <table class="table">
+ <thead>
+ <tr>
+ <th>Name</th>
+ <th>Badges</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr ng-repeat="person in persons.rows">
+ <td><a href="/person/{{person.uuid}}">{{person.name}}</a></td>
+ <td>{{person.badges.length}}</td>
+ </tr>
+ </tbody>
+ <tfoot>
+ <tr>
+ <td colspan="2">
+ <ul class="pager">
+ <li class="previous" ng-class="{disabled: persons.startIndex == 0}">
+ <a ng-click="persons.prev()">&larr; Older</a>
+ </li>
+ <li class="next">
+ <a ng-click="persons.next()">Newer &rarr;</a>
+ </li>
+ </ul>
+ </td>
+ </tr>
+ </tfoot>
+ </table>
</div>
diff --git a/src/main/webapp/apps/frontPageApp/frontPageApp.js b/src/main/webapp/apps/frontPageApp/frontPageApp.js
index c4fa0cc..21bc91f 100644..100755
--- a/src/main/webapp/apps/frontPageApp/frontPageApp.js
+++ b/src/main/webapp/apps/frontPageApp/frontPageApp.js
@@ -1,71 +1,10 @@
'use strict';
-var frontPageApp = angular.module('frontPageApp', ['ngGrid', 'person']).config(function ($routeProvider, $locationProvider) {
+var frontPageApp = angular.module('frontPageApp', ['ngGrid', 'person', 'pagingTableService']).config(function ($routeProvider, $locationProvider) {
$routeProvider.
when('/', {controller: FrontPageCtrl, templateUrl: '/apps/frontPageApp/frontPage.html?noCache=' + noCache});
});
-function FrontPageCtrl($scope, $http, Person) {
- $scope.persons = [];
-
- $scope.pagingOptions = {
- pageSizes: [10],
- pageSize: 10,
- totalServerItems: 0,
- currentPage: 1
- };
-
- $scope.personsGridOptions = {
- data: 'persons',
- displayFooter: true,
- enablePaging: true,
- enableRowReordering: false,
- enableColumnReordering: false,
- showFilter: false,
- showColumnMenu: false,
- canSelectRows: false,
- displaySelectionCheckbox: false,
- pagingOptions: $scope.pagingOptions,
- columnDefs: [
- {
- field: 'name',
- displayName: 'Name',
- cellTemplate: '<a href="/person/{{row.getProperty(\'uuid\')}}">{{row.getProperty(col.field)}}</a>'
- },
- {
- field: 'badges',
- displayName: 'Badges',
- cellTemplate: '<div>{{row.getProperty(col.field).length}}</div>'
- }
- ]
- };
-
- $scope.setPagingData = function(data, page, pageSize){
-// $scope.persons = data.slice((page - 1) * pageSize, page * pageSize);
- $scope.persons = data;
-// $scope.personsGridOptions.totalServerItems = data.length;
- window.x = $scope.personsGridOptions;
- if (!$scope.$$phase) {
- $scope.$apply();
- }
- };
-
- $scope.getPagedDataAsync = function (pageSize, page/*, searchText*/) {
- setTimeout(function () {
-
- Person.query({startIndex: page * pageSize, count: pageSize}, function (persons) {
- $scope.setPagingData(persons, page, pageSize);
- });
- }, 100);
- };
-
- $scope.$watch('pagingOptions', function () {
- $scope.getPagedDataAsync($scope.pagingOptions.pageSize, $scope.pagingOptions.currentPage);
- }, true);
-
-// $http.get('/resource/core/person-count').success(function(count) {
-// $scope.pagingOptions.totalServerItems = count;
-//
-// $scope.getPagedDataAsync($scope.pagingOptions.pageSize, $scope.pagingOptions.currentPage);
-// });
+function FrontPageCtrl($scope, Person, PagingTableService) {
+ $scope.persons = PagingTableService.create($scope, PagingTableService.defaultCallback(Person));
}
diff --git a/src/main/webapp/apps/personApp/personApp.js b/src/main/webapp/apps/personApp/personApp.js
index 8c13669..e8ef1d5 100644..100755
--- a/src/main/webapp/apps/personApp/personApp.js
+++ b/src/main/webapp/apps/personApp/personApp.js
@@ -1,39 +1,16 @@
'use strict';
-var personApp = angular.module('personApp', ['person', 'build']).config(function ($routeProvider, $locationProvider) {
+var personApp = angular.module('personApp', ['person', 'build', 'pagingTableService']).config(function ($routeProvider, $locationProvider) {
$routeProvider.
when('/', {controller: PersonCtrl, templateUrl: '/apps/personApp/person.html?noCache=' + noCache});
});
-function PersonCtrl($scope, $location, Person, Build) {
- function queryBuilds() {
- var builds = $scope.builds;
- Build.query({person: uuid, startIndex: builds.startIndex, count: builds.count}, function (builds) {
- $scope.builds.rows = builds;
- });
- }
+function PersonCtrl($scope, $routeParams, Person, Build, PagingTableService) {
+ var personUuid = uuid;
$scope.mode = 'overview';
- $scope.builds = {
- rows: [],
- startIndex: 0,
- count: 10,
- first: function() {
- $scope.builds.startIndex = 0;
- queryBuilds();
- },
- next: function() {
- $scope.builds.startIndex += $scope.builds.count;
- queryBuilds();
- },
- prev: function() {
- if($scope.builds.startIndex == 0) {
- return;
- }
- $scope.builds.startIndex -= $scope.builds.count;
- queryBuilds();
- }
- };
+
+ $scope.builds = PagingTableService.create($scope, PagingTableService.defaultCallback(Build, {person: personUuid}));
$scope.setMode = function(mode) {
$scope.mode = mode;