Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
Latest Job Activities heatmap on the home page is now updated in real…
Browse files Browse the repository at this point in the history
…time
  • Loading branch information
wa0x6e committed Oct 25, 2013
1 parent 1814703 commit 7ce2807
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions assets/js/controllers/lastestJobHeatmapController.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
angular.module("app").controller("lastestJobHeatmapController", [
"$scope", "$http", function($scope, $http) {
"$scope", "$http", "jobsSuccessCounter", "jobsFailedCounter", function($scope, $http, jobsSuccessCounter, jobsFailedCounter) {

"use strict";

Expand All @@ -9,16 +9,20 @@ angular.module("app").controller("lastestJobHeatmapController", [
$scope.predicate = "time";

var cal = new CalHeatMap();
var range = 6;
var range = 6; // Number of hours to display
var start = new Date().setHours(new Date().getHours() - (range - 1));
var CAL_RANGE = 1000 * 60 * 60 * range; // Number of milliseconds between the start and the end of the calendar

cal.init({
itemSelector : "#latest-jobs-heatmap",
scale : [10,20,30,40],
legend : [10,20,30,40],
itemName : ["job", "jobs"],
range: range,
start: new Date().setHours(new Date().getHours() - (range - 1)),
start: start,
cellSize: 10,
nextSelector: ".latest-jobs-graph .graph-browse-next",
previousSelector: ".latest-jobs-graph .graph-browse-previous",
animationDuration: 200,
data: "api/jobs/stats/{{t:start}}/{{t:end}}",
tooltip: true,
onClick : function(start) {
Expand All @@ -39,10 +43,34 @@ angular.module("app").controller("lastestJobHeatmapController", [
$scope.loading = false;
}).
error(function() {
});
});
}
});

start = cal.options.start; // Getting the start date of the calendar

jobsSuccessCounter.onmessage(function(message) {
updateHeatmap(message.data);
});

jobsFailedCounter.onmessage(function(message) {
updateHeatmap(message.data);
});

function updateHeatmap(datas) {
datas = JSON.parse(datas);
var d = new Date(datas.time).getTime();
var t = {};
t[parseInt(d/1000, 10)] = 1;
cal.update(t, true, cal.APPEND_ON_UPDATE);

// Shift the calendar by one hour
if ((d - start) >= (CAL_RANGE)) {
cal.next();
start =+ 1000 * 60 * 60;
}
}

$scope.clear = function() {
$scope.date = false;
$scope.jobs = [];
Expand Down

0 comments on commit 7ce2807

Please sign in to comment.