From 0f1458a3054d9d0313cac6d3cf87d2cf4c6e299c Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Mon, 4 Jul 2011 15:34:41 +0200 Subject: [PATCH] Feature #687: Several sunstone fixes: Fixed UNAME / GNAME new elements. Added user addgroup, chgrp, delgroup operations. Improved template update dialog. --- .../models/OpenNebulaJSON/UserJSON.rb | 13 +- src/sunstone/public/js/opennebula.js | 127 +++++++++++++++--- src/sunstone/public/js/plugins/groups-tab.js | 22 ++- src/sunstone/public/js/plugins/hosts-tab.js | 2 +- src/sunstone/public/js/plugins/images-tab.js | 14 +- .../public/js/plugins/templates-tab.js | 14 +- src/sunstone/public/js/plugins/users-tab.js | 117 ++++++++++++---- src/sunstone/public/js/plugins/vms-tab.js | 12 +- src/sunstone/public/js/plugins/vnets-tab.js | 12 +- src/sunstone/public/js/sunstone-util.js | 38 +++++- 10 files changed, 304 insertions(+), 67 deletions(-) diff --git a/src/sunstone/models/OpenNebulaJSON/UserJSON.rb b/src/sunstone/models/OpenNebulaJSON/UserJSON.rb index 0072ecf0c8..89f9780b7a 100644 --- a/src/sunstone/models/OpenNebulaJSON/UserJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/UserJSON.rb @@ -39,6 +39,8 @@ module OpenNebulaJSON rc = case action_hash['perform'] when "passwd" then self.passwd(action_hash['params']) when "chgrp" then self.chgrp(action_hash['params']) + when "addgroup" then self.addgroup(action_hash['params']) + when "delgroup" then self.delgroup(action_hash['params']) else error_msg = "#{action_hash['perform']} action not " << " available for this resource" @@ -52,7 +54,16 @@ module OpenNebulaJSON end def chgrp(params=Hash.new) - super(params['group_id']) + super(params['group_id'].to_i) end + + def addgroup(params=Hash.new) + super(params['group_id'].to_i) + end + + def delgroup(params=Hash.new) + super(params['group_id'].to_i) + end + end end diff --git a/src/sunstone/public/js/opennebula.js b/src/sunstone/public/js/opennebula.js index 09885d3188..6c9d1a3c0b 100644 --- a/src/sunstone/public/js/opennebula.js +++ b/src/sunstone/public/js/opennebula.js @@ -151,7 +151,7 @@ var OpenNebula = { { return Error('Incorrect Pool'); } - + var p_pool = []; if (response[pool_name]) { @@ -227,7 +227,7 @@ var OpenNebula = { var password = params.data.password; var remember = params.remember; - var resource = OpenNebula.Auth.resource; + var resource = OpenNebula.Auth.resource; var request = OpenNebula.Helper.request(resource,"login"); $.ajax({ @@ -709,7 +709,7 @@ var OpenNebula = { var callback_error = params.error; var timeout = params.timeout || false; var resource = OpenNebula.Network.resource; - + var request = OpenNebula.Helper.request(resource,"list"); $.ajax({ @@ -1257,7 +1257,7 @@ var OpenNebula = { var callback_error = params.error; var id = params.data.id; var resource = OpenNebula.VM.resource; - + var method = "suspend"; var action = OpenNebula.Helper.action(method); var request = OpenNebula.Helper.request(resource,method, id); @@ -1331,7 +1331,7 @@ var OpenNebula = { "type" : type } var resource = OpenNebula.VM.resource; - + var action = OpenNebula.Helper.action(method,saveas_params) var request = OpenNebula.Helper.request(resource,method, [id,disk_id, image_name, type]); @@ -1387,7 +1387,7 @@ var OpenNebula = { } }); }, - + "resubmit": function(params) { var callback = params.success; @@ -1419,7 +1419,7 @@ var OpenNebula = { } }); }, - + "startvnc" : function(params){ var callback = params.success; var callback_error = params.error; @@ -1449,7 +1449,7 @@ var OpenNebula = { } }); }, - + "stopvnc" : function(params){ var callback = params.success; var callback_error = params.error; @@ -1687,6 +1687,36 @@ var OpenNebula = { }); }, + "show" : function(params) + { + var callback = params.success; + var callback_error = params.error; + var id = params.data.id; + + var resource = OpenNebula.User.resource; + var request = OpenNebula.Helper.request(resource,"show", id); + + $.ajax({ + url: "user/" + id, + type: "GET", + dataType: "json", + success: function(response) + { + if (callback) + { + callback(request, response); + } + }, + error: function(response) + { + if (callback_error) + { + callback_error(request, OpenNebula.Error(response)); + } + } + }); + }, + "delete": function(params) { var callback = params.success; @@ -1759,7 +1789,7 @@ var OpenNebula = { var action = OpenNebula.Helper.action(method, { "password" : passwd }); - + var resource = OpenNebula.User.resource; var request = OpenNebula.Helper.request(resource,method, passwd); @@ -1794,6 +1824,67 @@ var OpenNebula = { var action = OpenNebula.Helper.action(method, {"group_id": gid}); var request = OpenNebula.Helper.request(OpenNebula.User.resource,method, [id, gid]); + $.ajax({ + url: "user/" + id + "/action", + type: "POST", + data: JSON.stringify(action), + success: function() + { + if (callback) + { + callback(request); + } + }, + error: function(response) + { + if (callback_error) + { + callback_error(request, OpenNebula.Error(response)); + } + } + }); + }, + + "addgroup" : function(params){ + var callback = params.success; + var callback_error = params.error; + var id = params.data.id; + var gid = params.data.extra_param; + + var method = "addgroup"; + var action = OpenNebula.Helper.action(method, {"group_id": gid}); + var request = OpenNebula.Helper.request(OpenNebula.User.resource,method, [id, gid]); + + $.ajax({ + url: "user/" + id + "/action", + type: "POST", + data: JSON.stringify(action), + success: function() + { + if (callback) + { + callback(request); + } + }, + error: function(response) + { + if (callback_error) + { + callback_error(request, OpenNebula.Error(response)); + } + } + }); + }, + "delgroup" : function(params){ + var callback = params.success; + var callback_error = params.error; + var id = params.data.id; + var gid = params.data.extra_param; + + var method = "delgroup"; + var action = OpenNebula.Helper.action(method, {"group_id": gid}); + var request = OpenNebula.Helper.request(OpenNebula.User.resource,method, [id, gid]); + $.ajax({ url: "user/" + id + "/action", type: "POST", @@ -2012,7 +2103,7 @@ var OpenNebula = { var method = "enable"; var action = OpenNebula.Helper.action(method); - + var resource = OpenNebula.Image.resource; var request = OpenNebula.Helper.request(resource,method, id); @@ -2141,7 +2232,7 @@ var OpenNebula = { var method = "persistent"; var action = OpenNebula.Helper.action(method); - + var resource = OpenNebula.Image.resource; var request = OpenNebula.Helper.request(resource,method, id); @@ -2174,7 +2265,7 @@ var OpenNebula = { var method = "nonpersistent"; var action = OpenNebula.Helper.action(method); - + var resource = OpenNebula.Image.resource; var request = OpenNebula.Helper.request(resource,method, id); @@ -2207,10 +2298,10 @@ var OpenNebula = { OpenNebula.Helper.chgrp(params,OpenNebula.Image.resource,"image"); } }, - + "Template" : { "resource" : "VMTEMPLATE", - + "create" : function(params) { var callback = params.success; @@ -2240,7 +2331,7 @@ var OpenNebula = { } } }); - + }, "fetch_template" : function(params) { @@ -2283,7 +2374,7 @@ var OpenNebula = { var method = "update"; var action = OpenNebula.Helper.action(method, template_obj); - var resource = OpenNebula.Template.resource; + var resource = OpenNebula.Template.resource; var request = OpenNebula.Helper.request(resource,method, [id, template_obj]); $.ajax({ @@ -2427,7 +2518,7 @@ var OpenNebula = { callback_error(request, OpenNebula.Error(response)); } } - }); + }); }, "delete" : function(params) { @@ -2455,7 +2546,7 @@ var OpenNebula = { callback_error(request, OpenNebula.Error(response)); } } - }); + }); }, "chown" : function(params){ diff --git a/src/sunstone/public/js/plugins/groups-tab.js b/src/sunstone/public/js/plugins/groups-tab.js index be557a1ab9..e78b0870b2 100644 --- a/src/sunstone/public/js/plugins/groups-tab.js +++ b/src/sunstone/public/js/plugins/groups-tab.js @@ -14,7 +14,7 @@ /* limitations under the License. */ /* -------------------------------------------------------------------------- */ -var group_select=""; +var groups_select=""; var group_list_json = {}; var dataTable_groups; @@ -28,8 +28,8 @@ var groups_tab_content = \ All\ ID\ - Owner\ Name\ + Users\ \ \ \ @@ -157,11 +157,23 @@ Sunstone.addMainTab('groups_tab',groups_tab); function groupElementArray(group_json){ var group = group_json.GROUP; + + var users_str=""; + if (group.USERS.ID && + group.USERS.ID.constructor == Array){ + for (var i=0; i', group.ID, - getUserName(group.UID), - group.NAME ]; + group.NAME, + users_str ]; } function groupInfoListener(){ @@ -176,7 +188,7 @@ function groupInfoListener(){ } function updateGroupSelect(){ - groups_select = makeSelectOptions(dataTable_groups,1,3,-1,"",-1); + groups_select = makeSelectOptions(dataTable_groups,1,2,-1,"",-1); } function updateGroupElement(request, group_json){ diff --git a/src/sunstone/public/js/plugins/hosts-tab.js b/src/sunstone/public/js/plugins/hosts-tab.js index 0ae4eae897..35674a5c71 100644 --- a/src/sunstone/public/js/plugins/hosts-tab.js +++ b/src/sunstone/public/js/plugins/hosts-tab.js @@ -222,7 +222,7 @@ var host_actions = { "Host.update_dialog" : { type: "custom", call: function() { - popUpTemplateUpdateDialog("Host",hosts_select); + popUpTemplateUpdateDialog("Host",hosts_select,getSelectedNodes(dataTable_hosts)); } }, diff --git a/src/sunstone/public/js/plugins/images-tab.js b/src/sunstone/public/js/plugins/images-tab.js index 191fb0c5be..343f345fc5 100644 --- a/src/sunstone/public/js/plugins/images-tab.js +++ b/src/sunstone/public/js/plugins/images-tab.js @@ -223,7 +223,7 @@ var image_actions = { "Image.update_dialog" : { type: "custom", call: function() { - popUpTemplateUpdateDialog("Image",images_select); + popUpTemplateUpdateDialog("Image",images_select,getSelectedNodes(dataTable_images)); } }, @@ -442,8 +442,8 @@ function imageElementArray(image_json){ return [ '', image.ID, - getUserName(image.UID), - getGroupName(image.GID), + image.UNAME, + image.GNAME, image.NAME, OpenNebula.Helper.image_type(image.TYPE), pretty_time(image.REGTIME), @@ -530,6 +530,14 @@ function updateImageInfo(request,img){ Name\ '+img_info.NAME+'\ \ + \ + Owner\ + '+img_info.UNAME+'\ + \ + \ + Group\ + '+img_info.GNAME+'\ + \ \ Type\ '+OpenNebula.Helper.image_type(img_info.TYPE)+'\ diff --git a/src/sunstone/public/js/plugins/templates-tab.js b/src/sunstone/public/js/plugins/templates-tab.js index 3fc9d0d659..51646f88cd 100644 --- a/src/sunstone/public/js/plugins/templates-tab.js +++ b/src/sunstone/public/js/plugins/templates-tab.js @@ -591,7 +591,7 @@ var template_actions = { "Template.update_dialog" : { type: "custom", call: function() { - popUpTemplateUpdateDialog("Template",templates_select); + popUpTemplateUpdateDialog("Template",templates_select,getSelectedNodes(dataTable_templates)); } }, @@ -768,8 +768,8 @@ function templateElementArray(template_json){ return [ '', template.ID, - getUserName(template.UID), - getGroupName(template.GID), + template.UNAME, + template.GNAME, template.NAME, pretty_time(template.REGTIME), parseInt(template.PUBLIC) ? "yes" : "no" @@ -852,6 +852,14 @@ function updateTemplateInfo(request,template){ Name\ '+template_info.NAME+'\ \ + \ + Owner\ + '+template_info.UNAME+'\ + \ + \ + Group\ + '+template_info.GNAME+'\ + \ \ Register time\ '+pretty_time(template_info.REGTIME)+'\ diff --git a/src/sunstone/public/js/plugins/users-tab.js b/src/sunstone/public/js/plugins/users-tab.js index b1e9c9df12..dc8f568dfc 100644 --- a/src/sunstone/public/js/plugins/users-tab.js +++ b/src/sunstone/public/js/plugins/users-tab.js @@ -97,6 +97,46 @@ var user_actions = { notify: false }, + "User.chgrp" : { + type: "multiple", + call: OpenNebula.User.chgrp, + callback : function(req){ + Sunstone.runAction("User.show",req.request.data[0]); + }, + elements : function() {return getSelectedNodes(dataTable_users);}, + error: onError, + notify: true + }, + + "User.addgroup" : { + type: "multiple", + call: OpenNebula.User.addgroup, + callback : function(req){ + Sunstone.runAction("User.show",req.request.data[0]); + }, + elements : function() {return getSelectedNodes(dataTable_users);}, + error: onError, + notify: true + }, + + "User.delgroup" : { + type: "multiple", + call: OpenNebula.User.delgroup, + callback : function(req){ + Sunstone.runAction("User.show",req.request.data[0]); + }, + elements : function() {return getSelectedNodes(dataTable_users);}, + error: onError, + notify: true + }, + + "User.show" : { + type: "single", + call: OpenNebula.User.show, + callback: updateUserElement, + error: onError + }, + "User.delete" : { type: "multiple", call: OpenNebula.User.delete, @@ -119,6 +159,27 @@ var user_buttons = { text: "+ New", condition: True }, + "User.chgrp" : { + type: "confirm_with_select", + text: "Change main group", + select: function(){ return groups_select; }, + tip: "This will change the main group of the selected users. Select the new group:", + condition: True + }, + "User.addgroup" : { + type: "confirm_with_select", + text: "Add to group", + select: function(){ return groups_select; }, + tip: "Select the new group to add users:", + condition: True + }, + "User.delgroup" : { + type: "confirm_with_select", + text: "Delete from group", + select: function(){ return groups_select; }, + tip: "Select the group from which to delete users:", + condition: True + }, "User.delete" : { type: "action", text: "Delete", @@ -146,30 +207,38 @@ function userElementArray(user_json){ name = user.NAME; } - var i = 1; - var groups_str=getGroupName(user.GID)+", "; - var groups_full_str=getGroupName(user.GID)+", "; - var group_field; + var groups_str=""; + if (user.GROUPS.ID.constructor == Array){ //several groups + for (var i=0; i< user.GROUPS.ID.length; i++){ + groups_str+=getGroupName(user.GROUPS.ID[i])+', '; + }; + groups_str = groups_str.slice(0,-2); + } else { //one group + groups_str = getGroupName(user.GROUPS.ID); + }; - if (user.GROUPS.ID){ - $.each(user.GROUPS.ID,function() { - if (i<=5) { - groups_str+=getGroupName(this)+", "; - }; - groups_full_str+=getGroupName(this)+", "; - i++; - }); - if (i>0){ - groups_str = groups_str.slice(0, -2); - groups_full_str = groups_str.slice(0, -2); - }; - if (i>5){ - groups_str+="..."; - group_field = '
'+groups_str+'
'; - } else { - group_field=groups_str; - }; - } + // var groups_full_str=getGroupName(user.GID)+", "; + // var group_field; + + // if (user.GROUPS.ID){ + // $.each(user.GROUPS.ID,function() { + // if (i<=5) { + // groups_str+=getGroupName(this)+", "; + // }; + // groups_full_str+=getGroupName(this)+", "; + // i++; + // }); + // if (i>0){ + // groups_str = groups_str.slice(0, -2); + // groups_full_str = groups_str.slice(0, -2); + // }; + // if (i>5){ + // groups_str+="..."; + // group_field = '
'+groups_str+'
'; + // } else { + // group_field=groups_str; + // }; + // } @@ -177,7 +246,7 @@ function userElementArray(user_json){ '', user.ID, name, - group_field + groups_str ] } diff --git a/src/sunstone/public/js/plugins/vms-tab.js b/src/sunstone/public/js/plugins/vms-tab.js index 090d10e9d2..035423e7ec 100644 --- a/src/sunstone/public/js/plugins/vms-tab.js +++ b/src/sunstone/public/js/plugins/vms-tab.js @@ -580,8 +580,8 @@ function vMachineElementArray(vm_json){ return [ '', vm.ID, - getUserName(vm.UID), - getGroupName(vm.GID), + vm.UNAME, + vm.GNAME, vm.NAME, state, vm.CPU, @@ -659,6 +659,14 @@ function updateVMInfo(request,vm){ Name\ '+vm_info.NAME+'\ \ + \ + Owner\ + '+vm_info.UNAME+'\ + \ + \ + Group\ + '+vm_info.GNAME+'\ + \ \ State\ '+OpenNebula.Helper.resource_state("vm",vm_info.STATE)+'\ diff --git a/src/sunstone/public/js/plugins/vnets-tab.js b/src/sunstone/public/js/plugins/vnets-tab.js index 922a8d105f..8658d833fb 100644 --- a/src/sunstone/public/js/plugins/vnets-tab.js +++ b/src/sunstone/public/js/plugins/vnets-tab.js @@ -318,8 +318,8 @@ function vNetworkElementArray(vn_json){ return [ '', network.ID, - getUserName(network.UID), - getGroupName(network.GID), + network.UNAME, + network.GNAME, network.NAME, parseInt(network.TYPE) ? "FIXED" : "RANGED", network.BRIDGE, @@ -401,8 +401,12 @@ function updateVNetworkInfo(request,vn){ '+vn_info.ID+'\ \ \ - UID\ - '+vn_info.UID+'\ + Owner\ + '+vn_info.UNAME+'\ + \ + \ + Group\ + '+vn_info.GNAME+'\ \ \ Public\ diff --git a/src/sunstone/public/js/sunstone-util.js b/src/sunstone/public/js/sunstone-util.js index 8c43b26883..bfed8e919d 100644 --- a/src/sunstone/public/js/sunstone-util.js +++ b/src/sunstone/public/js/sunstone-util.js @@ -375,11 +375,17 @@ function waitingNodes(dataTable){ }; function getUserName(uid){ - return getName(uid,dataTable_users); + if (typeof(dataTable_users) != "undefined"){ + return getName(uid,dataTable_users); + } + return uid; } function getGroupName(gid){ - return getName(gid,dataTable_groups); + if (typeof(dataTable_groups) != "undefined"){ + return getName(gid,dataTable_groups); + } + return gid; } function getName(id,dataTable){ @@ -598,9 +604,13 @@ function setupTemplateUpdateDialog(){ $('#template_update_dialog #template_update_select').live("change",function(){ var id = $(this).val(); - var resource = $('#template_update_dialog #template_update_button').val(); - $('#template_update_dialog #template_update_textarea').val("Loading..."); - Sunstone.runAction(resource+".fetch_template",id); + if (id.length){ + var resource = $('#template_update_dialog #template_update_button').val(); + $('#template_update_dialog #template_update_textarea').val("Loading..."); + Sunstone.runAction(resource+".fetch_template",id); + } else { + $('#template_update_dialog #template_update_textarea').val(""); + } }); $('#template_update_dialog #template_update_button').click(function(){ @@ -613,10 +623,26 @@ function setupTemplateUpdateDialog(){ }); } -function popUpTemplateUpdateDialog(elem_str,select_items){ +function popUpTemplateUpdateDialog(elem_str,select_items,sel_elems){ $('#template_update_dialog #template_update_button').val(elem_str); $('#template_update_dialog #template_update_select').html(select_items); $('#template_update_dialog #template_update_textarea').val(""); + + if (sel_elems.length >= 1){ //several items in the list are selected + //grep them + var new_select= sel_elems.length > 1? '' : ""; + $('option','').each(function(){ + if ($.inArray($(this).val(),sel_elems) >= 0){ + new_select+=''; + }; + }); + $('#template_update_dialog #template_update_select').html(new_select); + if (sel_elems.length == 1) { + $('#template_update_dialog #template_update_select option').attr("selected","selected"); + $('#template_update_dialog #template_update_select').trigger("change"); + } + }; + $('#template_update_dialog').dialog('open'); return false; }