]> git.sur5r.net Git - bacula/bacula/commitdiff
baculum: Set default job attributes (level, client, fileset, pool, storage, priority...
authorMarcin Haba <marcin.haba@bacula.pl>
Sat, 12 Dec 2015 12:54:34 +0000 (13:54 +0100)
committerMarcin Haba <marcin.haba@bacula.pl>
Sat, 12 Dec 2015 12:54:34 +0000 (13:54 +0100)
gui/baculum/protected/Portlets/JobConfiguration.php
gui/baculum/protected/Portlets/JobRunConfiguration.php

index b32b86681acbb1d69405959e4e9786a959f54b62..ba3fddb6ec240de48b4c8f9ba415b5ea69d54bbe 100644 (file)
@@ -29,6 +29,7 @@ class JobConfiguration extends Portlets {
        const DEFAULT_JOB_PRIORITY = 10;
 
        const RESOURCE_SHOW_PATTERN = '/^\s+--> %resource: name=(.+?(?=\s\S+\=.+)|.+$)/i';
+       const JOB_SHOW_PATTERN = '/^Job:\sname=(?P<jobname>.+)\sJobType=\d+\slevel=(?P<level>\w+)\sPriority=(?P<priority>\d+)/i';
 
        public $jobToVerify = array('C', 'O', 'd');
 
@@ -230,7 +231,7 @@ class JobConfiguration extends Portlets {
                return $verifyVals;
        }
 
-       private function getResourceName($resource, $jobshow) {
+       public function getResourceName($resource, $jobshow) {
                $resource_name = null;
                $pattern = str_replace('%resource', $resource, self::RESOURCE_SHOW_PATTERN);
                for ($i = 0; $i < count($jobshow); $i++) {
@@ -242,6 +243,19 @@ class JobConfiguration extends Portlets {
                return $resource_name;
        }
 
+       public function getJobAttr($jobshow) {
+               $attr = array();
+               for ($i = 0; $i < count($jobshow); $i++) {
+                       if (preg_match(self::JOB_SHOW_PATTERN, $jobshow[$i], $match) === 1) {
+                               $attr['jobname'] = $match['jobname'];
+                               $attr['level'] = $match['level'];
+                               $attr['priority'] = $match['priority'];
+                               break;
+                       }
+               }
+               return $attr;
+       }
+
        private function getPoolByName($name) {
                $pool = null;
                $pools = $this->Application->getModule('api')->get(array('pools'), true)->output;
index f3ea6a000699f03163bc9220c3a986d8f42eb867..f56e3eef4c807658cb61cda9e065ac30fe9b9ff6 100644 (file)
@@ -32,15 +32,26 @@ class JobRunConfiguration extends Portlets {
        public $verifyOptions = array('jobname' => 'Verify by Job Name', 'jobid' => 'Verify by JobId');
 
        public function configure($jobname) {
+               $jobshow = $this->Application->getModule('api')->get(array('jobs', 'show', 'name', rawurlencode($jobname)), true)->output;
+
                $this->JobName->Text = $jobname;
                $this->Estimation->Text = '';
 
-               $this->Level->dataSource = $this->Application->getModule('misc')->getJobLevels();
+               $levels = $this->Application->getModule('misc')->getJobLevels();
+               $jobAttr = $this->getPage()->JobConfiguration->getJobAttr($jobshow);
+               $levelsFlip = array_flip($levels);
+
+               $this->Level->dataSource = $levels;
+               if (array_key_exists('level', $jobAttr) && array_key_exists($jobAttr['level'], $levelsFlip)) {
+                       $this->Level->SelectedValue = $levelsFlip[$jobAttr['level']];
+
+                       $isVerifyOption = in_array($levelsFlip[$jobAttr['level']], $this->getPage()->JobConfiguration->jobToVerify);
+                       $this->JobToVerifyOptionsLine->Display = ($isVerifyOption === true) ? 'Dynamic' : 'None';
+                       $this->JobToVerifyJobNameLine->Display = ($isVerifyOption === true) ? 'Dynamic' : 'None';
+                       $this->JobToVerifyJobIdLine->Display = 'None';
+               }
                $this->Level->dataBind();
 
-               $this->JobToVerifyOptionsLine->Display = 'None';
-               $this->JobToVerifyJobNameLine->Display = 'None';
-               $this->JobToVerifyJobIdLine->Display = 'None';
                $this->AccurateLine->Display = 'Dynamic';
                $this->EstimateLine->Display = 'Dynamic';
 
@@ -64,38 +75,58 @@ class JobRunConfiguration extends Portlets {
                $this->JobToVerifyJobName->dataBind();
 
                $clients = $this->Application->getModule('api')->get(array('clients'), true)->output;
+               $selectedClient = $this->getPage()->JobConfiguration->getResourceName('client', $jobshow);
+               $selectedClientId = null;
                $clientsList = array();
                foreach($clients as $client) {
+                       if ($client->name === $selectedClient) {
+                               $selectedClientId = $client->clientid;
+                       }
                        $clientsList[$client->clientid] = $client->name;
                }
                $this->Client->dataSource = $clientsList;
+               $this->Client->SelectedValue = $selectedClientId;
                $this->Client->dataBind();
 
                $filesetsAll = $this->Application->getModule('api')->get(array('filesets'), true)->output;
+               $selectedFileset = $this->getPage()->JobConfiguration->getResourceName('fileset', $jobshow);
                $filesetsList = array();
                foreach($filesetsAll as $director => $filesets) {
                        $filesetsList = array_merge($filesets, $filesetsList);
                }
                $this->FileSet->dataSource = array_combine($filesetsList, $filesetsList);
+               $this->FileSet->SelectedValue = $selectedFileset;
                $this->FileSet->dataBind();
 
                $pools = $this->Application->getModule('api')->get(array('pools'), true)->output;
+               $selectedPool = $this->getPage()->JobConfiguration->getResourceName('pool', $jobshow);
+               $selectedPoolId = null;
                $poolList = array();
                foreach($pools as $pool) {
+                       if ($pool->name === $selectedPool) {
+                               $selectedPoolId = $pool->poolid;
+                       }
                        $poolList[$pool->poolid] = $pool->name;
                }
                $this->Pool->dataSource = $poolList;
+               $this->Pool->SelectedValue = $selectedPoolId;
                $this->Pool->dataBind();
 
                $storages = $this->Application->getModule('api')->get(array('storages'), true)->output;
+               $selectedStorage = $this->getPage()->JobConfiguration->getResourceName('storage', $jobshow);
+               $selectedStorageId = null;
                $storagesList = array();
                foreach($storages as $storage) {
+                       if ($storage->name === $selectedStorage) {
+                               $selectedStorageId = $storage->storageid;
+                       }
                        $storagesList[$storage->storageid] = $storage->name;
                }
                $this->Storage->dataSource = $storagesList;
+               $this->Storage->SelectedValue = $selectedStorageId;
                $this->Storage->dataBind();
 
-               $this->Priority->Text = self::DEFAULT_JOB_PRIORITY;
+               $this->Priority->Text = array_key_exists('priority', $jobAttr) ? $jobAttr['priority'] : self::DEFAULT_JOB_PRIORITY;
        }
 
        public function run_job($sender, $param) {