Skip to content

Commit

Permalink
Add comments throughout JS.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Pelletier committed Apr 2, 2016
1 parent dc32ef5 commit 1c22c2e
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions app/assets/javascripts/angular/controllers/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,35 @@ angular.module('dashboardApp', ['timer', 'ngAnimate'])
}

// Make the News Slideshow work appropriately.
// We use "index" here to refer to the position within the News array
// that represents the current article. It starts with the first, and
// adjusts on a timer.
$scope.newsIndex = 0;

$scope.setCurrentSlideIndex = function (index) {
$scope.newsIndex = index;
$scope.newsIndex = index;
};

$scope.isCurrentSlideIndex = function (index) {
return $scope.newsIndex === index;
return $scope.newsIndex === index;
};

// Update the news index every 8 seconds.
$interval(function(){
$scope.newsIndex = ($scope.newsIndex < $scope.news.length - 1) ? ++$scope.newsIndex : 0;
}, 8000);

// Get the width of the Terror Tracker.
// Calculate the width of the Terror Tracker.
// Based on a calculation of the Terror Tracker itself going up to 250.
// But represented as a percentage out of 100%.
$scope.getTerrorWidth = function() {
var terror = $scope.terror;

// If Terror hasn't been retrieved yet, don't break.
if (terror === undefined) {
// If Terror hasn't been retrieved yet, don't break.
$scope.terror_width = 0;
} else if (terror > 250) {
// Just in case.
$scope.terror = 250;
$scope.terror_width = 100;
} else {
Expand All @@ -84,17 +91,21 @@ angular.module('dashboardApp', ['timer', 'ngAnimate'])
};
};

// Get the colour of the Terror Tracker for the Thermometer Display.
// Get the colour of the Terror Tracker for the Display.
// We simply return this as a class rather than having a colour set within
// the JS, to ensure that our styling matches consistently.
// (ie: if we want our red to be more red, it can be changed in one place.)
$scope.getTerrorColour = function() {
// Check to see if the Terror amount is between two numbers.
function checkRange(x, n, m) {
if (x >= n && x <= m) { return x; }
else { return !x; }
}

// Store this simply so we don't have to keep calling it.
var terror = $scope.terror;

// Set thermometer colour based on the Terror amount.
// Set colour based on the Terror amount.
switch(terror) {
case checkRange(terror, 1, 50):
return'low';
Expand All @@ -116,14 +127,12 @@ angular.module('dashboardApp', ['timer', 'ngAnimate'])
}
};

// This is what calls our "refresh" method to make sure we are displaying
// the most recently set data. It currently calls an update every 3 seconds.
$scope.getStatus = function() {
apiCall();
};

$scope.range = function(n) {
return new Array(n);
};

$scope.getStatus();

$interval(function() {
Expand Down

0 comments on commit 1c22c2e

Please sign in to comment.