Skip to content

Commit

Permalink
Resolve merge conflicts with seeking branch
Browse files Browse the repository at this point in the history
  • Loading branch information
atruskie committed Feb 5, 2014
2 parents a6e3e42 + 8217ac3 commit fe50ddf
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 32 deletions.
21 changes: 19 additions & 2 deletions src/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ var app = angular.module('baw',
'templates-common',

'bawApp.directives', /* our directives.js */
'bawApp.directives.ngAudio', /* our directives.js */
'bawApp.filters', /* our filters.js */
'bawApp.services', /* our services.js */
'bawApp.services.unitConverter',
Expand Down Expand Up @@ -166,12 +167,28 @@ var app = angular.module('baw',
}])


.run(['$rootScope', '$location', '$route', '$http', 'AudioEvent', 'conf.paths',
function ($rootScope, $location, $route, $http, AudioEvent, paths) {
.run(['$rootScope', '$location', '$route', '$http', 'AudioEvent', 'conf.paths', 'UserProfile', 'ngAudioEvents',
function ($rootScope, $location, $route, $http, AudioEvent, paths, UserProfile, ngAudioEvents) {

// embed configuration for easy site-wide binding
$rootScope.paths = paths;

// user profile - update user preferences when they change
var eventCallbacks = {};
eventCallbacks[ngAudioEvents.volumeChanged] = function (event, api, value) {
if (api.profile.preferences.volume !== value) {
api.profile.preferences.volume = value;
api.updatePreferences();
}
};
eventCallbacks[ngAudioEvents.muteChanged] = function (event, api, value) {
if (api.profile.preferences.muted !== value) {
api.profile.preferences.muted = value;
api.updatePreferences();
}
};
UserProfile.listen(eventCallbacks);

// helper function for printing scope objects
baw.exports.print = $rootScope.print = function () {
var seen = [];
Expand Down
19 changes: 17 additions & 2 deletions src/app/listen/listen.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ angular.module('bawApp.listen', ['decipher.tags', 'ui.bootstrap.typeahead'])
'Taggings',
'Site',
'Project',
'UserProfile',
/**
* The listen controller.
* @param $scope
Expand All @@ -37,7 +38,7 @@ angular.module('bawApp.listen', ['decipher.tags', 'ui.bootstrap.typeahead'])
*/
function ListenCtrl(
$scope, $resource, $location, $routeParams, $route, $q, paths, constants, $url,
AudioRecording, Media, AudioEvent, Tag, Taggings, Site, Project) {
AudioRecording, Media, AudioEvent, Tag, Taggings, Site, Project, UserProfile) {

var CHUNK_DURATION_SECONDS = constants.listen.chunkDurationSeconds;

Expand Down Expand Up @@ -81,7 +82,10 @@ angular.module('bawApp.listen', ['decipher.tags', 'ui.bootstrap.typeahead'])
// set up some dummy objects for use later
$scope.jumpToHide = true;
$scope.model = {
audioElement: {},
audioElement: {
volume: null,
muted: null
},
audioEvents: [],
media: null,
selectedAudioEvent: null,
Expand All @@ -90,6 +94,17 @@ angular.module('bawApp.listen', ['decipher.tags', 'ui.bootstrap.typeahead'])
site: null
};

// bind user profile
var profileLoaded = function updateProfileSettings(event, UserProfile) {
$scope.model.audioElement.volume = UserProfile.profile.preferences.volume;
$scope.model.audioElement.muted = UserProfile.profile.preferences.muted;
};
$scope.$on(UserProfile.eventKeys.loaded, profileLoaded);
if (UserProfile.profile && UserProfile.profile.preferences) {
profileLoaded(null, UserProfile);
}


var formatPaths = function () {
if ($scope.model.media && $scope.model.media.hasOwnProperty('id')) {
//var authToken = $scope.authTokenQuery();
Expand Down
32 changes: 22 additions & 10 deletions src/baw.configuration.tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ angular.module('bawApp.configuration', ['url'])
* @param {...[string]} fragments
* @returns {*}
*/
function joinPathFragments(fragments) {
function joinPathFragments(fragments) {
fragments = Array.prototype.slice.call(arguments, 0);

if (fragments.length === 0) {
Expand All @@ -33,14 +33,14 @@ angular.module('bawApp.configuration', ['url'])
var f = fragments[i];

if ((typeof f) !== "string") {
throw "Path fragment " + f + " is not a string";
throw "joingPathFragments: Path fragment " + f + " is not a string";
}

var hasFirst = f[0] === "/";
var hasLast = (f.slice(-1))[0] === "/";

if (!hasFirst) {
f = "/" + f;
f = "/" + f;
}

if (hasLast && i !== (fragments.length - 1)) {
Expand All @@ -64,26 +64,30 @@ angular.module('bawApp.configuration', ['url'])
listShort: "/audio_recordings/{recordingId}",
show: "/audio_recordings/{recordingId}",
list: "/audio_recordings/"
},
},
audioEvent: {
list: "/audio_recordings/{recordingId}/audio_events",
show: "/audio_recordings/{recordingId}/audio_events/{audioEventId}",
csv : "/audio_events/download."
csv: "/audio_events/download."
},
tagging: {
list: "/audio_recordings/{recordingId}/audio_events/{audioEventId}/taggings",
show: "/audio_recordings/{recordingId}/audio_events/{audioEventId}/taggings/{taggingId}"
},
tag: {
list: '/tags/',
show: '/tags/{tagId}'
list: '/tags/',
show: '/tags/{tagId}'
},
media: {
show: "/audio_recordings/{recordingId}/media.{format}"
},
security: {
ping: "/security/sign_in",
signIn: "/my_account/sign_in"
},
user: {
profile: "/my_account",
settings: "/my_account/prefs"
}
},
links: {
Expand All @@ -101,7 +105,7 @@ angular.module('bawApp.configuration', ['url'])
listen: 'listen/listen.tpl.html',
annotationViewer: 'annotationViewer/annotationViewer.tpl.html',
navigation: 'navigation/navigation.tpl.html',
birdWalk : {
birdWalk: {
list: 'birdWalks/birdWalks.tpl.html',
detail: 'birdWalks/birdWalk.tpl.html',
spec: 'assets/bird_walk/bird_walk_spec.json',
Expand All @@ -121,7 +125,6 @@ angular.module('bawApp.configuration', ['url'])
};



// add helper paths
function recursivePath(source, root) {
for (var key in source) {
Expand Down Expand Up @@ -156,6 +159,15 @@ angular.module('bawApp.configuration', ['url'])
unitConverter: {
precisionSeconds: 9,
precisionHertz: 6

},
defaultProfile: {
createdAt: null,
email: null,
id: null,
preferences: {
volume: 1.0,
muted: false
},
userName: "Unknown user"
}
});
43 changes: 29 additions & 14 deletions src/components/directives/ngAudio.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
var bawds = bawds || angular.module("bawApp.directives", ["bawApp.configuration"]);
var ngAudio = ngAudio || angular.module('bawApp.directives.ngAudio', ['bawApp.configuration']);


ngAudio.constant("ngAudioEvents", {
volumeChanged: "ngAudio:volumeChanged",
muteChanged: "ngAudio:muted"
});

/**
* A directive for binding the model to data off an audio element.
Expand All @@ -7,9 +13,10 @@ var bawds = bawds || angular.module("bawApp.directives", ["bawApp.configuration"
* This directive is incomplete. The potential exists for many other cool bindings,
* like a "isBuffering" binding.
*/
bawds.directive("ngAudio", ["$parse", function ($parse) {
/* const */
var readyStates = {

ngAudio.directive("ngAudio", ["ngAudioEvents", "$parse", function (ngAudioEvents, $parse) {

/* const */ var readyStates = {
"haveNothing": 0,
"haveMetadata": 1,
"haveCurrentData": 2,
Expand Down Expand Up @@ -81,7 +88,6 @@ bawds.directive("ngAudio", ["$parse", function ($parse) {
});
};


function play() {
element.play();
}
Expand All @@ -94,8 +100,7 @@ bawds.directive("ngAudio", ["$parse", function ($parse) {
* REVERSE BINDING
*/

var propertiesToUpdate = ["duration", "src", "currentSrc", "volume", "muted", "playbackRate", "readyState"];

var propertiesToUpdate = ["duration", "src", "currentSrc", "playbackRate", "readyState"];
function updateObject(src, dest) {
for (var i = 0; i < propertiesToUpdate.length; i++) {
dest[propertiesToUpdate[i]] = src[propertiesToUpdate[i]];
Expand All @@ -120,24 +125,33 @@ bawds.directive("ngAudio", ["$parse", function ($parse) {
target.currentState = event && event.type || "unknown";


updateObject(element ,target);

target.isPlaying = !element.paused;
target.canPlay = element.readyState >= readyStates.haveFutureData;

// IMPORTANT - setting the position while playing is done by RAF.
// IMPORTANT - setting the position while playing is done by RAF.
// Do not set it here or else jittery playback will occur when any event is raised from the element.
// This includes resuming playback (from a paused state).
if (!target.isPlaying) {
target.position = element.currentTime;
}

updateObject(element, target);


if (target.volume != null) {
target.volume = element.volume;
scope.$emit(ngAudioEvents.volumeChanged, element.volume);
}

return;
if (target.muted != null) {
target.muted = element.muted;
scope.$emit(ngAudioEvents.muteChanged, element.muted);
}
}
scope.currentState = event && event.type || "unknown";
updateObject(element, scope);
else {
scope.currentState = event && event.type || 'unknown';
updateObject(element, scope);
}

});
}

Expand All @@ -153,6 +167,7 @@ bawds.directive("ngAudio", ["$parse", function ($parse) {
console.error("ngAudio:audioElement:errorEvent", event);
updateState(event);
},

"loadeddata": updateState,
"loadedmetadata": function(event) {
watchPosition();
Expand Down
50 changes: 50 additions & 0 deletions src/components/models/userProfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
var baw = window.baw = window.baw || {};


baw.UserProfile = (function () {

function UserProfile(profile, defaultProfile) {

if (!(this instanceof UserProfile)) {
throw new Error("Constructor called as a function");
}


if (!profile) {
profile = defaultProfile;
}

if (!defaultProfile) {
throw new Error("A default profile must be supplied");
}


profile.preferences = profile.preferences || {};


// make read only properties for all profile props returned
var props = Object.keys(profile)
.reduce(function (state, current, index, array) {
state[current] = {
value: profile[current],
writeable: false,
enumerable: true,
configurable: false
};
return state;
}, {});
Object.defineProperties(this, props);

// now create persistence settings logic
var merged = angular.extend(defaultProfile.preferences, this.preferences);
for (var key in merged) {
if (!merged.hasOwnProperty(key)) {
return;
}

this.preferences[key] = merged[key];
}
}

return UserProfile;
})();
5 changes: 1 addition & 4 deletions src/components/services/services.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function () {

/**...
* Helper method for adding a put request onto the standard angular resource service
* @param $resource - the stub resource
Expand Down Expand Up @@ -560,6 +560,3 @@
}
};
}]);


})();
Loading

0 comments on commit fe50ddf

Please sign in to comment.