diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2013-01-06 12:43:09 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2013-01-06 12:43:09 +0100 |
commit | 37207267bf3a1149f78a5022ed8e016cac6b85ca (patch) | |
tree | 6cb1166ba3904780ab64f5edf52528bc743c0817 | |
parent | a9543bd5570b7435b760a8eb3c8b457c889a5fca (diff) | |
download | esper-testing-37207267bf3a1149f78a5022ed8e016cac6b85ca.tar.gz esper-testing-37207267bf3a1149f78a5022ed8e016cac6b85ca.tar.bz2 esper-testing-37207267bf3a1149f78a5022ed8e016cac6b85ca.tar.xz esper-testing-37207267bf3a1149f78a5022ed8e016cac6b85ca.zip |
o Adding a view for showing a list of people.
10 files changed, 167 insertions, 82 deletions
diff --git a/src/main/java/io/trygvis/esper/testing/Util.java b/src/main/java/io/trygvis/esper/testing/Util.java index c33e64c..6b9d1b6 100755 --- a/src/main/java/io/trygvis/esper/testing/Util.java +++ b/src/main/java/io/trygvis/esper/testing/Util.java @@ -73,12 +73,37 @@ public class Util { } }; - public static Option<String> childText(Element e, String childName) { - return fromNull(e.getChildText(childName)); - } + // ----------------------------------------------------------------------- + // SQL + // ----------------------------------------------------------------------- - public static Option<Element> child(Element e, String childName) { - return fromNull(e.getChild(childName)); + public static String orderBy(Iterable<String> inputs, String... allowed) { + StringBuilder buffer = new StringBuilder(); + + for (String input : inputs) { + boolean desc = false; + + if (input.endsWith("-")) { + desc = true; + input = input.substring(0, input.length() - 1); + } + + for (String s : allowed) { + if (s.equals(input)) { + if (buffer.length() == 0) { + buffer.append(" ORDER BY "); + } else { + buffer.append(", "); + } + buffer.append(s); + if (desc) { + buffer.append(" DESC"); + } + } + } + } + + return buffer.toString(); } public static UUID[] toUuidArray(ResultSet rs, int index) throws SQLException { @@ -102,4 +127,16 @@ public class Util { } return list; } + + // ----------------------------------------------------------------------- + // XML + // ----------------------------------------------------------------------- + + public static Option<String> childText(Element e, String childName) { + return fromNull(e.getChildText(childName)); + } + + public static Option<Element> child(Element e, String childName) { + return fromNull(e.getChild(childName)); + } } diff --git a/src/main/java/io/trygvis/esper/testing/core/db/PersonDao.java b/src/main/java/io/trygvis/esper/testing/core/db/PersonDao.java index ec460ec..ba3f628 100755 --- a/src/main/java/io/trygvis/esper/testing/core/db/PersonDao.java +++ b/src/main/java/io/trygvis/esper/testing/core/db/PersonDao.java @@ -7,8 +7,8 @@ import io.trygvis.esper.testing.util.sql.*; import org.joda.time.*; import java.sql.*; -import java.util.*; import java.util.List; +import java.util.*; import static io.trygvis.esper.testing.Util.*; import static io.trygvis.esper.testing.util.sql.SqlOption.*; @@ -97,7 +97,13 @@ public class PersonDao { } public List<PersonDto> selectPersons(PageRequest pageRequest) throws SQLException { - try (PreparedStatement s = c.prepareStatement("SELECT " + PERSON + " FROM person ORDER BY created_date DESC, name LIMIT ? OFFSET ?")) { + String sql = "SELECT " + PERSON + " FROM person"; + + sql += orderBy(pageRequest.orderBy, "name", "created_date"); + + sql += " LIMIT ? OFFSET ?"; + + try (PreparedStatement s = c.prepareStatement(sql)) { int i = 1; s.setInt(i++, pageRequest.count.orSome(10)); s.setInt(i, pageRequest.startIndex.orSome(0)); @@ -199,7 +205,7 @@ public class PersonDao { try (PreparedStatement s = c.prepareStatement(sql)) { int i = 1; - if(person.isSome()) { + if (person.isSome()) { s.setString(i++, person.some().toUuidString()); } if (type.isSome()) { diff --git a/src/main/java/io/trygvis/esper/testing/util/sql/PageRequest.java b/src/main/java/io/trygvis/esper/testing/util/sql/PageRequest.java index 38d417d..b7c6750 100644 --- a/src/main/java/io/trygvis/esper/testing/util/sql/PageRequest.java +++ b/src/main/java/io/trygvis/esper/testing/util/sql/PageRequest.java @@ -1,28 +1,20 @@ package io.trygvis.esper.testing.util.sql; import fj.data.*; -import static fj.data.Option.fromNull; -import io.trygvis.esper.testing.*; - -import javax.servlet.http.*; public class PageRequest { public final Option<Integer> startIndex; public final Option<Integer> count; - public static final PageRequest FIRST_PAGE = new PageRequest(Option.<Integer>none(), Option.<Integer>none()); + public final List<String> orderBy; + public static final PageRequest FIRST_PAGE = new PageRequest(Option.<Integer>none(), Option.<Integer>none(), List.<String>nil()); - public PageRequest(Option<Integer> startIndex, Option<Integer> count) { + public PageRequest(Option<Integer> startIndex, Option<Integer> count, List<String> orderBy) { this.startIndex = startIndex; this.count = count; + this.orderBy = orderBy; } public String toString() { return "PageRequest{startIndex=" + startIndex + ", count=" + count + '}'; } - - public static PageRequest pageReq(HttpServletRequest req) { - return new PageRequest( - fromNull(req.getParameter("startIndex")).bind(Util.parseInt), - fromNull(req.getParameter("count")).bind(Util.parseInt)); - } } 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 3c86581..38cfd9d 100755 --- a/src/main/java/io/trygvis/esper/testing/web/JerseyApplication.java +++ b/src/main/java/io/trygvis/esper/testing/web/JerseyApplication.java @@ -15,7 +15,12 @@ import javax.ws.rs.core.*; import javax.ws.rs.ext.*; import java.lang.reflect.*; import java.util.*; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import static fj.data.List.iterableList; +import static fj.data.List.nil; import static fj.data.Option.*; import static io.trygvis.esper.testing.Util.parseInt; @@ -59,9 +64,18 @@ public class JerseyApplication extends Application { public Object getValue(HttpContext hc) { MultivaluedMap<String, String> queryParameters = hc.getRequest().getQueryParameters(); + List<String> list = queryParameters.get("orderBy"); + + fj.data.List<String> orderBy = nil(); + + if (list != null) { + orderBy = iterableList(list); + } + return new PageRequest( fromNull(queryParameters.getFirst("startIndex")).bind(parseInt), - fromNull(queryParameters.getFirst("count")).bind(parseInt)); + fromNull(queryParameters.getFirst("count")).bind(parseInt), + orderBy); } }; } else if (UUID.class.equals(type)) { diff --git a/src/main/java/io/trygvis/esper/testing/web/resource/CoreResource.java b/src/main/java/io/trygvis/esper/testing/web/resource/CoreResource.java index c58bc13..4ab95c6 100755 --- a/src/main/java/io/trygvis/esper/testing/web/resource/CoreResource.java +++ b/src/main/java/io/trygvis/esper/testing/web/resource/CoreResource.java @@ -35,9 +35,7 @@ public class CoreResource extends AbstractResource { @GET @Path("/person") - public List<PersonDetailJson> getPersons(@Context final HttpServletRequest req) throws Exception { - final PageRequest pageRequest = pageReq(req); - + public List<PersonDetailJson> getPersons(@MagicParam final PageRequest pageRequest) throws Exception { return da.inTransaction(new CoreDaosCallback<List<PersonDetailJson>>() { protected List<PersonDetailJson> run() throws SQLException { List<PersonDetailJson> list = new ArrayList<>(); diff --git a/src/main/webapp/apps/core/navbar.html b/src/main/webapp/apps/core/navbar.html index eb1f798..871bfde 100644 --- a/src/main/webapp/apps/core/navbar.html +++ b/src/main/webapp/apps/core/navbar.html @@ -5,8 +5,8 @@ <div class="nav-collapse collapse"> <ul class="nav"> <li class=""><a href="/#/">Home</a></li> - <li class=""><a href="/#/badge">Badged</a></li> - <li class=""><a href="/#/person">People</a></li> + <li class=""><a href="/#/badge/">Badges</a></li> + <li class=""><a href="/#/person/">People</a></li> <li class="divider-vertical"></li> <li class=""><a href="/jenkins">Jenkins</a></li> </ul> diff --git a/src/main/webapp/apps/frontPageApp/frontPage.html b/src/main/webapp/apps/frontPageApp/frontPage.html index 84e991b..c3db55c 100755 --- a/src/main/webapp/apps/frontPageApp/frontPage.html +++ b/src/main/webapp/apps/frontPageApp/frontPage.html @@ -22,7 +22,7 @@ <h3>Newcomers</h3> <ul class="unstyled"> - <li ng-repeat="person in persons.rows"> + <li ng-repeat="person in persons"> <a href="#/person/{{person.person.uuid}}">{{person.person.name}}</a> </li> </ul> diff --git a/src/main/webapp/apps/frontPageApp/frontPageApp.js b/src/main/webapp/apps/frontPageApp/frontPageApp.js index ef0de81..c973983 100755 --- a/src/main/webapp/apps/frontPageApp/frontPageApp.js +++ b/src/main/webapp/apps/frontPageApp/frontPageApp.js @@ -3,15 +3,20 @@ var frontPageApp = angular.module('frontPageApp', ['ngGrid', 'person', 'badge', 'build', 'pagingTableService', 'core.directives']).config(function ($routeProvider, $locationProvider) { $routeProvider. when('/', {controller: FrontPageCtrl, templateUrl: '/apps/frontPageApp/frontPage.html?noCache=' + noCache}). + when('/person/', {controller: PersonListCtrl, templateUrl: '/apps/frontPageApp/personList.html?noCache=' + noCache}). when('/person/:personUuid', {controller: PersonCtrl, templateUrl: '/apps/frontPageApp/person.html?noCache=' + noCache}); }); -function FrontPageCtrl($scope, Person, Badge, PagingTableService) { - $scope.persons = PagingTableService.create($scope, PagingTableService.defaultCallback(Person)); +function FrontPageCtrl($scope, Person, Badge) { + $scope.persons = Person.query(); $scope.recentBadges = Badge.query(); } -function PersonCtrl($scope, $routeParams, Person, Badge, Build, PagingTableService) { +function PersonListCtrl($scope, Person, PagingTableService) { + $scope.persons = PagingTableService.create($scope, PagingTableService.defaultCallback(Person, {orderBy: "name"})); +} + +function PersonCtrl($scope, $routeParams, Person, Build, PagingTableService) { var personUuid = $routeParams.personUuid; $scope.mode = 'overview'; diff --git a/src/main/webapp/apps/frontPageApp/person.html b/src/main/webapp/apps/frontPageApp/person.html index 8573afe..0ca5679 100755 --- a/src/main/webapp/apps/frontPageApp/person.html +++ b/src/main/webapp/apps/frontPageApp/person.html @@ -11,60 +11,58 @@ <li ng-class="{active: mode == 'builds'}"><a ng-click="setMode('builds')">Builds</a></li> </ul> - <div id="overview" ng-show="mode == 'overview'"> - <div class="row"> - <div class="span6"> - <h3>Upcoming</h3> - <table> - <tr ng-repeat="badge in person.badgesInProgress"> - <td style="padding-right: 1em">{{badge.name}}</td> - <td style="width: 100%"> - <div class="progress" style="margin-bottom: 0;" title="Progress: {{badge.progress}} of {{badge.goal}}"> - <div class="bar" style="width: {{badge.progress / badge.goal * 100}}%;"></div> - </div> - </td> - </tr> - </table> + <div id="overview" ng-show="mode == 'overview'" class="row"> + <div class="span6"> + <h3>Upcoming</h3> + <table> + <tr ng-repeat="badge in person.badgesInProgress"> + <td style="padding-right: 1em">{{badge.name}}</td> + <td style="width: 100%"> + <div class="progress" style="margin-bottom: 0;" title="Progress: {{badge.progress}} of {{badge.goal}}"> + <div class="bar" style="width: {{badge.progress / badge.goal * 100}}%;"></div> + </div> + </td> + </tr> + </table> - <h3>Badges</h3> - <ul class="unstyled"> - <li ng-repeat="badge in person.badges"> -<!-- - <span class="badge-level-{{badge.level}} badge">{{badge.name}}</span> ---> - <strong>{{badge.name}}</strong> -<!-- - <i class="icon-user ng-class: {{{1: 'badge-level-1', 2: 'badge-level-2', 3: 'badge-level-3'}[badge.level]}}"></i> ---> - <span class="badge-level-{{badge.level}} badge"> - <i class="icon-user"></i> - </span> + <h3>Badges</h3> + <ul class="unstyled"> + <li ng-repeat="badge in person.badges"> + <!-- + <span class="badge-level-{{badge.level}} badge">{{badge.name}}</span> + --> + <strong>{{badge.name}}</strong> + <!-- + <i class="icon-user ng-class: {{{1: 'badge-level-1', 2: 'badge-level-2', 3: 'badge-level-3'}[badge.level]}}"></i> + --> + <span class="badge-level-{{badge.level}} badge"> + <i class="icon-user"></i> + </span> - {{badge.createdDate | date:'medium'}} - </li> - </ul> - </div> - <div class="span6"> - <h3>Recent builds</h3> - <table class="table"> - <thead> -<!-- - <tr> - <th>Date</th> - <th>Success</th> - <th></th> - </tr> ---> - </thead> - <tbody> - <tr ng-repeat="build in recentBuilds" class="{{{true: 'success', false: 'error'}[build.success]}}"> - <td>{{build.timestamp | date:'medium'}}</td> - <td>{{{true: 'Success', false: 'Failure'}[build.success]}}</td> - <td><a href="/build/{{build.uuid}}">Details</a></td> - </tr> - </tbody> - </table> - </div> + {{badge.createdDate | date:'medium'}} + </li> + </ul> + </div> + <div class="span6"> + <h3>Recent builds</h3> + <table class="table"> + <thead> + <!-- + <tr> + <th>Date</th> + <th>Success</th> + <th></th> + </tr> + --> + </thead> + <tbody> + <tr ng-repeat="build in recentBuilds" class="{{{true: 'success', false: 'error'}[build.success]}}"> + <td>{{build.timestamp | date:'medium'}}</td> + <td>{{{true: 'Success', false: 'Failure'}[build.success]}}</td> + <td><a href="/build/{{build.uuid}}">Details</a></td> + </tr> + </tbody> + </table> </div> </div> diff --git a/src/main/webapp/apps/frontPageApp/personList.html b/src/main/webapp/apps/frontPageApp/personList.html new file mode 100755 index 0000000..a4f48c1 --- /dev/null +++ b/src/main/webapp/apps/frontPageApp/personList.html @@ -0,0 +1,35 @@ +<div class="container"> + + <navbar/> + + <div class="page-header"> + <h1>People</h1> + </div> + + <div class="row"> + <div class="span12"> + <table class="table"> + <tbody> + <tr ng-repeat="person in persons.rows"> + <td><a href="/#/person/{{person.person.uuid}}">{{person.person.name}}</a></td> + </tr> + </tbody> + <tfoot> + <tr> + <td colspan="2"> + <ul class="pager"> + <!--ng-class="{disabled: persons.startIndex == 0}"--> + <li class="previous" ng-hide="persons.startIndex == 0"> + <a ng-click="persons.prev()">← Prev</a> + </li> + <li class="next"> + <a ng-click="persons.next()">Next →</a> + </li> + </ul> + </td> + </tr> + </tfoot> + </table> + </div> + </div> +</div> |