mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-20 11:52:37 +09:00
Feature #3748: Refactor the VDC resources tab
This commit is contained in:
1 parent
9a0e2c7836
commit
09be9b3fe6
6 files changed
+289
-117
No files matched your search
@@ -3,9 +3,9 @@ define(function(require) {
|
||||
DEPENDENCIES
|
||||
*/
|
||||
|
||||
var TemplateHTML = require('hbs!./resources/html');
|
||||
var Locale = require('utils/locale');
|
||||
var Utils = require('../utils/common');
|
||||
var ResourcesTab = require('../utils/resources-tab');
|
||||
|
||||
/*
|
||||
CONSTANTS
|
||||
@@ -29,6 +29,8 @@ define(function(require) {
|
||||
|
||||
this.element = info[XML_ROOT];
|
||||
|
||||
this.resourcesTab = new ResourcesTab("vdc_info_panel");
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -43,21 +45,23 @@ define(function(require) {
|
||||
*/
|
||||
|
||||
function _html() {
|
||||
return TemplateHTML();
|
||||
return this.resourcesTab.html();
|
||||
}
|
||||
|
||||
function _setup(context) {
|
||||
var that = this;
|
||||
|
||||
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);
|
||||
that.resourcesTab.addResourcesZone(
|
||||
zone_id,
|
||||
Sunstone.getDataTable(ZONE_TAB_ID).getName(zone_id),
|
||||
context,
|
||||
indexed_resources);
|
||||
});
|
||||
|
||||
Utils.setupVdcResourceTab("vdc_info_panel", context);
|
||||
that.resourcesTab.setup(context);
|
||||
that.resourcesTab.onShow(context);
|
||||
}
|
||||
});
|
||||
@@ -5,14 +5,6 @@ define(function(require) {
|
||||
|
||||
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.
|
||||
|
||||
@@ -98,107 +90,8 @@ define(function(require) {
|
||||
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
|
||||
'VDC_ALL_RESOURCES': VDC_ALL_RESOURCES
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,99 @@
|
||||
define(function(require) {
|
||||
|
||||
var TemplateHTML = require('hbs!./resources-tab/html');
|
||||
var ResourcesZone = require('./resources-zone');
|
||||
|
||||
function ResourcesTab(unique_id_prefix) {
|
||||
this.unique_id_prefix = unique_id_prefix;
|
||||
this.zones = [];
|
||||
}
|
||||
|
||||
ResourcesTab.prototype.constructor = ResourcesTab;
|
||||
ResourcesTab.prototype.html = _html;
|
||||
ResourcesTab.prototype.setup = _setup;
|
||||
ResourcesTab.prototype.onShow = _onShow;
|
||||
ResourcesTab.prototype.retrieve = _retrieve;
|
||||
//ResourcesTab.prototype.fill = _fill;
|
||||
ResourcesTab.prototype.addResourcesZone = _addResourcesZone;
|
||||
|
||||
return ResourcesTab;
|
||||
|
||||
function _html() {
|
||||
return TemplateHTML({});
|
||||
}
|
||||
|
||||
function _onShow(context) {
|
||||
$.each(this.zones,function(i,resourcesZone){
|
||||
resourcesZone.onShow(context);
|
||||
});
|
||||
}
|
||||
|
||||
function _setup(context) {
|
||||
var that = this;
|
||||
|
||||
$("select.vdc_zones_select", context).change(function(){
|
||||
context.find(".vdc_zone_content").hide();
|
||||
$('div#'+that.unique_id_prefix+'_'+$(this).val()+'Tab', context).show();
|
||||
});
|
||||
|
||||
$("select.vdc_zones_select", context)[0].selectedIndex = 0;
|
||||
$("select.vdc_zones_select", context).change();
|
||||
}
|
||||
|
||||
function _retrieve(context) {
|
||||
var clusters = [];
|
||||
var hosts = [];
|
||||
var vnets = [];
|
||||
var datastores = [];
|
||||
|
||||
$.each(this.zones,function(i,resourcesZone){
|
||||
var resources = resourcesZone.retrieve(context);
|
||||
var zone_id = resourcesZone.getZoneId();
|
||||
|
||||
$.each(resources.clusters,function(j,cluster_id){
|
||||
clusters.push({zone_id: zone_id, cluster_id: cluster_id});
|
||||
});
|
||||
|
||||
$.each(resources.hosts,function(j,host_id){
|
||||
hosts.push({zone_id: zone_id, host_id: host_id});
|
||||
});
|
||||
$.each(resources.vnets,function(j,vnet_id){
|
||||
vnets.push({zone_id: zone_id, vnet_id: vnet_id});
|
||||
});
|
||||
$.each(resources.datastores,function(j,ds_id){
|
||||
datastores.push({zone_id: zone_id, ds_id: ds_id});
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
"clusters" : clusters,
|
||||
"hosts" : hosts,
|
||||
"vnets" : vnets,
|
||||
"datastores" : datastores
|
||||
};
|
||||
}
|
||||
|
||||
function _addResourcesZone(zone_id, zone_name, context, indexed_resources) {
|
||||
var unique_id = this.unique_id_prefix+'_'+zone_id;
|
||||
|
||||
var resourcesZone = new ResourcesZone(unique_id, zone_id, zone_name, context, indexed_resources);
|
||||
|
||||
// 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">'+
|
||||
resourcesZone.html()+
|
||||
'</div>';
|
||||
|
||||
$(html_tab_content).appendTo($(".vdc_zones_tabs_content", context));
|
||||
|
||||
$("select.vdc_zones_select", context).append(
|
||||
'<option value="'+zone_id+'">'+zone_name+'</option>');
|
||||
|
||||
var zoneSection = $('#' +unique_id+'Tab', context);
|
||||
|
||||
resourcesZone.setup(zoneSection);
|
||||
|
||||
this.zones.push(resourcesZone);
|
||||
}
|
||||
|
||||
});
|
||||
File renamed without changes.
@@ -0,0 +1,176 @@
|
||||
define(function(require) {
|
||||
|
||||
var TemplateHTML = require('hbs!./resources-zone/html');
|
||||
|
||||
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');
|
||||
var Utils = require('../utils/common');
|
||||
|
||||
var VDC_ALL_RESOURCES = Utils.VDC_ALL_RESOURCES;
|
||||
|
||||
function ResourcesZone(unique_id, zone_id, zone_name, context, indexed_resources) {
|
||||
this.unique_id = unique_id;
|
||||
this.zone_id = zone_id;
|
||||
|
||||
this.resources = undefined;
|
||||
if(indexed_resources != undefined && indexed_resources[zone_id] != undefined){
|
||||
this.resources = indexed_resources[zone_id];
|
||||
}
|
||||
}
|
||||
|
||||
ResourcesZone.prototype.constructor = ResourcesZone;
|
||||
ResourcesZone.prototype.html = _html;
|
||||
ResourcesZone.prototype.setup = _setup;
|
||||
ResourcesZone.prototype.onShow = _onShow;
|
||||
ResourcesZone.prototype.retrieve = _retrieve;
|
||||
//ResourcesZone.prototype.fill = _fill;
|
||||
ResourcesZone.prototype.getZoneId = _getZoneId;
|
||||
|
||||
return ResourcesZone;
|
||||
|
||||
function _getZoneId() {
|
||||
return this.zone_id;
|
||||
}
|
||||
|
||||
function _html() {
|
||||
var that = this;
|
||||
|
||||
var opts = {};
|
||||
|
||||
$.each(["clusters", "hosts", "vnets", "datastores"], function(i,res_name){
|
||||
if(that.resources != undefined){
|
||||
opts[res_name] = {
|
||||
info: true,
|
||||
select: true,
|
||||
selectOptions: {
|
||||
read_only: true,
|
||||
zone_id: that.zone_id
|
||||
}
|
||||
};
|
||||
|
||||
if (!(that.resources[res_name].length == 1 &&
|
||||
that.resources[res_name][0] == VDC_ALL_RESOURCES) ){
|
||||
|
||||
opts[res_name].selectOptions.fixed_ids = that.resources[res_name];
|
||||
}
|
||||
} else {
|
||||
opts[res_name] = {
|
||||
info: false,
|
||||
select: true,
|
||||
selectOptions: {
|
||||
multiple_choice: true,
|
||||
zone_id: that.zone_id
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
that.clustersTable = new ClustersTable("vdc_clusters_"+that.unique_id, opts["clusters"]);
|
||||
that.hostsTable = new HostsTable("vdc_hosts_"+that.unique_id, opts["hosts"]);
|
||||
that.vnetsTable = new VNetsTable("vdc_vnets_"+that.unique_id, opts["vnets"]);
|
||||
that.datastoresTable = new DatastoresTable("vdc_datastores_"+that.unique_id, opts["datastores"]);
|
||||
|
||||
return TemplateHTML({
|
||||
'unique_id': that.unique_id,
|
||||
'clustersTableHTML': that.clustersTable.dataTableHTML,
|
||||
'hostsTableHTML': that.hostsTable.dataTableHTML,
|
||||
'vnetsTableHTML': that.vnetsTable.dataTableHTML,
|
||||
'datastoresTableHTML': that.datastoresTable.dataTableHTML
|
||||
});
|
||||
}
|
||||
|
||||
function _onShow(context) {
|
||||
var that = this;
|
||||
|
||||
$.each([that.clustersTable, that.hostsTable,
|
||||
that.vnetsTable, that.datastoresTable], function(){
|
||||
|
||||
this.refreshResourceTableSelect();
|
||||
});
|
||||
}
|
||||
|
||||
function _setup(context){
|
||||
var that = this;
|
||||
|
||||
context.foundation();
|
||||
|
||||
$.each(["clusters", "hosts", "vnets", "datastores"], function(i,res_name){
|
||||
if(that.resources != undefined){
|
||||
if (that.resources[res_name].length == 1 &&
|
||||
that.resources[res_name][0] == VDC_ALL_RESOURCES){
|
||||
|
||||
$("#all_"+res_name+"_"+that.unique_id, context).prop("checked", "checked");
|
||||
}
|
||||
|
||||
$("#all_"+res_name+"_"+that.unique_id, context).prop("disabled", true);
|
||||
}
|
||||
|
||||
$("input[name='all_"+res_name+"_"+that.unique_id+"']", context).change(function(){
|
||||
if ($(this).prop("checked")){
|
||||
$("div.vdc_"+res_name+"_select", context).hide();
|
||||
} else {
|
||||
$("div.vdc_"+res_name+"_select", context).show();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$.each([that.clustersTable, that.hostsTable,
|
||||
that.vnetsTable, that.datastoresTable], function(){
|
||||
|
||||
this.initialize();
|
||||
});
|
||||
|
||||
Tips.setup(context);
|
||||
}
|
||||
|
||||
/*
|
||||
Return an object with the selected VDC resources in the zone tab
|
||||
{ clusters : [],
|
||||
hosts : [],
|
||||
vnets : [],
|
||||
datastores : []
|
||||
}
|
||||
*/
|
||||
function _retrieve(context) {
|
||||
var clusters;
|
||||
var hosts;
|
||||
var vnets;
|
||||
var datastores;
|
||||
|
||||
if ( $("input[name='all_clusters_"+this.unique_id+"']", context).prop("checked") ){
|
||||
clusters = [VDC_ALL_RESOURCES];
|
||||
} else {
|
||||
clusters = this.clustersTable.retrieveResourceTableSelect();
|
||||
}
|
||||
|
||||
if ( $("input[name='all_hosts_"+this.unique_id+"']", context).prop("checked") ){
|
||||
hosts = [VDC_ALL_RESOURCES];
|
||||
} else {
|
||||
hosts = this.hostsTable.retrieveResourceTableSelect();
|
||||
}
|
||||
|
||||
if ( $("input[name='all_vnets_"+this.unique_id+"']", context).prop("checked") ){
|
||||
vnets = [VDC_ALL_RESOURCES];
|
||||
} else {
|
||||
vnets = this.vnetsTable.retrieveResourceTableSelect();
|
||||
}
|
||||
|
||||
if ( $("input[name='all_datastores_"+this.unique_id+"']", context).prop("checked") ){
|
||||
datastores = [VDC_ALL_RESOURCES];
|
||||
} else {
|
||||
datastores = this.datastoresTable.retrieveResourceTableSelect();
|
||||
}
|
||||
|
||||
var resources = {
|
||||
clusters : clusters,
|
||||
hosts : hosts,
|
||||
vnets : vnets,
|
||||
datastores : datastores
|
||||
};
|
||||
|
||||
return resources;
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user