\ No newline at end of file
diff --git a/src/app/citizenScience/labels/thumbLabels/label.js b/src/app/citizenScience/labels/thumbLabels/label.js
index c1040a8a..b7af707c 100644
--- a/src/app/citizenScience/labels/thumbLabels/label.js
+++ b/src/app/citizenScience/labels/thumbLabels/label.js
@@ -3,7 +3,7 @@ angular.module("bawApp.components.citizenScienceThumbLabels.label",
"bawApp.components.citizenScienceThumbLabels.examples",
"bawApp.citizenScience.sampleLabels"
])
- .component("citizenScienceLabel", {
+ .component("citizenScienceThumbLabel", {
templateUrl: "citizenScience/labels/thumbLabels/label.tpl.html",
controller: [
"$scope",
@@ -43,7 +43,7 @@ angular.module("bawApp.components.citizenScienceThumbLabels.label",
* @param isSelected Boolean
*/
self.onToggleSelected = function (isSelected) {
- SampleLabels.setValue(self.label.id, isSelected);
+ SampleLabels.setValue(isSelected, self.label.id);
};
}],
diff --git a/src/app/citizenScience/labels/thumbLabels/labels.js b/src/app/citizenScience/labels/thumbLabels/labels.js
index be5fa8d7..14872158 100644
--- a/src/app/citizenScience/labels/thumbLabels/labels.js
+++ b/src/app/citizenScience/labels/thumbLabels/labels.js
@@ -37,6 +37,9 @@ angular.module("bawApp.components.citizenScienceThumbLabels",
$scope.examplesPosition = "0px";
+ /**
+ * Watch for labels to be updated so that the examples etc can be loaded
+ */
$scope.$watch(function () {
return self.labels;
}, function (newVal, oldVal) {
diff --git a/src/app/citizenScience/labels/thumbLabels/labels.tpl.html b/src/app/citizenScience/labels/thumbLabels/labels.tpl.html
index 4efbc89a..b0d6e65e 100644
--- a/src/app/citizenScience/labels/thumbLabels/labels.tpl.html
+++ b/src/app/citizenScience/labels/thumbLabels/labels.tpl.html
@@ -1,13 +1,13 @@
-
+ >
diff --git a/src/app/citizenScience/labels/yesnoLabels/labels.js b/src/app/citizenScience/labels/yesnoLabels/labels.js
index 5152a602..8d436eca 100644
--- a/src/app/citizenScience/labels/yesnoLabels/labels.js
+++ b/src/app/citizenScience/labels/yesnoLabels/labels.js
@@ -10,25 +10,22 @@ angular.module("bawApp.components.citizenScienceYesnoLabels",
var self = this;
// yesno questions only have one label
- $scope.label = self.questionData.labels[0].name;
+ $scope.label = self.labels[0].name;
- // binary can have 3 statuses: selected yes, selected no or not selected
-
- $scope.isSelected = function() {
- return SampleLabels.getValue(self.label.id);
+ $scope.isSelectedPositive = function() {
+ return SampleLabels.getValue() === 1;
};
/**
* callback when this label is either attached or detached from the current sample
- * @param isSelected Boolean
+ * @param value Boolean
*/
- self.onToggleSelected = function (isSelected) {
- SampleLabels.setValue(self.label.id, isSelected);
+ $scope.setValue = function (value) {
+ SampleLabels.setValue(value);
};
-
}],
bindings: {
- questionData: "=",
+ labels: "=",
}
});
\ No newline at end of file
diff --git a/src/app/citizenScience/labels/yesnoLabels/labels.tpl.html b/src/app/citizenScience/labels/yesnoLabels/labels.tpl.html
index 9afd9189..375c9af1 100644
--- a/src/app/citizenScience/labels/yesnoLabels/labels.tpl.html
+++ b/src/app/citizenScience/labels/yesnoLabels/labels.tpl.html
@@ -1,5 +1,9 @@
-
+
diff --git a/src/app/citizenScience/responses/citizenScienceSampleLabels.js b/src/app/citizenScience/responses/citizenScienceSampleLabels.js
index 785f7732..4b2016f2 100644
--- a/src/app/citizenScience/responses/citizenScienceSampleLabels.js
+++ b/src/app/citizenScience/responses/citizenScienceSampleLabels.js
@@ -46,62 +46,100 @@ sampleLabels.factory("SampleLabels", [
self.allowMulti = false;
}
+ // if label ids are not supplied, add them in.
+ if (!self.labels.every(l => l.hasOwnProperty("id"))) {
+
+ // if only some but not all label ids are supplied, error
+ if (self.labels.some(l => l.hasOwnProperty("id"))) {
+ console.error("Invalid question data: Some but not all labels have ids");
+ }
+
+ self.labels = self.labels.map((l,i) => {
+ l.id = i+1;
+ return(l);
+ });
+
+ }
+
}
return self.data;
};
- self.functions = {
- init : self.init,
+ /**
+ * updates the value of a labelId applied to a sampleId as either true or false
+ * @param labelId int; may be omitted if it is a binary (only one label) task.
+ * @param value int [0,1]
+ */
+ self.setValue = function (value, labelId) {
- /**
- * Looks up the data to see if there is a boolean value stored for a given sampleId and labelId
- * and if so, returns it.
- * @param sampleId. If omitted, will use the current sample if available
- * @param labelId
- * @returns {boolean}
- */
- getValue : function (labelId) {
+ if (labelId === undefined && self.labels.length === 1) {
+ labelId = 1;
+ }
- return self.data.labels.has(labelId);
+ 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);
+ }
+ } else {
+ console.warn("Label id not defined");
+ }
- },
+ };
- /**
- * updates the value of a labelId applied to a sampleId as either true or false
- * @param sampleId int; if null, will use the current sample id
- * @param labelId int; if omitted, we are not applying a label but noting that the sample has been viewed
- * @param value int [0,1]
- */
- setValue : function (labelId, value) {
- 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);
- }
- }
+ /**
+ * Looks up the data to see if there is a boolean value stored for a given sampleId and labelId
+ * and if so, returns it.
+ * @param sampleId. If omitted, will use the current sample if available
+ * @param labelId
+ * @returns {boolean}
+ */
+ self.getValue = function (labelId) {
- },
+ if (labelId === undefined && self.labels.length === 1) {
+ labelId = 1;
+ }
+ return self.data.labels.has(labelId);
+ };
+
+ self.functions = {
+
+ init : self.init,
+ getValue : self.getValue,
+ setValue : self.setValue,
+ setValueBinary : self.setValueBinary,
/**
* sends the response to the server using the questionResponse service
*/
- sendResponse : function (notes) {
+ sendResponse : function (notes, userNotes) {
if (self.data.datasetItemId) {
// convert labels to data json
- self.data.data = {"labels": [...self.data.labels]};
+ // just an array of label ids
+ self.data.data = {"labelIds": [...self.data.labels]};
+ // json object with status for all positive labels
+ self.data.data.labels = self.labels.reduce(function (map, obj, idx, src) {
+ if (self.data.labels.has(obj.id)) {
+ map.push(obj.name);
+ }
+ return map;
+ },[]);
if (notes) {
self.data.data.notes = notes;
}
+ if (userNotes) {
+ self.data.data.userNotes = userNotes;
+ }
QuestionResponse.createQuestionResponse(self.data.questionId, self.data.datasetItemId, self.data.studyId, self.data.data);
}