From c843d47ccc636bc274bb28497071752103157e36 Mon Sep 17 00:00:00 2001 From: Marcin Haba Date: Sat, 29 Nov 2014 16:38:42 +0100 Subject: [PATCH] baculum: Add possibility to execute actions on multiple volumes and jobs at a time + code refactor --- .../JavaScript/configuration-window.js | 27 +++- .../protected/JavaScript/slide-window.js | 150 +++++++++++++++++- gui/baculum/protected/Pages/Home.page | 24 +-- .../Portlets/ClientConfiguration.php | 35 ++-- .../Portlets/ClientConfiguration.tpl | 24 +-- gui/baculum/protected/Portlets/ClientList.php | 42 +++-- gui/baculum/protected/Portlets/ClientList.tpl | 12 +- .../protected/Portlets/ConfigurationPanel.tpl | 10 +- .../protected/Portlets/ISlideWindow.php | 34 ++++ .../protected/Portlets/JobConfiguration.php | 92 +++++------ .../protected/Portlets/JobConfiguration.tpl | 29 ++-- gui/baculum/protected/Portlets/JobList.php | 76 +++++++-- gui/baculum/protected/Portlets/JobList.tpl | 18 ++- .../Portlets/JobRunConfiguration.php | 62 +++----- .../Portlets/JobRunConfiguration.tpl | 22 +-- gui/baculum/protected/Portlets/JobRunList.php | 56 +++++-- gui/baculum/protected/Portlets/JobRunList.tpl | 12 +- .../protected/Portlets/PoolConfiguration.php | 46 ++++-- .../protected/Portlets/PoolConfiguration.tpl | 34 ++-- gui/baculum/protected/Portlets/PoolList.php | 32 +++- gui/baculum/protected/Portlets/PoolList.tpl | 12 +- gui/baculum/protected/Portlets/Portlets.php | 2 +- .../protected/Portlets/SlideWindow.php | 29 +++- .../protected/Portlets/SlideWindow.tpl | 92 ++++++++--- .../Portlets/StorageConfiguration.php | 69 ++++---- .../Portlets/StorageConfiguration.tpl | 5 +- .../protected/Portlets/StorageList.php | 41 +++-- .../protected/Portlets/StorageList.tpl | 12 +- .../Portlets/VolumeConfiguration.php | 66 ++++---- .../Portlets/VolumeConfiguration.tpl | 33 ++-- gui/baculum/protected/Portlets/VolumeList.php | 89 +++++++++-- gui/baculum/protected/Portlets/VolumeList.tpl | 18 ++- 32 files changed, 856 insertions(+), 449 deletions(-) create mode 100644 gui/baculum/protected/Portlets/ISlideWindow.php diff --git a/gui/baculum/protected/JavaScript/configuration-window.js b/gui/baculum/protected/JavaScript/configuration-window.js index 6bd47ae082..dbbe28268d 100644 --- a/gui/baculum/protected/JavaScript/configuration-window.js +++ b/gui/baculum/protected/JavaScript/configuration-window.js @@ -1,6 +1,12 @@ var ConfigurationWindowClass = new Class.create({ + objects: {}, + initialize: function(id) { - this.window_id = id + 'configuration'; + if(typeof(id) == "undefined") { + return; + } + var prefix = id.replace('Window', 'Configuration'); + this.window_id = prefix + 'configuration'; this.progress_id = 'configuration-progress'; this.lock = false; }, @@ -15,6 +21,24 @@ var ConfigurationWindowClass = new Class.create({ }.bind(this)); }, + objectExists: function(key) { + return this.objects.hasOwnProperty(key); + }, + + registerObj: function(key, obj) { + if(this.objectExists(key) === false) { + this.objects[key] = obj; + } + }, + + getObj: function(key) { + var obj = null; + if(this.objectExists(key) === true) { + obj = this.objects[key]; + } + return obj; + }, + hide: function() { $(this.window_id).setStyle({'display' : 'none'}); }, @@ -46,3 +70,4 @@ var ConfigurationWindowClass = new Class.create({ } }); +var ConfigurationWindow = new ConfigurationWindowClass(); diff --git a/gui/baculum/protected/JavaScript/slide-window.js b/gui/baculum/protected/JavaScript/slide-window.js index 9a485546d9..ed9857410e 100644 --- a/gui/baculum/protected/JavaScript/slide-window.js +++ b/gui/baculum/protected/JavaScript/slide-window.js @@ -11,6 +11,8 @@ var SlideWindowClass = Class.create({ loadRequest : null, repeaterEl: null, gridEl: null, + checked: [], + objects: {}, size: { widthNormal : '437px', @@ -28,11 +30,16 @@ var SlideWindowClass = Class.create({ contentItems : 'slide-window-element', contentAlternatingItems : 'slide-window-element-alternating', toolsButtonSuffix : '-slide-window-tools', + actionsSuffix : '-slide-window-actions', toolbarSuffix : '-slide-window-toolbar', titleSuffix : '-slide-window-title' }, initialize: function(windowId, data) { + if(typeof(windowId) == "undefined") { + return; + } + this.windowId = windowId; this.window = $(this.windowId + this.elements.containerSuffix); this.tools = $(this.windowId + this.elements.toolsButtonSuffix); @@ -67,6 +74,24 @@ var SlideWindowClass = Class.create({ this.setEvents(); }, + objectExists: function(key) { + return this.objects.hasOwnProperty(key); + }, + + registerObj: function(key, obj) { + if(this.objectExists(key) === false) { + this.objects[key] = obj; + } + }, + + getObj: function(key) { + var obj = null; + if(this.objectExists(key) === true) { + obj = this.objects[key]; + } + return obj; + }, + setEvents: function() { this.showEl.observe('click', function(){ this.openWindow(); @@ -166,7 +191,9 @@ var SlideWindowClass = Class.create({ this.repeaterEl = repeaterEl; this.gridEl = gridEl; this.loadRequest = requestObj; + this.markAllChecked(false); this.setLoadRequest(); + this.postWindowOpen(); }, setLoadRequest: function() { @@ -179,8 +206,15 @@ var SlideWindowClass = Class.create({ } dataList.each(function(tr) { - $(tr).observe('click', function() { - var el = $(tr).down('input') + $(tr).observe('click', function(index, clickedEl) { + var target = clickedEl.target || clickedEl.srcElement; + var clicked = $(target.id); + // for element selection action (clicked checkbox) configuration window is not open + if(clicked && clicked.hasAttribute('type') && clicked.readAttribute('type') == 'checkbox') { + return; + } + + var el = $(tr).down('input[type=hidden]') if(el) { var val = el.getValue(); this.loadRequest.ActiveControl.CallbackParameter = val; @@ -231,7 +265,7 @@ var SlideWindowClass = Class.create({ } else { return; } - while (--i >= 0) (function (i) { + while (--i >= 1) (function (i) { var dir = 1; th[i].addEventListener('click', function () { self.sortTable(i, (dir = 1 - dir)); @@ -265,10 +299,120 @@ var SlideWindowClass = Class.create({ $(count_el).update(' (' + elements_count + ')'); }, toggleToolbar: function() { + if (this.isToolbarOpen() === false) { + this.markAllChecked(false); + } Effect.toggle($(this.windowId + this.elements.toolbarSuffix), 'slide', { duration: 0.2}); + }, + isToolbarOpen: function() { + return $(this.windowId + this.elements.toolbarSuffix).visible(); + }, + setActions: function() { + var table = $(this.window).down('table'); + var checkboxes = table.select('input[name="actions_checkbox"]'); + checkboxes.each(function(el) { + el.observe('change', function() { + var is_checked = this.is_any_checked(checkboxes); + if(is_checked === true && !this.areActionsOpen()) { + this.showActions(); + } else if (is_checked === false && this.areActionsOpen()) { + this.hideActions(); + } + }.bind(this)); + }.bind(this)); + }, + is_any_checked: function(checkboxes) { + var is_checked = false; + checkboxes.each(function(ch) { + if(ch.checked == true) { + is_checked = true; + throw $break; + } + }); + return is_checked; + }, + + markAllChecked: function(check) { + this.checked = []; + var table = $(this.window).down('table'); + var checkboxes = table.select('input[name="actions_checkbox"]'); + var containerId; + if(checkboxes.length > 0) { + checkboxes.each(function(ch, index) { + if (ch.up('tr').visible()) { + containerId = ch.getAttribute('rel'); + if (ch.checked == false && check == true) { + ch.checked = true; + } else if (ch.checked == true && check == false) { + ch.checked = false; + } + this.markChecked(containerId, ch.checked, ch.value); + } + }.bind(this)); + this.packChecked(containerId); + } + + if(check) { + this.showActions(); + } else { + this.hideActions(); + } + }, + markChecked: function(containerId, checked, param, pack) { + if (this.checked.length == 0) { + if(checked == true) { + this.checked.push(param); + } + } else { + index = this.checked.indexOf(param); + if(checked === true && index == -1) { + this.checked.push(param); + } else if (checked === false && index > -1) { + this.checked.splice(index, 1); + } + } + + if(checked == true) { + this.showActions(); + } else if(this.checked.length == 0) { + this.hideActions(); + } + + if (pack === true) { + this.packChecked(containerId); + } + }, + packChecked: function(containerId) { + var values_packed = this.checked.join(';'); + $(containerId).setValue(values_packed); + }, + showActions: function() { + if (this.areActionsOpen()) { + return; + } + if (this.isToolbarOpen()) { + this.toggleToolbar(); + } + Effect.toggle($(this.windowId + this.elements.actionsSuffix), 'slide', { duration: 0.2}); + }, + hideActions: function() { + if (!this.areActionsOpen()) { + return; + } + this.checked = []; + Effect.toggle($(this.windowId + this.elements.actionsSuffix), 'slide', { duration: 0.2}); + }, + areActionsOpen: function() { + return $(this.windowId + this.elements.actionsSuffix).visible(); + }, + postWindowOpen: function() { + this.setActions(); + this.setElementsCount(); } }); +var SlideWindow = new SlideWindowClass() + document.observe("dom:loaded", function() { if(Prototype.Browser.IE || Prototype.Browser.Gecko) { $$('input[type=checkbox], input[type=submit], input[type=radio], a').each(function(el) { diff --git a/gui/baculum/protected/Pages/Home.page b/gui/baculum/protected/Pages/Home.page index ea96fb0a44..7d6c0e3def 100644 --- a/gui/baculum/protected/Pages/Home.page +++ b/gui/baculum/protected/Pages/Home.page @@ -6,24 +6,24 @@
- - - - - - + + + + + +
diff --git a/gui/baculum/protected/Portlets/ClientConfiguration.php b/gui/baculum/protected/Portlets/ClientConfiguration.php index 4d61010c47..9ed2c233ad 100644 --- a/gui/baculum/protected/Portlets/ClientConfiguration.php +++ b/gui/baculum/protected/Portlets/ClientConfiguration.php @@ -40,26 +40,21 @@ class ClientConfiguration extends Portlets { $this->AutoPrune->Checked = $client->autoprune == 1; } - public function save($sender, $param) { - switch($sender->getParent()->ID) { - case $this->Status->ID: { - $status = $this->Application->getModule('api')->get(array('clients', 'status', $this->ClientIdentifier->Text))->output; - $this->ShowClient->Text = implode(PHP_EOL, $status); - break; - } - case $this->Apply->ID: { - if($this->JobRetentionValidator->IsValid === false || $this->FileRetentionValidator->IsValid === false) { - return false; - } - $client = array(); - $client['clientid'] = $this->ClientIdentifier->Text; - $client['fileretention'] = $this->FileRetention->Text * 86400; // conversion to seconds - $client['jobretention'] = $this->JobRetention->Text * 86400; // conversion to seconds - $client['autoprune'] = (integer)$this->AutoPrune->Checked; - $this->Application->getModule('api')->set(array('clients', $client['clientid']), $client); - break; - } + public function status($sender, $param) { + $status = $this->Application->getModule('api')->get(array('clients', 'status', $this->ClientIdentifier->Text))->output; + $this->ShowClient->Text = implode(PHP_EOL, $status); + } + + public function apply($sender, $param) { + if($this->JobRetentionValidator->IsValid === false || $this->FileRetentionValidator->IsValid === false) { + return false; } + $client = array(); + $client['clientid'] = $this->ClientIdentifier->Text; + $client['fileretention'] = $this->FileRetention->Text * 86400; // conversion to seconds + $client['jobretention'] = $this->JobRetention->Text * 86400; // conversion to seconds + $client['autoprune'] = (integer)$this->AutoPrune->Checked; + $this->Application->getModule('api')->set(array('clients', $client['clientid']), $client); } public function fileRetentionValidator($sender, $param) { @@ -72,4 +67,4 @@ class ClientConfiguration extends Portlets { $param->setIsValid($isValid); } } -?> \ No newline at end of file +?> diff --git a/gui/baculum/protected/Portlets/ClientConfiguration.tpl b/gui/baculum/protected/Portlets/ClientConfiguration.tpl index f98b8bf45b..0660892bd4 100644 --- a/gui/baculum/protected/Portlets/ClientConfiguration.tpl +++ b/gui/baculum/protected/Portlets/ClientConfiguration.tpl @@ -1,6 +1,6 @@ <%@ MasterClass="Application.Portlets.ConfigurationPanel"%> - + <%[ Client name: ]%>

@@ -16,38 +16,38 @@
- +
- +
- +
- +
- +
diff --git a/gui/baculum/protected/Portlets/ClientList.php b/gui/baculum/protected/Portlets/ClientList.php index 1ea74be41c..f5fc17b37a 100644 --- a/gui/baculum/protected/Portlets/ClientList.php +++ b/gui/baculum/protected/Portlets/ClientList.php @@ -19,21 +19,44 @@ Prado::using('System.Web.UI.ActiveControls.TActiveRepeater'); Prado::using('System.Web.UI.ActiveControls.TActiveDataGrid'); +Prado::using('Application.Portlets.ISlideWindow'); Prado::using('Application.Portlets.Portlets'); -class ClientList extends Portlets { +class ClientList extends Portlets implements ISlideWindow { - public $ShowID, $windowTitle; + public $ID; + public $buttonID; + public $windowTitle; - public function onLoad($param) { - parent::onLoad($param); - $this->prepareData(); + public function setID($id) { + $this->ID = $id; + } + + public function getID($hideAutoID = true) { + return $this->ID; + } + + public function setButtonID($id) { + $this->buttonID = $id; + } + + public function getButtonID() { + return $this->buttonID; } public function setWindowTitle($param) { $this->windowTitle = $param; } + public function getWindowTitle() { + return $this->windowTitle; + } + + public function onLoad($param) { + parent::onLoad($param); + $this->prepareData(); + } + public function prepareData($forceReload = false) { $allowedButtons = array('ClientBtn', 'ReloadClients'); if($this->Page->IsPostBack || $this->Page->IsCallBack || $forceReload) { @@ -64,15 +87,6 @@ class ClientList extends Portlets { $this->DataGrid->dataBind(); } - - public function setShowID($ShowID) { - $this->ShowID = $this->getMaster()->ShowID = $ShowID; - } - - public function getShowID() { - return $this->ShowID; - } - public function configure($sender, $param) { if($this->Page->IsCallBack) { $this->getPage()->ClientConfiguration->configure($param->CallbackParameter); diff --git a/gui/baculum/protected/Portlets/ClientList.tpl b/gui/baculum/protected/Portlets/ClientList.tpl index 0c2341ebfd..00571ad293 100644 --- a/gui/baculum/protected/Portlets/ClientList.tpl +++ b/gui/baculum/protected/Portlets/ClientList.tpl @@ -1,12 +1,5 @@ <%@ MasterClass="Application.Portlets.SlideWindow"%> - @@ -52,6 +45,9 @@ - + + ConfigurationWindow.getObj('ClientWindow').show(); + ConfigurationWindow.getObj('ClientWindow').progress(false); + diff --git a/gui/baculum/protected/Portlets/ConfigurationPanel.tpl b/gui/baculum/protected/Portlets/ConfigurationPanel.tpl index 624db1cb84..95810b171c 100644 --- a/gui/baculum/protected/Portlets/ConfigurationPanel.tpl +++ b/gui/baculum/protected/Portlets/ConfigurationPanel.tpl @@ -1,12 +1,8 @@ -
-
+
+
- + -
- diff --git a/gui/baculum/protected/Portlets/ISlideWindow.php b/gui/baculum/protected/Portlets/ISlideWindow.php new file mode 100644 index 0000000000..785c4207c3 --- /dev/null +++ b/gui/baculum/protected/Portlets/ISlideWindow.php @@ -0,0 +1,34 @@ + diff --git a/gui/baculum/protected/Portlets/JobConfiguration.php b/gui/baculum/protected/Portlets/JobConfiguration.php index c3eae555d2..34a1a071ab 100644 --- a/gui/baculum/protected/Portlets/JobConfiguration.php +++ b/gui/baculum/protected/Portlets/JobConfiguration.php @@ -25,15 +25,6 @@ class JobConfiguration extends Portlets { private $runningJobStates = array('C', 'R'); - public function onInit($param) { - parent::onInit($param); - $this->Run->setActionClass($this); - $this->Status->setActionClass($this); - $this->Cancel->setActionClass($this); - $this->Delete->setActionClass($this); - $this->Estimate->setActionClass($this); - } - public function configure($jobId) { $jobdata = $this->Application->getModule('api')->get(array('jobs', $jobId))->output; $this->JobName->Text = $jobdata->job; @@ -88,51 +79,46 @@ class JobConfiguration extends Portlets { $this->CancelButton->Visible = in_array($jobdata->jobstatus, $this->runningJobStates); } - public function save($sender, $param) { - switch($sender->getParent()->ID) { - case $this->Estimate->ID: { - $params = array(); - $params['id'] = $this->JobID->Text; - $params['level'] = $this->Level->SelectedValue; - $params['fileset'] = $this->FileSet->SelectedValue; - $params['clientid'] = $this->Client->SelectedValue; - $params['accurate'] = (integer)$this->Accurate->Checked; - $result = $this->Application->getModule('api')->create(array('jobs', 'estimate'), $params)->output; - $this->Estimation->Text = implode(PHP_EOL, $result); - break; - } - case $this->Run->ID: { - if($this->PriorityValidator->IsValid === false) { - return false; - } - $params = array(); - $params['id'] = $this->JobID->Text; - $params['level'] = $this->Level->SelectedValue; - $params['fileset'] = $this->FileSet->SelectedValue; - $params['clientid'] = $this->Client->SelectedValue; - $params['storageid'] = $this->Storage->SelectedValue; - $params['poolid'] = $this->Pool->SelectedValue; - $params['priority'] = $this->Priority->Text; - $result = $this->Application->getModule('api')->create(array('jobs', 'run'), $params)->output; - $this->Estimation->Text = implode(PHP_EOL, $result); - break; - } - case $this->Delete->ID: { - $this->Application->getModule('api')->remove(array('jobs', $this->JobID->Text)); - $this->DeleteButton->Visible = false; - break; - } - case $this->Cancel->ID: { - $this->Application->getModule('api')->set(array('jobs', 'cancel', $this->JobID->Text), array('a' => 'b')); - $this->CancelButton->Visible = false; - break; - } - case $this->Status->ID: { - $joblog = $this->Application->getModule('api')->get(array('joblog', $this->JobID->Text))->output; - $this->Estimation->Text = is_array($joblog) ? implode(PHP_EOL, $joblog) : Prado::localize("Output for selected job is not available yet or you do not have enabled logging job logs to catalog database." . PHP_EOL . PHP_EOL . "For watching job log there is need to add to the job Messages resource next directive:" . PHP_EOL . PHP_EOL . "console = all, !skipped, !saved" . PHP_EOL); - break; - } + public function status($sender, $param) { + $joblog = $this->Application->getModule('api')->get(array('joblog', $this->JobID->Text))->output; + $this->Estimation->Text = is_array($joblog) ? implode(PHP_EOL, $joblog) : Prado::localize("Output for selected job is not available yet or you do not have enabled logging job logs to catalog database." . PHP_EOL . PHP_EOL . "For watching job log there is need to add to the job Messages resource next directive:" . PHP_EOL . PHP_EOL . "console = all, !skipped, !saved" . PHP_EOL); + } + + public function delete($sender, $param) { + $this->Application->getModule('api')->remove(array('jobs', $this->JobID->Text)); + $this->DeleteButton->Visible = false; + } + + public function cancel($sender, $param) { + $this->Application->getModule('api')->set(array('jobs', 'cancel', $this->JobID->Text), array('a' => 'b')); + $this->CancelButton->Visible = false; + } + + public function run_again($sender, $param) { + if($this->PriorityValidator->IsValid === false) { + return false; } + $params = array(); + $params['id'] = $this->JobID->Text; + $params['level'] = $this->Level->SelectedValue; + $params['fileset'] = $this->FileSet->SelectedValue; + $params['clientid'] = $this->Client->SelectedValue; + $params['storageid'] = $this->Storage->SelectedValue; + $params['poolid'] = $this->Pool->SelectedValue; + $params['priority'] = $this->Priority->Text; + $result = $this->Application->getModule('api')->create(array('jobs', 'run'), $params)->output; + $this->Estimation->Text = implode(PHP_EOL, $result); + } + + public function estimate($sender, $param) { + $params = array(); + $params['id'] = $this->JobID->Text; + $params['level'] = $this->Level->SelectedValue; + $params['fileset'] = $this->FileSet->SelectedValue; + $params['clientid'] = $this->Client->SelectedValue; + $params['accurate'] = (integer)$this->Accurate->Checked; + $result = $this->Application->getModule('api')->create(array('jobs', 'estimate'), $params)->output; + $this->Estimation->Text = implode(PHP_EOL, $result); } public function priorityValidator($sender, $param) { diff --git a/gui/baculum/protected/Portlets/JobConfiguration.tpl b/gui/baculum/protected/Portlets/JobConfiguration.tpl index f1bd05b433..298d5fe4ac 100644 --- a/gui/baculum/protected/Portlets/JobConfiguration.tpl +++ b/gui/baculum/protected/Portlets/JobConfiguration.tpl @@ -1,6 +1,6 @@ <%@ MasterClass="Application.Portlets.ConfigurationPanel"%> - + <%[ Job name: ]%>
- +
- +
- - - - + + + +
<%[ Console status ]%>
@@ -72,7 +73,7 @@
- +
diff --git a/gui/baculum/protected/Portlets/JobList.php b/gui/baculum/protected/Portlets/JobList.php index 37b8777c27..1748575f0a 100644 --- a/gui/baculum/protected/Portlets/JobList.php +++ b/gui/baculum/protected/Portlets/JobList.php @@ -22,28 +22,58 @@ Prado::using('System.Web.UI.ActiveControls.TActiveRepeater'); Prado::using('System.Web.UI.ActiveControls.TActiveLinkButton'); Prado::using('System.Web.UI.ActiveControls.TActivePanel'); Prado::using('System.Web.UI.ActiveControls.TCallback'); +Prado::using('Application.Portlets.ISlideWindow'); Prado::using('Application.Portlets.Portlets'); -class JobList extends Portlets { +class JobList extends Portlets implements ISlideWindow { - public $ShowID, $windowTitle; + public $ID; + public $buttonID; + public $windowTitle; + public $jobLevels; + private $jobStates; + private $jobTypes = array( + 'B' => 'Backup', + 'M' => 'Migrated', + 'V' => 'Verify', + 'R' => 'Restore', + 'I' => 'Internal', + 'D' => 'Admin', + 'A' => 'Archive', + 'C' => 'Copy', + 'g' => 'Migration' + ); - private $jobTypes = array('B' => 'Backup', 'M' => 'Migrated', 'V' => 'Verify', 'R' => 'Restore', 'I' => 'Internal', 'D' => 'Admin', 'A' => 'Archive', 'C' => 'Copy', 'g' => 'Migration'); + public function setID($id) { + $this->ID = $id; + } - private $jobStates; + public function getID($hideAutoID = true) { + return $this->ID; + } - public $jobLevels; + public function setButtonID($id) { + $this->buttonID = $id; + } - public function onLoad($param) { - parent::onLoad($param); - $this->prepareData(); - $this->jobLevels = $this->Application->getModule('misc')->getJobLevels(); + public function getButtonID() { + return $this->buttonID; } public function setWindowTitle($param) { $this->windowTitle = $param; } + public function getWindowTitle() { + return $this->windowTitle; + } + + public function onLoad($param) { + parent::onLoad($param); + $this->prepareData(); + $this->jobLevels = $this->Application->getModule('misc')->getJobLevels(); + } + public function getJobType($jobLetter) { return array_key_exists($jobLetter, $this->jobTypes) ? $this->jobTypes[$jobLetter] : null; } @@ -109,18 +139,30 @@ class JobList extends Portlets { $this->DataGrid->dataBind(); } - public function setShowID($ShowID) { - $this->ShowID = $this->getMaster()->ShowID = $ShowID; - } - - public function getShowID() { - return $this->ShowID; - } - public function configure($sender, $param) { if($this->Page->IsCallBack) { $this->getPage()->JobConfiguration->configure($param->CallbackParameter); } } + + public function executeAction($action) { + $params = explode(';', $this->CheckedValues->Value); + $commands = array(); + switch($action) { + case 'delete': { + for($i = 0; $i < count($params); $i++) { + $cmd = array('delete'); + $cmd[] = 'jobid="' . $params[$i] . '"'; + $cmd[] = 'yes'; + $cmd[] = PHP_EOL; + $commands[] = implode(' ', $cmd); + } + $this->getPage()->Console->CommandLine->Text = implode(' ', $commands); + $this->getPage()->Console->sendCommand(null, null); + break; + } + } + $this->CheckedValues->Value = ""; + } } ?> diff --git a/gui/baculum/protected/Portlets/JobList.tpl b/gui/baculum/protected/Portlets/JobList.tpl index bd4bf6cf34..9ab4e66fa2 100644 --- a/gui/baculum/protected/Portlets/JobList.tpl +++ b/gui/baculum/protected/Portlets/JobList.tpl @@ -1,12 +1,5 @@ <%@ MasterClass="Application.Portlets.SlideWindow" %> - @@ -28,6 +21,11 @@ ItemStyle.CssClass="slide-window-element" AlternatingItemStyle.CssClass="slide-window-element-alternating" > + + + + + + - + + ConfigurationWindow.getObj('JobWindow').show(); + ConfigurationWindow.getObj('JobWindow').progress(false); + diff --git a/gui/baculum/protected/Portlets/JobRunConfiguration.php b/gui/baculum/protected/Portlets/JobRunConfiguration.php index 4797ef886e..345a28e91f 100644 --- a/gui/baculum/protected/Portlets/JobRunConfiguration.php +++ b/gui/baculum/protected/Portlets/JobRunConfiguration.php @@ -23,12 +23,6 @@ class JobRunConfiguration extends Portlets { const DEFAULT_JOB_PRIORITY = 10; - public function onInit($param) { - parent::onInit($param); - $this->Run->setActionClass($this); - $this->Estimate->setActionClass($this); - } - public function configure($jobname) { $this->JobName->Text = $jobname; $this->Estimation->Text = ''; @@ -71,37 +65,31 @@ class JobRunConfiguration extends Portlets { $this->Priority->Text = self::DEFAULT_JOB_PRIORITY; } - public function save($sender, $param) { - switch($sender->getParent()->ID) { - case $this->Estimate->ID: { - $params = array(); - $params['name'] = $this->JobName->Text; - $params['level'] = $this->Level->SelectedValue; - $params['fileset'] = $this->FileSet->SelectedValue; - $params['clientid'] = $this->Client->SelectedValue; - $params['accurate'] = (integer)$this->Accurate->Checked; - var_dump($params); - $result = $this->Application->getModule('api')->create(array('jobs', 'estimate'), $params)->output; - $this->Estimation->Text = implode(PHP_EOL, $result); - break; - } - case $this->Run->ID: { - if($this->PriorityValidator->IsValid === false) { - return false; - } - $params = array(); - $params['name'] = $this->JobName->Text; - $params['level'] = $this->Level->SelectedValue; - $params['fileset'] = $this->FileSet->SelectedValue; - $params['clientid'] = $this->Client->SelectedValue; - $params['storageid'] = $this->Storage->SelectedValue; - $params['poolid'] = $this->Pool->SelectedValue; - $params['priority'] = $this->Priority->Text; - $result = $this->Application->getModule('api')->create(array('jobs', 'run'), $params)->output; - $this->Estimation->Text = implode(PHP_EOL, $result); - break; - } + public function run_job($sender, $param) { + if($this->PriorityValidator->IsValid === false) { + return false; } + $params = array(); + $params['name'] = $this->JobName->Text; + $params['level'] = $this->Level->SelectedValue; + $params['fileset'] = $this->FileSet->SelectedValue; + $params['clientid'] = $this->Client->SelectedValue; + $params['storageid'] = $this->Storage->SelectedValue; + $params['poolid'] = $this->Pool->SelectedValue; + $params['priority'] = $this->Priority->Text; + $result = $this->Application->getModule('api')->create(array('jobs', 'run'), $params)->output; + $this->Estimation->Text = implode(PHP_EOL, $result); + } + + public function estimate($sender, $param) { + $params = array(); + $params['name'] = $this->JobName->Text; + $params['level'] = $this->Level->SelectedValue; + $params['fileset'] = $this->FileSet->SelectedValue; + $params['clientid'] = $this->Client->SelectedValue; + $params['accurate'] = (integer)$this->Accurate->Checked; + $result = $this->Application->getModule('api')->create(array('jobs', 'estimate'), $params)->output; + $this->Estimation->Text = implode(PHP_EOL, $result); } public function priorityValidator($sender, $param) { @@ -109,4 +97,4 @@ class JobRunConfiguration extends Portlets { $param->setIsValid($isValid); } } -?> \ No newline at end of file +?> diff --git a/gui/baculum/protected/Portlets/JobRunConfiguration.tpl b/gui/baculum/protected/Portlets/JobRunConfiguration.tpl index 76c1bc902c..d83f29a540 100644 --- a/gui/baculum/protected/Portlets/JobRunConfiguration.tpl +++ b/gui/baculum/protected/Portlets/JobRunConfiguration.tpl @@ -1,6 +1,6 @@ <%@ MasterClass="Application.Portlets.ConfigurationPanel"%> - + <%[ Job name: ]%>
- +
- +
- +
<%[ Console status ]%>
@@ -69,7 +69,7 @@
- +
diff --git a/gui/baculum/protected/Portlets/JobRunList.php b/gui/baculum/protected/Portlets/JobRunList.php index fba2ef7f78..39ac4c56c0 100644 --- a/gui/baculum/protected/Portlets/JobRunList.php +++ b/gui/baculum/protected/Portlets/JobRunList.php @@ -22,25 +22,57 @@ Prado::using('System.Web.UI.ActiveControls.TActiveRepeater'); Prado::using('System.Web.UI.ActiveControls.TActiveLinkButton'); Prado::using('System.Web.UI.ActiveControls.TActivePanel'); Prado::using('System.Web.UI.ActiveControls.TCallback'); +Prado::using('Application.Portlets.ISlideWindow'); Prado::using('Application.Portlets.Portlets'); -class JobRunList extends Portlets { +class JobRunList extends Portlets implements ISlideWindow { - public $ShowID, $windowTitle, $oldDirector; + public $ID; + public $buttonID; + public $windowTitle; + public $oldDirector; + private $jobStates; + private $jobTypes = array( + 'B' => 'Backup', + 'M' => 'Migrated', + 'V' => 'Verify', + 'R' => 'Restore', + 'I' => 'Internal', + 'D' => 'Admin', + 'A' => 'Archive', + 'C' => 'Copy', + 'g' => 'Migration' + ); - private $jobTypes = array('B' => 'Backup', 'M' => 'Migrated', 'V' => 'Verify', 'R' => 'Restore', 'I' => 'Internal', 'D' => 'Admin', 'A' => 'Archive', 'C' => 'Copy', 'g' => 'Migration'); + public function setID($id) { + $this->ID = $id; + } - private $jobStates; + public function getID($hideAutoID = true) { + return $this->ID; + } - public function onLoad($param) { - parent::onLoad($param); - $this->prepareData(); + public function setButtonID($id) { + $this->buttonID = $id; + } + + public function getButtonID() { + return $this->buttonID; } public function setWindowTitle($param) { $this->windowTitle = $param; } + public function getWindowTitle() { + return $this->windowTitle; + } + + public function onLoad($param) { + parent::onLoad($param); + $this->prepareData(); + } + public function prepareData($forceReload = false) { $allowedButtons = array('JobRunBtn'); if($this->Page->IsPostBack || $this->Page->IsCallBack || $forceReload) { @@ -75,7 +107,7 @@ class JobRunList extends Portlets { return $jobs; } - public function sortDataGrid($sender, $param) { + public function sortDataGrid($sender, $param) { $params = $this->getUrlParams(array('jobs', 'tasks'), $this->getPage()->JobRunWindow->ID); $data = $this->Application->getModule('api')->get($params)->output; $data = $this->prepareJobs($data); @@ -83,14 +115,6 @@ class JobRunList extends Portlets { $this->DataGrid->dataBind(); } - public function setShowID($ShowID) { - $this->ShowID = $this->getMaster()->ShowID = $ShowID; - } - - public function getShowID() { - return $this->ShowID; - } - public function configure($sender, $param) { if($this->Page->IsCallBack) { $this->getPage()->JobRunConfiguration->configure($param->CallbackParameter); diff --git a/gui/baculum/protected/Portlets/JobRunList.tpl b/gui/baculum/protected/Portlets/JobRunList.tpl index 82fa83838d..a7532370d6 100644 --- a/gui/baculum/protected/Portlets/JobRunList.tpl +++ b/gui/baculum/protected/Portlets/JobRunList.tpl @@ -1,12 +1,5 @@ <%@ MasterClass="Application.Portlets.SlideWindow" %> - @@ -46,6 +39,9 @@ - + + ConfigurationWindow.getObj('JobRunWindow').show(); + ConfigurationWindow.getObj('JobRunWindow').progress(false); + diff --git a/gui/baculum/protected/Portlets/PoolConfiguration.php b/gui/baculum/protected/Portlets/PoolConfiguration.php index 12ec4d8e10..3e4d960d9d 100644 --- a/gui/baculum/protected/Portlets/PoolConfiguration.php +++ b/gui/baculum/protected/Portlets/PoolConfiguration.php @@ -23,13 +23,6 @@ Prado::using('Application.Portlets.Portlets'); class PoolConfiguration extends Portlets { - public function onInit($param) { - parent::onInit($param); - $this->Apply->setActionClass($this); - $this->RestoreConfiguration->setActionClass($this); - $this->UpdateVolumes->setActionClass($this); - } - public function configure($poolId) { $pooldata = $this->Application->getModule('api')->get(array('pools', $poolId))->output; $this->PoolName->Text = $pooldata->name; @@ -57,8 +50,33 @@ class PoolConfiguration extends Portlets { $this->ActionOnPurge->Checked = $pooldata->actiononpurge == 1; } - public function save($sender, $param) { - if(($sender->getParent()->ID == $this->Apply->ID) || ($sender->getParent()->ID == $this->UpdateVolumes->ID)) { + public function restore_configuration($sender, $param) { + $this->Application->getModule('api')->set(array('pools', 'update', $this->PoolID->Text), array('')); + } + + public function update_volumes($sender, $param) { + if($this->MaxVolumesValidator->IsValid === false || $this->MaxVolJobsValidator->IsValid === false || $this->MaxVolBytesValidator->IsValid === false || $this->UseDurationValidator->IsValid === false || $this->RetentionPeriodValidator->IsValid === false || $this->LabelFormatValidator->IsValid === false) { + return false; + } + $pooldata = array(); + $pooldata['poolid'] = $this->PoolID->Text; + $pooldata['enabled'] = (integer)$this->Enabled->Checked; + $pooldata['maxvols'] = $this->MaxVolumes->Text; + $pooldata['maxvoljobs'] = $this->MaxVolJobs->Text; + $pooldata['maxvolbytes'] = $this->MaxVolBytes->Text; + $pooldata['voluseduration'] = $this->UseDuration->Text * 3600; // conversion to seconds + $pooldata['volretention'] = $this->RetentionPeriod->Text * 3600; // conversion to seconds + $pooldata['labelformat'] = $this->LabelFormat->Text; + $pooldata['scratchpoolid'] = (integer)$this->ScratchPool->SelectedValue; + $pooldata['recyclepoolid'] = (integer)$this->RecyclePool->SelectedValue; + $pooldata['recycle'] = (integer)$this->Recycle->Checked; + $pooldata['autoprune'] = (integer)$this->AutoPrune->Checked; + $pooldata['actiononpurge'] = (integer)$this->ActionOnPurge->Checked; + $this->Application->getModule('api')->set(array('pools', $this->PoolID->Text), $pooldata); + $this->Application->getModule('api')->set(array('pools', 'update', 'volumes', $this->PoolID->Text), array('')); + } + + public function apply($sender, $param) { if($this->MaxVolumesValidator->IsValid === false || $this->MaxVolJobsValidator->IsValid === false || $this->MaxVolBytesValidator->IsValid === false || $this->UseDurationValidator->IsValid === false || $this->RetentionPeriodValidator->IsValid === false || $this->LabelFormatValidator->IsValid === false) { return false; } @@ -77,13 +95,7 @@ class PoolConfiguration extends Portlets { $pooldata['autoprune'] = (integer)$this->AutoPrune->Checked; $pooldata['actiononpurge'] = (integer)$this->ActionOnPurge->Checked; $this->Application->getModule('api')->set(array('pools', $this->PoolID->Text), $pooldata); - if($sender->getParent()->ID == $this->UpdateVolumes->ID) { - $this->Application->getModule('api')->set(array('pools', 'update', 'volumes', $this->PoolID->Text), array('')); - } - } elseif($sender->getParent()->ID == $this->RestoreConfiguration->ID) { - $this->Application->getModule('api')->set(array('pools', 'update', $this->PoolID->Text), array('')); - //@TOFIX $this->configure($this->PoolID->Text); - } + } public function maxVolumesValidator($sender, $param) { @@ -117,4 +129,4 @@ class PoolConfiguration extends Portlets { $param->setIsValid($isValid); } } -?> \ No newline at end of file +?> diff --git a/gui/baculum/protected/Portlets/PoolConfiguration.tpl b/gui/baculum/protected/Portlets/PoolConfiguration.tpl index fea8b97880..34f06a6b4e 100644 --- a/gui/baculum/protected/Portlets/PoolConfiguration.tpl +++ b/gui/baculum/protected/Portlets/PoolConfiguration.tpl @@ -1,6 +1,6 @@ <%@ MasterClass="Application.Portlets.ConfigurationPanel"%> - + <%[ Pool name: ]%>

- +
- +
- +
- +
- +
- +
@@ -80,20 +80,20 @@
- +
-   -   - + + +
diff --git a/gui/baculum/protected/Portlets/PoolList.php b/gui/baculum/protected/Portlets/PoolList.php index 7a1dd0437f..73c602d84c 100644 --- a/gui/baculum/protected/Portlets/PoolList.php +++ b/gui/baculum/protected/Portlets/PoolList.php @@ -18,21 +18,43 @@ */ Prado::using('System.Web.UI.ActiveControls.TActiveRepeater'); +Prado::using('Application.Portlets.ISlideWindow'); Prado::using('Application.Portlets.Portlets'); -class PoolList extends Portlets { +class PoolList extends Portlets implements ISlideWindow { - public $ShowID, $windowTitle; + public $ID; + public $buttonID; + public $windowTitle; - public function onLoad($param) { - parent::onLoad($param); - $this->prepareData(); + public function setID($id) { + $this->ID = $id; + } + + public function getID($hideAutoID = true) { + return $this->ID; + } + + public function setButtonID($id) { + $this->buttonID = $id; + } + + public function getButtonID() { + return $this->buttonID; } public function setWindowTitle($param) { $this->windowTitle = $param; } + public function getWindowTitle() { + return $this->windowTitle; + } + public function onLoad($param) { + parent::onLoad($param); + $this->prepareData(); + } + public function prepareData($forceReload = false) { $allowedButtons = array('PoolBtn', 'ReloadPools'); if($this->Page->IsPostBack || $this->Page->IsCallBack || $forceReload) { diff --git a/gui/baculum/protected/Portlets/PoolList.tpl b/gui/baculum/protected/Portlets/PoolList.tpl index 1d5dd63bc4..fa147f84d3 100644 --- a/gui/baculum/protected/Portlets/PoolList.tpl +++ b/gui/baculum/protected/Portlets/PoolList.tpl @@ -1,12 +1,5 @@ <%@ MasterClass="Application.Portlets.SlideWindow"%> - @@ -59,6 +52,9 @@ - + + ConfigurationWindow.getObj('PoolWindow').show(); + ConfigurationWindow.getObj('PoolWindow').progress(false); + diff --git a/gui/baculum/protected/Portlets/Portlets.php b/gui/baculum/protected/Portlets/Portlets.php index 9c15722cc7..56723bd7e8 100644 --- a/gui/baculum/protected/Portlets/Portlets.php +++ b/gui/baculum/protected/Portlets/Portlets.php @@ -59,4 +59,4 @@ class Portlets extends TTemplateControl { return $data; } } -?> \ No newline at end of file +?> diff --git a/gui/baculum/protected/Portlets/SlideWindow.php b/gui/baculum/protected/Portlets/SlideWindow.php index ea2b0fa447..ef12015e75 100644 --- a/gui/baculum/protected/Portlets/SlideWindow.php +++ b/gui/baculum/protected/Portlets/SlideWindow.php @@ -16,7 +16,9 @@ * * Bacula® is a registered trademark of Kern Sibbald. */ + +Prado::using('System.Web.UI.WebControls.TCompareValidator'); Prado::using('System.Web.UI.ActiveControls.TActiveLabel'); Prado::using('System.Web.UI.ActiveControls.TActivePanel'); Prado::using('System.Web.UI.ActiveControls.TActiveDropDownList'); @@ -29,10 +31,18 @@ Prado::using('Application.Portlets.Portlets'); class SlideWindow extends Portlets { public $elementsLimits = array(10, 25, 50, 100, 200, 500, 1000, 'unlimited'); - - public $ShowID; - public $Title; - public $WindowTitle; + public $actions = array( + 'VolumeWindow' => array( + 'NoAction' => 'select action', + 'delete' => 'Delete', + 'prune' => 'Prune', + 'purge' => 'Purge' + ), + 'JobWindow' => array( + 'NoAction' => 'select action', + 'delete' => 'Delete' + ) + ); const NORMAL_VIEW = 'simple'; const DETAIL_VIEW = 'details'; @@ -53,6 +63,9 @@ class SlideWindow extends Portlets { $this->Limit->dataBind(); $this->Simple->Checked = ($_SESSION['view' . $this->getParent()->ID] == self::NORMAL_VIEW); $this->Details->Checked = ($_SESSION['view' . $this->getParent()->ID] == self::DETAIL_VIEW); + $actions = array_key_exists($this->getParent()->ID, $this->actions) ? $this->actions[$this->getParent()->ID] : array(); + $this->Actions->dataSource = $actions; + $this->Actions->dataBind(); } } @@ -61,5 +74,11 @@ class SlideWindow extends Portlets { $_SESSION['limit' . $this->getParent()->ID] = $this->Limit->SelectedValue; $this->getParent()->prepareData(true); } + + public function action($sender, $param) { + if(method_exists($this->getParent(), 'executeAction')) { + $this->getParent()->executeAction($this->Actions->SelectedValue, $sender, $param); + } + } } -?> \ No newline at end of file +?> diff --git a/gui/baculum/protected/Portlets/SlideWindow.tpl b/gui/baculum/protected/Portlets/SlideWindow.tpl index 73d618eddb..01e06f7f92 100644 --- a/gui/baculum/protected/Portlets/SlideWindow.tpl +++ b/gui/baculum/protected/Portlets/SlideWindow.tpl @@ -1,46 +1,102 @@ -
- +
@@ -33,35 +33,35 @@
- +
- +
- +
- +
- +
@@ -76,18 +76,21 @@
- +
-    + + +
diff --git a/gui/baculum/protected/Portlets/VolumeList.php b/gui/baculum/protected/Portlets/VolumeList.php index 9272ebbc1e..66d6bdd5fa 100644 --- a/gui/baculum/protected/Portlets/VolumeList.php +++ b/gui/baculum/protected/Portlets/VolumeList.php @@ -21,22 +21,49 @@ Prado::using('System.Web.UI.ActiveControls.TActiveDataGrid'); Prado::using('System.Web.UI.ActiveControls.TActiveRepeater'); Prado::using('System.Web.UI.ActiveControls.TActiveLinkButton'); Prado::using('System.Web.UI.ActiveControls.TActivePanel'); +Prado::using('System.Web.UI.ActiveControls.TActiveHiddenField'); Prado::using('System.Web.UI.ActiveControls.TCallback'); +Prado::using('Application.Portlets.ISlideWindow'); Prado::using('Application.Portlets.Portlets'); -class VolumeList extends Portlets { +class VolumeList extends Portlets implements ISlideWindow { - public $ShowID, $pools, $oldPool, $view, $windowTitle; + public $ID; + public $buttonID; + public $windowTitle; + public $pools; + public $oldPool; + public $view; - public function onLoad($param) { - parent::onLoad($param); - $this->prepareData(); + public function setID($id) { + $this->ID = $id; + } + + public function getID($hideAutoID = true) { + return $this->ID; + } + + public function setButtonID($id) { + $this->buttonID = $id; + } + + public function getButtonID() { + return $this->buttonID; } public function setWindowTitle($param) { $this->windowTitle = $param; } + public function getWindowTitle() { + return $this->windowTitle; + } + + public function onLoad($param) { + parent::onLoad($param); + $this->prepareData(); + } + public function prepareData($forceReload = false) { $allowedButtons = array('MediaBtn', 'ReloadVolumes'); if($this->Page->IsPostBack || $this->Page->IsCallBack || $forceReload) { @@ -90,18 +117,54 @@ class VolumeList extends Portlets { $this->DataGrid->dataBind(); } - public function setShowID($ShowID) { - $this->ShowID = $this->getMaster()->ShowID = $ShowID; - } - - public function getShowID() { - return $this->ShowID; - } - public function configure($sender, $param) { if($this->Page->IsCallBack) { $this->getPage()->VolumeConfiguration->configure($param->CallbackParameter); } } + + public function executeAction($action) { + $params = explode(';', $this->CheckedValues->Value); + $commands = array(); + switch($action) { + case 'prune': { + for($i = 0; $i < count($params); $i++) { + $cmd = array('prune'); + $cmd[] = 'volume="' . $params[$i] . '"'; + $cmd[] = 'yes'; + $cmd[] = PHP_EOL; + $commands[] = implode(' ', $cmd); + } + $this->getPage()->Console->CommandLine->Text = implode(' ', $commands); + $this->getPage()->Console->sendCommand(null, null); + break; + } + case 'purge': { + for($i = 0; $i < count($params); $i++) { + $cmd = array('purge'); + $cmd[] = 'volume="' . $params[$i] . '"'; + $cmd[] = 'yes'; + $cmd[] = PHP_EOL; + $commands[] = implode(' ', $cmd); + } + $this->getPage()->Console->CommandLine->Text = implode(' ', $commands); + $this->getPage()->Console->sendCommand(null, null); + break; + } + case 'delete': { + for($i = 0; $i < count($params); $i++) { + $cmd = array('delete'); + $cmd[] = 'volume="' . $params[$i] . '"'; + $cmd[] = 'yes'; + $cmd[] = PHP_EOL; + $commands[] = implode(' ', $cmd); + } + $this->getPage()->Console->CommandLine->Text = implode(' ', $commands); + $this->getPage()->Console->sendCommand(null, null); + break; + } + } + $this->CheckedValues->Value = ""; + } } ?> diff --git a/gui/baculum/protected/Portlets/VolumeList.tpl b/gui/baculum/protected/Portlets/VolumeList.tpl index 1a60b7c46a..aecacfc3fc 100644 --- a/gui/baculum/protected/Portlets/VolumeList.tpl +++ b/gui/baculum/protected/Portlets/VolumeList.tpl @@ -1,12 +1,5 @@ <%@ MasterClass="Application.Portlets.SlideWindow" %> - @@ -31,6 +24,11 @@ ItemStyle.CssClass="slide-window-element" AlternatingItemStyle.CssClass="slide-window-element-alternating" > + + + + +
<%=$this->getParent()->Data['volumename']%>
@@ -59,8 +57,12 @@ DataField="whenexpire" /> +
- + + ConfigurationWindow.getObj('VolumeWindow').show(); + ConfigurationWindow.getObj('VolumeWindow').progress(false); +
-- 2.39.5