From 7663c88dba4da60afde4691fc925e2f4cf6e3c4b Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 6 Jan 2013 14:33:40 +0100 Subject: o Much better person list. --- .../io/trygvis/esper/testing/util/Gravatar.java | 28 +++++++++++ .../esper/testing/web/resource/CoreResource.java | 2 +- .../esper/testing/web/resource/PersonJson.java | 9 +++- src/main/webapp/apps/app.js | 49 ++++++++++++------- src/main/webapp/apps/core/PagingTableService.js | 19 +++++--- src/main/webapp/apps/frontPageApp/frontPageApp.js | 29 ++++++++--- src/main/webapp/apps/frontPageApp/personList.html | 56 +++++++++++++--------- 7 files changed, 139 insertions(+), 53 deletions(-) create mode 100644 src/main/java/io/trygvis/esper/testing/util/Gravatar.java (limited to 'src/main') diff --git a/src/main/java/io/trygvis/esper/testing/util/Gravatar.java b/src/main/java/io/trygvis/esper/testing/util/Gravatar.java new file mode 100644 index 0000000..c98662d --- /dev/null +++ b/src/main/java/io/trygvis/esper/testing/util/Gravatar.java @@ -0,0 +1,28 @@ +package io.trygvis.esper.testing.util; + +import java.io.*; +import java.security.*; + +public class Gravatar { + public static String hex(byte[] array) { + StringBuilder sb = new StringBuilder(); + for (byte anArray : array) { + sb.append(Integer.toHexString((anArray & 0xFF) | 0x100).substring(1, 3)); + } + return sb.toString(); + } + + public static String md5Hex(String message) { + try { + MessageDigest md = MessageDigest.getInstance("MD5"); + return hex(md.digest(message.getBytes("CP1252"))); + } catch (NoSuchAlgorithmException e) { + } catch (UnsupportedEncodingException e) { + } + return null; + } + + public static String gravatar(String mail) { + return "http://www.gravatar.com/avatar/" + md5Hex(mail.trim().toLowerCase()); + } +} 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 4ab95c6..22290d9 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 @@ -148,7 +148,7 @@ public class CoreResource extends AbstractResource { protected final SqlF getPersonJson = new SqlF() { public PersonJson apply(PersonDto person) throws SQLException { - return new PersonJson(person.uuid, person.name); + return new PersonJson(person.uuid, person.name, person.mail); } }; diff --git a/src/main/java/io/trygvis/esper/testing/web/resource/PersonJson.java b/src/main/java/io/trygvis/esper/testing/web/resource/PersonJson.java index 65b081c..285ae8e 100755 --- a/src/main/java/io/trygvis/esper/testing/web/resource/PersonJson.java +++ b/src/main/java/io/trygvis/esper/testing/web/resource/PersonJson.java @@ -4,13 +4,20 @@ import io.trygvis.esper.testing.*; import java.util.*; +import static io.trygvis.esper.testing.util.Gravatar.*; + public class PersonJson { public final Uuid uuid; public final String name; + public final String mail; + public final String gravatar; - public PersonJson(Uuid uuid, String name) { + public PersonJson(Uuid uuid, String name, String mail) { this.uuid = uuid; this.name = name; + this.mail = mail; + + gravatar = gravatar(mail); } } diff --git a/src/main/webapp/apps/app.js b/src/main/webapp/apps/app.js index 3e01e9e..3d200ec 100644 --- a/src/main/webapp/apps/app.js +++ b/src/main/webapp/apps/app.js @@ -1,5 +1,36 @@ var directives = angular.module('core.directives', []); +directives.filter('countBadgeByLevel', function () { + return function (badges) { + // 5 levels + var levels = [0, 0, 0, 0, 0]; + angular.forEach(badges, function(value, key){ + levels[value.level - 1]++; + }); + return levels; + } +}); + +directives.filter('gz', function () { + return function (num) { + if(angular.isArray(num)) { + var out = []; + angular.forEach(num, function(x){ + if(x > 0) { + out.push(x); + } + }); + + return out; + } + else if(angular.isNumber(num)) { + return num > 0; + } + console.log("fail"); + return undefined; + } +}); + directives.directive('navbar', function () { return { restrict: 'E', @@ -7,7 +38,7 @@ directives.directive('navbar', function () { }; }); -directives.directive('badge', function() { +directives.directive('badge', function () { return { restrict: 'E', scope: { @@ -19,19 +50,3 @@ directives.directive('badge', function() { '{{badgeDetail.person.name}}' } }); - -/* - - {{badge.name}} - - - - - - {{badge.createdDate | date:'medium'}} - -*/ \ No newline at end of file diff --git a/src/main/webapp/apps/core/PagingTableService.js b/src/main/webapp/apps/core/PagingTableService.js index d65e7f3..a6a10f7 100755 --- a/src/main/webapp/apps/core/PagingTableService.js +++ b/src/main/webapp/apps/core/PagingTableService.js @@ -1,14 +1,17 @@ function PagingTableService() { - var create = function ($scope, fetchCallback) { + var create = function ($scope, fetchCallback, options) { + options = options || {}; + var watcher = options.watcher || function(){}; var self = { rows: [], - startIndex: 0, - count: 10 + startIndex: options.startIndex || 0, + count: options.count }; var update = function(){ fetchCallback(self.startIndex, self.count, function(data) { self.rows = data.rows; + watcher(); }); }; @@ -40,12 +43,16 @@ function PagingTableService() { args = args || {}; return function(startIndex, count, cb) { console.log("fetching", arguments); - args.startIndex = startIndex; - args.count = count; + if(startIndex) { + args.startIndex = startIndex; + } + if(count) { + args.count = count; + } Resource.query(args, function(data, headers) { var totalResults = headers("total-results"); - console.log("got data", arguments); console.log("totalResults", totalResults); + console.log("got data", data); cb({ totalResults: totalResults, rows: data diff --git a/src/main/webapp/apps/frontPageApp/frontPageApp.js b/src/main/webapp/apps/frontPageApp/frontPageApp.js index c973983..39dbc9d 100755 --- a/src/main/webapp/apps/frontPageApp/frontPageApp.js +++ b/src/main/webapp/apps/frontPageApp/frontPageApp.js @@ -13,14 +13,35 @@ function FrontPageCtrl($scope, Person, Badge) { } function PersonListCtrl($scope, Person, PagingTableService) { - $scope.persons = PagingTableService.create($scope, PagingTableService.defaultCallback(Person, {orderBy: "name"})); + var personsWatcher = function () { + var array = $scope.persons.rows; + + var group = []; + var groups = []; + angular.forEach(array, function(element) { + group.push(element); + if(group.length == 4) { + groups.push(group); + group = []; + } + }); + + if(group.length != 0) { + groups.push(group); + } + + $scope.personGroups = groups; + }; + + $scope.persons = PagingTableService.create($scope, PagingTableService.defaultCallback(Person, {orderBy: "name"}), {count: 4 * 6, watcher: personsWatcher}); + + $scope.personGroups = []; } function PersonCtrl($scope, $routeParams, Person, Build, PagingTableService) { var personUuid = $routeParams.personUuid; $scope.mode = 'overview'; - $scope.builds = PagingTableService.create($scope, PagingTableService.defaultCallback(Build, {person: personUuid})); $scope.setMode = function(mode) { @@ -44,8 +65,4 @@ function PersonCtrl($scope, $routeParams, Person, Build, PagingTableService) { Build.query({person: personUuid}, function (builds) { $scope.recentBuilds = builds; }); - -// Badge.query({person: personUuid}, function (badges) { -// $scope.badges = badges; -// }); } diff --git a/src/main/webapp/apps/frontPageApp/personList.html b/src/main/webapp/apps/frontPageApp/personList.html index a4f48c1..5212ff6 100755 --- a/src/main/webapp/apps/frontPageApp/personList.html +++ b/src/main/webapp/apps/frontPageApp/personList.html @@ -6,30 +6,42 @@

People

+ +
- - - - - - - - - - - -
{{person.person.name}}
- -
+
+
+
+ + {{person.person.name}} +
+ + x {{level}} + +
+
+
+
-- cgit v1.2.3