1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

feature #3748: Add dashboard tab

This commit is contained in:
Daniel Molina 2015-06-12 18:24:20 +02:00
parent dadf4737ce
commit 53988d66fd
4 changed files with 195 additions and 0 deletions

View File

@ -4,6 +4,7 @@ define(function(require) {
var Sunstone = require('sunstone');
var _tabs = [
require('tabs/dashboard-tab'),
require('tabs/system-tab'),
require('tabs/users-tab'),
require('tabs/groups-tab'),

View File

@ -0,0 +1,161 @@
define(function(require) {
var Locale = require('utils/locale');
var Config = require('sunstone-config');
var Sunstone = require('sunstone');
var Notifier = require('utils/notifier');
var OpenNebulaVM = require('opennebula/vm');
var Accounting = require('utils/accounting');
var TemplateDashboard = require('hbs!./dashboard-tab/html');
var _activeWidgets = [];
var _widgets = {
'storage': {
'html': require('hbs!./dashboard-tab/storage'),
'onShow': function() {
Sunstone.runAction("Image.list");
}
},
'users': {
'html': require('hbs!./dashboard-tab/users'),
'onShow': function() {
Sunstone.runAction("User.list");
Sunstone.runAction("Group.list");
var end_time = -1; // today
var start_time = Math.floor(new Date().getTime() / 1000);
start_time = start_time - 604800; // 604800 = 7 days = 7*24*60*60
var options = {
"start_time": start_time,
"end_time": end_time
}
var no_table = true;
OpenNebulaVM.accounting({
success: function(req, response) {
Accounting.fillAccounting($("#dashboard_vdc_user_accounting"), req, response, no_table);
},
error: Notifier.onError,
data: options
});
}
},
'network': {
'html': require('hbs!./dashboard-tab/network'),
'onShow': function() {
Sunstone.runAction("Network.list");
}
},
'hosts': {
'html': require('hbs!./dashboard-tab/hosts'),
'onShow': function() {
Sunstone.runAction("Host.list");
}
},
'vms': {
'html': require('hbs!./dashboard-tab/vms'),
'onShow': function() {
Sunstone.runAction("VM.list");
var end_time = -1; // today
var start_time = Math.floor(new Date().getTime() / 1000);
start_time = start_time - 604800; // 604800 = 7 days = 7*24*60*60
var options = {
"start_time": start_time,
"end_time": end_time
}
var no_table = true;
OpenNebulaVM.accounting({
success: function(req, response) {
Accounting.fillAccounting($("#dashboard_vm_accounting"), req, response, no_table);
},
error: Notifier.onError,
data: options
});
}
},
'user_quotas': {
'html': require('hbs!./dashboard-tab/user-quotas'),
},
'group_quotas': {
'html': require('hbs!./dashboard-tab/group-quotas'),
},
'accounting': {
'html': require('hbs!./dashboard-tab/accounting'),
}
}
var _buttons = {
"Dashboard.refresh" : {
type: "action",
layout: "refresh",
alwaysActive: true
}
};
var _actions = {
"Dashboard.refresh" : {
type: "custom",
call: _onShow
},
}
var TAB_ID = require('./dashboard-tab/tabId');
var Tab = {
tabId: TAB_ID,
resource: 'Dashboard',
title: '<i class="fa fa-lg fa-fw fa-tachometer"></i>&emsp;' + Locale.tr("Dashboard"),
showOnTopMenu: false,
listHeader: '<i class="fa fa-lg fa-fw fa-tachometer"></i>&emsp;' + Locale.tr("Dashboard"),
buttons: _buttons,
actions: _actions,
content: _html()
};
return Tab;
function _html() {
var widgetsTemplates = {
'threePerRow': [],
'twoPerRow': [],
'onePerRow': [],
'oneFooter': []
}
$.each(Config.dashboardWidgets('widgets_three_per_row'), function(id, widget) {
_activeWidgets.push(widget);
widgetsTemplates['threePerRow'].push(_widgets[widget].html());
})
$.each(Config.dashboardWidgets('widgets_two_per_row'), function(id, widget) {
_activeWidgets.push(widget);
widgetsTemplates['twoPerRow'].push(_widgets[widget].html());
})
$.each(Config.dashboardWidgets('widgets_one_per_row'), function(id, widget) {
_activeWidgets.push(widget);
widgetsTemplates['onePerRow'].push(_widgets[widget].html());
})
$.each(Config.dashboardWidgets('widgets_one_footer'), function(id, widget) {
_activeWidgets.push(widget);
widgetsTemplates['oneFooter'].push(_widgets[widget].html());
});
return TemplateDashboard(widgetsTemplates);
}
function _onShow() {
$.each(_activeWidgets, function(id, widgetId) {
if (_widgets[widgetId].onShow) {
_widgets[widgetId].onShow();
}
});
}
});

View File

@ -0,0 +1,30 @@
<div>
<div id="one_per_row">
{{#each onePerRow}}
<div class="small-12 large-12 columns">
{{{this}}}
</div>
{{/each}}
</div>
<div id="three_per_row" class="row">
{{#each threePerRow}}
<div class="small-4 large-4 columns">
{{{this}}}
</div>
{{/each}}
</div>
<div id="two_per_row" class="row">
{{#each twoPerRow}}
<div class="small-6 large-6 columns">
{{{this}}}
</div>
{{/each}}
</div>
<div id="one_footer">
{{#each oneFooter}}
<div class="small-12 large-12 columns">
{{{this}}}
</div>
{{/each}}
</div>
</div>

View File

@ -0,0 +1,3 @@
define(function(require) {
return 'dashboard-tab';
});