Revision 0936e421 snf-cyclades-app/synnefo/ui/static/snf/js/ui/web/ui_icon_view.js
b/snf-cyclades-app/synnefo/ui/static/snf/js/ui/web/ui_icon_view.js | ||
---|---|---|
476 | 476 |
this.parent = view; |
477 | 477 |
this.sel = options.el || this.el_sel || ".lower"; |
478 | 478 |
this.el = this.parent.vm(vm).find(this.sel); |
479 |
this.selected_stats_period = 'hourly'; |
|
479 | 480 |
|
480 | 481 |
// elements shortcuts |
481 | 482 |
this.cpu_loading = this.el.find(".cpu-graph .stat-busy"); |
... | ... | |
488 | 489 |
this.loading = this.el.find(".stat-busy"); |
489 | 490 |
this.error = this.el.find(".stat-error"); |
490 | 491 |
this.img = this.el.find(".stat-img"); |
492 |
this.stats_period_options = this.el.find(".stats-select-option"); |
|
493 |
|
|
494 |
|
|
495 |
// handle stats period option select |
|
496 |
var self = this; |
|
497 |
this.stats_period_options.click(function(){ |
|
498 |
// skip if current selection is clicked |
|
499 |
if ($(this).filter(".stats-" + self.selected_stats_period).length) { |
|
500 |
return |
|
501 |
} else { |
|
502 |
// identify class |
|
503 |
var cls = $(this).attr("class"); |
|
504 |
regex = /.*\sstats-(\w+)/; |
|
505 |
self.set_stats_period(cls.match(regex)[1]); |
|
506 |
} |
|
507 |
}); |
|
491 | 508 |
|
492 | 509 |
// initial state paremeters |
493 | 510 |
this.stats = this.vm.get("stats"); |
... | ... | |
506 | 523 |
|
507 | 524 |
this.net_img.hide(); |
508 | 525 |
this.cpu_img.hide(); |
526 |
|
|
527 |
if (!window.t) { |
|
528 |
window.t = []; |
|
529 |
} |
|
530 |
if (this.parent.menu) { |
|
531 |
window.t[window.t.length] = this; |
|
532 |
} |
|
509 | 533 |
}, |
510 | 534 |
|
511 | 535 |
|
536 |
set_stats_period: function(period) { |
|
537 |
this.selected_stats_period = period; |
|
538 |
this.update_layout(); |
|
539 |
}, |
|
540 |
|
|
512 | 541 |
set_handlers: function() { |
513 | 542 |
// update view state when vm stats update gets triggered |
514 | 543 |
this.vm.bind("stats:update", _.bind(function(){ |
... | ... | |
517 | 546 |
}, this)); |
518 | 547 |
}, |
519 | 548 |
|
520 |
get_images: function (type) { |
|
521 |
if (type == "bar") { |
|
522 |
return {'cpu': this.stats.cpuBar, 'net': this.stats.netBar }; |
|
549 |
get_images: function (type, period) { |
|
550 |
var period = period || 'hourly'; |
|
551 |
var images; |
|
552 |
|
|
553 |
if (type == 'bar') { |
|
554 |
images = {'cpu': this.stats.cpuBar, 'net': this.stats.netBar }; |
|
523 | 555 |
} else { |
524 |
return {'cpu': this.stats.cpuTimeSeries, 'net': this.stats.netTimeSeries }; |
|
556 |
images = {'cpu': this.stats.cpuTimeSeries, |
|
557 |
'net': this.stats.netTimeSeries }; |
|
525 | 558 |
} |
559 |
|
|
560 |
if (period == 'weekly' && type != 'bar') { |
|
561 |
if (images.cpu) |
|
562 |
images.cpu = images.cpu.replace('.png', '-w.png') |
|
563 |
if (images.net) |
|
564 |
images.net = images.net.replace('.png', '-w.png') |
|
565 |
} |
|
566 |
return images |
|
526 | 567 |
}, |
527 | 568 |
|
528 | 569 |
update_layout: function() { |
... | ... | |
533 | 574 |
} else { |
534 | 575 |
this.loading.hide(); |
535 | 576 |
this.stats = this.vm.get("stats"); |
536 |
var images = this.get_images(this.stats_type); |
|
577 |
var images = this.get_images(this.stats_type, |
|
578 |
this.selected_stats_period) |
|
537 | 579 |
|
538 | 580 |
if (images.cpu) { |
539 | 581 |
this.cpu_img.attr({src:images.cpu}).show(); |
... | ... | |
551 | 593 |
this.net_error.show(); |
552 | 594 |
} |
553 | 595 |
} |
596 |
|
|
597 |
// update selected stats period |
|
598 |
this.stats_period_options.removeClass("selected"); |
|
599 |
this.stats_period_options.filter(".stats-" + this.selected_stats_period).addClass("selected") |
|
600 |
|
|
554 | 601 |
$(window).trigger("resize"); |
555 | 602 |
} |
556 | 603 |
}); |
Also available in: Unified diff