From 4c17e4ecfc0bac7cc8228a014b77d82f63681eb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 25 May 2015 13:15:12 +0200 Subject: [PATCH] Feature #3748: VDC Resources tab --- src/sunstone/public/app/tabs/vdcs-tab.js | 3 +- .../app/tabs/vdcs-tab/panels/resources.js | 63 ++++++ .../tabs/vdcs-tab/panels/resources/html.hbs | 14 ++ .../tabs/vdcs-tab/panels/resources/panelId.js | 3 + .../public/app/tabs/vdcs-tab/utils/common.js | 204 ++++++++++++++++++ .../app/tabs/vdcs-tab/utils/resourceTab.hbs | 68 ++++++ 6 files changed, 354 insertions(+), 1 deletion(-) create mode 100644 src/sunstone/public/app/tabs/vdcs-tab/panels/resources.js create mode 100644 src/sunstone/public/app/tabs/vdcs-tab/panels/resources/html.hbs create mode 100644 src/sunstone/public/app/tabs/vdcs-tab/panels/resources/panelId.js create mode 100644 src/sunstone/public/app/tabs/vdcs-tab/utils/common.js create mode 100644 src/sunstone/public/app/tabs/vdcs-tab/utils/resourceTab.hbs diff --git a/src/sunstone/public/app/tabs/vdcs-tab.js b/src/sunstone/public/app/tabs/vdcs-tab.js index 23710275b6..c203aedd3e 100644 --- a/src/sunstone/public/app/tabs/vdcs-tab.js +++ b/src/sunstone/public/app/tabs/vdcs-tab.js @@ -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 = { diff --git a/src/sunstone/public/app/tabs/vdcs-tab/panels/resources.js b/src/sunstone/public/app/tabs/vdcs-tab/panels/resources.js new file mode 100644 index 0000000000..82db96d1ce --- /dev/null +++ b/src/sunstone/public/app/tabs/vdcs-tab/panels/resources.js @@ -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); + } +}); diff --git a/src/sunstone/public/app/tabs/vdcs-tab/panels/resources/html.hbs b/src/sunstone/public/app/tabs/vdcs-tab/panels/resources/html.hbs new file mode 100644 index 0000000000..ec35706cbf --- /dev/null +++ b/src/sunstone/public/app/tabs/vdcs-tab/panels/resources/html.hbs @@ -0,0 +1,14 @@ +
+
+ +
+
+ +
+
+
+
+
+
+
\ No newline at end of file diff --git a/src/sunstone/public/app/tabs/vdcs-tab/panels/resources/panelId.js b/src/sunstone/public/app/tabs/vdcs-tab/panels/resources/panelId.js new file mode 100644 index 0000000000..b64d583c6e --- /dev/null +++ b/src/sunstone/public/app/tabs/vdcs-tab/panels/resources/panelId.js @@ -0,0 +1,3 @@ +define(function(require){ + return 'vdc_resources_tab'; +}) \ No newline at end of file diff --git a/src/sunstone/public/app/tabs/vdcs-tab/utils/common.js b/src/sunstone/public/app/tabs/vdcs-tab/utils/common.js new file mode 100644 index 0000000000..d1f6438747 --- /dev/null +++ b/src/sunstone/public/app/tabs/vdcs-tab/utils/common.js @@ -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 = + '
'+ + ResourceTabHTML({ + 'unique_id': unique_id, + 'clustersTableHTML': clustersTable.dataTableHTML, + 'hostsTableHTML': hostsTable.dataTableHTML, + 'vnetsTableHTML': vnetsTable.dataTableHTML, + 'datastoresTableHTML': datastoresTable.dataTableHTML + })+ + '
'; + + $(html_tab_content).appendTo($(".vdc_zones_tabs_content", context)); + + var zone_section = $('#' +unique_id+'Tab', context); + + $("select.vdc_zones_select", context).append( + ''); + + 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 + }; +}); diff --git a/src/sunstone/public/app/tabs/vdcs-tab/utils/resourceTab.hbs b/src/sunstone/public/app/tabs/vdcs-tab/utils/resourceTab.hbs new file mode 100644 index 0000000000..739e5aa0b1 --- /dev/null +++ b/src/sunstone/public/app/tabs/vdcs-tab/utils/resourceTab.hbs @@ -0,0 +1,68 @@ +
+
+
+

{{tr "Clusters"}}
+

{{tr "Hosts"}}
+

{{tr "VNets"}}
+

{{tr "Datastores"}}
+
+
+
+
+
+ +
+
+
+ {{{clustersTableHTML}}} +
+
+
+
+
+ +
+
+
+ {{{hostsTableHTML}}} +
+
+
+
+
+ +
+
+
+ {{{vnetsTableHTML}}} +
+
+
+
+
+ +
+
+
+ {{{datastoresTableHTML}}} +
+
+
+
+
\ No newline at end of file