This is an automated email from the ASF dual-hosted git repository.

jfthomps pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/vcl.git


The following commit(s) were added to refs/heads/develop by this push:
     new 07687eb  VCL-1110 - expose maxinitial time for images in web UI
07687eb is described below

commit 07687eb6b412cd02dffd3262079336a551260526
Author: Josh Thompson <[email protected]>
AuthorDate: Thu Jan 31 14:53:30 2019 -0500

    VCL-1110 - expose maxinitial time for images in web UI
    
    image.php:
    -modified fieldWidth: added case for maxinitialtime
    -modified fieldDisplayName: change title for maxinitial time from "Max 
Initial Time" to "Max Reservation Duration"
    -modified addEditDialogHTML: added form item for maxinitialtime
    -modified AJsaveResource: added check for maxinitialtime being changed, and 
add to $updates array if changed
    -modified validateResourceData: added check for maxinitialtime
    
    requests.php: modified AJeditRequest: modified code that determines how 
long a reservation can be extended to include maxinitialtime for the image if 
it is set
    
    image.js:
    -modified colformatter: separated maxinitialtime out into its own 
conditional
    -modified inlineEditResourceCB: added line to set maxinitialtime to passed 
in value
    -modified saveResource: added code to validate maxinitialtime
    -modified saveResourceCB: added line to set maxinitialtime to passed in 
value
---
 web/.ht-inc/image.php     | 16 +++++++++++++++-
 web/.ht-inc/requests.php  |  9 +++++++++
 web/js/resources/image.js | 30 ++++++++++++++++++++++++++++--
 3 files changed, 52 insertions(+), 3 deletions(-)

diff --git a/web/.ht-inc/image.php b/web/.ht-inc/image.php
index 4e07dcd..8f7bc88 100644
--- a/web/.ht-inc/image.php
+++ b/web/.ht-inc/image.php
@@ -96,6 +96,7 @@ class Image extends Resource {
                                $w = 12;
                                break;
                        case 'adauthenabled':
+                       case 'maxinitialtime':
                                $w = 9;
                                break;
                        default:
@@ -146,7 +147,7 @@ class Image extends Resource {
                        case 'forcheckout':
                                return i("Available for Checkout");
                        case 'maxinitialtime':
-                               return i("Max Initial Time");
+                               return i("Max Reservation Duration");
                        case 'checkuser':
                                return i("Check Logged in User");
                        case 'rootaccess':
@@ -431,6 +432,10 @@ class Image extends Resource {
                $h .= "<div id=\"sethostnamediv\">\n";
                $h .= labeledFormItem('sethostname', i('Set Computer 
Hostname'), 'select', $yesno);
                $h .= "</div>\n";
+               # Max reservation time
+               $tmp = array('0' => 'Default for User');
+               $lengths = $tmp + getReservationLengths(201600);
+               $h .= labeledFormItem('maxinitialtime', i('Max Reservation 
Duration'), 'select', $lengths);
                # sysprep
                if($add) {
                        $h .= "<div id=\"sysprepdiv\">\n";
@@ -799,6 +804,9 @@ class Image extends Resource {
                # forcheckout
                if($data['checkout'] != $olddata['forcheckout'])
                        $updates[] = "forcheckout = {$data['checkout']}";
+               # maxinitialtime
+               if($data['maxinitialtime'] != $olddata['maxinitialtime'])
+                       $updates[] = "maxinitialtime = 
{$data['maxinitialtime']}";
                # description
                if($data['desc'] != $olddata['description']) {
                        $escdesc = vcl_mysql_escape_string($data['desc']);
@@ -1604,6 +1612,7 @@ class Image extends Resource {
        /// \b checkuser - reservations should be checked for a logged in user\n
        /// \b rootaccess\n
        /// \b sysprep - use sysprep when capturing revisions of this image\n
+       /// \b maxinitialtime - max time in minutes reservation can be used\n
        /// \b connectmethodids - ids of assigned connect methods\n
        /// \b requestid - requestid associated with image capture\n
        /// \b imageid - id of base image\n
@@ -1635,6 +1644,7 @@ class Image extends Resource {
                $return["checkuser"] = processInputVar("checkuser", 
ARG_NUMERIC);
                $return["rootaccess"] = processInputVar("rootaccess", 
ARG_NUMERIC);
                $return["sethostname"] = processInputVar("sethostname", 
ARG_NUMERIC);
+               $return["maxinitialtime"] = processInputVar("maxinitialtime", 
ARG_NUMERIC);
                $return["sysprep"] = processInputVar("sysprep", ARG_NUMERIC); # 
only in add
                $return["connectmethodids"] = 
processInputVar("connectmethodids", ARG_STRING); # only in add
                $return["adauthenabled"] = processInputVar("adauthenabled", 
ARG_NUMERIC);
@@ -1741,6 +1751,10 @@ class Image extends Resource {
                        $return['error'] = 1;
                        $errormsg[] = i("Set Computer Hostname must be Yes or 
No");
                }
+               if($return['maxinitialtime'] < 0 || $return['maxinitialtime'] > 
201600) {
+                       $return['error'] = 1;
+                       $errormsg[] = i("Invalid Max Reservation Duration 
selected");
+               }
                if($return['mode'] == 'add' && $return['sysprep'] != 0 &&
                   $return['sysprep'] != 1) {
                        $return['error'] = 1;
diff --git a/web/.ht-inc/requests.php b/web/.ht-inc/requests.php
index ab13923..565c53c 100644
--- a/web/.ht-inc/requests.php
+++ b/web/.ht-inc/requests.php
@@ -3353,8 +3353,12 @@ function AJeditRequest() {
                return;
        }
        # check for max time being reached
+       $imgdata = getImages(1, $request['reservations'][0]['imageid']);
+       $maximglen = 
$imgdata[$request['reservations'][0]['imageid']]['maxinitialtime'];
        if($request['forimaging'] && $maxtimes['total'] < 720)
                $maxcheck = 720;
+       elseif(! $request['forimaging'] && $maximglen)
+               $maxcheck = $maximglen;
        else
                $maxcheck = $maxtimes['total'];
        if(! $openend && ($reslen >= $maxcheck)) {
@@ -3410,6 +3414,11 @@ function AJeditRequest() {
        $lengths = array();
        if($request['forimaging'] && $maxtimes['total'] < 720) # make sure at 
least 12 hours available for imaging reservations
                $maxtimes['total'] = 720;
+       elseif(! $request['forimaging'] && $maximglen) {
+               $maxtimes['total'] = $maximglen;
+               $currduration = (datetimeToUnix($request['end']) - 
datetimeToUnix($request['start'])) / 60;
+               $maxtimes['extend'] = $maximglen - $currduration;
+       }
        if($timeToNext == -1) {
                if($nousercheck)
                        $lengths["0"] = "No change";
diff --git a/web/js/resources/image.js b/web/js/resources/image.js
index dad3f47..b710c55 100644
--- a/web/js/resources/image.js
+++ b/web/js/resources/image.js
@@ -36,10 +36,29 @@ Image.prototype.colformatter = function(value, rowIndex, 
obj) {
                if(value == "1")
                        return '<span class="ready">' + _('true') + '</span>';
        }
-       if((obj.field == 'maxinitialtime' && value == 0) ||
-          (obj.field == 'addomain' && value == null) ||
+       if((obj.field == 'addomain' && value == null) ||
           (obj.field == 'baseOU' && value == null))
                return '(' + _('unset') + ')';
+       if(obj.field == 'maxinitialtime') {
+               if(value == 0) {
+                       return _('Default for User');
+               }
+               else if(value < 60) {
+                       return value + ' ' + _('minutes');
+               }
+               else if(value == 60) {
+                       return _('1 hour');
+               }
+               else if(value < 2880) {
+                       return parseInt(value / 60) + ' ' + _('hours');
+               }
+               else if(value <= 64800) {
+                       return parseInt(value / 1440) + ' ' + _('days');
+               }
+               else {
+                       return parseInt(value / 10080) + ' ' + _('weeks');
+               }
+       }
        return value;
 }
 
@@ -67,6 +86,7 @@ function inlineEditResourceCB(data, ioArgs) {
                dijit.byId('checkuser').set('value', data.items.data.checkuser);
                dijit.byId('rootaccess').set('value', 
data.items.data.rootaccess);
                dijit.byId('sethostname').set('value', 
data.items.data.sethostname);
+               dijit.byId('maxinitialtime').set('value', 
data.items.data.maxinitialtime);
                if(data.items.data.ostype == 'windows' || 
data.items.data.ostype == 'linux')
                        dojo.removeClass('sethostnamediv', 'hidden');
                else
@@ -257,6 +277,11 @@ function saveResource() {
                        return;
                }
        }
+       data['maxinitialtime'] = 
parseInt(dijit.byId('maxinitialtime').get('value'));
+       if(data['maxinitialtime'] < 0 || data['maxinitialtime'] > 201600) {
+               errobj.innerHTML = _('Invalid Max Reservation Duration 
selected');
+               return;
+       }
        if(dijit.byId('sysprep')) {
                data['sysprep'] = parseInt(dijit.byId('sysprep').get('value'));
                if(data['sysprep'] != 0 && data['sysprep'] != 1) {
@@ -341,6 +366,7 @@ function saveResourceCB(data, ioArgs) {
                                        resourcegrid.store.setValue(item, 
'checkuser', data.items.data.checkuser);
                                        resourcegrid.store.setValue(item, 
'rootaccess', parseInt(data.items.data.rootaccess));
                                        resourcegrid.store.setValue(item, 
'sethostname', parseInt(data.items.data.sethostname));
+                                       resourcegrid.store.setValue(item, 
'maxinitialtime', parseInt(data.items.data.maxinitialtime));
                                        resourcegrid.store.setValue(item, 
'reloadtime', data.items.data.reloadtime);
                                        resourcegrid.store.setValue(item, 
'adauthenabled', data.items.data.adauthenabled);
                                        resourcegrid.store.setValue(item, 
'addomainid', data.items.data.addomainid);

Reply via email to