Skip to content

Commit

Permalink
feat(citSci): fixed text label component for use with binary label qu…
Browse files Browse the repository at this point in the history
…estion
  • Loading branch information
peichins committed Jun 12, 2019
1 parent ca32c9a commit 400ebb7
Show file tree
Hide file tree
Showing 16 changed files with 223 additions and 158 deletions.
6 changes: 3 additions & 3 deletions src/app/citizenScience/bristlebird/bristlebird.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ class BristlebirdController {
} else if (studies.length > 1) {
console.warn("More than one study found. Using the first one");
}

$scope.study = studies[0];
$scope.study_id = $scope.study.id;

Question.questions($scope.study_id).then(x => {
Question.questions($scope.study.id).then(x => {
console.log("questions loaded", x);
//TODO: update to allow multiple questions
$scope.questionData = x.data.data[0].questionData;

SampleLabels.init(x.data.data[0], $scope.study_id);
SampleLabels.init(x.data.data[0], $scope.study.id);
});
});

Expand Down
9 changes: 2 additions & 7 deletions src/app/citizenScience/bristlebird/listen.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,13 @@ <h2>Eastern Bristlebird Search

<volume-slider class="form-group form-group-without-feedback progressCell" audio-element-model="audioElementModel"></volume-slider>

<dataset-progress></dataset-progress>
<dataset-progress dataset-id="study.datasetId"></dataset-progress>

</nav>




<citizen-science-labels question-data="questionData"></citizen-science-labels>



</div> <!-- #main -->
</div> <!-- #main-container -->

</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ csSamples.factory("CsSamples", [

var self = this;

// the dataset id for this citizen science project
// todo: integrate with settings for cs project
self.datasetId = 3;

self.resetlist = function () {
self.currentIndex = { page: -1, item: -1};
self.pages = [];
Expand Down Expand Up @@ -138,7 +134,8 @@ csSamples.factory("CsSamples", [
});
},

init : function () {
init : function (datasetId) {
self.datasetId = datasetId;
self.requestPageOfItems(true);
},

Expand Down
40 changes: 23 additions & 17 deletions src/app/citizenScience/datasetProgress/datasetProgress.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,32 @@ angular.module("bawApp.components.progress", ["bawApp.citizenScience.csSamples"]
controller: ["$scope", "$routeParams", "CsSamples", "SampleLabels",
function ($scope, $routeParams, CsSamples, SampleLabels) {

if ($routeParams.sampleNum) {
CsSamples.selectById($routeParams.sampleNum);
$scope.nextItem = function () {
SampleLabels.sendResponse("using_routed");
return true;
};
$scope.isRoutedSample = true;
} else {
CsSamples.init();
$scope.nextItem = function () {
SampleLabels.sendResponse();
CsSamples.nextItem();
};
$scope.isRoutedSample = false;
}
var self = this;


// need to wait for the study's dataset_id before initialising
$scope.$watch(function () { return self.datasetId; }, function (newVal, oldVal){
if (newVal > 0) {
if ($routeParams.sampleNum) {
CsSamples.selectById($routeParams.sampleNum);
$scope.nextItem = function () {
SampleLabels.sendResponse("using_routed");
return true;
};
$scope.isRoutedSample = true;
} else {
CsSamples.init(self.datasetId);
$scope.nextItem = function () {
SampleLabels.sendResponse();
CsSamples.nextItem();
};
$scope.isRoutedSample = false;
}
}
});

$scope.$watch(() => CsSamples.currentItem(), (newVal, oldVal) => {
var newDatasetItemId = newVal.id;
SampleLabels.reset(newDatasetItemId);
SampleLabels.reset(newVal.id);
});

$scope.$on("autoNextTrigger", function (x) {
Expand All @@ -58,5 +63,6 @@ angular.module("bawApp.components.progress", ["bawApp.citizenScience.csSamples"]

}],
bindings: {
datasetId: "="
}
});
1 change: 1 addition & 0 deletions src/app/citizenScience/labels/citizenScienceLabels.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var csLabels = angular.module("bawApp.citizenScience.csLabels", [
"bawApp.citizenScience.common",
"bawApp.components.citizenScienceYesnoLabels",
"bawApp.components.citizenScienceThumbLabels",
"bawApp.components.citizenScienceTextLabels",
"bawApp.citizenScience.sampleLabels"
]);

Expand Down
6 changes: 3 additions & 3 deletions src/app/citizenScience/labels/labels.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@


<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>

-->
<citizen-science-text-labels ng-if="labelType=='yesno' || labelType=='text'" labels="labels"></citizen-science-text-labels>




30 changes: 30 additions & 0 deletions src/app/citizenScience/labels/textLabels/label.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
angular.module("bawApp.components.citizenScienceTextLabels.label",
[
"bawApp.citizenScience.sampleLabels"
])
.component("citizenScienceTextLabel", {
templateUrl: "citizenScience/labels/textLabels/label.tpl.html",
controller: [
"$scope",
"SampleLabels",
function ($scope, SampleLabels) {

var self = this;

$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(isSelected, self.label.id);
};

}],
bindings: {
label: "=",
}
});
5 changes: 5 additions & 0 deletions src/app/citizenScience/labels/textLabels/label.tpl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<label-check
is-checked="isSelected"
on-toggle-selected="$ctrl.onToggleSelected"
text="$ctrl.label.name"
></label-check>
128 changes: 60 additions & 68 deletions src/app/citizenScience/labels/textLabels/labels.js
Original file line number Diff line number Diff line change
@@ -1,88 +1,80 @@
angular.module("bawApp.components.citizenScienceTextLabels", ["bawApp.citizenScience.common"])
angular.module("bawApp.components.citizenScienceTextLabels",
[
"bawApp.components.citizenScienceTextLabels.label",
"bawApp.citizenScience.sampleLabels"
])
.component("citizenScienceTextLabels", {
templateUrl: "citizenScience/labels/textLabels/labels.tpl.html",
controller: [
"$scope",
"$http",
"CitizenScienceCommon",
function ($scope, $http, CitizenScienceCommon) {
"SampleLabels",
function ($scope, SampleLabels) {
//console.log("dataset progress component scope");console.log($scope);

var self = this;

/**
* Add or remove the lable num to the list of selected labels for this sample
* Send the new set of labels to the dataset
* Note, we can't guarantee the order that the api calls will reach the google sheet.
* if the user adds and removes a label in quick succession, they might arrive out of order
* resulting in the wrong labels being applied.
* @param label string
*/
$scope.toggleLabel = function (labelNum) {
console.log(self);

var currentSample = self.samples[self.currentSampleNum];
////////////////

currentSample.labels[labelNum] = !currentSample.labels[labelNum];

currentSample.done = true;

var tags = self.labels.filter(function (value, index) {
return currentSample.labels[index];
}).map(function (value) {
return value.tags;
});

var url = CitizenScienceCommon.apiUrl("setLabels",
self.csProject,
currentSample.name,
currentSample.recordingId,
currentSample.startOffset,
CitizenScienceCommon.labelsAsString(tags));
$http.get(url).then(function (response) {
console.log(response.data);
});
////////////////

};

/**
* Whether the label has been attached to the current sample
* @param label Object
* @returns Boolean
*/
$scope.labelSelected = function (labelNum) {
if(self.currentSampleNum === -1) {
return false;
}
var currentSample = self.samples[self.currentSampleNum];

return currentSample.labels[labelNum];

};

/**
* Toggles whether the examples are showing for the given label number
* hides examples from other labels.
* TODO: move this into examples component
* @param key int
*/
$scope.toggleShowExamples = function (key) {
self.labels.forEach(function (el, index) {
if (index !== key) {
el.showExamples = false;
} else if (el.hasOwnProperty("showExamples")) {
el.showExamples = !el.showExamples;
} else {
el.showExamples = true;
}
});
};
// /**
// * Add or remove the lable num to the list of selected labels for this sample
// * Send the new set of labels to the dataset
// * Note, we can't guarantee the order that the api calls will reach the google sheet.
// * if the user adds and removes a label in quick succession, they might arrive out of order
// * resulting in the wrong labels being applied.
// * @param label string
// */
// $scope.toggleLabel = function (labelNum) {
//
// var currentSample = self.samples[self.currentSampleNum];
//
// currentSample.labels[labelNum] = !currentSample.labels[labelNum];
//
// currentSample.done = true;
//
// var tags = self.labels.filter(function (value, index) {
// return currentSample.labels[index];
// }).map(function (value) {
// return value.tags;
// });
//
// var url = CitizenScienceCommon.apiUrl("setLabels",
// self.csProject,
// currentSample.name,
// currentSample.recordingId,
// currentSample.startOffset,
// CitizenScienceCommon.labelsAsString(tags));
// $http.get(url).then(function (response) {
// console.log(response.data);
// });
//
// };
//
// /**
// * Whether the label has been attached to the current sample
// * @param label Object
// * @returns Boolean
// */
// $scope.labelSelected = function (labelNum) {
// if(self.currentSampleNum === -1) {
// return false;
// }
// var currentSample = self.samples[self.currentSampleNum];
//
// return currentSample.labels[labelNum];
//
// };
//


}],
bindings: {
labels: "=labels",
samples: "=samples",
currentSampleNum: "=currentSampleNum",
csProject: "=csProject"
labels: "=labels"
}
});
11 changes: 4 additions & 7 deletions src/app/citizenScience/labels/textLabels/labels.tpl.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<div id="label-buttons">
<span ng-repeat="(key,label) in $ctrl.labels" ng-class="{selected : (labelSelected(key) > -1)}">
<a ng-click="toggleLabel(key)" class="main-button">
<i class="fa"
ng-class="{true: 'fa-check-square-o', false : 'fa-square-o'}[labelSelected(key)]"
aria-hidden="true"></i><span>{{label.label}}</span>
<a><a class="fa fa-eye example-toggle" aria-hidden="true" ng-click="toggleShowExamples(key)" ng-class="{selected : (label.showExamples)}" ng-if="label.examples.length"></a>
</span>
<citizen-science-text-label
ng-repeat="label in $ctrl.labels"
label="label"
></citizen-science-text-label>
</div>
4 changes: 2 additions & 2 deletions src/app/citizenScience/labels/thumbLabels/label.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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);
};

}],
Expand Down
3 changes: 3 additions & 0 deletions src/app/citizenScience/labels/thumbLabels/labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/app/citizenScience/labels/thumbLabels/labels.tpl.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<div class="thumb-labels-container">

<citizen-science-label
<citizen-science-thumb-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>
></citizen-science-thumb-label>

</div>

Loading

0 comments on commit 400ebb7

Please sign in to comment.