fix alert hang. make dismissable

This commit is contained in:
Stewart Allen 2019-01-18 16:36:14 -05:00
commit 983d0516da
2 changed files with 35 additions and 12 deletions

View file

@ -511,7 +511,7 @@ self.kiri.license = exports.LICENSE;
mouseMoved = false, mouseMoved = false,
camStock = null, camStock = null,
camTopZ = 0, camTopZ = 0,
alerts = []; alerts = [ [ "version " + kiri.version, Date.now() ] ];
DBUG.enable(); DBUG.enable();
@ -561,18 +561,24 @@ self.kiri.license = exports.LICENSE;
updateAlerts(); updateAlerts();
} }
setInterval(updateAlerts, 1000); function updateAlerts(clear) {
if (clear) {
function updateAlerts() { alerts = [];
}
let now = Date.now(); let now = Date.now();
while (alerts.length && now - alerts[0][1] > alerts[0][2] || 5000) { // filter out by age
alerts = alerts.filter(alert => {
return (now - alert[1]) < ((alert[2] || 5) * 1000);
});
// limit to 5 showing
while (alerts.length > 5) {
alerts.shift(); alerts.shift();
} }
if (alerts.length) { if (alerts.length > 0) {
$('alert-text').innerHTML = alerts.map(v => ['<p>',v[0],'</p>'].join('')).join(''); UI.alert.text.innerHTML = alerts.map(v => ['<p>',v[0],'</p>'].join('')).join('');
$('alert-area').style.display = 'flex'; UI.alert.dialog.style.display = 'flex';
} else { } else {
$('alert-area').style.display = 'none'; UI.alert.dialog.style.display = 'none';
} }
} }
@ -1181,7 +1187,7 @@ self.kiri.license = exports.LICENSE;
ajax(host+"/api/wait?key="+json.key, function(data) { ajax(host+"/api/wait?key="+json.key, function(data) {
data = js2o(data); data = js2o(data);
DBUG.log(data); DBUG.log(data);
alert("print to "+target+": "+data.status, 10000); alert("print to "+target+": "+data.status, 600);
}); });
} else { } else {
alert("grid:host error\nstatus: "+status+"\nmessage: "+xhtr.responseText, 10000); alert("grid:host error\nstatus: "+status+"\nmessage: "+xhtr.responseText, 10000);
@ -2266,6 +2272,11 @@ self.kiri.license = exports.LICENSE;
print: $('print'), print: $('print'),
help: $('help'), help: $('help'),
alert: {
dialog: $('alert-area'),
text: $('alert-text')
},
devices: $('devices'), devices: $('devices'),
deviceAdd: $('device-add'), deviceAdd: $('device-add'),
deviceDelete: $('device-del'), deviceDelete: $('device-del'),
@ -3607,6 +3618,13 @@ self.kiri.license = exports.LICENSE;
// load settings provided in url hash // load settings provided in url hash
loadSettingsFromServer(); loadSettingsFromServer();
// clear alerts as they build up
setInterval(updateAlerts, 1000);
UI.alert.dialog.onclick = function() {
updateAlerts(true);
};
} }
restoreWorkspace(ondone) || checkSeed(ondone) || ondone(); restoreWorkspace(ondone) || checkSeed(ondone) || ondone();

View file

@ -687,15 +687,20 @@ button[import="1"] {
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
width: 50%; min-width: 25%;
max-width: 50%;
background-color: rgba(255,230,230,0.8); background-color: rgba(255,230,230,0.8);
border: 3px solid rgba(255,200,200,0.5); border: 3px solid rgba(255,200,200,0.5);
border-radius: 5px; border-radius: 5px;
} }
#alert-border:hover {
background-color: rgba(255,230,230,0.9);
border: 3px solid rgba(255,200,200,0.95);
}
#alert-text { #alert-text {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
text-align: center; text-align: left;
font-weight: bold; font-weight: bold;
color: black; color: black;
margin: 5px; margin: 5px;