From: Marcin Haba Date: Sun, 28 Feb 2016 16:23:25 +0000 (+0100) Subject: baculum: Show jobs stored on volume X-Git-Tag: Release-7.4.1~26 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=27765d1b7544edcdc48e20ccc5a8588ee26f69d3;p=bacula%2Fbacula baculum: Show jobs stored on volume --- diff --git a/gui/baculum/protected/Class/JobManager.php b/gui/baculum/protected/Class/JobManager.php index 729b806157..f08a27001b 100644 --- a/gui/baculum/protected/Class/JobManager.php +++ b/gui/baculum/protected/Class/JobManager.php @@ -113,5 +113,23 @@ class JobManager extends TModule { $pdo = null; return $jobtotals; } + + /** + * Get jobs stored on given volume. + * + * @param string $mediaid volume identifier + * @param array $allowed_jobs jobs allowed to show + * @return array jobs stored on volume + */ + public function getJobsOnVolume($mediaid, $allowed_jobs = array()) { + $jobs_criteria = ''; + if (count($allowed_jobs) > 0) { + $jobs_sql = implode("', '", $allowed_jobs); + $jobs_criteria = " AND Job.Name IN ('" . $jobs_sql . "')"; + } + $sql = "SELECT DISTINCT Job.* FROM Job, JobMedia WHERE JobMedia.MediaId='$mediaid' AND JobMedia.JobId=Job.JobId $jobs_criteria"; + return JobRecord::finder()->findAllBySql($sql); + } + } ?> diff --git a/gui/baculum/protected/JavaScript/misc.js b/gui/baculum/protected/JavaScript/misc.js index 4c1f6d044d..bec1322cd0 100644 --- a/gui/baculum/protected/JavaScript/misc.js +++ b/gui/baculum/protected/JavaScript/misc.js @@ -1,21 +1,30 @@ var Units = { get_decimal_size: function(size) { + var dec_size; + var size_unit = 'B'; + var units = ['K', 'M', 'G', 'T', 'P']; + if (size === null) { size = 0; } - size = parseInt(size, 10); - var size_unit = 'B'; - var units = ['K', 'M', 'G', 'T', 'P']; - var unit; - var dec_size = size.toString() + ((size > 0 ) ? size_unit : ''); - while(size >= 1000) { - size /= 1000; - unit = units.shift(units); - } - if (unit) { - dec_size = (Math.floor(size * 10) / 10).toFixed(1); - dec_size += unit + size_unit; + var size_pattern = new RegExp('^[\\d\\.]+(' + units.join('|') + ')?' + size_unit + '$'); + + if (size_pattern.test(size.toString())) { + // size is already formatted + dec_size = size; + } else { + size = parseInt(size, 10); + var unit; + dec_size = size.toString() + ((size > 0 ) ? size_unit : ''); + while(size >= 1000) { + size /= 1000; + unit = units.shift(units); + } + if (unit) { + dec_size = (Math.floor(size * 10) / 10).toFixed(1); + dec_size += unit + size_unit; + } } return dec_size; } diff --git a/gui/baculum/protected/JavaScript/slide-window.js b/gui/baculum/protected/JavaScript/slide-window.js index 557b6e826d..423566ce13 100644 --- a/gui/baculum/protected/JavaScript/slide-window.js +++ b/gui/baculum/protected/JavaScript/slide-window.js @@ -316,8 +316,8 @@ var SlideWindowClass = Class.create({ return is_open; }, - sortTable: function (col, reverse, set_cookie) { - var table = document.getElementById(this.gridEl); + sortTable: function (grid_id, col, reverse, set_cookie) { + var table = document.getElementById(grid_id); var tb = table.tBodies[0], tr = Array.prototype.slice.call(tb.rows, 0), i; reverse = -((+reverse) || -1); tr = tr.sort(function (a, b) { @@ -353,9 +353,18 @@ var SlideWindowClass = Class.create({ } }, - makeSortable: function () { + makeSortable: function (grid) { var self = this; - var table = document.getElementById(this.gridEl); + var grid_id, set_cookie; + if (grid) { + grid_id = grid; + // for external grids (non-slide) do not remember sorting order + set_cookie = false; + } else { + grid_id = this.gridEl; + set_cookie = true; + } + var table = document.getElementById(grid_id); table.tHead.style.cursor = 'pointer'; var th = table.tHead, i; th && (th = th.rows[0]) && (th = th.cells); @@ -372,7 +381,7 @@ var SlideWindowClass = Class.create({ while (--i >= downCounter) (function (i) { var dir = 1; th[i].addEventListener('click', function () { - self.sortTable(i, (dir = 1 - dir), true); + self.sortTable(grid_id, i, (dir = 1 - dir), set_cookie); }); }(i)); }, @@ -383,7 +392,7 @@ var SlideWindowClass = Class.create({ var sort_param = sorting.split(':'); var col = parseInt(sort_param[0], 10); var order = -(parseInt(sort_param[1], 10)); - this.sortTable(col, order); + this.sortTable(this.gridEl, col, order); } }, diff --git a/gui/baculum/protected/Lang/en/messages.mo b/gui/baculum/protected/Lang/en/messages.mo index 474318dcf0..5fc682c7ea 100644 Binary files a/gui/baculum/protected/Lang/en/messages.mo and b/gui/baculum/protected/Lang/en/messages.mo differ diff --git a/gui/baculum/protected/Lang/en/messages.po b/gui/baculum/protected/Lang/en/messages.po index 08e8266ff8..3b630625d7 100644 --- a/gui/baculum/protected/Lang/en/messages.po +++ b/gui/baculum/protected/Lang/en/messages.po @@ -1136,3 +1136,9 @@ msgstr "Please note that for each user (excluding administrator) there should ex msgid "Invalid login value. Login may contain a-z A-Z 0-9 characters." msgstr "Invalid login value. Login may contain a-z A-Z 0-9 characters." +msgid "Jobs on Volume" +msgstr "Jobs on Volume" + +msgid "No jobs on the volume." +msgstr "No jobs on the volume." + diff --git a/gui/baculum/protected/Lang/pl/messages.mo b/gui/baculum/protected/Lang/pl/messages.mo index a309360e05..7b2fe04242 100644 Binary files a/gui/baculum/protected/Lang/pl/messages.mo and b/gui/baculum/protected/Lang/pl/messages.mo differ diff --git a/gui/baculum/protected/Lang/pl/messages.po b/gui/baculum/protected/Lang/pl/messages.po index f04920467f..6b6f6c04f0 100644 --- a/gui/baculum/protected/Lang/pl/messages.po +++ b/gui/baculum/protected/Lang/pl/messages.po @@ -1137,3 +1137,9 @@ msgstr "Uwaga! Dla każdego użytkownika (wyłączając administratora) powinien msgid "Invalid login value. Login may contain a-z A-Z 0-9 characters." msgstr "Niepoprawny login. Login może zawierać znaki z zakresu: a-z A-Z 0-9" +msgid "Jobs on Volume" +msgstr "Zadania na volumenie" + +msgid "No jobs on the volume." +msgstr "Na wolumenie nie ma żadnych zadań." + diff --git a/gui/baculum/protected/Lang/pt/messages.mo b/gui/baculum/protected/Lang/pt/messages.mo index 53e55e53d5..73e8e97cac 100644 Binary files a/gui/baculum/protected/Lang/pt/messages.mo and b/gui/baculum/protected/Lang/pt/messages.mo differ diff --git a/gui/baculum/protected/Lang/pt/messages.po b/gui/baculum/protected/Lang/pt/messages.po index 5493c2ef22..75c6eedc52 100644 --- a/gui/baculum/protected/Lang/pt/messages.po +++ b/gui/baculum/protected/Lang/pt/messages.po @@ -1139,3 +1139,9 @@ msgstr "Atenção, cada usuário (com excessão do usuário administrador) preci msgid "Invalid login value. Login may contain a-z A-Z 0-9 characters." msgstr "Usuário inválido! O usuário deve conter apenas os seguintes caracteres [a-z A-Z 0-9]." +msgid "Jobs on Volume" +msgstr "Jobs on Volume" + +msgid "No jobs on the volume." +msgstr "No jobs on the volume." + diff --git a/gui/baculum/protected/Pages/API/JobsOnVolume.php b/gui/baculum/protected/Pages/API/JobsOnVolume.php new file mode 100644 index 0000000000..ef785a1d50 --- /dev/null +++ b/gui/baculum/protected/Pages/API/JobsOnVolume.php @@ -0,0 +1,46 @@ +Request['id']); + $error = false; + if (!is_null($this->user)) { + $allowed_jobs = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs'), $this->user); + if ($allowed_jobs->exitcode === 0) { + $allowed = $allowed_jobs->output; + } else { + $error = true; + $this->output = $allowed_jobs->output; + $this->error = $allowed_jobs->exitcode; + } + } + + if ($error === false) { + $jobs = $this->getModule('job')->getJobsOnVolume($mediaid, $allowed); + $this->output = $jobs; + $this->error = JobError::ERROR_NO_ERRORS; + } + } +} +?> diff --git a/gui/baculum/protected/Portlets/VolumeConfiguration.php b/gui/baculum/protected/Portlets/VolumeConfiguration.php index efa8fc14cd..e9e0215528 100644 --- a/gui/baculum/protected/Portlets/VolumeConfiguration.php +++ b/gui/baculum/protected/Portlets/VolumeConfiguration.php @@ -21,6 +21,7 @@ */ Prado::using('System.Web.UI.ActiveControls.TActiveDropDownList'); +Prado::using('System.Web.UI.ActiveControls.TActiveDataGrid'); Prado::using('System.Web.UI.ActiveControls.TActiveLabel'); Prado::using('System.Web.UI.ActiveControls.TActiveTextBox'); Prado::using('System.Web.UI.ActiveControls.TActiveCheckBox'); @@ -65,6 +66,10 @@ class VolumeConfiguration extends Portlets { $this->Pool->dataSource = $poolList; $this->Pool->SelectedValue = $voldata->poolid; $this->Pool->dataBind(); + + $jobs_on_volume = $this->Application->getModule('api')->get(array('volumes', 'jobs', $voldata->mediaid))->output; + $this->JobsOnVolume->DataSource = $this->Application->getModule('misc')->objectToArray($jobs_on_volume); + $this->JobsOnVolume->dataBind(); } public function prune($sender, $param) { @@ -96,6 +101,11 @@ class VolumeConfiguration extends Portlets { $this->Application->getModule('api')->set(array('volumes', $voldata['mediaid']), $voldata); } + public function openJob($sender, $param) { + $jobid = $param->CallbackParameter; + $this->getPage()->JobConfiguration->configure($jobid); + } + public function getVolumeStates($forSetOnly = false) { $states = ($forSetOnly === true ) ? $this->volumeStatesForSet : array_merge($this->volumeStatesByDirectorOnly, $this->volumeStatesForSet); return $states; diff --git a/gui/baculum/protected/Portlets/VolumeConfiguration.tpl b/gui/baculum/protected/Portlets/VolumeConfiguration.tpl index 584f80e00c..4b7070295e 100644 --- a/gui/baculum/protected/Portlets/VolumeConfiguration.tpl +++ b/gui/baculum/protected/Portlets/VolumeConfiguration.tpl @@ -2,104 +2,199 @@ <%[ Volume name: ]%> -
- -
-
-
- + <%[ Actions ]%> + <%[ Jobs on Volume ]%> +
+
+ +
+
+
+ +
-
-
-
-
- - +
+
+
+ + +
-
-
-
-
- +
+
+
+ +
-
-
-
-
- - +
+
+
+ + +
-
-
-
-
- - +
+
+
+ + +
-
-
-
-
- - +
+
+
+ + +
-
-
-
-
- - +
+
+
+ + +
-
-
-
-
- - +
+
+
+ + +
-
-
-
-
-
-
-
-
-
-
-
-
-
- - -
- - - + +
+ + + +
+
+ diff --git a/gui/baculum/protected/Portlets/VolumeList.tpl b/gui/baculum/protected/Portlets/VolumeList.tpl index 59570fed82..382e05588d 100644 --- a/gui/baculum/protected/Portlets/VolumeList.tpl +++ b/gui/baculum/protected/Portlets/VolumeList.tpl @@ -72,6 +72,8 @@ ConfigurationWindow.getObj('VolumeWindow').show(); + Formatters.set_formatters(); + bind_jobs_on_volume_action(); ConfigurationWindow.getObj('VolumeWindow').progress(false); diff --git a/gui/baculum/protected/application.xml b/gui/baculum/protected/application.xml index 7f4c77477b..38cf970894 100644 --- a/gui/baculum/protected/application.xml +++ b/gui/baculum/protected/application.xml @@ -45,6 +45,7 @@ +