Last active
August 29, 2015 14:09
-
-
Save eurica/9d772d15cc1e8be12157 to your computer and use it in GitHub Desktop.
Pseudocode for dashboard example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initiate PDJS: | |
PDJS = new PDJSobj({ | |
subdomain: config["subdomain"], | |
token: config["token"], | |
}) | |
loadIncidents = function () { | |
//Hit the incidents API: | |
PDJS.api({ | |
res: "incidents", | |
data: { | |
sort_by: "created_on:desc" // get the most recent incidents | |
}, | |
//Once we've gotten new incidents display them: | |
success: function (json) { | |
//Throw away the last incidents: | |
$("#mytimeline").html("") | |
//Update the title to the current time | |
t = moment(new Date()); | |
$("#title").html("PagerDuty incidents as of "+t.format("dddd, MMMM Do YYYY, h:mm:ss a")+":") | |
// Round the current time down (for the spacing) | |
t.seconds(0).milliseconds(0).subtract(t.minutes()%config["minuteblocks"], "minutes") | |
//iterate over each incident | |
$.each(json["incidents"], function (n, i) { | |
created_at = moment(i.created_on) | |
// Format a pretty incident | |
html = "<div class='incident "+i.status+"'>" | |
html += "<span class='service'>"+i.service.name+"</span>" | |
// ... Format the incidents. This code is neither pretty nor complicated. | |
html += "<div>" | |
//Loop over however many breaks happened after this incident | |
while(t>created_at) { | |
$("#mytimeline").append("<div class='hour'>"+t.format("h:mm a")+"</div>") | |
t.subtract(config["minuteblocks"], 'minutes') | |
} | |
//print this incident | |
$("#mytimeline").append(html) | |
}) | |
// Refresh the list after a timeout | |
window.setTimeout(loadIncidents, config["refresh"]*1000) | |
}, | |
}) | |
} | |
// Run once the window has loaded | |
$(window).load(function(){ | |
loadIncidents() | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment