Skip to content

Commit

Permalink
feat(citSci): started adding capability for questions of different sh…
Browse files Browse the repository at this point in the history
…apes
  • Loading branch information
peichins committed Jun 7, 2019
1 parent 8952909 commit 7bedaaf
Show file tree
Hide file tree
Showing 17 changed files with 487 additions and 195 deletions.
82 changes: 29 additions & 53 deletions src/app/citizenScience/bristlebird/bristlebird.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,21 @@ class BristlebirdController {
$location,
CitizenScienceCommon,
CsSamples,
CsLabels,
SampleLabels,
backgroundImage,
paths,
Question) {
Question,
$routeParams,
StudyService
) {

var self = this;

/**
* The name of the css project as it appears in the dataset definition
* @type {string}
*/
$scope.csProject = "ebb";

/**
* The duration of each audio sample
* currently all samples will be the same duration (not set per sample in the dataset)
* @type {number}
*/
self.sampleDuration = 25;

$scope.csProject = $routeParams.studyName;

/**
* The current sample object, including sample id
Expand All @@ -55,8 +49,6 @@ class BristlebirdController {
// to be populated after getting samples from dataset
$scope.media = null;


// load populate the onboarding steps as they are loaded.
$scope.onboarding = {};

$scope.onboarding.steps = [
Expand Down Expand Up @@ -94,52 +86,36 @@ class BristlebirdController {
};



/**
* Labels that the user can select.
* applies one or more tags which are not shown to the user.
* example response from server
* [{
* "tags": ["ebb", "type1"],
* "name": "Eastern Bristlebird",
* "examples": [{
* "annotationId": 124730
* }, {
* "annotationId": 124727
* }, {
* "annotationId": 98378
* }]
* },
* {
* "tags": ["ground_parrot", "type1"],
* "name": "Ground Parrot",
* "examples": [{
* "annotationId": 124622
* }]
* },
* {
* "tags": ["quoll", "type1"],
* "label": "Spotted Quoll",
* "examples": []
* }];
*/

$scope.labels = [];
$scope.questionData = {};

// the model passed to ngAudio
$scope.audioElementModel = CitizenScienceCommon.getAudioModel();

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

//TODO: replace hardcoded value with routed study id
$scope.study_id = 1;
Question.questions($scope.study_id).then(x => {
console.log("questions loaded", x);
//TODO: update to allow multiple questions
$scope.labels = x.data.data[0].questionData.labels;
SampleLabels.init(x.data.data[0].id, $scope.study_id);

StudyService.studyByName($routeParams.studyName).then(x => {
var studies = x.data.data;
if (studies.length === 0) {
console.warn("No study " + $routeParams.studyName + " exists");
return;
} else if (studies.length > 1) {
console.warn("More than one study found. Using the first one");
}
$scope.study = studies[0];
$scope.study_id = $scope.study.id;

Question.questions($scope.study_id).then(x => {
console.log("questions loaded", x);
//TODO: update to allow multiple questions
$scope.questionData = x.data.data[0].questionData;

SampleLabels.init(x.data.data[0], $scope.study_id);
});
});


//SampleLabels.init($scope.csProject, $scope.samples, $scope.labels);

/**
Expand Down Expand Up @@ -194,8 +170,7 @@ angular
"bawApp.components.citizenScienceThumbLabels",
"bawApp.components.onboarding",
"bawApp.components.background",
"bawApp.citizenScience.csSamples",
"bawApp.citizenScience.csLabels"
"bawApp.citizenScience.csSamples"
])
.controller(
"BristlebirdController",
Expand All @@ -205,11 +180,12 @@ angular
"$location",
"CitizenScienceCommon",
"CsSamples",
"CsLabels",
"SampleLabels",
"backgroundImage",
"conf.paths",
"Question",
"$routeParams",
"Study",
BristlebirdController
])
.controller(
Expand Down
21 changes: 5 additions & 16 deletions src/app/citizenScience/bristlebird/listen.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,11 @@ <h2>Eastern Bristlebird Search
</nav>


<citizen-science-labels labels="labels"
samples="samples"
current-sample-num="currentSampleNum"
cs-project="csProject"></citizen-science-labels>


<!-- text-only labels
<citizen-science-text-labels labels="labels"
samples="samples"
current-sample-num="currentSampleNum"
cs-project="csProject"></citizen-science-labels>
-->
<!-- examples not used as labels
<citizen-science-examples labels="labels"></citizen-science-examples>
-->


<citizen-science-labels ng-if="questionData.labels.length > 1" question-data="questionData"></citizen-science-labels>



</div> <!-- #main -->
</div> <!-- #main-container -->
Expand Down
146 changes: 73 additions & 73 deletions src/app/citizenScience/labels/citizenScienceLabels.js
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
var csLabels = angular.module("bawApp.citizenScience.csLabels", ["bawApp.citizenScience.common"]);


/**
* Manages the data for labels that will be applied to cs samples
*/
csLabels.factory("CsLabels", [
"CitizenScienceCommon",
"$http",
function CsLabels(CitizenScienceCommon, $http) {

var self = this;
self.useLocalData = true;
self.sheets_api_url = "http://" + window.location.hostname + ":8081";
self.local_api_url = "/public/citizen_science";


/**
* Constructs a url for the request by concatenating the arguments, joined by "/"
* and appending to the relevant baseURL. Allows experimenting with different sources
* for the data without changing everything
* @returns {string|*}
*/
self.apiUrl = function () {
// convert to array
var base_url, url;
if (self.useLocalData) {
base_url = self.local_api_url;
} else {
base_url = self.sheets_api_url;
}
var args = Array.prototype.slice.call(arguments);

url = [base_url].concat(args).join("/");

if (self.useLocalData) {
url = url + ".json";
}

return url;
};


self.publicFunctions = {


/**
* Gets all labels associated with the specified citizen science project
* @param project string
*/
getLabels: function (project) {
var response = $http.get(self.apiUrl(
"labels",
project
));

return response.then(function (response) {
var labels = [];
if (Array.isArray(response.data)) {
labels = response.data;
}

return labels;
});
},

};

return self.publicFunctions;

}]);


// var csLabels = angular.module("bawApp.citizenScience.csLabels", ["bawApp.citizenScience.common"]);
//
//
// /**
// * Manages the data for labels that will be applied to cs samples
// */
// csLabels.factory("CsLabels", [
// "CitizenScienceCommon",
// "$http",
// function CsLabels(CitizenScienceCommon, $http) {
//
// var self = this;
// self.useLocalData = true;
// self.sheets_api_url = "http://" + window.location.hostname + ":8081";
// self.local_api_url = "/public/citizen_science";
//
//
// /**
// * Constructs a url for the request by concatenating the arguments, joined by "/"
// * and appending to the relevant baseURL. Allows experimenting with different sources
// * for the data without changing everything
// * @returns {string|*}
// */
// self.apiUrl = function () {
// // convert to array
// var base_url, url;
// if (self.useLocalData) {
// base_url = self.local_api_url;
// } else {
// base_url = self.sheets_api_url;
// }
// var args = Array.prototype.slice.call(arguments);
//
// url = [base_url].concat(args).join("/");
//
// if (self.useLocalData) {
// url = url + ".json";
// }
//
// return url;
// };
//
//
// self.publicFunctions = {
//
//
// /**
// * Gets all labels associated with the specified citizen science project
// * @param project string
// */
// getLabels: function (project) {
// var response = $http.get(self.apiUrl(
// "labels",
// project
// ));
//
// return response.then(function (response) {
// var labels = [];
// if (Array.isArray(response.data)) {
// labels = response.data;
// }
//
// return labels;
// });
// },
//
// };
//
// return self.publicFunctions;
//
// }]);
//
//
25 changes: 22 additions & 3 deletions src/app/citizenScience/responses/citizenScienceSampleLabels.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ sampleLabels.factory("SampleLabels", [
// the data for questionResponses. Each question will have a unique key
self.data = {};
self.hasResponse = false;
self.allowEmpty = true;
self.allowMulti = true;



Expand All @@ -29,15 +31,29 @@ sampleLabels.factory("SampleLabels", [
* @param questionid int
* @param studyId int
*/
self.init = function (questionId = false, studyId = false) {
self.init = function (question = false, studyId = false) {

if (studyId !== false) {
self.data.studyId = studyId;
}
if (questionId !== false) {
self.data.questionId = questionId;
if (question !== false) {
self.data.questionId = question.id;

if (question.data.hasOwnProperty("allowEmpty")) {
self.allowEmpty = question.data.allowEmpty;
}

if (question.data.hasOwnProperty("allowMulti")) {
self.allowMulti = question.data.allowMulti;
}
if (question.data.labels.length === 1) {
// for binary yes/no there is only one label, therefore no multi select
self.allowMulti = false;
}

}


return self.data;

};
Expand Down Expand Up @@ -70,6 +86,9 @@ sampleLabels.factory("SampleLabels", [
if (labelId !== undefined) {
self.hasResponse = true;
if (value) {
if (!self.allowMulti) {
self.data.labels.clear();
}
self.data.labels.add(labelId);
} else {
self.data.labels.delete(labelId);
Expand Down
Loading

0 comments on commit 7bedaaf

Please sign in to comment.