Feature #3748: VDC Resources tab

This commit is contained in:
Carlos Martín committed 2015-05-25 13:15:12 +02:00
1 parent ce4e553f97
commit 4c17e4ecfc
6 files changed
+354 -1

No files matched your search

+2 -1
View File
@@ -12,7 +12,8 @@ define(function(require) {
var _panels = [
require('./vdcs-tab/panels/info'),
require('./vdcs-tab/panels/groups')
require('./vdcs-tab/panels/groups'),
require('./vdcs-tab/panels/resources')
];
var Tab = {
@@ -0,0 +1,63 @@
define(function(require) {
/*
DEPENDENCIES
*/
var TemplateHTML = require('hbs!./resources/html');
var Locale = require('utils/locale');
var Utils = require('../utils/common');
/*
CONSTANTS
*/
var TAB_ID = require('../tabId');
var PANEL_ID = require('./resources/panelId');
var RESOURCE = "Vdc";
var XML_ROOT = "VDC";
var ZONE_TAB_ID = require('tabs/zones-tab/tabId');
var Sunstone = require('sunstone');
/*
CONSTRUCTOR
*/
function Panel(info) {
this.title = Locale.tr("Resources");
this.icon = "fa-th";
this.element = info[XML_ROOT];
return this;
}
Panel.PANEL_ID = PANEL_ID;
Panel.prototype.html = _html;
Panel.prototype.setup = _setup;
return Panel;
/*
FUNCTION DEFINITIONS
*/
function _html() {
return TemplateHTML();
}
function _setup(context) {
var indexed_resources = Utils.indexedVdcResources(this.element);
$.each(indexed_resources, function(zone_id,objects){
Utils.addVdcResourceTab(
"vdc_info_panel",
zone_id,
Sunstone.getDataTable(ZONE_TAB_ID).getName(zone_id),
context,
indexed_resources);
});
Utils.setupVdcResourceTab("vdc_info_panel", context);
}
});
@@ -0,0 +1,14 @@
<div class="row">
<div class="large-8 medium-6 columns">
<label class="inline right">{{tr "Zone"}}</label>
</div>
<div class="large-4 medium-6 columns end">
<select class="vdc_zones_select">
</select>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<div class="tabs-content vdc_zones_tabs_content"></div>
</div>
</div>
@@ -0,0 +1,3 @@
define(function(require){
return 'vdc_resources_tab';
})
@@ -0,0 +1,204 @@
define(function(require) {
/*
Common functions for VDCs
*/
var VDC_ALL_RESOURCES = "-10";
var ResourceTabHTML = require('hbs!./resourceTab');
var ClustersTable = require('tabs/clusters-tab/datatable');
var HostsTable = require('tabs/hosts-tab/datatable');
var VNetsTable = require('tabs/vnets-tab/datatable');
var DatastoresTable = require('tabs/datastores-tab/datatable');
var Tips = require('utils/tips');
/**
Return an object with the VDC resources indexed by zone_id.
{ zone_id :
{ clusters : [],
hosts : [],
vnets : [],
datastores : []
}
}
*/
function _indexedVdcResources(vdc){
var resources = {};
var clusters_array = [];
var hosts_array = [];
var vnets_array = [];
var datastores_array = [];
if (vdc.CLUSTERS.CLUSTER){
clusters_array = vdc.CLUSTERS.CLUSTER;
if (!$.isArray(clusters_array)){
clusters_array = [clusters_array];
}
}
if (vdc.HOSTS.HOST){
hosts_array = vdc.HOSTS.HOST;
if (!$.isArray(hosts_array)){
hosts_array = [hosts_array];
}
}
if (vdc.VNETS.VNET){
vnets_array = vdc.VNETS.VNET;
if (!$.isArray(vnets_array)){
vnets_array = [vnets_array];
}
}
if (vdc.DATASTORES.DATASTORE){
datastores_array = vdc.DATASTORES.DATASTORE;
if (!$.isArray(datastores_array)){
datastores_array = [datastores_array];
}
}
function init_resources_zone(zone_id){
if (resources[zone_id] == undefined){
resources[zone_id] = {
clusters : [],
hosts : [],
vnets : [],
datastores : []
}
}
}
$.each(clusters_array, function(i,e){
init_resources_zone(e.ZONE_ID);
resources[e.ZONE_ID].clusters.push(e.CLUSTER_ID);
});
$.each(hosts_array, function(i,e){
init_resources_zone(e.ZONE_ID);
resources[e.ZONE_ID].hosts.push(e.HOST_ID);
});
$.each(vnets_array, function(i,e){
init_resources_zone(e.ZONE_ID);
resources[e.ZONE_ID].vnets.push(e.VNET_ID);
});
$.each(datastores_array, function(i,e){
init_resources_zone(e.ZONE_ID);
resources[e.ZONE_ID].datastores.push(e.DATASTORE_ID);
});
return resources;
}
function _addVdcResourceTab(unique_id_prefix, zone_id, zone_name, context, indexed_resources) {
var unique_id = unique_id_prefix+'_'+zone_id;
var resources = undefined;
if(indexed_resources != undefined && indexed_resources[zone_id] != undefined){
resources = indexed_resources[zone_id];
}
var opts = {};
$.each(["clusters", "hosts", "vnets", "datastores"], function(i,res_name){
if(resources != undefined){
opts[res_name] = {
info: true,
select: true,
selectOptions: {
read_only: true,
zone_id: zone_id
}
};
if (!(resources[res_name].length == 1 && resources[res_name][0] == VDC_ALL_RESOURCES)){
opts[res_name].selectOptions.fixed_ids = resources[res_name];
}
} else {
opts[res_name] = {
info: true,
select: true,
selectOptions: {
multiple_choice: true,
zone_id: zone_id
}
};
}
});
var clustersTable = new ClustersTable("vdc_clusters_"+unique_id, opts["clusters"]);
var hostsTable = new HostsTable("vdc_hosts_"+unique_id, opts["hosts"]);
var vnetsTable = new VNetsTable("vdc_vnets_"+unique_id, opts["vnets"]);
var datastoresTable = new DatastoresTable("vdc_datastores_"+unique_id, opts["datastores"]);
// Append the new div containing the tab and add the tab to the list
var html_tab_content =
'<div id="'+unique_id+'Tab" class="vdc_zone_content">'+
ResourceTabHTML({
'unique_id': unique_id,
'clustersTableHTML': clustersTable.dataTableHTML,
'hostsTableHTML': hostsTable.dataTableHTML,
'vnetsTableHTML': vnetsTable.dataTableHTML,
'datastoresTableHTML': datastoresTable.dataTableHTML
})+
'</div>';
$(html_tab_content).appendTo($(".vdc_zones_tabs_content", context));
var zone_section = $('#' +unique_id+'Tab', context);
$("select.vdc_zones_select", context).append(
'<option value="'+zone_id+'">'+zone_name+'</option>');
zone_section.foundation();
$.each(["clusters", "hosts", "vnets", "datastores"], function(i,res_name){
if(resources != undefined){
if (resources[res_name].length == 1 && resources[res_name][0] == VDC_ALL_RESOURCES){
$("#all_"+res_name+"_"+unique_id, zone_section).prop("checked", "checked");
}
$("#all_"+res_name+"_"+unique_id, zone_section).prop("disabled", true);
}
$("input[name='all_"+res_name+"_"+unique_id+"']", zone_section).change(function(){
if ($(this).prop("checked")){
$("div.vdc_"+res_name+"_select", zone_section).hide();
} else {
$("div.vdc_"+res_name+"_select", zone_section).show();
}
});
});
$.each([clustersTable, hostsTable, vnetsTable, datastoresTable], function(){
this.initialize();
this.refreshResourceTableSelect();
});
Tips.setup(zone_section);
}
function _setupVdcResourceTab(unique_id_prefix, context){
$("select.vdc_zones_select", context).change(function(){
context.find(".vdc_zone_content").hide();
$('div#'+unique_id_prefix+'_'+$(this).val()+'Tab', context).show();
});
$("select.vdc_zones_select", context)[0].selectedIndex = 0;
$("select.vdc_zones_select", context).change();
}
return {
'indexedVdcResources': _indexedVdcResources,
'addVdcResourceTab': _addVdcResourceTab,
'setupVdcResourceTab': _setupVdcResourceTab
};
});
@@ -0,0 +1,68 @@
<div class="row">
<div class="large-12 columns">
<dl class="tabs right-info-tabs text-center" data-tab>
<dd class="active"><a href="#vdcClustersTab_{{unique_id}}"><i class="fa fa-th"></i><br>{{tr "Clusters"}}</a></dd>
<dd><a href="#vdcHostsTab_{{unique_id}}"><i class="fa fa-hdd-o"></i><br>{{tr "Hosts"}}</a></dd>
<dd><a href="#vdcVnetsTab_{{unique_id}}"><i class="fa fa-globe"></i><br>{{tr "VNets"}}</a></dd>
<dd><a href="#vdcDatastoresTab_{{unique_id}}"><i class="fa fa-folder-open"></i><br>{{tr "Datastores"}}</a></dd>
</dl>
<div class="tabs-content">
<div class="content active" id="vdcClustersTab_{{unique_id}}" class="content">
<div class="row">
<div class="large-12 columns">
<label for="all_clusters_{{unique_id}}">
<input type="checkbox" name="all_clusters_{{unique_id}}" id="all_clusters_{{unique_id}}" />
{{tr "All"}}
<span class="tip">{{tr "Selects all current and future clusters"}}</span>
</label>
</div>
</div>
<div class="vdc_clusters_select">
{{{clustersTableHTML}}}
</div>
</div>
<div id="vdcHostsTab_{{unique_id}}" class="content">
<div class="row">
<div class="large-12 columns">
<label for="all_hosts_{{unique_id}}">
<input type="checkbox" name="all_hosts_{{unique_id}}" id="all_hosts_{{unique_id}}" />
{{tr "All"}}
<span class="tip">{{tr "Selects all current and future hosts"}}</span>
</label>
</div>
</div>
<div class="vdc_hosts_select">
{{{hostsTableHTML}}}
</div>
</div>
<div id="vdcVnetsTab_{{unique_id}}" class="content">
<div class="row">
<div class="large-12 columns">
<label for="all_vnets_{{unique_id}}">
<input type="checkbox" name="all_vnets_{{unique_id}}" id="all_vnets_{{unique_id}}" />
{{tr "All"}}
<span class="tip">{{tr "Selects all current and future vnets"}}</span>
</label>
</div>
</div>
<div class="vdc_vnets_select">
{{{vnetsTableHTML}}}
</div>
</div>
<div id="vdcDatastoresTab_{{unique_id}}" class="content">
<div class="row">
<div class="large-12 columns">
<label for="all_datastores_{{unique_id}}">
<input type="checkbox" name="all_datastores_{{unique_id}}" id="all_datastores_{{unique_id}}" />
{{tr "All"}}
<span class="tip">{{tr "Selects all current and future datastores"}}</span>
</label>
</div>
</div>
<div class="vdc_datastores_select">
{{{datastoresTableHTML}}}
</div>
</div>
</div>
</div>
</div>