aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2013-01-10 07:32:02 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2013-01-10 07:32:02 +0100
commit7838a06e5521db39aee8b3b87785fcb5e32cd7ad (patch)
treef10592e5f062d17522dcf08c11faa6ad166254e1
parentbc54871dac7ef10102edecf91a747d6595a4640f (diff)
downloadesper-testing-7838a06e5521db39aee8b3b87785fcb5e32cd7ad.tar.gz
esper-testing-7838a06e5521db39aee8b3b87785fcb5e32cd7ad.tar.bz2
esper-testing-7838a06e5521db39aee8b3b87785fcb5e32cd7ad.tar.xz
esper-testing-7838a06e5521db39aee8b3b87785fcb5e32cd7ad.zip
o Creating a single (awarded) badge view.
-rw-r--r--src/main/java/io/trygvis/esper/testing/core/badge/BadgeService.java39
-rw-r--r--src/main/java/io/trygvis/esper/testing/core/badge/UnbreakableBadge.java6
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/core/db/PersonDao.java8
-rw-r--r--src/main/java/io/trygvis/esper/testing/web/resource/BadgeJson.java16
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/web/resource/CoreResource.java25
-rwxr-xr-xsrc/main/webapp/apps/app.js3
-rw-r--r--src/main/webapp/apps/core/CoreResources.js2
-rwxr-xr-xsrc/main/webapp/apps/frontPageApp/badge.html30
-rwxr-xr-xsrc/main/webapp/apps/frontPageApp/frontPageApp.js8
9 files changed, 121 insertions, 16 deletions
diff --git a/src/main/java/io/trygvis/esper/testing/core/badge/BadgeService.java b/src/main/java/io/trygvis/esper/testing/core/badge/BadgeService.java
index bf06fbb..d747d5c 100644
--- a/src/main/java/io/trygvis/esper/testing/core/badge/BadgeService.java
+++ b/src/main/java/io/trygvis/esper/testing/core/badge/BadgeService.java
@@ -15,6 +15,39 @@ public class BadgeService {
this.objectMapper = objectMapper;
}
+ public UnbreakableBadge unbreakable(PersonalBadgeDto dto) {
+ return getProgress(dto.state, UnbreakableBadge.class);
+ }
+
+ // -----------------------------------------------------------------------
+ // Badge
+ // -----------------------------------------------------------------------
+
+ public PersonalBadge badge(PersonalBadgeDto dto) {
+ switch (dto.type) {
+ case UNBREAKABLE:
+ return getProgress(dto.state, UnbreakableBadge.class);
+ }
+
+ throw new RuntimeException("Unknown badge type: " + dto.type);
+ }
+
+ public <T extends PersonalBadge> T badge(PersonalBadgeDto dto, Class<T> klass) {
+ switch (dto.type) {
+ case UNBREAKABLE:
+ if(!klass.equals(UnbreakableBadgeProgress.class)) {
+ throw new RuntimeException("Badge is not of the expected type: UNBREAKABLE.");
+ }
+ return getProgress(dto.state, klass);
+ }
+
+ throw new RuntimeException("Unknown badge type: " + dto.type);
+ }
+
+ // -----------------------------------------------------------------------
+ // Badge Progress
+ // -----------------------------------------------------------------------
+
public BadgeProgress badgeProgress(PersonBadgeProgressDto dto) {
switch (PersonalBadgeDto.BadgeType.valueOf(dto.badge)) {
case UNBREAKABLE:
@@ -36,9 +69,9 @@ public class BadgeService {
throw new RuntimeException("Unknown badge type: " + dto.badge);
}
- public UnbreakableBadge unbreakable(PersonalBadgeDto dto) {
- return getProgress(dto.state, UnbreakableBadge.class);
- }
+ // -----------------------------------------------------------------------
+ //
+ // -----------------------------------------------------------------------
public String serialize(Object badge) {
try {
diff --git a/src/main/java/io/trygvis/esper/testing/core/badge/UnbreakableBadge.java b/src/main/java/io/trygvis/esper/testing/core/badge/UnbreakableBadge.java
index 6b1c78d..f2d69c4 100644
--- a/src/main/java/io/trygvis/esper/testing/core/badge/UnbreakableBadge.java
+++ b/src/main/java/io/trygvis/esper/testing/core/badge/UnbreakableBadge.java
@@ -12,6 +12,12 @@ class UnbreakableBadge extends PersonalBadge {
public final List<UUID> builds;
+ @SuppressWarnings("UnusedDeclaration")
+ private UnbreakableBadge() {
+ super(null, 0);
+ builds = null;
+ }
+
UnbreakableBadge(Uuid person, int level, List<UUID> builds) {
super(person, level);
this.builds = builds;
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 4b22100..58af119 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
@@ -175,12 +175,10 @@ public class PersonDao {
}
}
- public SqlOption<PersonalBadgeDto> selectBadge(UUID person, BadgeType type, int level) throws SQLException {
- try (PreparedStatement s = c.prepareStatement("SELECT " + PERSON_BADGE + " FROM person_badge WHERE person=? AND name=? AND level=? LIMIT 1")) {
+ public SqlOption<PersonalBadgeDto> selectBadge(Uuid uuid) throws SQLException {
+ try (PreparedStatement s = c.prepareStatement("SELECT " + PERSON_BADGE + " FROM person_badge WHERE uuid=?")) {
int i = 1;
- s.setString(i++, person.toString());
- s.setString(i++, type.toString());
- s.setInt(i, level);
+ s.setString(i, uuid.toUuidString());
return fromRs(s.executeQuery()).map(personBadge);
}
}
diff --git a/src/main/java/io/trygvis/esper/testing/web/resource/BadgeJson.java b/src/main/java/io/trygvis/esper/testing/web/resource/BadgeJson.java
index ded97ae..90d9c93 100644
--- a/src/main/java/io/trygvis/esper/testing/web/resource/BadgeJson.java
+++ b/src/main/java/io/trygvis/esper/testing/web/resource/BadgeJson.java
@@ -1,8 +1,12 @@
package io.trygvis.esper.testing.web.resource;
+import io.trygvis.esper.testing.core.badge.*;
import org.joda.time.*;
+import java.util.*;
+
public class BadgeJson {
+ public final UUID uuid;
public final DateTime createdDate;
public final String name;
public final int level;
@@ -13,7 +17,8 @@ public class BadgeJson {
/**
* For completed badges.
*/
- public BadgeJson(DateTime createdDate, String name, int level) {
+ public BadgeJson(UUID uuid, DateTime createdDate, String name, int level) {
+ this.uuid = uuid;
this.createdDate = createdDate;
this.name = name;
this.level = level;
@@ -24,8 +29,9 @@ public class BadgeJson {
/**
* For badges in progress.
*/
- public BadgeJson(DateTime createdDate, String name, int level, int progress, int goal) {
- this.createdDate = createdDate;
+ public BadgeJson(String name, int level, int progress, int goal) {
+ this.uuid = null;
+ this.createdDate = null;
this.name = name;
this.level = level;
this.progress = progress;
@@ -35,10 +41,12 @@ public class BadgeJson {
class BadgeDetailJson {
public final BadgeJson badge;
+ public final PersonalBadge personalBadge;
public final PersonJson person;
- BadgeDetailJson(BadgeJson badge, PersonJson person) {
+ BadgeDetailJson(BadgeJson badge, PersonalBadge personalBadge, PersonJson person) {
this.badge = badge;
+ this.personalBadge = personalBadge;
this.person = 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 bd61855..83f5144 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
@@ -116,6 +116,9 @@ public class CoreResource extends AbstractResource {
// Badge
// -----------------------------------------------------------------------
+ /**
+ * This shouldn't return a detailed list by default.
+ */
@GET
@Path("/badge")
public List<BadgeDetailJson> getBadges(@MagicParam final PageRequest page, @MagicParam(query = "person") final Uuid person) throws Exception {
@@ -132,6 +135,22 @@ public class CoreResource extends AbstractResource {
});
}
+ @GET
+ @Path("/badge/{uuid}")
+ public BadgeDetailJson getBadges(@MagicParam final Uuid uuid) throws Exception {
+ return sql(new CoreDaosCallback<SqlOption<BadgeDetailJson>>() {
+ protected SqlOption<BadgeDetailJson> run() throws SQLException {
+ return daos.personDao.selectBadge(uuid).map(getBadgeDetailJson);
+ }
+ });
+ }
+
+ SqlF<PersonalBadgeDto, PersonalBadge> badge = new SqlF<PersonalBadgeDto, PersonalBadge>() {
+ public PersonalBadge apply(PersonalBadgeDto dto) throws SQLException {
+ return badgeService.badge(dto);
+ }
+ };
+
abstract class CoreDaosCallback<T> implements DatabaseAccess.DaosCallback<T> {
protected Daos daos;
@@ -201,17 +220,19 @@ public class CoreResource extends AbstractResource {
protected SqlF<PersonalBadgeDto, BadgeJson> getBadgeJson = new SqlF<PersonalBadgeDto, BadgeJson>() {
public BadgeJson apply(PersonalBadgeDto badge) throws SQLException {
- return new BadgeJson(badge.createdDate, badge.type.name(), badge.level);
+ return new BadgeJson(badge.uuid, badge.createdDate, badge.type.name(), badge.level);
}
};
private BadgeJson getBadge(BadgeProgress progress) {
- return new BadgeJson(null, progress.type.name(), progress.progressingAgainstLevel(), progress.progression(), progress.goal());
+ return new BadgeJson(progress.type.name(), progress.progressingAgainstLevel(), progress.progression(), progress.goal());
}
protected final SqlF<PersonalBadgeDto, BadgeDetailJson> getBadgeDetailJson = new SqlF<PersonalBadgeDto, BadgeDetailJson>() {
public BadgeDetailJson apply(PersonalBadgeDto badgeDto) throws SQLException {
+
return new BadgeDetailJson(getBadgeJson.apply(badgeDto),
+ badge.apply(badgeDto),
daos.personDao.selectPerson(badgeDto.person).map(getPersonJson).get());
}
};
diff --git a/src/main/webapp/apps/app.js b/src/main/webapp/apps/app.js
index 8c683b6..068f454 100755
--- a/src/main/webapp/apps/app.js
+++ b/src/main/webapp/apps/app.js
@@ -55,7 +55,8 @@ directives.directive('badge', function () {
' <i class="icon-user"></i>' +
'</span>' +
' awarded to ' +
- '<a href="/#/person/{{badgeDetail.person.uuid}}">{{badgeDetail.person.name}}</a>'
+ '<a href="/#/person/{{badgeDetail.person.uuid}}">{{badgeDetail.person.name}}</a>. ' +
+ '<a href="/#/badge/{{badgeDetail.badge.uuid}}">More</a>'
}
});
diff --git a/src/main/webapp/apps/core/CoreResources.js b/src/main/webapp/apps/core/CoreResources.js
index aec6a15..b258c85 100644
--- a/src/main/webapp/apps/core/CoreResources.js
+++ b/src/main/webapp/apps/core/CoreResources.js
@@ -19,7 +19,7 @@ function BuildParticipant($resource) {
angular.module('buildParticipant', ['ngResource']).factory('BuildParticipant', BuildParticipant);
function Badge($resource) {
- return $resource('/resource/core/badge');
+ return $resource('/resource/core/badge/:uuid', {uuid: '@uuid'});
}
angular.module('badge', ['ngResource']).factory('Badge', Badge);
diff --git a/src/main/webapp/apps/frontPageApp/badge.html b/src/main/webapp/apps/frontPageApp/badge.html
new file mode 100755
index 0000000..92fc7ae
--- /dev/null
+++ b/src/main/webapp/apps/frontPageApp/badge.html
@@ -0,0 +1,30 @@
+<div class="container">
+
+ <navbar/>
+
+ <div class="page-header">
+ <h1>Badge</h1>
+ </div>
+
+ <div class="row">
+ <div class="span12">
+ The badge <badge-span badge="badge.badge"></badge-span> was awarded to <person-link person="badge.person"></person-link> at
+ {{badge.badge.createdDate | date:'medium'}}.
+ </div>
+ </div>
+
+ <div class="row" ng-switch="badge.badge.name">
+ <div class="span12" ng-switch-when="UNBREAKABLE">
+ <h2>Details</h2>
+ <p>
+ The badge was awarded for having {{badge.personalBadge.builds.length}} successful builds in a row:
+ </p>
+ <ul class="unstyled">
+ <li ng-repeat="b in badge.personalBadge.builds">
+ <a class="btn" href="/build/{{b}}">{{$index + 1}} <i class="icon-chevron-right"></i></a>
+ </li>
+ </ul>
+ </div>
+ </div>
+
+</div>
diff --git a/src/main/webapp/apps/frontPageApp/frontPageApp.js b/src/main/webapp/apps/frontPageApp/frontPageApp.js
index a67e2dc..6f80d0f 100755
--- a/src/main/webapp/apps/frontPageApp/frontPageApp.js
+++ b/src/main/webapp/apps/frontPageApp/frontPageApp.js
@@ -4,6 +4,7 @@ var frontPageApp = angular.module('frontPageApp', ['ngGrid', 'person', 'badge',
$routeProvider.
when('/', {controller: FrontPageCtrl, templateUrl: '/apps/frontPageApp/frontPage.html?noCache=' + noCache}).
when('/badge/', {controller: BadgeListCtrl, templateUrl: '/apps/frontPageApp/badgeList.html?noCache=' + noCache}).
+ when('/badge/:badgeUuid', {controller: BadgeCtrl, templateUrl: '/apps/frontPageApp/badge.html?noCache=' + noCache}).
when('/person/', {controller: PersonListCtrl, templateUrl: '/apps/frontPageApp/personList.html?noCache=' + noCache}).
when('/person/:personUuid', {controller: PersonCtrl, templateUrl: '/apps/frontPageApp/person.html?noCache=' + noCache}).
when('/build/', {controller: BuildListCtrl, templateUrl: '/apps/frontPageApp/buildList.html?noCache=' + noCache});
@@ -56,6 +57,13 @@ function BadgeListCtrl($scope, Badge, PagingTableService) {
$scope.badgeGroups = [];
}
+function BadgeCtrl($scope, $routeParams, Badge) {
+ var badgeUuid = $routeParams.badgeUuid;
+ Badge.get({uuid: badgeUuid}, function (badge) {
+ $scope.badge = badge;
+ });
+}
+
function PersonListCtrl($scope, Person, PagingTableService) {
var groupSize = 4;
var personsWatcher = function () {