From b83c4eed1a75e9e68279ab6f84cd7b5eb602abec Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Tue, 22 Jan 2013 22:52:09 +0100 Subject: NavbarService: o Storing the current tab with $location.search. JenkinsApp: o Implementing job search. --- .../io/trygvis/esper/testing/jenkins/JenkinsDao.java | 18 +++++++++++++++--- .../esper/testing/web/resource/JenkinsResource.java | 17 +++++++++++++++-- .../resources/webapp/apps/core/PagingTableService.js | 2 +- .../resources/webapp/apps/jenkinsApp/jenkinsApp.js | 18 +++++++++++------- src/main/resources/webapp/apps/jenkinsApp/server.html | 9 ++++++++- 5 files changed, 50 insertions(+), 14 deletions(-) (limited to 'src/main') diff --git a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java index f8291b5..bd85e89 100755 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java @@ -91,7 +91,7 @@ public class JenkinsDao { String sql = "SELECT " + JENKINS_SERVER + " FROM jenkins_server"; if (enabledOnly) { - sql += " WHERE enabled=true"; + sql += " WHERE enabled=TRUE"; } sql += " ORDER BY url"; @@ -119,10 +119,22 @@ public class JenkinsDao { } } - public List selectJobsByServer(UUID server, PageRequest page) throws SQLException { - try (PreparedStatement s = c.prepareStatement("SELECT " + JENKINS_JOB + " FROM jenkins_job WHERE server=? ORDER BY created_date DESC LIMIT ? OFFSET ?")) { + public List selectJobsByServer(UUID server, PageRequest page, Option name) throws SQLException { + String sql = "SELECT " + JENKINS_JOB + " FROM jenkins_job WHERE server=?"; + + if (name.isSome()) { + sql += " AND lower(display_name) LIKE '%' || lower(?) || '%'"; + } + + sql += orderBy(ifEmpty(page.orderBy, "created_date-"), "created_date"); + sql += " LIMIT ? OFFSET ?"; + + try (PreparedStatement s = c.prepareStatement(sql)) { int i = 1; s.setString(i++, server.toString()); + if (name.isSome()) { + s.setString(i++, name.some()); + } s.setInt(i++, page.count.orSome(10)); s.setInt(i, page.startIndex.orSome(0)); return toList(s, jenkinsJob); diff --git a/src/main/java/io/trygvis/esper/testing/web/resource/JenkinsResource.java b/src/main/java/io/trygvis/esper/testing/web/resource/JenkinsResource.java index fd8ea91..450463b 100755 --- a/src/main/java/io/trygvis/esper/testing/web/resource/JenkinsResource.java +++ b/src/main/java/io/trygvis/esper/testing/web/resource/JenkinsResource.java @@ -16,6 +16,9 @@ import java.util.List; import javax.ws.rs.*; import javax.ws.rs.core.*; +import static fj.data.Option.fromNull; +import static org.apache.commons.lang.StringUtils.trimToNull; + @Path("/resource/jenkins") public class JenkinsResource extends AbstractResource { @@ -54,11 +57,21 @@ public class JenkinsResource extends AbstractResource { @GET @Path("/job") @Produces(MediaType.APPLICATION_JSON) - public List getJobs(@MagicParam(query = "server") final UUID server, @MagicParam final PageRequest page) throws Exception { + public List getJobs(@MagicParam(query = "server") final UUID server, + @MagicParam final PageRequest page, + @QueryParam("query") final String query) throws Exception { + if (server == null) { + throw new WebApplicationException(Response.Status.BAD_REQUEST); + } + return da.inTransaction(new JenkinsDaosCallback>() { protected List run() throws SQLException { + List dtos; + + dtos = daos.jenkinsDao.selectJobsByServer(server, page, fromNull(trimToNull(query))); + List jobs = new ArrayList<>(); - for (JenkinsJobDto job : daos.jenkinsDao.selectJobsByServer(server, page)) { + for (JenkinsJobDto job : dtos) { jobs.add(getJenkinsJobJson.apply(job)); } return jobs; diff --git a/src/main/resources/webapp/apps/core/PagingTableService.js b/src/main/resources/webapp/apps/core/PagingTableService.js index 802c0c8..61446a6 100755 --- a/src/main/resources/webapp/apps/core/PagingTableService.js +++ b/src/main/resources/webapp/apps/core/PagingTableService.js @@ -156,7 +156,7 @@ function PagingTableService() { console.log("Fetching page. args =", args); Resource.query(args, function(data, headers) { var totalResults = headers("total-results"); - console.log("Total results =", totalResults, "Data =", data); + console.log("Total results =", totalResults, "data.length =", data.length, "Data =", data); cb({ totalResults: totalResults, rows: data diff --git a/src/main/resources/webapp/apps/jenkinsApp/jenkinsApp.js b/src/main/resources/webapp/apps/jenkinsApp/jenkinsApp.js index d632aaf..d31b81c 100755 --- a/src/main/resources/webapp/apps/jenkinsApp/jenkinsApp.js +++ b/src/main/resources/webapp/apps/jenkinsApp/jenkinsApp.js @@ -1,15 +1,19 @@ 'use strict'; -function NavbarService() { - var create = function(tabs) { - console.log("create", tabs); - var currentIndex = 0; +function NavbarService($location) { + var create = function(name, tabs) { + var keys = _.map(tabs, function(element) { + return element.toLowerCase().replace(' ', '-'); + }); + + var currentKey = $location.search()[name] || ""; + var currentIndex = _.indexOf(keys, currentKey) || 0; var currentTab = tabs[currentIndex]; var onClick = function(tab) { - console.log("onClick", arguments); currentTab = tab; currentIndex = _.indexOf(tabs, tab); + $location.search(name, keys[currentIndex]); }; var selected = function() { @@ -58,9 +62,9 @@ function ServerCtrl($scope, $routeParams, JenkinsServer, JenkinsJob, PagingTable $scope.server = server; }); - $scope.jobs = PagingTableService.create($scope, PagingTableService.defaultCallback(JenkinsJob, {server: $scope.serverUuid})); + $scope.jobs = PagingTableService.create($scope, PagingTableService.defaultCallback(JenkinsJob, {server: $scope.serverUuid, orderBy: "display_name"})); - $scope.navbar = NavbarService.create(["Overview", "Jobs", "Recent Builds"]); + $scope.navbar = NavbarService.create("view", ["Overview", "Jobs", "Recent Builds"]); } function JobCtrl($scope, $location, $routeParams, JenkinsJob, JenkinsBuild, PagingTableService) { diff --git a/src/main/resources/webapp/apps/jenkinsApp/server.html b/src/main/resources/webapp/apps/jenkinsApp/server.html index 2a220db..80544b0 100755 --- a/src/main/resources/webapp/apps/jenkinsApp/server.html +++ b/src/main/resources/webapp/apps/jenkinsApp/server.html @@ -57,7 +57,14 @@
-

Jobs

+ +
+
-- cgit v1.2.3