Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Guests: See volunteer shifts with name conflicts

When there is a first-name conflict, allow the
guest to narrow things down further.
  • Loading branch information...
commit c9c6d33592315b720dac73d112f5fd97c0eb2ecb 1 parent 718a01a
@exclsr exclsr authored
Showing with 88 additions and 41 deletions.
  1. +25 −5 _app/server.js
  2. +29 −5 guests/client-1.1.js
  3. +34 −31 guests/volunteers.html
View
30 _app/server.js
@@ -207,14 +207,34 @@ app.get('/data/volunteers/shifts/', function (req, res) {
res.send(200);
})
+var getVolunteerShifts = function (name, callback) {
+ var volunteerName = name.toLowerCase();
+ fs.readFile('data/volunteerSchedule.json', 'utf8', function (err, data) {
+ data = JSON.parse(data);
+ callback(data[volunteerName]);
+ });
+};
+
app.get('/data/volunteers/shifts/:volunteerName', function (req, res) {
var volunteerName = req.params.volunteerName.toLowerCase();
+ getVolunteerShifts(volunteerName, function (data) {
+ res.send(200, data);
+ });
+});
+
+app.get('/data/volunteers/shifts/:volunteerName/:personName', function (req, res) {
+ var volunteerName = req.params.volunteerName.toLowerCase();
+ var personName = req.params.personName;
- fs.readFile('data/volunteerSchedule.json', 'utf8', function (err, data) {
- data = JSON.parse(data);
- console.log(data[volunteerName]);
- res.send(200, data[volunteerName]);
- })
+ getVolunteerShifts(volunteerName, function (data) {
+ var filteredData = [];
+ for (var entry in data) {
+ if (data[entry].person === personName) {
+ filteredData.push(data[entry]);
+ }
+ }
+ res.send(200, filteredData);
+ });
});
//----------------------------------------------------------------
View
34 guests/client-1.1.js
@@ -7,12 +7,16 @@ projectModule.config(function($routeProvider) {
when('/food', {controller:MainCtrl, templateUrl:'food.html'}).
when('/volunteers', {controller:VolunteersCtrl, templateUrl: 'volunteers.html'}).
when('/volunteers/:who', {controller:VolunteersCtrl, templateUrl: 'volunteers.html'}).
+ when('/volunteers/:who/:exactly', {controller:VolunteersCtrl, templateUrl: 'volunteers.html'}).
otherwise({redirectTo:'/'});
});
projectModule.filter('capitalize', function() {
// http://scofred.com/2013/12/20/angularjs-filter-to-auto-capitalize-the-first-letter/
return function (input, scope) {
+ if (!input) {
+ return "";
+ }
if (input!=null) {
input = input.toLowerCase();
}
@@ -42,17 +46,25 @@ function MainCtrl($scope, $location, $window) {
function VolunteersCtrl($scope, $location, $window, $routeParams, $http) {
initController($scope, $location, $window);
- var showSchedule = function (name) {
+ var showSchedule = function (name, exactly) {
if (name) {
$scope.name = name;
}
+ if (exactly) {
+ $scope.exactly = exactly;
+ }
var friday = [];
var saturday = [];
var sunday = [];
var personList = {};
- $http.get('/data/volunteers/shifts/' + name)
+ var requestUrl = '/data/volunteers/shifts/' + name;
+ if (exactly) {
+ requestUrl += '/' + exactly;
+ }
+
+ $http.get(requestUrl)
.success(function (data) {
for (var key in data) {
var entry = data[key];
@@ -66,9 +78,11 @@ function VolunteersCtrl($scope, $location, $window, $routeParams, $http) {
sunday.push(entry);
}
+ // for name conflicts
personList[entry.person] = entry.person;
}
+ // do we have name conflicts?
$scope.personList = personList;
$scope.personCount = 0;
for (var person in personList) {
@@ -81,14 +95,24 @@ function VolunteersCtrl($scope, $location, $window, $routeParams, $http) {
});
}
- $scope.showSchedule = function(name) {
+ $scope.showSchedule = function(name, exactly) {
+ var path;
if (name && name !== undefined) {
- $location.path("/volunteers/" + name);
+ path = "/volunteers/" + name
+ if (exactly && exactly !== undefined) {
+ path += '/' + exactly;
+ }
+ }
+
+ if (path) {
+ $location.path(path);
}
};
if ($routeParams.who) {
- showSchedule($routeParams.who);
+ $scope.volunteer = {};
+ $scope.volunteer.name = $routeParams.who;
+ showSchedule($routeParams.who, $routeParams.exactly);
}
}
View
65 guests/volunteers.html
@@ -4,44 +4,47 @@
<button class="btn" ng-click="showSchedule(volunteer.name)">That's me</button>
</form>
-<div ng-show="personCount > 1">Which {{name | capitalize}}?</div>
-<div ng-repeat="person in personList">
- {{person}}
+<div ng-show="personCount > 1">Which {{name | capitalize}}?
+ <div ng-repeat="person in personList">
+ <a href="" ng-click="showSchedule(volunteer.name, person)">{{person}}</a>
+ </div>
</div>
-<p ng-show="name" ng-hide="personCount > 1">Showing schedule for {{name | capitalize}}:</p>
+<div ng-hide="personCount > 1">
+ <p ng-hide="!name">Showing schedule for {{name | capitalize}}<span ng-show="exactly">.
+ More specifically, {{exactly}}</span>:</p>
-<div ng-show="friday.length > 0" ng-hide="personCount > 1">
- <h4>Friday</h4>
- <div class="timeslot" ng-repeat="slot in friday" ng-class-odd="'odd'">
- <div><strong>{{slot.time}}</strong></div>
- <div>Location: {{slot.location}}</div>
- <div>Role: {{slot.role}}</div>
- <div>Specifics: {{slot.detail}}</div>
- <div>Contact: {{slot.contact}}</div>
+ <div ng-show="friday.length > 0">
+ <h4>Friday</h4>
+ <div class="timeslot" ng-repeat="slot in friday" ng-class-odd="'odd'">
+ <div><strong>{{slot.time}}</strong></div>
+ <div>Location: {{slot.location}}</div>
+ <div>Role: {{slot.role}}</div>
+ <div>Specifics: {{slot.detail}}</div>
+ <div>Contact: {{slot.contact}}</div>
+ </div>
</div>
-</div>
-<div ng-show="saturday.length > 0" ng-hide="personCount > 1">
- <h4>Saturday</h4>
- <div class="timeslot" ng-repeat="slot in saturday" ng-class-odd="'odd'">
- <div><strong>{{slot.time}}</strong></div>
- <div>Location: {{slot.location}}</div>
- <div>Role: {{slot.role}}</div>
- <div>Specifics: {{slot.detail}}</div>
- <div>Contact: {{slot.contact}}</div>
+ <div ng-show="saturday.length > 0">
+ <h4>Saturday</h4>
+ <div class="timeslot" ng-repeat="slot in saturday" ng-class-odd="'odd'">
+ <div><strong>{{slot.time}}</strong></div>
+ <div>Location: {{slot.location}}</div>
+ <div>Role: {{slot.role}}</div>
+ <div>Specifics: {{slot.detail}}</div>
+ <div>Contact: {{slot.contact}}</div>
+ </div>
</div>
-</div>
-<div ng-show="sunday.length > 0" ng-hide="personCount > 1">
- <h4>Sunday</h4>
- <div class="timeslot" ng-repeat="slot in sunday" ng-class-odd="'odd'">
- <div><strong>{{slot.time}}</strong></div>
- <div>Location: {{slot.location}}</div>
- <div>Role: {{slot.role}}</div>
- <div>Specifics: {{slot.detail}}</div>
- <div>Contact: {{slot.contact}}</div>
+ <div ng-show="sunday.length > 0">
+ <h4>Sunday</h4>
+ <div class="timeslot" ng-repeat="slot in sunday" ng-class-odd="'odd'">
+ <div><strong>{{slot.time}}</strong></div>
+ <div>Location: {{slot.location}}</div>
+ <div>Role: {{slot.role}}</div>
+ <div>Specifics: {{slot.detail}}</div>
+ <div>Contact: {{slot.contact}}</div>
+ </div>
</div>
</div>
-
Please sign in to comment.
Something went wrong with that request. Please try again.