Author: jfthomps
Date: Mon Apr 30 15:59:22 2012
New Revision: 1332269

URL: http://svn.apache.org/viewvc?rev=1332269&view=rev
Log:
VCL-515
suggest available time when selection not available instead of showing time 
table

utils.php:
-modified findAvailableTimes - added check for nodes that have no controlling 
management node available; reworked check for concurrent use of image violations
-added fATconcurrentOverlap

requests.js: modified selectLater - set newsubmit button text to Create 
Reservation

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

Modified: incubator/vcl/trunk/web/.ht-inc/utils.php
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/web/.ht-inc/utils.php?rev=1332269&r1=1332268&r2=1332269&view=diff
==============================================================================
--- incubator/vcl/trunk/web/.ht-inc/utils.php (original)
+++ incubator/vcl/trunk/web/.ht-inc/utils.php Mon Apr 30 15:59:22 2012
@@ -6945,27 +6945,6 @@ function findAvailableTimes($start, $end
                }
        }
 
-       # remove slots that would cause a concurrent use violation
-       $imgdata = getImages(0, $imageid);
-       if($imgdata[$imageid]['maxconcurrent'] != NULL) {
-               $query = "SELECT UNIX_TIMESTAMP(rq.start) AS start, "
-                      .        "UNIX_TIMESTAMP(rq.end) AS end, "
-                      .        "rs.computerid AS compid "
-                      . "FROM request rq, "
-                      .      "reservation rs "
-                      . "WHERE rq.id = rs.requestid AND "
-                      .       "rs.imageid = $imageid AND "
-                      .       "rq.start < '$maxenddt' AND ";
-               if($reqid != '')
-                       $query .=   "rq.id != $reqid AND ";
-               $query .=      "rq.end > '$minstartdt'";
-               $qh = doQuery($query);
-               while($row = mysql_fetch_assoc($qh)) {
-                       if(array_key_exists($row['compid'], $slots))
-                               fATremoveOverlaps($slots, $row['compid'], 
$row['start'], $row['end'], 0);
-               }
-       }
-
        # remove slots overlapping with scheduled maintenance
        $query = "SELECT UNIX_TIMESTAMP(start) AS start, "
               .        "UNIX_TIMESTAMP(end) AS end, "
@@ -6980,6 +6959,7 @@ function findAvailableTimes($start, $end
                                          $row['allowreservations']);
        }
 
+       $imgdata = getImages(0, $imageid);
        $options = array();
        foreach($slots AS $comp) {
                foreach($comp AS $data) {
@@ -6992,6 +6972,15 @@ function findAvailableTimes($start, $end
                                elseif($data['duration'] > (SECINDAY * 2))
                                        $data['duration'] = $data['duration'] - 
($data['duration'] % SECINDAY);
                        }
+                       # skip computers that have no controlling management 
node
+                       if(! findManagementNode($data['compid'], 
$data['start'], 'future'))
+                               continue;
+                       # skip slots that would cause a concurrent use violation
+                       if($imgdata[$imageid]['maxconcurrent'] != NULL &&
+                               fATconcurrentOverlap($data['startts'], 
$data['duration'], $imageid,
+                                                    
$imgdata[$imageid]['maxconcurrent'], $ignorestates,
+                                                    $extendonly, $reqid))
+                               continue;
                        if(array_key_exists($data['startts'], $options)) {
                                if($data['duration'] > 
$options[$data['startts']]['duration']) {
                                        $options[$data['startts']]['duration'] 
= $data['duration'];
@@ -7084,6 +7073,49 @@ function fATremoveOverlaps(&$array, $com
 
 
////////////////////////////////////////////////////////////////////////////////
 ///
+/// \fn fATconcurrentOverlap($start, $length, $imageid, $maxoverlap,
+//                           $ignorestates, $extendonly, $reqid)
+///
+/// \param $start - start time (epoch time)
+/// \param $length - desired duration in seconds
+/// \param $imageid - id of image
+/// \param $maxoverlap - max allowed overlapping reservations for image
+/// \param $ignorestates - computers with these states should be ignored
+/// \param $extendonly - 1 if this is an extension, 0 otherwise
+/// \param $reqid - id of request if $extendonly is 1
+///
+/// \return 1 if this would violate max concurrent use of the image, 0 if not
+///
+/// \brief determines if a reservation during the specified time slot would
+/// violate the max concurrent reservations for $imageid
+///
+////////////////////////////////////////////////////////////////////////////////
+function fATconcurrentOverlap($start, $length, $imageid, $maxoverlap,
+                              $ignorestates, $extendonly, $reqid) {
+       $end = $start + $length;
+       $query = "SELECT rq.start, "
+              .        "rq.end "
+              . "FROM request rq, "
+              .      "reservation rs, "
+              .      "state s, "
+              .      "computer c "
+              . "WHERE rs.requestid = rq.id AND "
+              .       "rs.computerid = c.id AND "
+              .       "rs.imageid = $imageid AND "
+              .       "UNIX_TIMESTAMP(rq.start) < $end AND "
+              .       "UNIX_TIMESTAMP(rq.end) > $start AND "
+              .       "c.stateid = s.id AND "
+              .       "s.name NOT IN ($ignorestates)";
+       if($extendonly)
+               $query .= " AND rq.id != $reqid";
+       $qh = doQuery($query);
+       if(mysql_num_rows($qh) >= $maxoverlap)
+               return 1;
+       return 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+///
 /// \fn sortAvailableTimesByStart($a, $b)
 ///
 /// \param $a - first item

Modified: incubator/vcl/trunk/web/js/requests.js
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/web/js/requests.js?rev=1332269&r1=1332268&r2=1332269&view=diff
==============================================================================
--- incubator/vcl/trunk/web/js/requests.js (original)
+++ incubator/vcl/trunk/web/js/requests.js Mon Apr 30 15:59:22 2012
@@ -157,6 +157,8 @@ function useSuggestedSlot() {
 
 function selectLater() {
        dojo.byId('laterradio').checked = true;
+       if(dojo.byId('newsubmit'))
+               dojo.byId('newsubmit').value = 'Create Reservation';
        dojo.byId('waittime').innerHTML = '';
 }
 


Reply via email to