Skip to content

Commit

Permalink
Changed breadcrumbs to get title from route configuration.
Browse files Browse the repository at this point in the history
Active item in navbar is now selected based on url.
Bird walk resources added (not committed), along with abilty to load and display thumbnails of available bird walks.
  • Loading branch information
Mark Cottman-Fields committed Nov 8, 2013
1 parent 34c4eda commit b71d612
Show file tree
Hide file tree
Showing 9 changed files with 499 additions and 278 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ doc/
/log/*.log
/tmp


# bird walk resources
/src/assets/bird_walk/*

/.project

Expand Down
7 changes: 4 additions & 3 deletions src/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ var app = angular.module('baw',
when('/recordings/:recordingId',
{templateUrl: '/assets/recording.html', controller: 'RecordingCtrl' }).

when('/listen', {templateUrl: paths.site.files.listen, controller: 'ListenCtrl'}).
when('/listen/:recordingId', {templateUrl: paths.site.files.listen, controller: 'ListenCtrl'}).
when('/listen', {templateUrl: paths.site.files.listen, controller: 'ListenCtrl', title: 'Listen'}).
when('/listen/:recordingId', {templateUrl: paths.site.files.listen, controller: 'ListenCtrl', title: ':recordingId'}).
//when('/listen/:recordingId/start=:start/end=:end', {templateUrl: paths.site.files.listen, controller: 'ListenCtrl'}).

when('/accounts', {templateUrl: '/assets/accounts_sign_in.html', controller: 'AccountsCtrl'}).
Expand All @@ -125,7 +125,8 @@ var app = angular.module('baw',

when('/attribution', {templateUrl: '/assets/attributions.html'}).

when('/birdWalks', {templateUrl: paths.site.files.birdWalks, controller: 'BirdWalkCtrl'}).
when('/birdWalks', {templateUrl: paths.site.files.birdWalks, controller: 'BirdWalkCtrl', title: 'Bird Walks'}).
when('/birdWalks/:birdWalkId', {templateUrl: paths.site.files.birdWalks, controller: 'BirdWalkCtrl', title: ':birdWalkId'}).

// experiments
when('/experiments/:experiment',
Expand Down
57 changes: 48 additions & 9 deletions src/app/birdWalks/birdWalks.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,54 @@
angular.module('bawApp.birdWalks', [])
.controller(
'BirdWalkCtrl',
['$scope', '$resource', '$routeParams',
/**
* The navigation controller. Here we setup breadcrumbs.
* @param $scope
* @param $resource
* @constructor
* @param $routeParams
*/
function BirdWalkCtrl($scope, $resource, $routeParams) {
['$scope', '$resource', '$routeParams','$route', '$http',
function BirdWalkCtrl($scope, $resource, $routeParams, $route, $http) {
// set up results
$scope.results = {
allowContact: true,
consented: false,
ethicsStatementViewed: false,
pageHit: (new Date()).toISOString()
};

$scope.spec = {};

$scope.imagesPath = '/assets/bird_walk/images/';

// download bird walk specification
downloadResources('/assets/bird_walk/bird_walk_spec.json', 'birdWalkSpec');

function downloadResources(primaryResource, primaryStoreProperty) {
var maxAttempts = 5;

function downloadRecursive(attemptsLeft, resource, storeProperty) {
if (attemptsLeft > 0) {
$http.get(resource + "?antiCache=" + Date.now().toString())
.success(function (data, status, headers, config) {
$scope.spec[storeProperty] = data;

console.info("Downloading resource " + resource + " succeeded.", data);

if (data.additionalResources) {
angular.forEach(data.additionalResources, function (value, key) {
downloadRecursive(maxAttempts, value, key);
});
}
})
.error(function (data, status, headers, config) {
console.error("Downloading resource " + resource + " failed. Attempt " + (maxAttempts - attemptsLeft) + " of " + maxAttempts);

downloadRecursive(attemptsLeft--, resource, storeProperty);
});
}
else {
console.error("Downloading resource " + resource + " failed after " + maxAttempts + "attempts");
}
}

downloadRecursive(maxAttempts, primaryResource, primaryStoreProperty);


}
}
]);
46 changes: 46 additions & 0 deletions src/app/birdWalks/birdWalks.tpl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<div class="row" data-ng-controller="BirdWalkCtrl">

<div class="col-sm-6 col-md-3" data-ng-repeat="(name, walkSpec) in spec.birdWalkSpec.walks">
<div class="thumbnail">
<img data-ng-src="{{$parent.imagesPath + $parent.spec.birdWalkSpec.locations[walkSpec.locationName].backgroundImageName}}"
alt="{{name}}" class="img-responsive">

<div class="caption">
<h3>{{name}}
<small>{{walkSpec.waypoints.length}} waypoint(s)</small>
</h3>
<p>{{walkSpec.description}}</p>

<p>
<a href="#" class="btn btn-default" role="button">Begin Bird Walk</a>
</p>

<p class="text-muted small">
Image Source:
<a data-ng-href="{{$parent.spec.birdWalkSpec.locations[walkSpec.locationName].backgroundImageAttributionLink}}">
{{$parent.spec.birdWalkSpec.locations[walkSpec.locationName].backgroundImageAttribution}}
</a>
</p>
<!--
<h3>{{$parent.spec.birdWalkSpec.locations[walkSpec.locationName].name}}</h3>
<p>{{$parent.spec.birdWalkSpec.locations[walkSpec.locationName].locationDescription}}
<a data-ng-href="{{$parent.spec.birdWalkSpec.locations[walkSpec.locationName].locationDescriptionAttributionLink}}"
class="small">
{{$parent.spec.birdWalkSpec.locations[walkSpec.locationName].locationDescriptionAttribution}}
</a>
</p>
<h4>{{$parent.spec.birdWalkSpec.locations[walkSpec.locationName].environmentType}}</h4>
<p>{{$parent.spec.birdWalkSpec.locations[walkSpec.locationName].environmentDescription}}
<a data-ng-href="{{$parent.spec.birdWalkSpec.locations[walkSpec.locationName].environmentDescriptionAttributionLink}}"
class="small">
{{$parent.spec.birdWalkSpec.locations[walkSpec.locationName].environmentDescriptionAttribution}}
</a>
</p>
-->
</div>
</div>
</div>
</div>
17 changes: 6 additions & 11 deletions src/app/navigation/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,15 @@ angular.module('bawApp.navigation', [])
return {
restrict: 'E',
templateUrl: paths.site.files.navigation
};
};
}])

.controller(
'NavigationCtrl',
['$scope', '$resource', '$routeParams',
/**
* The navigation controller. Here we setup breadcrumbs.
* @param $scope
* @param $resource
* @constructor
* @param $routeParams
*/
function NavigationCtrl($scope, $resource, $routeParams) {

['$scope', '$resource', '$route', '$routeParams', '$location', 'breadcrumbs',
function NavigationCtrl($scope, $resource, $route, $routeParams, $location, breadcrumbs) {
$scope.$location = $location;
$scope.$route = $route;
$scope.breadcrumbs = breadcrumbs;
}
]);
12 changes: 7 additions & 5 deletions src/app/navigation/navigation.tpl.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<ol class="breadcrumb">
<li><a href="/">Home</a></li>
<li><a href="/listen">Listen</a></li>
<li class="active">Listening to 40</li>
</ol>
<ul class="breadcrumb">
<li ng-repeat="breadcrumb in breadcrumbs.getAll()" ng-class="{ active: $last }">
<a ng-if="!$last" ng-href="{{breadcrumb.path}}">{{breadcrumb.title}}</a>
<span ng-if="$last">{{breadcrumb.title}}</span>
</li>
</ul>

41 changes: 41 additions & 0 deletions src/common/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,47 @@ if (!Array.prototype.filter) {

}());

// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
if (!Object.keys) {
Object.keys = (function () {
'use strict';
var hasOwnProperty = Object.prototype.hasOwnProperty,
hasDontEnumBug = !({toString: null}).propertyIsEnumerable('toString'),
dontEnums = [
'toString',
'toLocaleString',
'valueOf',
'hasOwnProperty',
'isPrototypeOf',
'propertyIsEnumerable',
'constructor'
],
dontEnumsLength = dontEnums.length;

return function (obj) {
if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) {
throw new TypeError('Object.keys called on non-object');
}

var result = [], prop, i;

for (prop in obj) {
if (hasOwnProperty.call(obj, prop)) {
result.push(prop);
}
}

if (hasDontEnumBug) {
for (i = 0; i < dontEnumsLength; i++) {
if (hasOwnProperty.call(obj, dontEnums[i])) {
result.push(dontEnums[i]);
}
}
}
return result;
};
}());
}

///**
// * moment duration patch
Expand Down
Loading

0 comments on commit b71d612

Please sign in to comment.