Skip to content

Commit

Permalink
Fixed race condition with bookmarks/media/userprofile
Browse files Browse the repository at this point in the history
Also Fixed checked in conflicts
  • Loading branch information
atruskie committed Sep 10, 2014
1 parent 3c955ea commit b0fa860
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 68 deletions.
28 changes: 18 additions & 10 deletions src/app/listen/listen.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ angular.module('bawApp.listen', ['decipher.tags', 'ui.bootstrap.typeahead'])
profileLoaded(null, UserProfile);
}




// auto play feature
$scope.$on(ngAudioEvents.ended, function navigate(event) {

Expand All @@ -135,7 +138,7 @@ angular.module('bawApp.listen', ['decipher.tags', 'ui.bootstrap.typeahead'])
$scope.$on('event:auth-loginRequired', function(){ $scope.model.media.formatPaths(); });
$scope.$on('event:auth-loginConfirmed', function(){ $scope.model.media.formatPaths(); });

MediaService
var media = MediaService
.get(
{
recordingId: $routeParams.recordingId,
Expand All @@ -162,17 +165,22 @@ angular.module('bawApp.listen', ['decipher.tags', 'ui.bootstrap.typeahead'])
},
function mediaGetFailure() {
console.error("retrieval of media json failed");
})
.$promise
});



// bookmarks
$q
.all([Bookmark.applicationBookmarksPromise, media.$promise])
.then(
function() {
Bookmark.savePlaybackPosition(
$scope.model.media.recording.id,
$scope.model.media.commonParameters.startOffset);
},
function() {
console.error("Bookmark saving error", arguments);
});
Bookmark.savePlaybackPosition(
$scope.model.media.recording.id,
$scope.model.media.commonParameters.startOffset);
},
function() {
console.error("Bookmark saving error", arguments);
});


var getAudioRecording = function getAudioRecording(recordingId) {
Expand Down
10 changes: 0 additions & 10 deletions src/components/services/bawResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,13 @@ angular.module("bawApp.services.resource", ["ngResource"])
* @return {*}
*/
var bawResource = function resourcePut(path, paramDefaults, actions) {
<<<<<<< HEAD
var convertedPath = uriConvert(path);

var a = actions || {};
a.update = a.update || { method: 'PUT' };
var resource = $resource(convertedPath, paramDefaults, a);

resource.modifiedPath = convertedPath;
=======
path = uriConvert(path);

var a = actions || {};
a.update = a.update || { method: 'PUT' };
var resource = $resource(path, paramDefaults, a);

resource.modifiedPath = path;
>>>>>>> c1598ec2106c3ea77b28aac985caadebf8fcb5ac

return resource;
};
Expand Down
48 changes: 0 additions & 48 deletions src/components/services/bookmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,17 @@ bawss.factory('Bookmark', [
function (bawResource, paths, constants, UserProfile, $q) {
var bc = constants.bookmark;

<<<<<<< HEAD
var resource = bawResource(
paths.api.routes.bookmark.showAbsolute,
{},
{query:{method: "GET", isArray: false}});
=======
// valid query options: category
// required parameters: userId
// optional parameters: bookmarkId

// at the moment we only support bookmark modification for users (not for recordings)
var resource = bawResource(paths.api.routes.bookmark.showAbsolute, {});
>>>>>>> c1598ec2106c3ea77b28aac985caadebf8fcb5ac

// retrieve or set the playback bookmark
resource.applicationBookmarks = {};
function getApplicationBookmarks(userProfile) {
console.info("User profile hook success, retrieving app bookmarks", arguments);
var deferred = $q.defer();

<<<<<<< HEAD
// todo: replace with queryBuilder
resource.query({
filter_category: bc.appCategory,
Expand All @@ -55,27 +45,6 @@ bawss.factory('Bookmark', [

deferred.reject();
});
=======
resource.query({
category: bc.appCategory,
userId: userProfile.id
},
function appBookmarksQuerySuccess(values, headers) {
console.info("Application bookmarks received", values);

// transform into associative hash
values.forEach(function (value, index) {
resource.applicationBookmarks[value.name] = value;
});

deferred.resolve(values);
},
function appBookmarksQueryFailure() {
console.error("Retrieving application bookmarks failed");

deferred.reject();
});
>>>>>>> c1598ec2106c3ea77b28aac985caadebf8fcb5ac

return deferred.promise;
}
Expand All @@ -88,7 +57,6 @@ bawss.factory('Bookmark', [


resource.savePlaybackPosition = function savePlaybackPosition(recordingId, offset) {
<<<<<<< HEAD
function bookmarkSaveSuccess(value, headers) {
console.log("Bookmark save success");
var bookmark = value.data;
Expand All @@ -99,23 +67,17 @@ bawss.factory('Bookmark', [
console.error("Bookmark create/save failed", arguments);
}

=======
>>>>>>> c1598ec2106c3ea77b28aac985caadebf8fcb5ac
var bookmark = resource.applicationBookmarks[bc.lastPlaybackPositionName];
if (bookmark) {
// update
bookmark.offsetSeconds = offset;
bookmark.audioRecordingId = recordingId;
<<<<<<< HEAD
console.debug("Updating bookmark", bookmark);

resource
.update({bookmarkId: bookmark.id}, bookmark)
.$promise
.then(bookmarkSaveSuccess, bookmarkSaveError);
=======

>>>>>>> c1598ec2106c3ea77b28aac985caadebf8fcb5ac
}
else {
// create
Expand All @@ -125,24 +87,14 @@ bawss.factory('Bookmark', [
offsetSeconds: offset,
audioRecordingId: recordingId
};
<<<<<<< HEAD
console.debug("Creating bookmark", bookmark);

resource
.save({}, bookmark)
.$promise
.then(bookmarkSaveSuccess, bookmarkSaveError);
=======


>>>>>>> c1598ec2106c3ea77b28aac985caadebf8fcb5ac
}
};


<<<<<<< HEAD
return resource;
=======
return resource;
>>>>>>> c1598ec2106c3ea77b28aac985caadebf8fcb5ac
}]);

0 comments on commit b0fa860

Please sign in to comment.