Skip to content

Commit

Permalink
feat(questions): Question service to use questions from server for ci…
Browse files Browse the repository at this point in the history
…tizen science labels
  • Loading branch information
peichins committed Mar 21, 2019
1 parent b946ab0 commit 93be50e
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 6 deletions.
13 changes: 10 additions & 3 deletions src/app/citizenScience/bristlebird/bristlebird.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class BristlebirdController {
CsLabels,
SampleLabels,
backgroundImage,
paths) {
paths,
Question) {

var self = this;

Expand Down Expand Up @@ -105,8 +106,13 @@ class BristlebirdController {

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

CsLabels.getLabels($scope.csProject).then(function (labels) {
$scope.labels = labels;
//TODO: replace hardcoded value with routed study id
self.study_id = 1;
Question.questions(self.study_id).then(x => {

console.log("questions loaded", x);
$scope.labels = x.data.data[0].questionData.labels;

});

SampleLabels.init($scope.csProject, $scope.samples, $scope.labels);
Expand Down Expand Up @@ -193,6 +199,7 @@ angular
"SampleLabels",
"backgroundImage",
"conf.paths",
"Question",
BristlebirdController
])
.controller(
Expand Down
6 changes: 5 additions & 1 deletion src/baw.paths.nobuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ module.exports = function (environment) {
"list": "/progress_events",
"show": "/progress_events/{progressEventId}",
"createByDatasetItemAttributes": "datasets/{datasetId}/progress_events/audio_recordings/{audioRecordingId}/start/{startTimeSeconds}/end/{endTimeSeconds}"
}
},
"question": {
"list": "/studies/{studyId}/questions",
"show": "/questions/{questionId}"
},
},
"links": {
"projects": "/projects",
Expand Down
3 changes: 2 additions & 1 deletion src/components/models/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ angular.module(
"bawApp.models.userProfile",
//"bawApp.models.authenticator",
"bawApp.models.datasetItem",
"bawApp.models.progressEvent"
"bawApp.models.progressEvent",
"bawApp.models.question"

]);

Expand Down
24 changes: 24 additions & 0 deletions src/components/models/question.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
angular
.module("bawApp.models.question", [])
.factory("baw.models.question", [
"baw.models.ApiBase",
function (ApiBase) {

class Question extends ApiBase {
constructor(resource) {
super(resource);
this.customSettings = this.customSettings || null;
}

get questionData() {
return JSON.parse(this.data);
}

set questionData(value) {
this.data = JSON.stringify(value);
}

}

return Question;
}]);
34 changes: 34 additions & 0 deletions src/components/services/question.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
angular
.module("bawApp.services.question", [])
.factory(
"Question",
[
"$resource",
"$http",
"bawResource",
"$url",
"conf.paths",
"baw.models.question",
function ($resource, $http, bawResource, $url, paths, QuestionModel) {

var resource = bawResource(
paths.api.routes.question.list,
{studyId: "@studyId", questionId: "@questionId"},
{});

resource.questions = function getQuestions(studyId) {
var url = $url.formatUri(paths.api.routes.question.listAbsolute, {studyId: studyId});
return $http.get(url).then(x => {
return QuestionModel.makeFromApi(x);
});
};

resource.question = function getQuestion(questionId) {
var url = $url.formatUri(paths.api.routes.datasetItem.showAbsolute, {questionId: questionId});
return $http.get(url).then(x => QuestionModel.makeFromApi(x));
};

return resource;
}
]
);
3 changes: 2 additions & 1 deletion src/components/services/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ angular.module(
"bawApp.services.userProfile",
"bawApp.services.authenticator",
"bawApp.services.datasetItem",
"bawApp.services.progressEvent"
"bawApp.services.progressEvent",
"bawApp.services.question",

]);

Expand Down

0 comments on commit 93be50e

Please sign in to comment.