Skip to content

Commit

Permalink
feat(citSci): enable autoplay, allow notes for question responses.
Browse files Browse the repository at this point in the history
If autoplay button is enabled then on arrival at the end of the dataset item, the
response will be automatically sent and the next clip loaded. A 'notes' field will contain
a flag to say that it was sent as the result of an autoplay.
The notes field is also used to indicate whether the dataset item was routed.
  • Loading branch information
peichins committed Mar 29, 2019
1 parent bf8fa1c commit 50e62bf
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 35 deletions.
19 changes: 8 additions & 11 deletions src/app/citizenScience/bristlebird/bristlebird.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ class BristlebirdController {
backgroundImage.currentBackground = backgroundPath;
$scope.$broadcast("update-selected-labels", SampleLabels.getLabelsForSample(item.id));

// todo: check where this is used
//$scope.numSamplesViewed = SampleLabels.getNumSamplesViewed();
}
}, true);

Expand All @@ -144,19 +142,18 @@ class BristlebirdController {
* is initialised to null, then reverse bound bound from the data progress component
*TODO: make this work with non-url progress
$scope.nextLink = null;
*/
//$scope.nextLink = null;
$scope.$on(ngAudioEvents.ended, function navigate(event) {
var uriNext = $scope.nextLink();
if (uriNext && $scope.audioElementModel.autoPlay) {
console.info("Changing page to next sample...");
$scope.$apply(function () {
$location.url(uriNext);
});

console.log(event);

if (event.targetScope.audioElementModel === $scope.audioElementModel && $scope.audioElementModel.autoPlay) {
$scope.$broadcast("autoNextTrigger");
}
});

*/


self.backgroundPaths = ["1.jpg", "2.jpg", "3.jpg", "4.jpg"].map(fn => paths.site.assets.backgrounds.citizenScience + fn);

Expand Down
18 changes: 15 additions & 3 deletions src/app/citizenScience/datasetProgress/datasetProgress.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,30 @@ angular.module("bawApp.components.progress", ["bawApp.citizenScience.csSamples"]

if ($routeParams.sampleNum) {
CsSamples.selectById($routeParams.sampleNum);
$scope.nextItem = false;
$scope.nextItem = function () {
SampleLabels.sendResponse("using_routed");
return true;
};
$scope.isRoutedSample = true;
} else {
CsSamples.init();
$scope.nextItem = function () {
console.log("next item");
SampleLabels.sendResponse();
CsSamples.nextItem();
};
$scope.isRoutedSample = false;
}



$scope.$watch(() => CsSamples.currentItem(), (newVal, oldVal) => {
var newDatasetItemId = newVal.id;
SampleLabels.submitAndClear(newDatasetItemId);
SampleLabels.reset(newDatasetItemId);
});

$scope.$on("autoNextTrigger", function (x) {
SampleLabels.sendResponse("autoplay");
CsSamples.nextItem();
});

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@

<div class="btn-group citSci-next">
<button ng-if="nextItem"
<button ng-if="!isRoutedSample"
class="btn btn-default"
ng-disabled="nextDisabled()"
ng-click="nextItem()"
title="Next Clip">
{{nextText()}} <span class="glyphicon glyphicon-arrow-right"></span>
</button>
<a ng-if="!nextItem"
<a ng-if="isRoutedSample"
href="/citsci/bristlebird/listen/"
ng-click="nextItem()"
class="btn btn-default"
title="Next Clip">
{{nextText()}} <span class="glyphicon glyphicon-arrow-right"></span>
Expand Down
35 changes: 16 additions & 19 deletions src/app/citizenScience/responses/citizenScienceSampleLabels.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,6 @@ sampleLabels.factory("SampleLabels", [

};

/**
* Happens whenever we get a new dataset item
* @param newDatasetItemId int
*/
self.setup = function (newDatasetItemId) {

self.data.datasetItemId = newDatasetItemId;
self.data.labels = new Set();
// hasResponse will be stay true if a value has been added and then removed
// until this init function is called.
self.hasResponse = false;

};

self.functions = {

init : self.init,
Expand Down Expand Up @@ -94,20 +80,31 @@ sampleLabels.factory("SampleLabels", [

/**
* sends the response to the server using the questionResponse service
* and reinitialises with a new datasetItemId
* @param newDatasetItemId
*/
submitAndClear : function (newDatasetItemId) {
sendResponse : function (notes) {

if (self.data.datasetItemId) {
// convert labels to data json
self.data.data = {"labels": [...self.data.labels]};
if (notes) {
self.data.data.notes = notes;
}
QuestionResponse.createQuestionResponse(self.data.questionId, self.data.datasetItemId, self.data.studyId, self.data.data);
}

},

/**
* empties the data and updates the datasetItemId
* @param newDatasetItemId
*/
reset : function (newDatasetItemId) {

// todo: is it better to do this in the promise success, incase it doesn't work? but then it should be linkedto the current dataset item shown.
self.setup(newDatasetItemId);
self.data.datasetItemId = newDatasetItemId;
self.data.labels = new Set();
// hasResponse will be stay true if a value has been added and then removed
// until this init function is called.
self.hasResponse = false;

},

Expand Down

0 comments on commit 50e62bf

Please sign in to comment.