Added duration to events. Backported a few API changes
This commit is contained in:
parent
55cda1de8c
commit
7f1d370224
97
global.js
97
global.js
@ -632,67 +632,56 @@ function timeString(ms, includeSuffix)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Break into units
|
// Break into years, days, hours, minutes, seconds, and ms
|
||||||
var years = 0, days = 0, hours = 0, minutes = 0, seconds = 0;
|
var units = [0, 0, 0, 0, 0, ms.toFixed(0)];
|
||||||
while (ms >= 31536000000) {
|
var unitNames = ["year", "day", "hour", "minute", "second", "millisecond"];
|
||||||
ms -= 31536000000;
|
while (units[5] >= 31536000000) {
|
||||||
years++;
|
units[5] -= 31536000000;
|
||||||
|
units[0]++;
|
||||||
}
|
}
|
||||||
while (ms >= 86400000) {
|
while (units[5] >= 86400000) {
|
||||||
ms -= 86400000;
|
units[5] -= 86400000;
|
||||||
days++;
|
units[1]++;
|
||||||
}
|
}
|
||||||
while (ms >= 3600000) {
|
while (units[5] >= 3600000) {
|
||||||
ms -= 3600000;
|
units[5] -= 3600000;
|
||||||
hours++;
|
units[2]++;
|
||||||
}
|
}
|
||||||
while (ms >= 60000) {
|
while (units[5] >= 60000) {
|
||||||
ms -= 60000;
|
units[5] -= 60000;
|
||||||
minutes++;
|
units[3]++;
|
||||||
}
|
}
|
||||||
while (ms >= 1000) {
|
while (units[5] >= 1000) {
|
||||||
ms -= 1000;
|
units[5] -= 1000;
|
||||||
seconds++;
|
units[4]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stringify
|
// Grab the first two non-zero units
|
||||||
if (years == 1)
|
var first = "";
|
||||||
years = years + " year";
|
var second = "";
|
||||||
else
|
for (var i = 0; i < units.length; i++) {
|
||||||
years = years + " years";
|
if (!units[i])
|
||||||
if (days == 1)
|
continue;
|
||||||
days = days + " day";
|
|
||||||
else
|
|
||||||
days = days + " days";
|
|
||||||
if (hours == 1)
|
|
||||||
hours = hours + " hour";
|
|
||||||
else
|
|
||||||
hours = hours + " hours";
|
|
||||||
if (minutes == 1)
|
|
||||||
minutes = minutes + " minute";
|
|
||||||
else
|
|
||||||
minutes = minutes + " minutes";
|
|
||||||
if (seconds == 1)
|
|
||||||
seconds = seconds + " second";
|
|
||||||
else
|
|
||||||
seconds = seconds + " seconds";
|
|
||||||
if (ms == 1)
|
|
||||||
ms = ms + " millisecond";
|
|
||||||
else
|
|
||||||
ms = ms + " milliseconds";
|
|
||||||
|
|
||||||
// Return the final string
|
if (!first.length) {
|
||||||
if (years[0] != "0")
|
first = units[i] + " " + unitNames[i];
|
||||||
return years + " " + days + " " + suffix;
|
if (units[i] > 1)
|
||||||
if (days[0] != "0")
|
first += "s";
|
||||||
return days + " " + hours + " " + suffix;
|
continue;
|
||||||
if (hours[0] != "0")
|
}
|
||||||
return hours + " " + minutes + " " + suffix;
|
|
||||||
if (minutes[0] != "0")
|
if (!second.length) {
|
||||||
return minutes + " " + seconds + " " + suffix;
|
second = " " + units[i] + " " + unitNames[i];
|
||||||
if (seconds[0] != "0")
|
if (units[i] > 1)
|
||||||
return seconds + " " + ms + " " + suffix;
|
second += "s";
|
||||||
return ms + " " + suffix;
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!first.length)
|
||||||
|
return "0 milliseconds" + suffix;
|
||||||
|
else
|
||||||
|
return first + second + suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Translates a kernel slug into a label and sets the contents of an element
|
// Translates a kernel slug into a label and sets the contents of an element
|
||||||
|
@ -317,22 +317,37 @@ import { settings, elements, apiDelete, apiGet, apiPost, eventTitles, parseParam
|
|||||||
var eventDate = new Date(event.created + "Z");
|
var eventDate = new Date(event.created + "Z");
|
||||||
var curDate = new Date();
|
var curDate = new Date();
|
||||||
jobInfo.innerHTML = "Entered: " + timeString(curDate - eventDate, true);
|
jobInfo.innerHTML = "Entered: " + timeString(curDate - eventDate, true);
|
||||||
if (event.percent_complete && event.percent_complete != 100)
|
if (event.duration)
|
||||||
jobInfo.innerHTML += " - " + event.percent_complete + "%";
|
jobInfo.innerHTML += " - Took: " + timeString(event.duration * 1000, false);
|
||||||
if (event.time_remaining) {
|
else if (event.status != "notification")
|
||||||
var times = event.time_remaining.split(":");
|
jobInfo.innerHTML += " - Waiting...";
|
||||||
var ms = 0;
|
|
||||||
ms += parseInt(times[0]) * 3600000;
|
|
||||||
ms += parseInt(times[1]) * 60000;
|
|
||||||
ms += parseInt(times[2]) * 1000;
|
|
||||||
jobInfo.innerHTML += " - " + timeString(ms, false) + " Remaining";
|
|
||||||
}
|
|
||||||
detailsCell.appendChild(jobType);
|
detailsCell.appendChild(jobType);
|
||||||
detailsCell.appendChild(jobDetails);
|
detailsCell.appendChild(jobDetails);
|
||||||
detailsCell.appendChild(br);
|
detailsCell.appendChild(br);
|
||||||
detailsCell.appendChild(jobInfo);
|
detailsCell.appendChild(jobInfo);
|
||||||
row.appendChild(detailsCell);
|
row.appendChild(detailsCell);
|
||||||
|
|
||||||
|
// Progress cell
|
||||||
|
var progressCell = document.createElement("td");
|
||||||
|
if (event.percent_complete && event.percent_complete != 100)
|
||||||
|
progressCell.innerHTML = event.percent_complete + "%";
|
||||||
|
if (event.time_remaining) {
|
||||||
|
if (progressCell.innerHTML.length)
|
||||||
|
progressCell.innerHTML += ", ";
|
||||||
|
var times = event.time_remaining.split(":");
|
||||||
|
var ms = 0;
|
||||||
|
ms += parseInt(times[0]) * 3600000;
|
||||||
|
ms += parseInt(times[1]) * 60000;
|
||||||
|
ms += parseInt(times[2]) * 1000;
|
||||||
|
progressCell.innerHTML += timeString(ms, false) + " to go";
|
||||||
|
}
|
||||||
|
if (event.rate) {
|
||||||
|
if (progressCell.innerHTML.length)
|
||||||
|
progressCell.innerHTML += ", ";
|
||||||
|
progressCell.innerHTML += event.rate;
|
||||||
|
}
|
||||||
|
row.appendChild(progressCell);
|
||||||
|
|
||||||
return row;
|
return row;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -427,33 +442,6 @@ import { settings, elements, apiDelete, apiGet, apiPost, eventTitles, parseParam
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Callback for backups API call
|
|
||||||
var displayBackups = function(response)
|
|
||||||
{
|
|
||||||
// Find time of most recent backup
|
|
||||||
var mostRecent = new Date(0);
|
|
||||||
for (var i = 0; i < response.automatic.length; i++) {
|
|
||||||
if (response.automatic[i].status == "successful") {
|
|
||||||
var time = new Date(response.automatic[i].finished + "Z");
|
|
||||||
if (time > mostRecent)
|
|
||||||
mostRecent = time;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (response.snapshot.current && response.snapshot.current.status == "successful") {
|
|
||||||
var time = new Date(response.snapshot.current.finished + "Z");
|
|
||||||
if (time > mostRecent)
|
|
||||||
mostRecent = time;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1970 means no backups happened
|
|
||||||
if (mostRecent.getUTCFullYear() == 1970)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var curDate = new Date();
|
|
||||||
ui.lastBackupTime.innerHTML = timeString(curDate - mostRecent, true);
|
|
||||||
ui.lastBackup.style.display = "block";
|
|
||||||
};
|
|
||||||
|
|
||||||
// Callback for config profile API call
|
// Callback for config profile API call
|
||||||
var displayConfigs = function(response)
|
var displayConfigs = function(response)
|
||||||
{
|
{
|
||||||
@ -516,6 +504,12 @@ import { settings, elements, apiDelete, apiGet, apiPost, eventTitles, parseParam
|
|||||||
if (data.linode.backups.enabled) {
|
if (data.linode.backups.enabled) {
|
||||||
ui.backups.innerHTML = "Enabled!";
|
ui.backups.innerHTML = "Enabled!";
|
||||||
ui.backups.className += " " + elements.backupsEnabled;
|
ui.backups.className += " " + elements.backupsEnabled;
|
||||||
|
if (data.linode.backups.last_successful) {
|
||||||
|
var backupDate = new Date(data.linode.backups.last_successful + "Z");
|
||||||
|
var now = new Date();
|
||||||
|
ui.lastBackupTime.innerHTML = timeString(now - backupDate, true);
|
||||||
|
ui.lastBackup.style.display = "block";
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ui.backups.innerHTML = "";
|
ui.backups.innerHTML = "";
|
||||||
var text = document.createElement("span");
|
var text = document.createElement("span");
|
||||||
@ -821,7 +815,6 @@ import { settings, elements, apiDelete, apiGet, apiPost, eventTitles, parseParam
|
|||||||
apiGet("/linode/instances/" + data.params.lid + "/disks", displayDisks, null);
|
apiGet("/linode/instances/" + data.params.lid + "/disks", displayDisks, null);
|
||||||
apiGet("/linode/instances/" + data.params.lid + "/volumes", displayVolumes, null);
|
apiGet("/linode/instances/" + data.params.lid + "/volumes", displayVolumes, null);
|
||||||
apiGet("/linode/instances/" + data.params.lid + "/transfer", displayTransfer, null);
|
apiGet("/linode/instances/" + data.params.lid + "/transfer", displayTransfer, null);
|
||||||
apiGet("/linode/instances/" + data.params.lid + "/backups", displayBackups, null);
|
|
||||||
var filter = {
|
var filter = {
|
||||||
"entity.type": "linode",
|
"entity.type": "linode",
|
||||||
"entity.id": parseInt(data.params.lid)
|
"entity.id": parseInt(data.params.lid)
|
||||||
|
@ -94,16 +94,17 @@ along with Linode Manager Classic. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
<table class="lmc-table">
|
<table class="lmc-table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2">Host Job Queue <a id="moar-jobs" href="#">(more)</a></td>
|
<td colspan="3">Host Job Queue <a id="moar-jobs" href="#">(more)</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id="event-table">
|
<tbody id="event-table">
|
||||||
<tr id="job-progress-row" class="lmc-tr1">
|
<tr id="job-progress-row" class="lmc-tr1">
|
||||||
<td colspan="2"><progress id="job-progress" max="100" value="50">50%</progress></td>
|
<td colspan="3"><progress id="job-progress" max="100" value="0">0%</progress></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr id="loading-jobs" class="lmc-tr3">
|
<tr id="loading-jobs" class="lmc-tr3">
|
||||||
<td></td>
|
<td></td>
|
||||||
<td>Loading jobs...</td>
|
<td>Loading jobs...</td>
|
||||||
|
<td></td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
Loading…
Reference in New Issue
Block a user