Author: jfthomps
Date: Mon Oct  3 18:57:10 2011
New Revision: 1178519

URL: http://svn.apache.org/viewvc?rev=1178519&view=rev
Log:
VCL-400
virtual hosts page shows all unassigned vms instead of checking which ones the 
user can access

vm.php:
modified editVMInfo - added section (noaccessdiv) to display assigned VMs user 
does not have access to remove
modified vmhostdata - added $noaccess - contains assigned VMs that user does 
not have access to remove from host; don't put unassigned VMs user has no 
access to in $freevms or $allvms

vm.js - modified VMHostDataCB - unhide and populate noaccessdiv if there are 
assigned VMs that user does not have access to remove; hide it if user has 
access to all VMs

Modified:
    incubator/vcl/trunk/web/.ht-inc/vm.php
    incubator/vcl/trunk/web/js/vm.js

Modified: incubator/vcl/trunk/web/.ht-inc/vm.php
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/web/.ht-inc/vm.php?rev=1178519&r1=1178518&r2=1178519&view=diff
==============================================================================
--- incubator/vcl/trunk/web/.ht-inc/vm.php (original)
+++ incubator/vcl/trunk/web/.ht-inc/vm.php Mon Oct  3 18:57:10 2011
@@ -120,6 +120,10 @@ function editVMInfo() {
                print "</select><br>\n";
                print "State of selected vm:<br>\n";
                print "<span id=vmstate></span>\n";
+               print "<div id=\"noaccessdiv\" class=\"hidden\"><hr>VMs 
assigned to ";
+               print "host that you<br>do not have access to 
remove:<br><br>\n";
+               print "<div id=\"noaccess\"></div>\n";
+               print "</div>\n";
                print "</td>\n";
                # transfer buttons
                print "<td style=\"vertical-align: middle;\">\n";
@@ -308,6 +312,7 @@ function vmhostdata() {
                sendJSON(array('failed' => 'noaccess'));
                return;
        }
+       $computers = $resources['computer'];
 
        # get vms assigned to vmhost
        $query = "SELECT c.id, "
@@ -326,18 +331,24 @@ function vmhostdata() {
        $ids = array();
        $allvms = array();
        $currvms = array();
+       $noaccess = array();
        $freevms = array();
        while($row = mysql_fetch_assoc($qh)) {
                if($row['vmhostid'] == $vmhostid) {
                        $ids[$row['id']] = $row['hostname'];
-                       $currvms[$row['id']] = array('id' => $row['id'],
-                                                    'name' => $row['hostname'],
-                                                    'state' => $row['state']);
+                       if(array_key_exists($row['id'], $computers))
+                               $currvms[$row['id']] = array('id' => $row['id'],
+                                                            'name' => 
$row['hostname'],
+                                                            'state' => 
$row['state']);
+                       else
+                               $noaccess[$row['id']] = array('id' => 
$row['id'],
+                                                             'name' => 
$row['hostname'],
+                                                             'state' => 
$row['state']);
                        $allvms[] = array('id' => $row['id'],
                                          'name' => $row['hostname'],
                                          'inout' => 1);
                }
-               else {
+               elseif(array_key_exists($row['id'], $computers)) {
                        $freevms[] = array('id' => $row['id'],
                                           'name' => $row['hostname']);
                        $allvms[] = array('id' => $row['id'],
@@ -347,6 +358,7 @@ function vmhostdata() {
        }
        uasort($allvms, "sortKeepIndex");
        uasort($currvms, "sortKeepIndex");
+       uasort($noaccess, "sortKeepIndex");
        uasort($freevms, "sortKeepIndex");
 
        $keys = array_keys($ids);
@@ -376,6 +388,7 @@ function vmhostdata() {
 
        $allvms = array_merge($allvms);
        $currvms = array_merge($currvms);
+       $noaccess = array_merge($noaccess);
        $freevms = array_merge($freevms);
        $cont = addContinuationsEntry('AJchangeVMprofile', array(), 3600, 1, 0);
        $arr = array('vmlimit' => $data[$vmhostid]['vmlimit'],
@@ -383,6 +396,7 @@ function vmhostdata() {
                     'continuation' => $cont,
                     'allvms' => $allvms,
                     'currvms' => $currvms,
+                    'noaccess' => $noaccess,
                     'freevms' => $freevms,
                     'movevms' => $movevms);
        sendJSON($arr);

Modified: incubator/vcl/trunk/web/js/vm.js
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/web/js/vm.js?rev=1178519&r1=1178518&r2=1178519&view=diff
==============================================================================
--- incubator/vcl/trunk/web/js/vm.js (original)
+++ incubator/vcl/trunk/web/js/vm.js Mon Oct  3 18:57:10 2011
@@ -99,6 +99,18 @@ function VMHostDataCB(data, ioArgs) {
        for(var i = 0; i < data.items.freevms.length; i++) {
                outobj.options[outobj.options.length] = new 
Option(data.items.freevms[i].name, data.items.freevms[i].id);
        }
+       if(data.items.noaccess.length) {
+               dojo.removeClass('noaccessdiv', 'hidden');
+               var tmp = new Array();
+               for(var i = 0; i < data.items.noaccess.length; i++) {
+                       tmp.push(data.items.noaccess[i].name);
+               }
+               dojo.byId('noaccess').innerHTML = tmp.join('<br>');
+       }
+       else {
+               dojo.addClass('noaccessdiv', 'hidden');
+               dojo.byId('noaccess').innerHTML = '';
+       }
 
        if(data.items.movevms.length) {
                document.getElementById('movevms').className = 'shown';


Reply via email to