From bc54871dac7ef10102edecf91a747d6595a4640f Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Wed, 9 Jan 2013 17:04:10 +0100 Subject: o Adding basic build list in the front page application. --- src/main/java/io/trygvis/esper/testing/Uuid.java | 88 ++++++++++++---------- .../esper/testing/web/resource/CoreResource.java | 78 +++++++++++++------ src/main/webapp/apps/app.css | 17 +++++ src/main/webapp/apps/app.js | 2 +- src/main/webapp/apps/buildApp/build.html | 8 +- src/main/webapp/apps/buildApp/buildApp.js | 5 +- src/main/webapp/apps/core/navbar.html | 7 +- src/main/webapp/apps/frontPageApp/buildList.html | 50 ++++++++++++ src/main/webapp/apps/frontPageApp/frontPageApp.js | 7 +- src/main/webapp/apps/frontPageApp/person.html | 2 +- 10 files changed, 189 insertions(+), 75 deletions(-) mode change 100644 => 100755 src/main/webapp/apps/app.css mode change 100644 => 100755 src/main/webapp/apps/app.js mode change 100644 => 100755 src/main/webapp/apps/buildApp/buildApp.js mode change 100644 => 100755 src/main/webapp/apps/core/navbar.html create mode 100755 src/main/webapp/apps/frontPageApp/buildList.html (limited to 'src/main') diff --git a/src/main/java/io/trygvis/esper/testing/Uuid.java b/src/main/java/io/trygvis/esper/testing/Uuid.java index 64fd6e5..a884959 100755 --- a/src/main/java/io/trygvis/esper/testing/Uuid.java +++ b/src/main/java/io/trygvis/esper/testing/Uuid.java @@ -17,6 +17,10 @@ public class Uuid { return uuid.toString(); } + public UUID toUUID() { + return uuid; + } + public String toString() { return toStringBase64(); } @@ -89,67 +93,71 @@ public class Uuid { } if (s.length() == 22) { - long most = 0; - int i = 0; - int shift = 64; - for(; i < 10; i++) { - char c = s.charAt(i); - long b = alphabetR[c]; - - if(b == 0) { - throw new IllegalArgumentException(s); - } - - b--; + return parseBase64(s); + } - shift -= 6; + throw new IllegalArgumentException("Illegal: " + s); + } - long l = b << shift; + public static Uuid parseBase64(String s) { + long most = 0; + int i = 0; + int shift = 64; + for(; i < 10; i++) { + char c = s.charAt(i); + long b = alphabetR[c]; - most |= l; + if(b == 0) { + throw new IllegalArgumentException(s); } - long least; - - { - char c = s.charAt(i++); - long b = alphabetR[c]; + b--; - if (b == 0) { - throw new IllegalArgumentException(s); - } + shift -= 6; - b--; + long l = b << shift; - long l = b >> 2; + most |= l; + } - most |= l; + long least; - shift = 64 - 2; + { + char c = s.charAt(i++); + long b = alphabetR[c]; - least = (b & 0x03) << shift; + if (b == 0) { + throw new IllegalArgumentException(s); } - for(; i < 22; i++) { - char c = s.charAt(i); - long b = alphabetR[c]; + b--; + + long l = b >> 2; + + most |= l; - if(b == 0) { - throw new IllegalArgumentException(s); - } + shift = 64 - 2; - b--; + least = (b & 0x03) << shift; + } - shift -= 6; + for(; i < 22; i++) { + char c = s.charAt(i); + long b = alphabetR[c]; - long l = b << shift; - least |= l; + if(b == 0) { + throw new IllegalArgumentException(s); } - return new Uuid(new UUID(most, least)); + b--; + + shift -= 6; + + long l = b << Math.max(shift, 0); + least |= l; } - throw new IllegalArgumentException("Illegal: " + s); + return new Uuid(new UUID(most, least)); } // http://en.wikipedia.org/wiki/Base64 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 22290d9..bd61855 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 @@ -8,7 +8,6 @@ import io.trygvis.esper.testing.util.sql.*; import io.trygvis.esper.testing.web.*; import org.joda.time.*; -import javax.servlet.http.*; import javax.ws.rs.*; import javax.ws.rs.core.*; import java.sql.*; @@ -16,7 +15,6 @@ import java.util.*; import java.util.List; import static fj.data.Option.fromNull; -import static io.trygvis.esper.testing.util.sql.PageRequest.*; @Path("/resource/core") @Produces(MediaType.APPLICATION_JSON) @@ -49,7 +47,7 @@ public class CoreResource extends AbstractResource { @GET @Path("/person/{uuid}") - public PersonDetailJson getPerson(@PathParam("uuid") final Uuid uuid) throws Exception { + public PersonDetailJson getPerson(@MagicParam final Uuid uuid) throws Exception { return sql(new CoreDaosCallback>() { protected SqlOption run() throws SQLException { return daos.personDao.selectPerson(uuid).map(super.getPersonDetailJson); @@ -63,20 +61,27 @@ public class CoreResource extends AbstractResource { @GET @Path("/build") - public List getBuilds(@MagicParam final PageRequest page, @MagicParam(query = "person") final Uuid person) throws Exception { - return da.inTransaction(new DatabaseAccess.DaosCallback>() { - public List run(Daos daos) throws SQLException { + public List getBuilds(@MagicParam final PageRequest page, + @MagicParam(query = "person") final Uuid person, + @QueryParam("fields") final List fields) throws Exception { + return da.inTransaction(new CoreDaosCallback>() { + public List run() throws SQLException { List buildDtos; + boolean detailed = fields.contains("detailed"); + if (person != null) { buildDtos = daos.buildDao.selectBuildsByPerson(person, page); } else { buildDtos = daos.buildDao.selectBuilds(page); } - List list = new ArrayList<>(); + List list = new ArrayList<>(); + + SqlF buildDtoSqlF = detailed ? getBuildDetailJson : getBuildJson; + for (BuildDto build : buildDtos) { - list.add(getBuildJson(build)); + list.add(buildDtoSqlF.apply(build)); } return list; } @@ -99,23 +104,14 @@ public class CoreResource extends AbstractResource { @GET @Path("/build/{uuid}") - public BuildJson getBuild(@MagicParam final UUID uuid) throws Exception { - return get(new DatabaseAccess.DaosCallback>() { - public Option run(Daos daos) throws SQLException { - SqlOption o = daos.buildDao.selectBuild(uuid); - if (o.isNone()) { - return Option.none(); - } - - return Option.some(getBuildJson(o.get())); + public BuildDetailJson getBuild(@MagicParam final UUID uuid) throws Exception { + return sql(new CoreDaosCallback>() { + public SqlOption run() throws SQLException { + return daos.buildDao.selectBuild(uuid).map(getBuildDetailJson); } }); } - private BuildJson getBuildJson(BuildDto build) { - return new BuildJson(build.uuid, build.timestamp, build.success); - } - // ----------------------------------------------------------------------- // Badge // ----------------------------------------------------------------------- @@ -146,6 +142,10 @@ public class CoreResource extends AbstractResource { return run(); } + // ----------------------------------------------------------------------- + // Person + // ----------------------------------------------------------------------- + protected final SqlF getPersonJson = new SqlF() { public PersonJson apply(PersonDto person) throws SQLException { return new PersonJson(person.uuid, person.name, person.mail); @@ -173,6 +173,32 @@ public class CoreResource extends AbstractResource { } }; + // ----------------------------------------------------------------------- + // Build + // ----------------------------------------------------------------------- + + protected final SqlF getBuildJson = new SqlF() { + public BuildJson apply(BuildDto dto) throws SQLException { + return new BuildJson(dto.uuid, dto.timestamp, dto.success); + } + }; + + protected final SqlF getBuildDetailJson = new SqlF() { + public BuildDetailJson apply(BuildDto build) throws SQLException { + List list = new ArrayList<>(); + for (PersonDto person : daos.buildDao.selectPersonsFromBuildParticipant(build.uuid)) { + list.add(getPersonJson.apply(person)); + } + + return new BuildDetailJson(getBuildJson.apply(build), + list); + } + }; + + // ----------------------------------------------------------------------- + // Badge + // ----------------------------------------------------------------------- + protected SqlF getBadgeJson = new SqlF() { public BadgeJson apply(PersonalBadgeDto badge) throws SQLException { return new BadgeJson(badge.createdDate, badge.type.name(), badge.level); @@ -203,3 +229,13 @@ class BuildJson { this.success = success; } } + +class BuildDetailJson { + public final BuildJson build; + public final List participants; + + BuildDetailJson(BuildJson build, List participants) { + this.build = build; + this.participants = participants; + } +} diff --git a/src/main/webapp/apps/app.css b/src/main/webapp/apps/app.css old mode 100644 new mode 100755 index 5ffd104..3088282 --- a/src/main/webapp/apps/app.css +++ b/src/main/webapp/apps/app.css @@ -1,3 +1,6 @@ +/* + * Badges + */ /* bronze = #8c7853 bronze ii = #a67d3d @@ -7,6 +10,20 @@ .badge-level-2 { background-color: silver; color: #000000 } .badge-level-3 { background-color: #ffd700; color: #000000 } +/* + * Avatar + */ + +/* This has to match the Gravatar image */ +.avatar80 { + width: 80px; + height: 80px; +} + +/* + * + */ + #content { background-color: #ffffff; padding-bottom: 60px; diff --git a/src/main/webapp/apps/app.js b/src/main/webapp/apps/app.js old mode 100644 new mode 100755 index 36736cd..8c683b6 --- a/src/main/webapp/apps/app.js +++ b/src/main/webapp/apps/app.js @@ -91,6 +91,6 @@ directives.directive('personAvatar', function () { scope: { person: '=person' }, - template: '' + template: '' } }); diff --git a/src/main/webapp/apps/buildApp/build.html b/src/main/webapp/apps/buildApp/build.html index 2feee28..fec38d2 100755 --- a/src/main/webapp/apps/buildApp/build.html +++ b/src/main/webapp/apps/buildApp/build.html @@ -9,19 +9,19 @@ - +
Date{{build.timestamp | date:'medium'}}{{build.build.timestamp | date:'medium'}}
Status - SUCCESS - FAILURE + SUCCESS + FAILURE

Participants

-

+

{{participant.name}}

diff --git a/src/main/webapp/apps/buildApp/buildApp.js b/src/main/webapp/apps/buildApp/buildApp.js old mode 100644 new mode 100755 index 187b240..170af16 --- a/src/main/webapp/apps/buildApp/buildApp.js +++ b/src/main/webapp/apps/buildApp/buildApp.js @@ -7,9 +7,6 @@ var buildApp = angular.module('buildApp', ['build', 'buildParticipant']).config( function BuildCtrl($scope, Build, BuildParticipant) { Build.get({uuid: uuid}, function(build) { - window.build = $scope.build = build; - }); - BuildParticipant.query({uuid: uuid}, function(persons) { - $scope.participants = persons; + $scope.build = build; }); } diff --git a/src/main/webapp/apps/core/navbar.html b/src/main/webapp/apps/core/navbar.html old mode 100644 new mode 100755 index 871bfde..914258e --- a/src/main/webapp/apps/core/navbar.html +++ b/src/main/webapp/apps/core/navbar.html @@ -4,9 +4,10 @@ Wat