From 93be50eb9542e93be27e015ef8be8c4d0cccb0af Mon Sep 17 00:00:00 2001 From: Philip Eichinski Date: Thu, 21 Mar 2019 16:06:23 +1000 Subject: [PATCH] feat(questions): Question service to use questions from server for citizen science labels --- .../citizenScience/bristlebird/bristlebird.js | 13 +++++-- src/baw.paths.nobuild.js | 6 +++- src/components/models/models.js | 3 +- src/components/models/question.js | 24 +++++++++++++ src/components/services/question.js | 34 +++++++++++++++++++ src/components/services/services.js | 3 +- 6 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 src/components/models/question.js create mode 100644 src/components/services/question.js diff --git a/src/app/citizenScience/bristlebird/bristlebird.js b/src/app/citizenScience/bristlebird/bristlebird.js index a91b4050..2fe9a113 100644 --- a/src/app/citizenScience/bristlebird/bristlebird.js +++ b/src/app/citizenScience/bristlebird/bristlebird.js @@ -25,7 +25,8 @@ class BristlebirdController { CsLabels, SampleLabels, backgroundImage, - paths) { + paths, + Question) { var self = this; @@ -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); @@ -193,6 +199,7 @@ angular "SampleLabels", "backgroundImage", "conf.paths", + "Question", BristlebirdController ]) .controller( diff --git a/src/baw.paths.nobuild.js b/src/baw.paths.nobuild.js index 85aa7875..700119ba 100644 --- a/src/baw.paths.nobuild.js +++ b/src/baw.paths.nobuild.js @@ -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", diff --git a/src/components/models/models.js b/src/components/models/models.js index 9ce96f05..6f24183b 100644 --- a/src/components/models/models.js +++ b/src/components/models/models.js @@ -25,7 +25,8 @@ angular.module( "bawApp.models.userProfile", //"bawApp.models.authenticator", "bawApp.models.datasetItem", - "bawApp.models.progressEvent" + "bawApp.models.progressEvent", + "bawApp.models.question" ]); diff --git a/src/components/models/question.js b/src/components/models/question.js new file mode 100644 index 00000000..4b1cb833 --- /dev/null +++ b/src/components/models/question.js @@ -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; + }]); diff --git a/src/components/services/question.js b/src/components/services/question.js new file mode 100644 index 00000000..ae67604d --- /dev/null +++ b/src/components/services/question.js @@ -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; + } + ] + ); \ No newline at end of file diff --git a/src/components/services/services.js b/src/components/services/services.js index 46a27fa8..54729371 100644 --- a/src/components/services/services.js +++ b/src/components/services/services.js @@ -35,7 +35,8 @@ angular.module( "bawApp.services.userProfile", "bawApp.services.authenticator", "bawApp.services.datasetItem", - "bawApp.services.progressEvent" + "bawApp.services.progressEvent", + "bawApp.services.question", ]);