Revision 96d725ac ui/static/snf/js/ui/web/ui_icon_view.js

b/ui/static/snf/js/ui/web/ui_icon_view.js
103 103

  
104 104
                if (this.toggler.hasClass("open")) {
105 105
                    this.toggler.removeClass("open");
106
                    this.vm.do_update_stats = false;
106 107
                } else {
107 108
                    this.toggler.addClass("open");
108
                    get_server_stats(this.vm.id);
109
                    this.vm.do_update_stats = true;
109 110
                }
110 111
                
111 112
                var self = this;
......
441 442
            this.net_loading = this.el.find(".network-graph .stat-busy");
442 443
            this.net_error = this.el.find(".network-graph .stat-error");
443 444
            this.net_img = this.el.find(".network-graph .stat-img");
445

  
446
            this.loading = this.el.find(".stat-busy");
447
            this.error = this.el.find(".stat-error");
448
            this.img = this.el.find(".stat-img");
444 449
            
445 450
            // initial state paremeters
446
            this.is_building = (this.vm.get("status") == "BUILD");
447
            this.stats_error = false;
448 451
            this.stats = this.vm.get("stats");
449
            this.loading = false;
450 452

  
451 453
            // timeseries or bar images ?
452 454
            this.stats_type = options.stats_type || "bar";
453
            
454
            // stats undefined so probably not loaded yet
455
            if (this.stats === undefined) {
456
                this.loading = true;
457
            }
458 455

  
459 456
            views.VMStatsView.__super__.initialize.apply(this, arguments);
460 457
            this.set_handlers();
461 458
            this.update_layout();
459

  
460
            this.net_loading.show();
461
            this.net_error.hide();
462
            this.cpu_loading.show();
463
            this.cpu_error.hide();
464

  
465
            this.net_img.hide();
466
            this.cpu_img.hide();
462 467
        },
463 468

  
464 469
        
465 470
        set_handlers: function() {
466 471
            // update view state when vm stats update gets triggered
467 472
            this.vm.bind("stats:update", _.bind(function(){
468
                // update building state
469
                if (this.vm.get("status") == "BUILD") {
470
                    this.is_building = true;
471
                } else {
472
                    this.is_building = false;
473
                }
474
                
475
                // update loading state
476
                this.stats = this.vm.get("stats");
477
                if (this.stats == undefined) {
478
                    this.loading = true
479
                } else {
480
                    this.loading = false;
481
                }
482
                
483 473
                // update the layout
484 474
                this.update_layout();
485 475
            }, this));
486

  
487
            this.vm.bind("stats:error", _.bind(function(){
488
                this.stats_error = true;
489
            }, this))
490

  
491
            this.cpu_img.error(_.bind(function(){
492
                this.stats_error = true;
493
                this.update_layout();
494
            }, this));
495

  
496
            this.net_img.error(_.bind(function(){
497
                this.stats_error = true;
498
                this.update_layout();
499
            }, this));
500 476
        },
501 477
        
502 478
        get_images: function (type) {
......
508 484
        },
509 485

  
510 486
        update_layout: function() {
511
            if (this.stats_error) {
512
                this.net_loading.hide();
513
                this.cpu_loading.hide();
514
                this.net_img.hide();
515
                this.cpu_img.hide();
516
                this.cpu_error.show();
517
                this.net_error.show();
518
                return;
519
            }
487
            if (!this.vm.stats_available) {
488
                this.loading.show();
489
                this.img.hide();
490
                this.error.hide();
491
            } else {
492
                this.loading.hide();
493
                this.stats = this.vm.get("stats");
494
                var images = this.get_images(this.stats_type);
520 495

  
521
            if (this.loading) {
522
                this.net_loading.show();
523
                this.cpu_loading.show();
524
                this.net_img.hide();
525
                this.cpu_img.hide();
526
                this.cpu_error.hide();
527
                this.net_error.hide();
528
                return;
529
            }
496
                if (images.cpu) {
497
                    this.cpu_img.attr({src:images.cpu}).show();
498
                    this.cpu_error.hide();
499
                } else {
500
                    this.cpu_img.hide();
501
                    this.cpu_error.show();
502
                }
530 503

  
531
            this.net_loading.hide();
532
            this.cpu_loading.hide();
533
            this.cpu_error.hide();
534
            this.net_error.hide();
535
            
536
            this.net_img.attr("src", this.get_images(this.stats_type).net);
537
            this.cpu_img.attr("src", this.get_images(this.stats_type).cpu);
538
            this.net_img.show();
539
            this.cpu_img.show();
504
                if (images.net) {
505
                    this.net_img.attr({src:images.net}).show();
506
                    this.net_error.hide();
507
                } else {
508
                    this.net_img.hide();
509
                    this.net_error.show();
510
                }
511
            }
512
            $(window).trigger("resize");
540 513
        }
541 514
    });
542 515

  

Also available in: Unified diff