Skip to content

Commit

Permalink
feat(datasets): Started work to use dataset items from the server for…
Browse files Browse the repository at this point in the history
… cs samples
  • Loading branch information
peichins committed Jul 31, 2018
1 parent ea054f4 commit 1599960
Show file tree
Hide file tree
Showing 10 changed files with 269 additions and 216 deletions.
12 changes: 6 additions & 6 deletions src/app/citizenScience/bristlebird/bristlebird.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class BristlebirdController {
ngAudioEvents,
$location,
CitizenScienceCommon,
CsApi,
CsSamples,
SampleLabels,
backgroundImage,
paths) {
Expand Down Expand Up @@ -100,7 +100,7 @@ class BristlebirdController {

this.showAudio = CitizenScienceCommon.bindShowAudio($scope);

CsApi.getLabels($scope.csProject).then(function (labels) {
CsSamples.getLabels($scope.csProject).then(function (labels) {
$scope.labels = labels;
});

Expand All @@ -109,7 +109,7 @@ class BristlebirdController {
/**
* Retrieve settings about this citizen science project
*/
CsApi.getSettings($scope.csProject).then(
CsSamples.getSettings($scope.csProject).then(
function (settings) {
$scope.settings = settings;
if ($scope.settings.hasOwnProperty("sampleDuration")) {
Expand All @@ -123,7 +123,7 @@ class BristlebirdController {
*/
$scope.$watch("currentSample", function () {
if ($scope.currentSample.id !== undefined) {
self.showAudio($scope.currentSample.recordingId, $scope.currentSample.startOffset, self.sampleDuration);
self.showAudio($scope.currentSample.audioRecordingId, $scope.currentSample.startTimeSeconds, $scope.currentSample.endTimeSeconds);
// for now, we cycle through backgrounds arbitrarily, based on the id of the sample number
// todo: store background images as part of the dataset or cs project
var backgroundPath = self.backgroundPaths[parseInt($scope.currentSample.id) % (self.backgroundPaths.length - 1)];
Expand Down Expand Up @@ -166,7 +166,7 @@ angular
"bawApp.components.citizenScienceThumbLabels",
"bawApp.components.onboarding",
"bawApp.components.background",
"bawApp.citizenScience.csApiMock"
"bawApp.citizenScience.csSamples"
])
.controller(
"BristlebirdController",
Expand All @@ -175,7 +175,7 @@ angular
"ngAudioEvents",
"$location",
"CitizenScienceCommon",
"CsApi",
"CsSamples",
"SampleLabels",
"backgroundImage",
"conf.paths",
Expand Down
4 changes: 2 additions & 2 deletions src/app/citizenScience/citizenScienceCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ citizenScienceCommon.factory("CitizenScienceCommon", [
*/
bindShowAudio: function ($scope) {

var showAudio = function (recordingId, startOffset, duration) {
var showAudio = function (recordingId, startOffset, endOffset) {

var mediaParams = {
recordingId: recordingId,
startOffset: startOffset,
endOffset: startOffset + duration,
endOffset: endOffset,
format: "json"
};

Expand Down
121 changes: 70 additions & 51 deletions src/app/citizenScience/datasetProgress/datasetProgress.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,84 @@
angular.module("bawApp.components.progress", ["bawApp.citizenScience.csApiMock"])
angular.module("bawApp.components.progress", ["bawApp.citizenScience.csSamples"])
.component("datasetProgress", {
templateUrl: "citizenScience/datasetProgress/datasetProgress.tpl.html",
controller: ["$scope", "$routeParams", "$url", "conf.paths", "CsApi", "SampleLabels",
function ($scope, $routeParams, $url, paths, CsApi, SampleLabels) {
controller: ["$scope", "$routeParams", "$url", "conf.paths", "CsSamples", "SampleLabels",
function ($scope, $routeParams, $url, paths, CsSamples, SampleLabels) {

var self = this;
$scope.selectItem = function (itemId) {
console.log("selecting item", itemId);
CsApi.getSample(itemId).then(function (apiResponse) {
self.currentSample = apiResponse;
SampleLabels.registerCurrentSampleId(self.currentSample.id);
$scope.totalSamplesViewed = SampleLabels.getNumSamplesViewed();
console.log("setting selected to ", itemId);
});
};
var self = this;

$scope.selectItem($routeParams.sampleNum);

/**
* Load the new sample whenever the route params change.
*/
$scope.$watch(
function () {
return $routeParams.sampleNum;
}, function (newVal, oldVal) {
console.log("route params changed from ", oldVal, "to", newVal);
$scope.selectItem = function (itemId) {
console.log("selecting item", itemId);
self.currentSample = CsSamples.getSample(itemId);
if (self.currentSample) {
SampleLabels.registerCurrentSampleId(self.currentSample.id);
$scope.totalSamplesViewed = SampleLabels.getNumSamplesViewed();
console.log("setting selected to ", itemId);
}
};

// call the api to get the sample based on the route params
$scope.selectItem($routeParams.sampleNum);
// don't do this yet, because we'll watch for ready
//$scope.selectItem($routeParams.sampleNum);

});
/**
* Load the new sample whenever the route params change.
*/
$scope.$watch(
function () {
return $routeParams.sampleNum;
}, function (newVal, oldVal) {
console.log("route params changed from ", oldVal, "to", newVal);

//TODO: this gets called constantly while the audio is playing
/**
* returns a link for routing based on the id for the next and
* previous samples. That id is returned in the request for metadata of
* the current sample (contained in the route).
* @returns string
*/
$scope.previousLink = function () {
if (self.currentSample.previousSampleId) {
return $url.formatUri(paths.site.ngRoutes.citizenScience.listen, {sampleNum:self.currentSample.previousSampleId});
} else {
return "";
}
};
$scope.nextLink = function () {
if (self.currentSample.nextSampleId) {
return $url.formatUri(paths.site.ngRoutes.citizenScience.listen, {sampleNum:self.currentSample.nextSampleId});
} else {
return "";
}
};
// call the api to get the sample based on the route params
$scope.selectItem($routeParams.sampleNum);

// reverse binding of this functions to make
// them accessible to the parent controller for autoplay
self.nextLink = $scope.nextLink;
});

self.progressNav = true;
/**
* Load sample when the list of samples is ready
*/

}],
$scope.$watch(
function () {
return CsSamples.isReady;
},
function (newVal, oldVal) {
if (newVal) {
$scope.selectItem($routeParams.sampleNum);
}
},
true);


//TODO: this gets called constantly while the audio is playing
/**
* returns a link for routing based on the id for the next and
* previous samples. That id is returned in the request for metadata of
* the current sample (contained in the route).
* @returns string
*/
$scope.previousLink = function () {
if (self.currentSample.previousSampleId) {
return $url.formatUri(paths.site.ngRoutes.citizenScience.listen, {sampleNum: self.currentSample.previousSampleId});
} else {
return "";
}
};
$scope.nextLink = function () {
if (self.currentSample.nextSampleId) {
return $url.formatUri(paths.site.ngRoutes.citizenScience.listen, {sampleNum: self.currentSample.nextSampleId});
} else {
return "";
}
};

// reverse binding of this functions to make
// them accessible to the parent controller for autoplay
self.nextLink = $scope.nextLink;

self.progressNav = true;

}],
bindings: {
audioElementModel: "=",
currentSample: "=",
Expand Down
155 changes: 0 additions & 155 deletions src/app/citizenScience/dummyApi/citizenScienceApiMock.js

This file was deleted.

Loading

0 comments on commit 1599960

Please sign in to comment.