Revision cbadb3d8

b/ui/static/synnefo.js
1574 1574
}
1575 1575

  
1576 1576
// set timeout function to update machine stats
1577
function set_stats_update_handler(vm_id, interval) {
1577
function set_stats_update_handler(vm_id, interval, clear) {
1578 1578
    var vm = get_machine(vm_id);
1579 1579

  
1580
    if (vm.stats_timeout) {
1581
        window.clearTimeout(vm.stats_timeout);
1580
    if (clear) {
1581
        window.clearInterval(vm.stats_timeout);
1582
        vm.stats_timeout = false;
1583
        return;
1582 1584
    }
1583 1585
    
1584
    vm.stats_timeout = window.setTimeout(function(){
1585
        get_server_stats(vm_id);
1586
    }, interval * 1000);
1586
    if (!vm.stats_timeout) {
1587
        vm.stats_timeout = window.setInterval(function(){
1588
            get_server_stats(vm_id);
1589
        }, interval * 1000);
1590
    }
1587 1591
}
1588 1592

  
1589 1593
// update machine stats
......
1593 1597
    var els = get_current_view_stats_elements(vm_id);
1594 1598
    var from_error = false;
1595 1599
    var vm = get_machine(vm_id);    
1600
    var clear = false;
1596 1601

  
1597 1602
    // api error
1598 1603
    if (!data) {
......
1618 1623
    // apply logic
1619 1624
    if (from_error) {
1620 1625
        // api call returned error show error messages
1621
        return;
1626
        clear = true;
1622 1627
    } else {
1623 1628
        // no need to show stats while machine in building state
1624 1629
        if (vm.status == "BUILD") {
......
1648 1653
    // stats container is hidden
1649 1654
    // do not update the stats
1650 1655
    if (!els.cont.is(":visible")) {
1651
        return false;
1656
        clear = true;
1652 1657
    }
1653 1658
    
1654 1659
    // set timeout to call the stats update
1655
    set_stats_update_handler(vm_id, data.stats.refresh);
1660
    set_stats_update_handler(vm_id, data.stats.refresh, clear);
1656 1661
}
1657 1662

  
1658 1663

  

Also available in: Unified diff