Skip to content

Commit

Permalink
Finished template for experiments.
Browse files Browse the repository at this point in the history
Disabled unicorn gem for dev coz it bad n shizznee

Disabled all of Mark's crappy google maps controls - coz they no work yet

modified:   Gemfile
modified:   app/assets/javascripts/angular/controllers/experiments.js
modified:   app/assets/javascripts/angular/controllers/home.js
modified:   app/assets/javascripts/app.js
new file:   app/assets/templates/experiment_base.html
modified:   app/assets/templates/home.html
modified:   app/assets/templates/rapid_scanning_experiment.html
new file:   public/ParticipantInformation.html
new file:   public/QUT_Square_CMYK.jpg
new file:   public/experiments/error.png
new file:   public/experiments/info.png
modified:   public/experiments/rapid_scan.json
new file:   public/experiments/success.png
new file:   public/experiments/warning.png
  • Loading branch information
atruskie committed Mar 9, 2013
1 parent f2fa4dc commit f0f0229
Show file tree
Hide file tree
Showing 13 changed files with 562 additions and 131 deletions.
95 changes: 88 additions & 7 deletions app/assets/javascripts/angular/controllers/experiments.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,107 @@
* @param Tag
* @param Media
* @param $route
* @param $http
* @param $http
*/
function ExperimentsCtrl($scope, $resource, $routeParams, $route, $http, Media, AudioEvent, Tag) {
function ExperimentsCtrl($scope, $resource, $routeParams, $route, $http, Media, AudioEvent, Tag) {

$scope.results = {};
$scope.PREFACE_STAGE = "preface";
$scope.EXPERIMENT_STAGE = "experiment";
$scope.FINAL_STAGE = "conclusion";

$scope.results = {
allowContact: true,
consented: false,
ethicsStatementViewed: false
};
$scope.errors = [];
$scope.spec = {
experimentSteps: []
};
$scope.stage = $scope.PREFACE_STAGE;
$scope.step = 0;
$scope.resultsSending = false;
$scope.resultsSentSuccessfully = undefined;

// todo: populate user information

// download experiment protocol
$http.get('/experiments/rapid_scan.json').
success(function(data, status, headers, config) {
success(function (data, status, headers, config) {
$scope.spec = data;
}).error(function( data, status, headers, config) {
$scope.results.experiment = $scope.spec.experiment;
}).error(function (data, status, headers, config) {
alert("downloading test specification failed");
});

$scope.login = function () {
$scope.$emit('event:auth-loginRequired');
};

$scope.isChrome = function () {
return Boolean(window.chrome);
};

$scope.verifyPreface = function verifyPreface() {
$scope.errors.length = 0;

if ($scope.results.consented !== true) {
$scope.errors.push("You must consent to participate in this experiment.");
}

if ($scope.results.ethicsStatementViewed !== true) {
$scope.errors.push("You must view the ethics statement before continuing (click on the link please).")
}

if ($scope.loggedIn && $scope.userData) {
$scope.results.userData = angular.copy($scope.userData);
}
else {
$scope.errors.push("You must be logged in to participate in this experiment, please log in.")
}

if (!$scope.isChrome()) {
$scope.errors.push("You must be using the Google Chrome web browser to continue")
}

if ($scope.errors.length > 0) {
return;
}

$scope.step = 0;
$scope.stage = $scope.EXPERIMENT_STAGE;

};

$scope.$watch(function () {
return $scope.step;
}, function (newValue, oldValue) {
if (newValue > $scope.spec.experimentSteps.length) {
$scope.finishExperiment();
}
});


$scope.finishExperiment = function () {

$scope.step = 0;
$scope.stage = $scope.FINAL_STAGE;

// send back results to server
$scope.resultsSending = true;
$scope.resultsSentSuccessfully = undefined;
$http.post('', $scope.results)
.success(function (data, status, headers, config) {

function downloadResults() {
$scope.resultsSending = false;
$scope.resultsSentSuccessfully = true;
})
.error(function (data, status, headers, config) {
$scope.resultsSending = false;
$scope.resultsSentSuccessfully = false;
});
};

}

}]);
})();
135 changes: 68 additions & 67 deletions app/assets/javascripts/angular/controllers/home.js
Original file line number Diff line number Diff line change
@@ -1,73 +1,74 @@
"use strict";

function HomeCtrl($scope, $resource, $routeParams, Project) {

// to get projects to display
// make request only include lat/long and title/desc/id
$scope.projectsResource = $resource('/projects', {});
$scope.projects = $scope.projectsResource.query();

$scope.loadProjects = function(){
console.log('loadProjects');
$scope.populateProjectMarkers();
};

// for map
$scope.myMarkers = [];

$scope.mapOptions = {
center: new google.maps.LatLng(-20.911882621985757, 144.80555550000008),
zoom: 4,
mapTypeId: google.maps.MapTypeId.HYBRID
};

$scope.openMarkerInfo = function(marker) {
console.log('openMarkerInfo');
$scope.currentMarker = marker;
$scope.currentMarkerLat = marker.getPosition().lat();
$scope.currentMarkerLng = marker.getPosition().lng();
$scope.currentMarkerTitle = marker.getTitle();
$scope.currentMarkerId = marker.get('id');
$scope.myInfoWindow.open($scope.projectMap, marker);
};

$scope.addMarker = function($event) {
$scope.myMarkers.push(new google.maps.Marker({
map: $scope.projectMap,
position: $event.latLng
}));
};

$scope.setMarkerPosition = function(marker, lat, lng) {
marker.setPosition(new google.maps.LatLng(lat, lng));
};

$scope.populateProjectMarkers = function(){
var theProjects = $scope.projects;
var projectCount = theProjects.length;
angular.forEach(theProjects, function(value, key){
$scope.myMarkers.push(new google.maps.Marker({
map: $scope.projectMap,
position: new google.maps.LatLng (value.latitude, value.longitude),
title: value.name,
id: value.id
}));
});

$scope.zoomMapToFitMarkers();
};

$scope.zoomMapToFitMarkers = function(){
var bounds = new google.maps.LatLngBounds ();
var markerCount = $scope.myMarkers.length;
for (var index = 0; index < markerCount; index++) {
// And increase the bounds to take this point
bounds.extend ($scope.myMarkers[index].getPosition());
}

// Fit these bounds to the map
$scope.projectMap.fitBounds (bounds);
};
//// TODO: disabled - authentication required for home page - BAD!
//// TODO: properly package this mess ... way too much in this controller
// // to get projects to display
// // make request only include lat/long and title/desc/id
// $scope.projectsResource = $resource('/projects', {});
// $scope.projects = $scope.projectsResource.query();
//
// $scope.loadProjects = function(){
// console.log('loadProjects');
// $scope.populateProjectMarkers();
// };
//
// // for map
// $scope.myMarkers = [];
//
// $scope.mapOptions = {
// center: new google.maps.LatLng(-20.911882621985757, 144.80555550000008),
// zoom: 4,
// mapTypeId: google.maps.MapTypeId.HYBRID
// };
//
// $scope.openMarkerInfo = function(marker) {
// console.log('openMarkerInfo');
// $scope.currentMarker = marker;
// $scope.currentMarkerLat = marker.getPosition().lat();
// $scope.currentMarkerLng = marker.getPosition().lng();
// $scope.currentMarkerTitle = marker.getTitle();
// $scope.currentMarkerId = marker.get('id');
// $scope.myInfoWindow.open($scope.projectMap, marker);
// };
//
// $scope.addMarker = function($event) {
// $scope.myMarkers.push(new google.maps.Marker({
// map: $scope.projectMap,
// position: $event.latLng
// }));
// };
//
// $scope.setMarkerPosition = function(marker, lat, lng) {
// marker.setPosition(new google.maps.LatLng(lat, lng));
// };
//
// $scope.populateProjectMarkers = function(){
// var theProjects = $scope.projects;
// var projectCount = theProjects.length;
// angular.forEach(theProjects, function(value, key){
// $scope.myMarkers.push(new google.maps.Marker({
// map: $scope.projectMap,
// position: new google.maps.LatLng (value.latitude, value.longitude),
// title: value.name,
// id: value.id
// }));
// });
//
// $scope.zoomMapToFitMarkers();
// };
//
// $scope.zoomMapToFitMarkers = function(){
// var bounds = new google.maps.LatLngBounds ();
// var markerCount = $scope.myMarkers.length;
// for (var index = 0; index < markerCount; index++) {
// // And increase the bounds to take this point
// bounds.extend ($scope.myMarkers[index].getPosition());
// }
//
// // Fit these bounds to the map
// $scope.projectMap.fitBounds (bounds);
// };
}

HomeCtrl.$inject = ['$scope', '$resource', '$routeParams', 'Project'];
4 changes: 2 additions & 2 deletions app/assets/javascripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ var bawApp = (function (undefined) {
when('/attribution', {templateUrl: '/assets/attributions.html'}).

// experiments
when('/experiments/tour', {templateUrl: '/assets/tour_experiment.html', controller: 'ExperimentsCtrl'}).
when('/experiments/rapidScan', {templateUrl: '/assets/rapid_scanning_experiment.html', controller: 'ExperimentsCtrl'}).
when('/experiments/tour', {templateUrl: '/assets/experiment_base.html', controller: 'ExperimentsCtrl'}).
when('/experiments/rapidScan', {templateUrl: '/assets/experiment_base.html', controller: 'ExperimentsCtrl'}).

// missing route page
when('/', {templateUrl: '/assets/home.html', controller: 'HomeCtrl'}).
Expand Down
Loading

0 comments on commit f0f0229

Please sign in to comment.