Skip to content

Commit

Permalink
feat(citSci): reorganised folder structure for label components
Browse files Browse the repository at this point in the history
  • Loading branch information
peichins committed Jun 11, 2019
1 parent 7bedaaf commit ca32c9a
Show file tree
Hide file tree
Showing 24 changed files with 137 additions and 252 deletions.
5 changes: 2 additions & 3 deletions src/app/citizenScience/bristlebird/bristlebird.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/app/citizenScience/bristlebird/listen.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ <h2>Eastern Bristlebird Search



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



Expand Down
116 changes: 43 additions & 73 deletions src/app/citizenScience/labels/citizenScienceLabels.js
Original file line number Diff line number Diff line change
@@ -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: {
}
});

12 changes: 12 additions & 0 deletions src/app/citizenScience/labels/labels.tpl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@



<citizen-science-thumb-labels ng-if="labelType=='thumb'" labels="labels"></citizen-science-thumb-labels>
<!--
<citizen-science-yesno-labels ng-if="labelType=='yesno'" question-data="questionData"></citizen-science-yesno-labels>
-->


Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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();
}
});

Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -113,6 +112,6 @@ angular.module("bawApp.components.citizenScienceThumbLabels",
};
}],
bindings: {
questionData: "=",
labels: "=",
}
});
13 changes: 13 additions & 0 deletions src/app/citizenScience/labels/thumbLabels/labels.tpl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="thumb-labels-container">

<citizen-science-label
ng-repeat="label in $ctrl.labels"
class="label-thumbs"
ng-if="label.examples.length"
label="label"
current-details-label-id="currentDetailsLabelId"

></citizen-science-label>

</div>

34 changes: 34 additions & 0 deletions src/app/citizenScience/labels/yesnoLabels/labels.js
Original file line number Diff line number Diff line change
@@ -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: "=",
}
});
5 changes: 5 additions & 0 deletions src/app/citizenScience/labels/yesnoLabels/labels.tpl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="yesno-labels-container">


</div>

24 changes: 10 additions & 14 deletions src/app/citizenScience/responses/citizenScienceSampleLabels.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -23,7 +17,7 @@ sampleLabels.factory("SampleLabels", [
self.hasResponse = false;
self.allowEmpty = true;
self.allowMulti = true;

self.labels = false;


/**
Expand All @@ -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;

};
Expand Down Expand Up @@ -145,7 +139,9 @@ sampleLabels.factory("SampleLabels", [
*/
hasResponse : function () {
return self.hasResponse;
}
},

getLabels: function () { return self.labels; }

};

Expand Down
16 changes: 0 additions & 16 deletions src/app/citizenScience/thumbLabels/labels.tpl.html

This file was deleted.

Loading

0 comments on commit ca32c9a

Please sign in to comment.