-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from vicriveros/alert_template
ils-status - Alert template
- Loading branch information
Showing
4 changed files
with
148 additions
and
46 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="dns-prefetch" href="https://cdn.toolkit.illinois.edu"> | ||
<link rel="icon" href="https://cdn.brand.illinois.edu/favicon.ico"> | ||
<link rel="stylesheet" href="https://cdn.toolkit.illinois.edu/2.14/toolkit.css" media="all"> | ||
<script src="https://cdn.toolkit.illinois.edu/2.14/toolkit.js"></script> | ||
<script src="status.js"></script> | ||
<link rel="stylesheet" href="status.css" media="all"> | ||
<title>Testing status widget</title> | ||
</head> | ||
<body> | ||
<div class="il-formatted"> | ||
<h2>Testing status alert widget</h2> | ||
|
||
<div class="ils-status" data-ils-status-serviceids="65281,65280,64985,64974" data-ils-status-template="down" data-ils-status-daysahead="12"></div> | ||
|
||
<div class="ils-status" data-ils-status-serviceids="65281,65280,64985,64974" data-ils-status-template="affected" data-ils-status-daysahead="12"></div> | ||
|
||
<div class="ils-status" data-ils-status-serviceids="65281,65280,64985,64974" data-ils-status-template="maintenance" data-ils-status-daysahead="12"></div> | ||
|
||
</div> | ||
|
||
|
||
</body> | ||
</html> |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,89 @@ | ||
window.addEventListener('load', (event) => { | ||
var target = document.querySelector('div.ils-status'); | ||
if (target && target != null) { | ||
checkStatus(); | ||
setInterval(function () { checkStatus(); }, 12000); | ||
} | ||
const targets = Array.from(document.querySelectorAll('div.ils-status')); | ||
targets.forEach(target => { | ||
checkStatus(target); | ||
setInterval(function () { checkStatus(target); }, 12000); | ||
}); | ||
}); | ||
|
||
function checkStatus() { | ||
var target = document.querySelector('div.ils-status'); | ||
fetch('https://statushub.itpartners.illinois.edu/api/GetSimpleStatus?name=illinois', { method: 'GET', headers: { "Content-type": "application/x-www-form-urlencoded; charset=UTF-8" } }) | ||
.then(res => res.json()) | ||
.then(data => { | ||
target.innerHTML = `<a id='ils-status-link' href='https://illinois.statushub.io' aria-label='Go to the Status at Illinois page'><ul class='ils-status-row'> | ||
<li class='ils-status-bubble'><span class='ils-status-green'>${data.NumberUp}</span><span>up</span></li> | ||
<li class='ils-status-bubble'><span class='ils-status-yellow'>${data.NumberAffected}</span><span>affected</span></li> | ||
<li class='ils-status-bubble'><span class='ils-status-red'>${data.NumberDown}</span><span>down</span></li> | ||
</ul></a>`; | ||
if (data.DownServices.length > 0) { | ||
target.innerHTML += '<p>The following services are down: </p><ul>'; | ||
data.DownServices.forEach(d => { | ||
target.innerHTML += `<li><a href='${d.Url}'>${d.Name}</a><br>${d.Incident}</li>`; | ||
}); | ||
target.innerHTML += '</ul>'; | ||
const dataSourceSimple = 'https://statushub.itpartners.illinois.edu/api/GetSimpleStatus?name=illinois'; | ||
const dataSourceDetailed = 'https://statushub.itpartners.illinois.edu/api/GetDetailedStatus?name=illinois'; | ||
|
||
async function fetchData(dataSource){ | ||
const response = await fetch(dataSource, { method: 'GET', headers: { "Content-type": "application/x-www-form-urlencoded; charset=UTF-8" } }); | ||
const data = await response.json(); | ||
return data; | ||
} | ||
|
||
async function checkStatus(target) { | ||
let serviceids = target.getAttribute('data-ils-status-serviceids'); | ||
if (serviceids && serviceids != null) { | ||
let daysahead = target.getAttribute('data-ils-status-daysahead'); | ||
let daysaheadString = daysahead == null ? '' : '&daysAhead='+daysahead; | ||
let template = target.getAttribute('data-ils-status-template'); | ||
let url = dataSourceDetailed + '&serviceIds='+serviceids+daysaheadString; | ||
let data = await fetchData(url); | ||
alertTemplate(target, data, template); | ||
}else{ | ||
let data = await fetchData(dataSourceSimple); | ||
simpleStatusTemplate(target, data); | ||
} | ||
} | ||
|
||
function simpleStatusTemplate(target, data) { | ||
target.innerHTML = `<a id='ils-status-link' href='https://illinois.statushub.io' aria-label='Go to the Status at Illinois page'><ul class='ils-status-row'> | ||
<li class='ils-status-bubble'><span class='ils-status-green'>${data.NumberUp}</span><span>up</span></li> | ||
<li class='ils-status-bubble'><span class='ils-status-yellow'>${data.NumberAffected}</span><span>affected</span></li> | ||
<li class='ils-status-bubble'><span class='ils-status-red'>${data.NumberDown}</span><span>down</span></li> | ||
</ul></a>`; | ||
if (data.DownServices.length > 0) { | ||
target.innerHTML += '<p>The following services are down: </p><ul>'; | ||
data.DownServices.forEach(d => { | ||
target.innerHTML += `<li><a href='${d.Url}'>${d.Name}</a><br>${d.Incident}</li>`; | ||
}); | ||
target.innerHTML += '</ul>'; | ||
|
||
let downHeader = document.createElement('p'); | ||
downHeader.innerHTML = 'Down services:'; | ||
let down = document.createElement('ul'); | ||
data.AffectedServices.forEach(d => { | ||
let li = document.createElement('li'); | ||
li.innerHTML = `<a href='${d.Url}'>${d.Name}</a><br>${d.Incident}`; | ||
down.appendChild(li); | ||
}); | ||
target.appendChild(downHeader); | ||
target.appendChild(down); | ||
let downHeader = document.createElement('p'); | ||
downHeader.innerHTML = 'Down services:'; | ||
let down = document.createElement('ul'); | ||
data.AffectedServices.forEach(d => { | ||
let li = document.createElement('li'); | ||
li.innerHTML = `<a href='${d.Url}'>${d.Name}</a><br>${d.Incident}`; | ||
down.appendChild(li); | ||
}); | ||
target.appendChild(downHeader); | ||
target.appendChild(down); | ||
|
||
} | ||
if (data.AffectedServices.length > 0) { | ||
let affectedHeader = document.createElement('p'); | ||
affectedHeader.innerHTML = 'Affected services:'; | ||
let affected = document.createElement('ul'); | ||
data.AffectedServices.forEach(a => { | ||
let li = document.createElement('li'); | ||
li.innerHTML = `<a href='${a.Url}'>${a.Name}</a><br>${a.Incident}`; | ||
affected.appendChild(li); | ||
}); | ||
target.appendChild(affectedHeader); | ||
target.appendChild(affected); | ||
} | ||
console.log(target.innerHTML); | ||
}); | ||
} | ||
if (data.AffectedServices.length > 0) { | ||
let affectedHeader = document.createElement('p'); | ||
affectedHeader.innerHTML = 'Affected services:'; | ||
let affected = document.createElement('ul'); | ||
data.AffectedServices.forEach(a => { | ||
let li = document.createElement('li'); | ||
li.innerHTML = `<a href='${a.Url}'>${a.Name}</a><br>${a.Incident}`; | ||
affected.appendChild(li); | ||
}); | ||
target.appendChild(affectedHeader); | ||
target.appendChild(affected); | ||
} | ||
} | ||
|
||
function alertTemplate(target, data, templateName){ | ||
let template = data.DownServices; | ||
let label = 'Down - '; | ||
let style = 'danger'; | ||
let alert ='', date=''; | ||
if(templateName == 'maintenance'){template = data.MaintenanceServices; label = 'Maintenance - '; style = 'warning';} | ||
if(templateName == 'affected'){template = data.AffectedServices; label = 'Affected - '; style = 'warning';} | ||
template.forEach(d => { | ||
if(templateName == 'maintenance'){date = d.StartDate.substr(0, 5); label = 'Maintenance ('+ date +') - ';} | ||
alert += ` | ||
<div class="ils-status-alert ils-status-alert-${style}"> | ||
<h2 class="ils-status-sr-only">Status alert announcement</h2> | ||
<span>${label}</span> <a title="Alert information" href="${d.Url}"> ${d.Incident} </a> | ||
</div>`; | ||
}) | ||
|
||
target.innerHTML = alert; | ||
} |