Skip to content

Commit

Permalink
transcription and emotion are now firebasing
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcook committed Jan 18, 2015
1 parent 53359cc commit 333302b
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 40 deletions.
109 changes: 96 additions & 13 deletions www/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,17 +236,57 @@ function(auth, $scope, $state, $stateParams, $ionicModal, $firebase) {
};
}])

.controller('EmotionCtrl', function($scope, $stateParams, $ionicModal) {
$scope.modal_text = "Pick the best sentiment based on the provided. Ranges from Strongly Negative, Negative, Neutral, Positive, and Strongly Positive from left to right."
popupModal($scope, $ionicModal);
})

.controller('TaggingCtrl', ['currentAuth', '$scope', '$state', '$stateParams', '$ionicModal', '$firebase',
.controller('EmotionCtrl', ['currentAuth', '$scope', '$state', '$stateParams', '$ionicModal', '$firebase',
function(auth, $scope, $state, $stateParams, $ionicModal, $firebase) {
$scope.openGoogle = function(){
window.open('http://google.com', '_system', 'location=yes');
var uid = verifyAuth(auth, $scope, $state);
var ref = new Firebase('https://mobile-turk.firebaseio.com/types/emotion');
var catRef = null;

if (uid) {
var userRef = new Firebase('https://mobile-turk.firebaseio.com/users/' + uid);
var userLast = userRef.child('tasks/emotion/last');
$scope.formData = {};

$scope.submitCat = function() {
var data = {};
data[uid] = $scope.formData.response;
catRef.child('responses').update(data);
$scope.formData = {};
catRef.once('value', function(snap) {
userLast.transaction(function(current) {
current = current ? current : 0;
return current < snap.val().createdAt ? snap.val().createdAt : current;
});
});
};// Get User Data to find last task completed/skipped
userLast.on('value', function(snap) {
var lastTime = snap.val() ? snap.val() : 0;
var q = ref.orderByChild('createdAt').startAt(lastTime+1).limitToFirst(1);
$scope.category = $firebase(q).$asObject();

// Load the last task from firebase
$scope.category.$loaded()
.then(function(data) {
var key = null
for (var i in data) {
if (i[0] !== '$' && i !== 'forEach') {
key = i;
break;
}
}
// Make the value returned accesible
$scope.category.val = $scope.category[key];
catRef = ref.child(key);
$scope.helpModalText = $scope.category.val.description;
$scope.helpModalPrice = $scope.category.val.price;
popupModal($scope, $ionicModal);
});
});
};
}])

.controller('TaggingCtrl', ['currentAuth', '$scope', '$state', '$stateParams', '$ionicModal', '$firebase',
function(auth, $scope, $state, $stateParams, $ionicModal, $firebase) {
var uid = verifyAuth(auth, $scope, $state);
var ref = new Firebase('https://mobile-turk.firebaseio.com/types/tagging');
var catRef = null;
Expand All @@ -258,7 +298,6 @@ function(auth, $scope, $state, $stateParams, $ionicModal, $firebase) {

$scope.submitCat = function() {
var data = {};
console.log($scope.formData);
data[uid] = $scope.formData.responses;
catRef.child('responses').update(data);
$scope.formData = {};
Expand Down Expand Up @@ -295,10 +334,54 @@ function(auth, $scope, $state, $stateParams, $ionicModal, $firebase) {
};
}])

.controller('TranscribeCtrl', function($scope, $stateParams, $ionicModal) {
$scope.modal_text = "Pick the best sentiment based on the provided. Ranges from Strongly Negative, Negative, Neutral, Positive, and Strongly Positive from left to right."
popupModal($scope, $ionicModal);
});
.controller('TranscribeCtrl', ['currentAuth', '$scope', '$state', '$stateParams', '$ionicModal', '$firebase',
function(auth, $scope, $state, $stateParams, $ionicModal, $firebase) {
var uid = verifyAuth(auth, $scope, $state);
var ref = new Firebase('https://mobile-turk.firebaseio.com/types/transcription');
var catRef = null;

if (uid) {
var userRef = new Firebase('https://mobile-turk.firebaseio.com/users/' + uid);
var userLast = userRef.child('tasks/trascription/last');
$scope.formData = {};

$scope.submitCat = function() {
var data = {};
data[uid] = $scope.formData.response;
catRef.child('responses').update(data);
$scope.formData = {};
catRef.once('value', function(snap) {
userLast.transaction(function(current) {
current = current ? current : 0;
return current < snap.val().createdAt ? snap.val().createdAt : current;
});
});
};// Get User Data to find last task completed/skipped
userLast.on('value', function(snap) {
var lastTime = snap.val() ? snap.val() : 0;
var q = ref.orderByChild('createdAt').startAt(lastTime+1).limitToFirst(1);
$scope.category = $firebase(q).$asObject();

// Load the last task from firebase
$scope.category.$loaded()
.then(function(data) {
var key = null
for (var i in data) {
if (i[0] !== '$' && i !== 'forEach') {
key = i;
break;
}
}
// Make the value returned accesible
$scope.category.val = $scope.category[key];
catRef = ref.child(key);
$scope.helpModalText = $scope.category.val.description;
$scope.helpModalPrice = $scope.category.val.price;
popupModal($scope, $ionicModal);
});
});
};
}]);

var verifyAuth = function(auth, $scope, $state) {
if (typeof auth !== undefined && auth !== null) {
Expand Down
9 changes: 3 additions & 6 deletions www/templates/types/emotion.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,21 @@
<i class="icon ion-ios7-help-outline" ng-click="openModal()"></i>
</div>
<div class="item item-text-wrap">
If you loved Firefly TV show, amazing Amazon price for entire series: about $27 BlueRay & $17 DVD.
{{category.val.phrase}}
</div>
</div>

<div class="row button-bar bar-light">
<a class="button button-clear"><i class="icon ion-close-circled"></i></a>
<a class="button button-clear"><i class="icon ion-close"></i></a>
<a class="button button-clear"><i class="icon ion-minus"></i></a>
<a class="button button-clear"><i class="icon ion-checkmark"></i></a>
<a class="button button-clear"><i class="icon ion-checkmark-circled"></i></a>
</div>

<div class="range">
<input type="range" name="volume" min="0" max="4" value="2">
<input type="range" name="volume" min="0" max="4" value="2" ng-model='formData.response'>
</div>

<div class="padding">
<button class="button button-block button-outline button-balanced">Submit</button>
<button class="button button-block button-outline button-balanced" ng-click="submitCat()">Submit</button>
</div>
</ion-content>
</ion-view>
23 changes: 2 additions & 21 deletions www/templates/types/transcription.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,16 @@
<h2>Transcribe Text From the Image</h2>
<i class="icon ion-ios7-help-outline" ng-click="openModal()"></i>
</div>
<form>
<div class="bounding-box" style="height: 165px; background-image: url({{category.val.image}})");
<ion-list>
</div>
<label class="item item-radio" ng-repeat="cat in category.val.categories" ng-hide='{{cat == undefined}}'>
<input type="radio" name="group" ng-model="formData.category", value="{{cat}}">
<div class="item-content">
{{cat}}
</div>
<i class="radio-icon ion-checkmark"></i>
</label>
</ion-list>
<div class="bounding-box" style="height: 165px; background-image: url({{category.val.image}})"></div>
</div>

<div class="list">
<div class="item item-input-inset">
<label class="item-input-wrapper">
<input type="text" placeholder="Transcribe Here...">
</label>
<button class="button button-small">
Submit Line
</button>
<input type="text" placeholder="Transcribe Here..." ng-model='formData.response'>
</div>
</div>

<div class="padding">
<button class="button button-block button-outline button-balanced" ng-click="submitCat()">Submit</button>
</div>
</form>

</ion-content>
</ion-view>

0 comments on commit 333302b

Please sign in to comment.