diff --git a/bower.json b/bower.json index ecb1d32..94849da 100644 --- a/bower.json +++ b/bower.json @@ -22,7 +22,8 @@ "angular-translate": "~2.8.0", "lodash": "~3.10.1", "bootstrap": "~3.3.5", - "angular-google-maps": "~2.2.1" + "angular-google-maps": "~2.2.1", + "angular-smart-table": "~2.1.5" }, "resolutions": { "angular": "1.4.6" diff --git a/index.html b/index.html index 1618154..4e06a5a 100644 --- a/index.html +++ b/index.html @@ -13,10 +13,12 @@ + + diff --git a/js/app.js b/js/app.js index aab9fbd..56fe292 100644 --- a/js/app.js +++ b/js/app.js @@ -2,7 +2,8 @@ angular.module('Come2HelpApp', [ 'ngRoute', 'Come2HelpController', 'uiGmapgoogle-maps', - 'pascalprecht.translate' + 'pascalprecht.translate', + 'smart-table' ]) .config(['$routeProvider', function ($routeProvider) { @@ -15,6 +16,11 @@ angular.module('Come2HelpApp', [ when('/register/done', { templateUrl: 'partials/registerDone.html' }). + when('/organisation/volunteerList', { + templateUrl: 'partials/organisation/volunteerList.html', + controller: 'VolunteerListController', + controllerAs: 'ctrl' + }). otherwise({ redirectTo: '/register' }); diff --git a/js/organisation.js b/js/organisation.js new file mode 100644 index 0000000..bc7df78 --- /dev/null +++ b/js/organisation.js @@ -0,0 +1,24 @@ +angular.module('Come2HelpController').factory('Volunteers', ['$resource', function ($resource) { + return $resource('api/volunteers/:id'); +}]); + +angular.module('Come2HelpController').controller('VolunteerListController', ['Volunteers', 'geocoder', function (Volunteers, geocoder) { + var vm = this; + + vm.volunteers = []; + + vm.search = function () { + var result = geocoder.geocode('Germany, ' + vm.zipCode, function (results) { + var latitude = results.results[0].geometry.location.lat(); + var longitude = results.results[0].geometry.location.lng(); + + Volunteers.query({ + latitude: latitude, + longitude: longitude, + distance: vm.distance * 1000 + }, function (data) { + vm.volunteers = data; + }); + }); + }; +}]); diff --git a/partials/organisation/volunteerList.html b/partials/organisation/volunteerList.html new file mode 100644 index 0000000..b2e8c2a --- /dev/null +++ b/partials/organisation/volunteerList.html @@ -0,0 +1,30 @@ +

{{ 'Volunteers' | translate }}

+ + + + + + + + + + + + + + + + + + + +
{{ 'Given Name' | translate }}{{ 'Surname' | translate }}{{ 'Zip Code' | translate }}{{ 'Phone' | translate }}{{ 'E-Mail' | translate }}{{ 'Abilities' | translate }}
{{volunteer.givenName}}{{volunteer.surname}}{{volunteer.address.zipCode}}{{volunteer.phone}}{{volunteer.email}}{{volunteer.abilities}}
\ No newline at end of file diff --git a/test/behaviour/mocks/volunteers.js b/test/behaviour/mocks/volunteers.js index d6fee57..b43a259 100644 --- a/test/behaviour/mocks/volunteers.js +++ b/test/behaviour/mocks/volunteers.js @@ -1,4 +1,29 @@ module.exports = [ + { + request: { + path: '/volunteers', + method: 'GET' + }, + response: { + data: [{ + id: 1, + givenName: 'Max 1', + surname: 'Mustermann 1', + address: {zipCode: '76133'}, + phone: '01234 567890', + adult: true, + abilities: [] + }, { + id: 1, + givenName: 'Max 2', + surname: 'Mustermann 2', + address: {zipCode: '76133'}, + phone: '01234 567890', + adult: true, + abilities: [] + }] + } + }, { request: { path: '/volunteers', diff --git a/test/behaviour/organisation.js b/test/behaviour/organisation.js new file mode 100644 index 0000000..7b16fe6 --- /dev/null +++ b/test/behaviour/organisation.js @@ -0,0 +1,33 @@ +require('./asserters')(); + +var mock = require('./http-mock'); + +describe('Volunteer List', function () { + this.timeout(2 * 60 * 1000); + + var volunteers = by.repeater('volunteer in ctrl.displayedVolunteers'); + + it('is default an empty list', function () { + expect(element.all(volunteers).count()).to.eventually.equal(0); + }); + + it('allows searching zip code of "Karlsruhe" and result contains two "Max Mustermann" entries', function () { + mock(['volunteers']); + + browser.getPart('organisation/volunteerList'); + + var zipCode = browser.findElement(by.model('ctrl.zipCode')); + zipCode.sendKeys('76133'); + + var distance = browser.findElement(by.model('ctrl.distance')); + distance.sendKeys('10'); + + element(by.partialButtonText('Search')).click(function () { + expect(element.all(volunteers).count()).to.eventually.equal(2); + for (var i = 0; i < 2; i++) { + expect(element(volunteers.column('volunteer.surname').row(i)).getInnerHtml()).to.eventually.contain('Mustermann'); + expect(element(volunteers.column('volunteer.givenName').row(i)).getInnerHtml()).to.eventually.contain('Max'); + } + }); + }); +}); \ No newline at end of file