Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(listen) Fixed various bugs on the listen page #228

Merged
merged 1 commit into from
Aug 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"watch": "grunt watch",
"build": "grunt",
"setup": "npm install && bower install",
"start": "npm run build",
"start": "npm run watch",
"test": "npm run build"
},
"private": true,
Expand Down
42 changes: 41 additions & 1 deletion src/app/listen/listen.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ angular.module('bawApp.listen', ['decipher.tags', 'ui.bootstrap.typeahead'])
'conf.paths',
'conf.constants',
'$url',
"lodash",
'ngAudioEvents',
'AudioRecording',
'Media',
Expand Down Expand Up @@ -50,7 +51,7 @@ angular.module('bawApp.listen', ['decipher.tags', 'ui.bootstrap.typeahead'])
* @param moment
*/
function ListenCtrl(
$scope, $resource, $location, $routeParams, $route, $q, paths, constants, $url, ngAudioEvents,
$scope, $resource, $location, $routeParams, $route, $q, paths, constants, $url, _, ngAudioEvents,
AudioRecording, MediaService, Media, AudioEvent, Tag, TagModel, Taggings, Site, Project, UserProfile,
UserProfileEvents, Bookmark, moment) {

Expand Down Expand Up @@ -535,15 +536,43 @@ angular.module('bawApp.listen', ['decipher.tags', 'ui.bootstrap.typeahead'])
tagTemplateUrl: "/templates/tags.html"
};

var hackIndexOf = function hackIndexOf(event) {
// do hyper hacky hack to fix dodgy ass library
// see: https://github.com/QutBioacoustics/baw-client/issues/227
event.targetScope.srcTags.indexOf = function myOwnHackyIndexOf(item) {
if (item.name) {
return this.findIndex(c => c.text == item.name);
}
else {
// revert back to the standard implementation
return Array.prototype.indexOf.call(this, item);
}
};
};

var hackyCleaningOfFakeTags = function(arr) {
arr.forEach(function(current, index) {
if (!(current instanceof TagModel)) {
var real = $scope.tags.find(c => c.text == current.name);
arr[index] = real;
}
});
};

$scope.$on('decipher.tags.initialized', function (event) {
event.stopPropagation();

hackIndexOf(event);

console.debug('decipher.tags.initialized', arguments);
});
$scope.$on('decipher.tags.keyup', function (event) {
hackIndexOf(event);
event.stopPropagation();
console.debug('decipher.tags.keyup', arguments);
});
$scope.$on('decipher.tags.added', function (event, addedTag) {
hackIndexOf(event);
event.stopPropagation();
console.debug('decipher.tags.added', arguments);

Expand All @@ -554,12 +583,21 @@ angular.module('bawApp.listen', ['decipher.tags', 'ui.bootstrap.typeahead'])

var index = $scope.model.selectedAudioEvent.tags.length; //.indexOf(addedTag.tag);

// HACK: find a proper tag when the tag is fake tag
if (!addedTag.tag.id) {
var actualTagIndex = $scope.tags.findIndex(c => c.text == addedTag.tag.name);
addedTag.tag = $scope.tags[actualTagIndex];
// MORE HACKS! repair its cache of deleted fake tags as well
hackyCleaningOfFakeTags(event.targetScope._deletedSrcTags);
hackyCleaningOfFakeTags(event.targetScope.tags);
}

Taggings.save(taggingParameters, {tagId: addedTag.tag.id},
function success(value, headers) {

// possible race condition: may no longer may be selected after async
$scope.model.selectedAudioEvent.taggings[index] = new baw.Tagging(value);
$scope.model.selectedAudioEvent.tags[index] = addedTag.tag;

console.assert(
$scope.model.selectedAudioEvent.tags.length ==
Expand All @@ -573,10 +611,12 @@ angular.module('bawApp.listen', ['decipher.tags', 'ui.bootstrap.typeahead'])
});
});
$scope.$on('decipher.tags.addfailed', function (event) {
hackIndexOf(event);
event.stopPropagation();
console.debug('decipher.tags.addfailed', arguments);
});
$scope.$on('decipher.tags.removed', function (event, removedTag) {
hackIndexOf(event);
event.stopPropagation();
console.debug('decipher.tags.removed', arguments);

Expand Down
3 changes: 2 additions & 1 deletion src/app/listen/listen.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ <h1 id="chunkInfo" class="row">

</div>

<volume-control model="model.audioElement" class="input-group btn-group"></volume-control>
<!-- form-group form-group-without-feedback required here due to a bug with ngFormGroup -->
<volume-control model="model.audioElement" class="input-group btn-group form-group form-group-without-feedback"></volume-control>

<toggle-switch model="model.audioElement.autoPlay" disabled="disabled" mode="push-toggle" title="Enable/disable autoplay" >
<toggle-switch-state switch-state="on">
Expand Down
4 changes: 2 additions & 2 deletions src/components/services/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ angular

function memoize(result) {
if (angular.isArray(result)) {
result.forEach(value => tagsCache.add(value.id, value));
result.forEach(value => tagsCache.set(value.id, value));
}
else {
tagsCache.add(result.id, result);
tagsCache.set(result.id, result);
}
}

Expand Down