diff --git a/src/app/citizenScience/bristlebird/bristlebird.js b/src/app/citizenScience/bristlebird/bristlebird.js index c3bc760c..e9d13cd5 100644 --- a/src/app/citizenScience/bristlebird/bristlebird.js +++ b/src/app/citizenScience/bristlebird/bristlebird.js @@ -167,10 +167,9 @@ angular "bawApp.components.progress", "bawApp.citizenScience.common", "bawApp.citizenScience.sampleLabels", - "bawApp.components.citizenScienceThumbLabels", + "bawApp.citizenScience.csLabels", "bawApp.components.onboarding", - "bawApp.components.background", - "bawApp.citizenScience.csSamples" + "bawApp.components.background" ]) .controller( "BristlebirdController", diff --git a/src/app/citizenScience/bristlebird/listen.tpl.html b/src/app/citizenScience/bristlebird/listen.tpl.html index dc0dc3a2..1f852100 100644 --- a/src/app/citizenScience/bristlebird/listen.tpl.html +++ b/src/app/citizenScience/bristlebird/listen.tpl.html @@ -49,7 +49,7 @@

Eastern Bristlebird Search - + diff --git a/src/app/citizenScience/labels/citizenScienceLabels.js b/src/app/citizenScience/labels/citizenScienceLabels.js index d952321d..d6a306f7 100644 --- a/src/app/citizenScience/labels/citizenScienceLabels.js +++ b/src/app/citizenScience/labels/citizenScienceLabels.js @@ -1,73 +1,43 @@ -// 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", + "bawApp.components.citizenScienceYesnoLabels", + "bawApp.components.citizenScienceThumbLabels", + "bawApp.citizenScience.sampleLabels" +]); + + +csLabels.component("citizenScienceLabels", { + templateUrl: "citizenScience/labels/labels.tpl.html", + controller: [ + "$scope", + "SampleLabels", + function ($scope, SampleLabels) { + + var self = this; + + console.log(self); + + $scope.$watch(SampleLabels.getLabels, function (newVal, oldVal) { + + if (typeof(newVal) === "object") { + if (newVal === 1) { + $scope.labelType = "yesno"; + } else if (newVal.length > 0 && + newVal.every(l => l.hasOwnProperty("examples") && l.examples.length > 0 )) { + // if all labels have an example + $scope.labelType = "thumb"; + } else { + // this is not yet implemented but should be just a list of checkboxes next to the label text string + $scope.labelType = "text"; + } + + $scope.labels = newVal; + } + + }, true); + + }], + bindings: { + } + }); + diff --git a/src/app/citizenScience/labels/labels.tpl.html b/src/app/citizenScience/labels/labels.tpl.html new file mode 100644 index 00000000..c9e74f75 --- /dev/null +++ b/src/app/citizenScience/labels/labels.tpl.html @@ -0,0 +1,12 @@ + + + + + + + diff --git a/src/app/citizenScience/textLabels/_citizenScienceLabels.scss b/src/app/citizenScience/labels/textLabels/_citizenScienceLabels.scss similarity index 100% rename from src/app/citizenScience/textLabels/_citizenScienceLabels.scss rename to src/app/citizenScience/labels/textLabels/_citizenScienceLabels.scss diff --git a/src/app/citizenScience/textLabels/labelCheck.js b/src/app/citizenScience/labels/textLabels/labelCheck.js similarity index 90% rename from src/app/citizenScience/textLabels/labelCheck.js rename to src/app/citizenScience/labels/textLabels/labelCheck.js index b8c1f037..f9c6469b 100644 --- a/src/app/citizenScience/textLabels/labelCheck.js +++ b/src/app/citizenScience/labels/textLabels/labelCheck.js @@ -1,6 +1,6 @@ angular.module("bawApp.components.citizenScienceLabelCheck", ["bawApp.citizenScience.common"]) .component("labelCheck", { - templateUrl: "citizenScience/textLabels/labelCheck.tpl.html", + templateUrl: "citizenScience/labels/textLabels/labelCheck.tpl.html", controller: [ "$scope", function ($scope) { diff --git a/src/app/citizenScience/textLabels/labelCheck.tpl.html b/src/app/citizenScience/labels/textLabels/labelCheck.tpl.html similarity index 100% rename from src/app/citizenScience/textLabels/labelCheck.tpl.html rename to src/app/citizenScience/labels/textLabels/labelCheck.tpl.html diff --git a/src/app/citizenScience/textLabels/labels.js b/src/app/citizenScience/labels/textLabels/labels.js similarity index 97% rename from src/app/citizenScience/textLabels/labels.js rename to src/app/citizenScience/labels/textLabels/labels.js index 46b02998..f802fcf0 100644 --- a/src/app/citizenScience/textLabels/labels.js +++ b/src/app/citizenScience/labels/textLabels/labels.js @@ -1,6 +1,6 @@ angular.module("bawApp.components.citizenScienceTextLabels", ["bawApp.citizenScience.common"]) .component("citizenScienceTextLabels", { - templateUrl: "citizenScience/TextLabels/labels.tpl.html", + templateUrl: "citizenScience/labels/textLabels/labels.tpl.html", controller: [ "$scope", "$http", diff --git a/src/app/citizenScience/textLabels/labels.tpl.html b/src/app/citizenScience/labels/textLabels/labels.tpl.html similarity index 100% rename from src/app/citizenScience/textLabels/labels.tpl.html rename to src/app/citizenScience/labels/textLabels/labels.tpl.html diff --git a/src/app/citizenScience/thumbLabels/_thumbs.scss b/src/app/citizenScience/labels/thumbLabels/_thumbs.scss similarity index 100% rename from src/app/citizenScience/thumbLabels/_thumbs.scss rename to src/app/citizenScience/labels/thumbLabels/_thumbs.scss diff --git a/src/app/citizenScience/thumbLabels/examples.js b/src/app/citizenScience/labels/thumbLabels/examples.js similarity index 97% rename from src/app/citizenScience/thumbLabels/examples.js rename to src/app/citizenScience/labels/thumbLabels/examples.js index 41864b62..fa85f204 100644 --- a/src/app/citizenScience/thumbLabels/examples.js +++ b/src/app/citizenScience/labels/thumbLabels/examples.js @@ -4,7 +4,7 @@ angular.module("bawApp.components.citizenScienceThumbLabels.examples", "bawApp.components.citizenScienceLabelCheck" ]) .component("citizenScienceLabelExamples", { - templateUrl: "citizenScience/thumbLabels/examples.tpl.html", + templateUrl: "citizenScience/labels/thumbLabels/examples.tpl.html", transclude: true, controller: [ "$scope", diff --git a/src/app/citizenScience/thumbLabels/examples.tpl.html b/src/app/citizenScience/labels/thumbLabels/examples.tpl.html similarity index 100% rename from src/app/citizenScience/thumbLabels/examples.tpl.html rename to src/app/citizenScience/labels/thumbLabels/examples.tpl.html diff --git a/src/app/citizenScience/thumbLabels/label.js b/src/app/citizenScience/labels/thumbLabels/label.js similarity index 96% rename from src/app/citizenScience/thumbLabels/label.js rename to src/app/citizenScience/labels/thumbLabels/label.js index d23b04cd..c1040a8a 100644 --- a/src/app/citizenScience/thumbLabels/label.js +++ b/src/app/citizenScience/labels/thumbLabels/label.js @@ -4,7 +4,7 @@ angular.module("bawApp.components.citizenScienceThumbLabels.label", "bawApp.citizenScience.sampleLabels" ]) .component("citizenScienceLabel", { - templateUrl: "citizenScience/thumbLabels/label.tpl.html", + templateUrl: "citizenScience/labels/thumbLabels/label.tpl.html", controller: [ "$scope", "SampleLabels", diff --git a/src/app/citizenScience/thumbLabels/label.tpl.html b/src/app/citizenScience/labels/thumbLabels/label.tpl.html similarity index 100% rename from src/app/citizenScience/thumbLabels/label.tpl.html rename to src/app/citizenScience/labels/thumbLabels/label.tpl.html diff --git a/src/app/citizenScience/thumbLabels/labels.js b/src/app/citizenScience/labels/thumbLabels/labels.js similarity index 84% rename from src/app/citizenScience/thumbLabels/labels.js rename to src/app/citizenScience/labels/thumbLabels/labels.js index 9288f1b9..be5fa8d7 100644 --- a/src/app/citizenScience/thumbLabels/labels.js +++ b/src/app/citizenScience/labels/thumbLabels/labels.js @@ -1,22 +1,23 @@ angular.module("bawApp.components.citizenScienceThumbLabels", [ - "bawApp.components.citizenScienceThumbLabels.label" + "bawApp.components.citizenScienceThumbLabels.label", + "bawApp.citizenScience.sampleLabels" ]) - .component("citizenScienceLabels", { - templateUrl: "citizenScience/thumbLabels/labels.tpl.html", + .component("citizenScienceThumbLabels", { + templateUrl: "citizenScience/labels/thumbLabels/labels.tpl.html", controller: [ "$scope", "$http", "CitizenScienceCommon", "annotationLibraryCommon", "AudioEvent", - "baw.models.AudioEvent", - "$q", + "SampleLabels", function ($scope, $http, CitizenScienceCommon, libraryCommon, - AudioEventService) { + AudioEventService, + SampleLabels) { var self = this; @@ -37,12 +38,10 @@ angular.module("bawApp.components.citizenScienceThumbLabels", $scope.examplesPosition = "0px"; $scope.$watch(function () { - return self.questionData; + return self.labels; }, function (newVal, oldVal) { - if (newVal !== null && typeof newVal === "object") { - if (newVal.hasOwnProperty("labels")) { - self.fetchAnnotationData(); - } + if (Array.isArray(newVal)) { + self.fetchAnnotationData(); } }); @@ -55,7 +54,7 @@ angular.module("bawApp.components.citizenScienceThumbLabels", self.fetchAnnotationData = function () { // transform labels structure into a single array of annotationsIds - var labels = self.questionData.labels; + var labels = self.labels; var annotationIds = [].concat.apply([], labels.map(l => l.examples)).map(e => e.annotationId); if (annotationIds.length === 0) { @@ -97,7 +96,7 @@ angular.module("bawApp.components.citizenScienceThumbLabels", // add annotations back into labels object response.annotations.forEach(function (annotation) { - self.questionData.labels.forEach(function (l) { + self.labels.forEach(function (l) { l.examples.forEach(function (e) { if (e.annotationId === annotation.id) { e.annotation = annotation; @@ -113,6 +112,6 @@ angular.module("bawApp.components.citizenScienceThumbLabels", }; }], bindings: { - questionData: "=", + labels: "=", } }); \ No newline at end of file diff --git a/src/app/citizenScience/labels/thumbLabels/labels.tpl.html b/src/app/citizenScience/labels/thumbLabels/labels.tpl.html new file mode 100644 index 00000000..4efbc89a --- /dev/null +++ b/src/app/citizenScience/labels/thumbLabels/labels.tpl.html @@ -0,0 +1,13 @@ +
+ + + +
+ diff --git a/src/app/citizenScience/yesnoLabels/_yesnoLabels.scss b/src/app/citizenScience/labels/yesnoLabels/_yesnoLabels.scss similarity index 100% rename from src/app/citizenScience/yesnoLabels/_yesnoLabels.scss rename to src/app/citizenScience/labels/yesnoLabels/_yesnoLabels.scss diff --git a/src/app/citizenScience/labels/yesnoLabels/labels.js b/src/app/citizenScience/labels/yesnoLabels/labels.js new file mode 100644 index 00000000..5152a602 --- /dev/null +++ b/src/app/citizenScience/labels/yesnoLabels/labels.js @@ -0,0 +1,34 @@ +angular.module("bawApp.components.citizenScienceYesnoLabels", + [ + ]) + .component("citizenScienceYesnoLabels", { + templateUrl: "citizenScience/labels/yesnoLabels/labels.tpl.html", + controller: [ + "$scope", + "SampleLabels", + function ($scope, SampleLabels) { + + var self = this; + // yesno questions only have one label + $scope.label = self.questionData.labels[0].name; + + // binary can have 3 statuses: selected yes, selected no or not selected + + $scope.isSelected = function() { + return SampleLabels.getValue(self.label.id); + }; + + /** + * callback when this label is either attached or detached from the current sample + * @param isSelected Boolean + */ + self.onToggleSelected = function (isSelected) { + SampleLabels.setValue(self.label.id, isSelected); + }; + + + }], + bindings: { + questionData: "=", + } + }); \ 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 new file mode 100644 index 00000000..9afd9189 --- /dev/null +++ b/src/app/citizenScience/labels/yesnoLabels/labels.tpl.html @@ -0,0 +1,5 @@ +
+ + +
+ diff --git a/src/app/citizenScience/responses/citizenScienceSampleLabels.js b/src/app/citizenScience/responses/citizenScienceSampleLabels.js index b02049a1..785f7732 100644 --- a/src/app/citizenScience/responses/citizenScienceSampleLabels.js +++ b/src/app/citizenScience/responses/citizenScienceSampleLabels.js @@ -3,12 +3,6 @@ var sampleLabels = angular.module("bawApp.citizenScience.sampleLabels", /** * Keeps track of the labels applied to the current sample. - * Sends as a data for a questionResponse in the following structure - * { - * 'labelsIds': [1,3,4,7] - * } - * - * */ sampleLabels.factory("SampleLabels", [ "CitizenScienceCommon", @@ -23,7 +17,7 @@ sampleLabels.factory("SampleLabels", [ self.hasResponse = false; self.allowEmpty = true; self.allowMulti = true; - + self.labels = false; /** @@ -38,22 +32,22 @@ sampleLabels.factory("SampleLabels", [ } if (question !== false) { self.data.questionId = question.id; + self.labels = question.questionData.labels; - if (question.data.hasOwnProperty("allowEmpty")) { - self.allowEmpty = question.data.allowEmpty; + if (question.questionData.hasOwnProperty("allowEmpty")) { + self.allowEmpty = question.questionData.allowEmpty; } - if (question.data.hasOwnProperty("allowMulti")) { - self.allowMulti = question.data.allowMulti; + if (question.questionData.hasOwnProperty("allowMulti")) { + self.allowMulti = question.questionData.allowMulti; } - if (question.data.labels.length === 1) { + if (question.questionData.labels.length === 1) { // for binary yes/no there is only one label, therefore no multi select self.allowMulti = false; } } - return self.data; }; @@ -145,7 +139,9 @@ sampleLabels.factory("SampleLabels", [ */ hasResponse : function () { return self.hasResponse; - } + }, + + getLabels: function () { return self.labels; } }; diff --git a/src/app/citizenScience/thumbLabels/labels.tpl.html b/src/app/citizenScience/thumbLabels/labels.tpl.html deleted file mode 100644 index 980d678f..00000000 --- a/src/app/citizenScience/thumbLabels/labels.tpl.html +++ /dev/null @@ -1,16 +0,0 @@ - - -
- - - -
-
- diff --git a/src/app/citizenScience/yesnoLabels/label.js b/src/app/citizenScience/yesnoLabels/label.js deleted file mode 100644 index d23b04cd..00000000 --- a/src/app/citizenScience/yesnoLabels/label.js +++ /dev/null @@ -1,56 +0,0 @@ -angular.module("bawApp.components.citizenScienceThumbLabels.label", - [ - "bawApp.components.citizenScienceThumbLabels.examples", - "bawApp.citizenScience.sampleLabels" - ]) - .component("citizenScienceLabel", { - templateUrl: "citizenScience/thumbLabels/label.tpl.html", - controller: [ - "$scope", - "SampleLabels", - function ($scope, SampleLabels) { - - /** - * A label is "selected" if it has been applied to the current sample - * A label is "active" if it has been clicked to show details - */ - - var self = this; - - $scope.isSelected = function() { - return SampleLabels.getValue(self.label.id); - }; - - $scope.isShowingDetails = function () { - return self.currentDetailsLabelId.value === self.label.id; - }; - - /** - * toggles whether the details pane is showing for the current label - */ - $scope.toggleShowDetails = function () { - if ($scope.isShowingDetails()) { - self.currentDetailsLabelId.value = -1; - } else { - self.currentDetailsLabelId.value = self.label.id; - } - console.log("showing details for label:", self.currentDetailsLabelId.value); - - }; - - /** - * callback when this label is either attached or detached from the current sample - * @param isSelected Boolean - */ - self.onToggleSelected = function (isSelected) { - SampleLabels.setValue(self.label.id, isSelected); - }; - - }], - bindings: { - - label: "=", - currentDetailsLabelId: "=" - - } - }); \ No newline at end of file diff --git a/src/app/citizenScience/yesnoLabels/labels.js b/src/app/citizenScience/yesnoLabels/labels.js deleted file mode 100644 index 01b94b0d..00000000 --- a/src/app/citizenScience/yesnoLabels/labels.js +++ /dev/null @@ -1,24 +0,0 @@ -angular.module("bawApp.components.citizenScienceThumbLabels", - [ - "bawApp.components.citizenScienceThumbLabels.label" - ]) - .component("citizenScienceLabels", { - templateUrl: "citizenScience/yesnoLabels/labels.tpl.html", - controller: [ - "$scope", - "$http", - "CitizenScienceCommon", - "annotationLibraryCommon", - "baw.models.AudioEvent", - "$q", - function ($scope) { - - var self = this; - // yesno questions only have one label - $scope.label = questionData.labels[0].name - - }], - bindings: { - questionData: "=", - } - }); \ No newline at end of file diff --git a/src/app/citizenScience/yesnoLabels/labels.tpl.html b/src/app/citizenScience/yesnoLabels/labels.tpl.html deleted file mode 100644 index 4512152b..00000000 --- a/src/app/citizenScience/yesnoLabels/labels.tpl.html +++ /dev/null @@ -1,47 +0,0 @@ -
- - - - -
- - -
- - - - - {{$ctrl.label.name}} -
- - - - - - - -
- - - - - -
- -
-