Commit 67622b86 by Bach Dániel

dashboard: move activity vars

parent 5f3e7e7b
var in_progress = false;
var activity_hash = 5;
var show_all = false;
var reload_vm_detail = false;
$(function() { $(function() {
var in_progress = false;
var activity_hash = 5;
var show_all = false;
var reload_vm_detail = false;
/* do we need to check for new activities */ /* do we need to check for new activities */
if(decideActivityRefresh()) { if(decideActivityRefresh()) {
if(!in_progress) { if(!in_progress) {
...@@ -102,83 +102,82 @@ $(function() { ...@@ -102,83 +102,82 @@ $(function() {
return false; return false;
}); });
}); function decideActivityRefresh() {
var check = false;
/* if something is still spinning */
if($('.timeline .activity i').hasClass('fa-spin'))
check = true;
return check;
}
function decideActivityRefresh() { function checkNewActivity(runs) {
var check = false; $.ajax({
/* if something is still spinning */ type: 'GET',
if($('.timeline .activity i').hasClass('fa-spin')) url: $('a[href="#activity"]').attr('data-activity-url'),
check = true; data: {'show_all': show_all},
success: function(data) {
return check; var new_activity_hash = (data.activities + "").hashCode();
} if(new_activity_hash != activity_hash) {
$("#activity-refresh").html(data.activities);
function checkNewActivity(runs) { }
$.ajax({ activity_hash = new_activity_hash;
type: 'GET',
url: $('a[href="#activity"]').attr('data-activity-url'), $("#ops").html(data.ops);
data: {'show_all': show_all}, $("#disk-ops").html(data.disk_ops);
success: function(data) { $("[title]").tooltip();
var new_activity_hash = (data.activities + "").hashCode();
if(new_activity_hash != activity_hash) { /* changing the status text */
$("#activity-refresh").html(data.activities); var icon = $("#vm-details-state i");
} if(data.is_new_state) {
activity_hash = new_activity_hash; if(!icon.hasClass("fa-spin"))
icon.prop("class", "fa fa-spinner fa-spin");
$("#ops").html(data.ops); } else {
$("#disk-ops").html(data.disk_ops); icon.prop("class", "fa " + data.icon);
$("[title]").tooltip();
/* changing the status text */
var icon = $("#vm-details-state i");
if(data.is_new_state) {
if(!icon.hasClass("fa-spin"))
icon.prop("class", "fa fa-spinner fa-spin");
} else {
icon.prop("class", "fa " + data.icon);
}
var vm_state = $("#vm-details-state");
if (vm_state.length) {
vm_state.data("status", data['status']);
$("#vm-details-state span").html(data['human_readable_status'].toUpperCase());
}
if(data['status'] == "RUNNING") {
if(data['connect_uri']) {
$("#dashboard-vm-details-connect-button").removeClass('disabled');
} }
$("[data-target=#_console]").attr("data-toggle", "pill").attr("href", "#console").parent("li").removeClass("disabled"); var vm_state = $("#vm-details-state");
} else { if (vm_state.length) {
if(data['connect_uri']) { vm_state.data("status", data['status']);
$("#dashboard-vm-details-connect-button").addClass('disabled'); $("#vm-details-state span").html(data['human_readable_status'].toUpperCase());
}
if(data['status'] == "RUNNING") {
if(data['connect_uri']) {
$("#dashboard-vm-details-connect-button").removeClass('disabled');
}
$("[data-target=#_console]").attr("data-toggle", "pill").attr("href", "#console").parent("li").removeClass("disabled");
} else {
if(data['connect_uri']) {
$("#dashboard-vm-details-connect-button").addClass('disabled');
}
$("[data-target=#_console]").attr("data-toggle", "_pill").attr("href", "#").parent("li").addClass("disabled");
} }
$("[data-target=#_console]").attr("data-toggle", "_pill").attr("href", "#").parent("li").addClass("disabled");
}
if(data.status == "STOPPED" || data.status == "PENDING") { if(data.status == "STOPPED" || data.status == "PENDING") {
$(".change-resources-button").prop("disabled", false); $(".change-resources-button").prop("disabled", false);
$(".change-resources-help").hide(); $(".change-resources-help").hide();
} else { } else {
$(".change-resources-button").prop("disabled", true); $(".change-resources-button").prop("disabled", true);
$(".change-resources-help").show(); $(".change-resources-help").show();
} }
if(runs > 0 && decideActivityRefresh()) { if(runs > 0 && decideActivityRefresh()) {
setTimeout( setTimeout(
function() {checkNewActivity(runs + 1);}, function() {checkNewActivity(runs + 1);},
1000 + Math.exp(runs * 0.05) 1000 + Math.exp(runs * 0.05)
); );
} else { } else {
in_progress = false;
if(reload_vm_detail) location.reload();
}
$('a[href="#activity"] i').removeClass('fa-spin');
},
error: function() {
in_progress = false; in_progress = false;
if(reload_vm_detail) location.reload();
} }
$('a[href="#activity"] i').removeClass('fa-spin'); });
}, }
error: function() { });
in_progress = false;
}
});
}
String.prototype.hashCode = function() { String.prototype.hashCode = function() {
var hash = 0, i, chr, len; var hash = 0, i, chr, len;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment