aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java18
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/web/resource/JenkinsResource.java17
-rwxr-xr-xsrc/main/resources/webapp/apps/core/PagingTableService.js2
-rwxr-xr-xsrc/main/resources/webapp/apps/jenkinsApp/jenkinsApp.js18
-rwxr-xr-xsrc/main/resources/webapp/apps/jenkinsApp/server.html9
5 files changed, 50 insertions, 14 deletions
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<JenkinsJobDto> 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<JenkinsJobDto> selectJobsByServer(UUID server, PageRequest page, Option<String> 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<JenkinsJobJson> getJobs(@MagicParam(query = "server") final UUID server, @MagicParam final PageRequest page) throws Exception {
+ public List<JenkinsJobJson> 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<List<JenkinsJobJson>>() {
protected List<JenkinsJobJson> run() throws SQLException {
+ List<JenkinsJobDto> dtos;
+
+ dtos = daos.jenkinsDao.selectJobsByServer(server, page, fromNull(trimToNull(query)));
+
List<JenkinsJobJson> 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 @@
<div ng-show="navbar.selectedIndex() == 1" class="row">
<div class="span12">
- <h3>Jobs</h3>
+ <form class="form-search form-inline well">
+ <div class="input-append">
+ <input type="text" class="span2 search-query" ng-model="jobs.query" ng-change="jobs.onSearchChange()">
+ <button type="submit" class="btn" ng-click="jobs.onSearch()">Search</button>
+ </div>
+ </form>
+ </div>
+ <div class="span12">
<table class="table">
<tbody>
<tr ng-repeat="job in jobs.rows">