From dfb72423ed82a293eec85b1b36d9e4c895d7b49c Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 12 Jan 2013 18:05:04 +0100 Subject: o Implementing search on people page. --- .../trygvis/esper/testing/core/db/PersonDao.java | 11 ++++++- .../esper/testing/web/resource/CoreResource.java | 5 ++-- src/main/resources/webapp/apps/app.js | 4 ++- .../webapp/apps/core/PagingTableService.js | 18 ++++++++++-- .../webapp/apps/frontPageApp/buildList.html | 34 ++++++++++------------ .../webapp/apps/frontPageApp/frontPageApp.js | 4 +++ .../webapp/apps/frontPageApp/personList.html | 11 +++++++ 7 files changed, 62 insertions(+), 25 deletions(-) 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 8d74264..2b74771 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 @@ -96,15 +96,24 @@ public class PersonDao { } } - public List selectPersons(PageRequest pageRequest) throws SQLException { + public List selectPersons(PageRequest pageRequest, Option query) throws SQLException { String sql = "SELECT " + PERSON + " FROM person"; + if (query.isSome()) { + sql += " WHERE lower(name) LIKE '%' || ? || '%'"; + } + sql += orderBy(pageRequest.orderBy, "name", "created_date"); sql += " LIMIT ? OFFSET ?"; try (PreparedStatement s = c.prepareStatement(sql)) { int i = 1; + + if (query.isSome()) { + s.setString(i++, query.some()); + } + s.setInt(i++, pageRequest.count.orSome(10)); s.setInt(i, pageRequest.startIndex.orSome(0)); return toList(s, person); 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 83f5144..11935cf 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 @@ -33,11 +33,12 @@ public class CoreResource extends AbstractResource { @GET @Path("/person") - public List getPersons(@MagicParam final PageRequest pageRequest) throws Exception { + public List getPersons(@MagicParam final PageRequest pageRequest, + @QueryParam("query") final String query) throws Exception { return da.inTransaction(new CoreDaosCallback>() { protected List run() throws SQLException { List list = new ArrayList<>(); - for (PersonDto person : daos.personDao.selectPersons(pageRequest)) { + for (PersonDto person : daos.personDao.selectPersons(pageRequest, fromNull(query))) { list.add(super.getPersonDetailJson.apply(person)); } return list; diff --git a/src/main/resources/webapp/apps/app.js b/src/main/resources/webapp/apps/app.js index 068f454..960f704 100755 --- a/src/main/resources/webapp/apps/app.js +++ b/src/main/resources/webapp/apps/app.js @@ -92,6 +92,8 @@ directives.directive('personAvatar', function () { scope: { person: '=person' }, - template: '' + template: '' + + '' + + '' } }); diff --git a/src/main/resources/webapp/apps/core/PagingTableService.js b/src/main/resources/webapp/apps/core/PagingTableService.js index af593df..f550a39 100755 --- a/src/main/resources/webapp/apps/core/PagingTableService.js +++ b/src/main/resources/webapp/apps/core/PagingTableService.js @@ -4,12 +4,13 @@ function PagingTableService() { var watcher = options.watcher || function(){}; var self = { rows: [], + query: "", startIndex: options.startIndex || 0, count: options.count || 10 }; var update = function(){ - fetchCallback(self.startIndex, self.count, function(data) { + fetchCallback(self.startIndex, self.count, self.query, function(data) { self.rows = data.rows; watcher(); }); @@ -33,6 +34,16 @@ function PagingTableService() { update(); }; + self.onSearch = function () { + console.log("search: " + self.query); + update(); + }; + + self.onSearchChange = function () { + console.log("search: " + self.query); + update(); + }; + // Do an initial fetch update(); @@ -41,13 +52,16 @@ function PagingTableService() { var defaultCallback = function(Resource, args) { args = args || {}; - return function(startIndex, count, cb) { + return function(startIndex, count, query, cb) { if(startIndex) { args.startIndex = startIndex; } if(count) { args.count = count; } + if(query) { + args.query = query; + } console.log("fetching", args); Resource.query(args, function(data, headers) { var totalResults = headers("total-results"); diff --git a/src/main/resources/webapp/apps/frontPageApp/buildList.html b/src/main/resources/webapp/apps/frontPageApp/buildList.html index 13a1dc3..c6196d4 100755 --- a/src/main/resources/webapp/apps/frontPageApp/buildList.html +++ b/src/main/resources/webapp/apps/frontPageApp/buildList.html @@ -16,27 +16,23 @@ } +
+
+

+ {{build.build.timestamp | date:'medium'}}: + SUCCESS + FAILURE +

+ +

Participants

+ + + +
+
+
- - - - - - - - - - - -
{{build.build.timestamp | date:'medium'}} - SUCCESS - FAILURE -
- - - -