From e0433a61af4e1b9796cee8f095486fec85eb136f Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Tue, 22 Jan 2013 23:39:51 +0100 Subject: NavbarService: o Renamed to NavTabService. o Listing builds per server, with paging. --- .../trygvis/esper/testing/jenkins/JenkinsDao.java | 16 ++++++++++- .../esper/testing/jenkins/JenkinsServerActor.java | 3 ++ .../testing/web/resource/JenkinsResource.java | 22 +++++++++++---- src/main/resources/webapp/apps/app.js | 11 ++++++++ src/main/resources/webapp/apps/core/pager.html | 12 ++++++++ .../resources/webapp/apps/jenkinsApp/jenkinsApp.js | 19 +++++++------ .../resources/webapp/apps/jenkinsApp/server.html | 32 ++++++++++++---------- 7 files changed, 87 insertions(+), 28 deletions(-) create mode 100644 src/main/resources/webapp/apps/core/pager.html (limited to 'src') 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 bd85e89..375187e 100755 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java @@ -56,7 +56,7 @@ public class JenkinsDao { } }; - public static final String JENKINS_BUILD = "uuid, created_date, job, file, entry_id, url, users"; + public static final String JENKINS_BUILD = "jenkins_build.uuid, jenkins_build.created_date, jenkins_build.job, jenkins_build.file, jenkins_build.entry_id, jenkins_build.url, jenkins_build.users"; public static final SqlF jenkinsBuild = new SqlF() { public JenkinsBuildDto apply(ResultSet rs) throws SQLException { @@ -212,6 +212,20 @@ public class JenkinsDao { } } + public List selectBuildByServer(UUID server, PageRequest page) throws SQLException { + String sql = "SELECT " + JENKINS_BUILD + " FROM jenkins_build, jenkins_job WHERE jenkins_job.uuid = jenkins_build.job AND jenkins_job.server=?"; + 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()); + s.setInt(i++, page.count.orSome(10)); + s.setInt(i, page.startIndex.orSome(0)); + return toList(s, jenkinsBuild); + } + } + public SqlOption selectBuild(UUID uuid) throws SQLException { try (PreparedStatement s = c.prepareStatement("SELECT " + JENKINS_BUILD + " FROM jenkins_build WHERE uuid=?")) { int i = 1; diff --git a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java index f573b23..651d4b8 100755 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java @@ -50,6 +50,9 @@ public class JenkinsServerActor implements TransactionalActor { logger.info("Got " + list.size() + " entries."); + // Process the list from the oldest first. + Collections.reverse(list); + int i = 0; Map authors = new HashMap<>(); 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 450463b..e36952c 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 @@ -93,14 +93,26 @@ public class JenkinsResource extends AbstractResource { @GET @Path("/build") @Produces(MediaType.APPLICATION_JSON) - public List getBuilds(@MagicParam(query = "job") final UUID job, @MagicParam final PageRequest page) throws Exception { + public List getBuilds(@MagicParam(query = "job") final UUID job, + @MagicParam(query = "server") final UUID server, + @MagicParam final PageRequest page) throws Exception { return da.inTransaction(new JenkinsDaosCallback>() { protected List run() throws SQLException { - List builds = new ArrayList<>(); + List daos; + if(job != null) { - for (JenkinsBuildDto dto : daos.jenkinsDao.selectBuildByJob(job, page)) { - builds.add(getJenkinsBuildJson.apply(dto)); - } + daos = this.daos.jenkinsDao.selectBuildByJob(job, page); + } + else if(server != null) { + daos = this.daos.jenkinsDao.selectBuildByServer(server, page); + } + else { + throw new WebApplicationException(Response.Status.BAD_REQUEST); + } + + List builds = new ArrayList<>(); + for (JenkinsBuildDto dto : daos) { + builds.add(getJenkinsBuildJson.apply(dto)); } return builds; } diff --git a/src/main/resources/webapp/apps/app.js b/src/main/resources/webapp/apps/app.js index 69106aa..f3fca90 100755 --- a/src/main/resources/webapp/apps/app.js +++ b/src/main/resources/webapp/apps/app.js @@ -110,6 +110,17 @@ directives.directive('dogtagXl', function () { } }); +directives.directive('pager', function () { + return { + restrict: 'A', + scope: { + pager: '=x', + colspan: '=colspan' + }, + templateUrl: '/apps/core/pager.html' + } +}); + directives.directive('spinner', function () { return function($scope, element, attr) { var opts = { diff --git a/src/main/resources/webapp/apps/core/pager.html b/src/main/resources/webapp/apps/core/pager.html new file mode 100644 index 0000000..7a141b4 --- /dev/null +++ b/src/main/resources/webapp/apps/core/pager.html @@ -0,0 +1,12 @@ + + + + + diff --git a/src/main/resources/webapp/apps/jenkinsApp/jenkinsApp.js b/src/main/resources/webapp/apps/jenkinsApp/jenkinsApp.js index d31b81c..f59c107 100755 --- a/src/main/resources/webapp/apps/jenkinsApp/jenkinsApp.js +++ b/src/main/resources/webapp/apps/jenkinsApp/jenkinsApp.js @@ -1,13 +1,14 @@ 'use strict'; -function NavbarService($location) { +function NavTabsService($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 currentIndex = _.indexOf(keys, currentKey); + currentIndex = currentIndex != -1 ? currentIndex : 0; var currentTab = tabs[currentIndex]; var onClick = function(tab) { @@ -38,13 +39,13 @@ function NavbarService($location) { } angular. - module('navbarService', ['ngResource']). - factory('NavbarService', NavbarService); + module('navTabsService', ['ngResource']). + factory('NavTabsService', NavTabsService); -var jenkinsApp = angular.module('jenkinsApp', ['jenkinsServer', 'jenkinsJob', 'jenkinsBuild', 'core.directives', 'navbarService', 'pagingTableService']).config(function ($routeProvider) { +var jenkinsApp = angular.module('jenkinsApp', ['jenkinsServer', 'jenkinsJob', 'jenkinsBuild', 'core.directives', 'navTabsService', 'pagingTableService']).config(function ($routeProvider) { $routeProvider. when('/', {controller: ServerListCtrl, templateUrl: '/apps/jenkinsApp/server-list.html?noCache=' + noCache}). - when('/server/:serverUuid', {controller: ServerCtrl, templateUrl: '/apps/jenkinsApp/server.html?noCache=' + noCache}). + when('/server/:serverUuid', {controller: ServerCtrl, templateUrl: '/apps/jenkinsApp/server.html?noCache=' + noCache, reloadOnSearch: false}). when('/server/:serverUuid/job/:jobUuid', {controller: JobCtrl, templateUrl: '/apps/jenkinsApp/job.html?noCache=' + noCache}). when('/server/:serverUuid/job/:jobUuid/build/:buildUuid', {controller: BuildCtrl, templateUrl: '/apps/jenkinsApp/build.html?noCache=' + noCache}); }); @@ -55,16 +56,18 @@ function ServerListCtrl($scope, $location, JenkinsServer) { }); } -function ServerCtrl($scope, $routeParams, JenkinsServer, JenkinsJob, PagingTableService, NavbarService) { +function ServerCtrl($scope, $routeParams, JenkinsServer, JenkinsJob, JenkinsBuild, PagingTableService, NavTabsService) { $scope.serverUuid = $routeParams.serverUuid; + $scope.navTabs = NavTabsService.create("view", ["Overview", "Jobs", "Recent Builds"]); + JenkinsServer.get({uuid: $scope.serverUuid}, function (server) { $scope.server = server; }); $scope.jobs = PagingTableService.create($scope, PagingTableService.defaultCallback(JenkinsJob, {server: $scope.serverUuid, orderBy: "display_name"})); - $scope.navbar = NavbarService.create("view", ["Overview", "Jobs", "Recent Builds"]); + $scope.builds = PagingTableService.create($scope, PagingTableService.defaultCallback(JenkinsBuild, {server: $scope.serverUuid, orderBy: "created_date-"})); } 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 80544b0..bf54bb8 100755 --- a/src/main/resources/webapp/apps/jenkinsApp/server.html +++ b/src/main/resources/webapp/apps/jenkinsApp/server.html @@ -2,7 +2,6 @@ - @@ -12,20 +11,13 @@
  • Server
  • - -
    +

    Overview

    @@ -55,7 +47,7 @@ -
    +
    @@ -91,9 +83,21 @@
    -
    +
    -

    Recent builds

    +
    + + + + + + + + + +
    {{b.timestamp | date:'medium'}}{{b.result}}Job + +
    -- cgit v1.2.3