]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add to client status modal window to set bandwidth limit for job
authorMarcin Haba <marcin.haba@bacula.pl>
Thu, 15 Aug 2019 16:02:45 +0000 (18:02 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Sat, 14 Dec 2019 14:55:58 +0000 (15:55 +0100)
13 files changed:
gui/baculum/protected/Web/Lang/en/messages.mo
gui/baculum/protected/Web/Lang/en/messages.po
gui/baculum/protected/Web/Lang/ja/messages.mo
gui/baculum/protected/Web/Lang/ja/messages.po
gui/baculum/protected/Web/Lang/pl/messages.mo
gui/baculum/protected/Web/Lang/pl/messages.po
gui/baculum/protected/Web/Lang/pt/messages.mo
gui/baculum/protected/Web/Lang/pt/messages.po
gui/baculum/protected/Web/Pages/ClientView.page
gui/baculum/protected/Web/Pages/ClientView.php
gui/baculum/protected/Web/Portlets/ClientBandwidthLimit.tpl
gui/baculum/protected/Web/Portlets/JobBandwidthLimit.php [new file with mode: 0644]
gui/baculum/protected/Web/Portlets/JobBandwidthLimit.tpl [new file with mode: 0644]

index ee971932c68be258375241d2637457d2471a3354..117c15440a41da5ac55390eb14c0292bd4184e76 100644 (file)
Binary files a/gui/baculum/protected/Web/Lang/en/messages.mo and b/gui/baculum/protected/Web/Lang/en/messages.mo differ
index 68b525a16949e6ca820a2e3bd702f053752bb2a1..e2c11a04c68320253102020e8e66592e0dd678cf 100644 (file)
@@ -2332,3 +2332,9 @@ msgstr "Here you can set bandwidth limit on client. This change is applied on ru
 
 msgid "Setting 0 (zero) value disables bandwidth limitation."
 msgstr "Setting 0 (zero) value disables bandwidth limitation."
+
+msgid "Set job bandwidth limit"
+msgstr "Set job bandwidth limit"
+
+msgid "Here you can set bandwidth limit for job. This change is applied on running job."
+msgstr "Here you can set bandwidth limit for job. This change is applied on running job."
index 0e253be0a91df9b9125c5c64518142d07574c50d..b9922366d38eef979ae5b31927b63b14d5667172 100644 (file)
Binary files a/gui/baculum/protected/Web/Lang/ja/messages.mo and b/gui/baculum/protected/Web/Lang/ja/messages.mo differ
index 581c727d311cb807a06a3d2f3dda9d340bc2eb65..5f774110656696032cca13a5324bf21bfc229284 100644 (file)
@@ -2418,3 +2418,9 @@ msgstr "Here you can set bandwidth limit on client. This change is applied on ru
 
 msgid "Setting 0 (zero) value disables bandwidth limitation."
 msgstr "Setting 0 (zero) value disables bandwidth limitation."
+
+msgid "Set job bandwidth limit"
+msgstr "Set job bandwidth limit"
+
+msgid "Here you can set bandwidth limit for job. This change is applied on running job."
+msgstr "Here you can set bandwidth limit for job. This change is applied on running job."
index cb3786abcca438731ed1a1f1941d7d9bd1291e78..4209f147a9ff0674c56326e7ed80226a92b45d25 100644 (file)
Binary files a/gui/baculum/protected/Web/Lang/pl/messages.mo and b/gui/baculum/protected/Web/Lang/pl/messages.mo differ
index 55b626e0a26165c35aa42b236907eff28731040c..5ec9a4b95328d94f7ac1e770061e9e86b6c9d247 100644 (file)
@@ -2339,3 +2339,9 @@ msgstr "Tutaj możesz ustawić limit transferu dla klienta. Ta zmiana jest zasto
 
 msgid "Setting 0 (zero) value disables bandwidth limitation."
 msgstr "Ustawienie wartości 0 (zero) wyłącza limitowanie transferu."
+
+msgid "Set job bandwidth limit"
+msgstr "Ustaw limit transferu dla zadania"
+
+msgid "Here you can set bandwidth limit for job. This change is applied on running job."
+msgstr "Tutaj możesz ustawić limit transferu dla zadania. Ta zmiana jest stosowana do uruchomionego zadania."
index 8e4261818e435b2af1107d8175fcc2b8be5da913..a7339727d4ec3ad4d27ad72ce3499abc7ce060ff 100644 (file)
Binary files a/gui/baculum/protected/Web/Lang/pt/messages.mo and b/gui/baculum/protected/Web/Lang/pt/messages.mo differ
index 0fa163d07622173ec5847639bef81ba9a9067232..84126853ecda6bd69ea2f07d5e22c0c5b97bdb52 100644 (file)
@@ -2347,3 +2347,9 @@ msgstr "Here you can set bandwidth limit on client. This change is applied on ru
 
 msgid "Setting 0 (zero) value disables bandwidth limitation."
 msgstr "Setting 0 (zero) value disables bandwidth limitation."
+
+msgid "Set job bandwidth limit"
+msgstr "Set job bandwidth limit"
+
+msgid "Here you can set bandwidth limit for job. This change is applied on running job."
+msgstr "Here you can set bandwidth limit for job. This change is applied on running job."
index a41d9147770ca8ca4668fbbb765f4839f511dd65..00ce35eed7b020bfc4cb3596b444070e525b7fe6 100644 (file)
                                                <h5 id="status_client_no_jobs_running" style="display: none"><%[ No jobs running ]%></h5>
                                                <div id="status_client_running_jobs"></div>
                                        </div>
+<com:Application.Web.Portlets.JobBandwidthLimit
+       ID="JobBandwidth"
+       OnCallback="status"
+/>
+<com:TCallback ID="JobBandwidthCb"
+       OnCallback="setBandwidthControl"
+       ClientSide.OnComplete="oJobBandwidthLimit.open_popup();"
+/>
 <script type="text/javascript">
 var oGraphicalClientStatus = {
        data: {},
@@ -313,12 +321,31 @@ var oGraphicalClientStatus = {
 
                // Bandwidth limit
                var bwlimit = '<%[ No limit ]%>';
+               var span = document.createElement('SPAN');
                var l = parseInt(job.bwlimit, 10);
                if (l > 0) {
-                       var fl = Units.format_speed(l, null, true, true);
+                       fl = Units.format_speed(l, null, true, true);
                        bwlimit = fl.value.toFixed(2) + ' ' + fl.format;
                }
-               this.add_job_row(table, '<%[ Bandwidth limit: ]%>', bwlimit);
+               var text = document.createTextNode(bwlimit + '\u00A0\u00A0');
+               span.appendChild(text);
+               var a = document.createElement('A');
+               a.className = 'w3-hover-opacity';
+               a.href = 'javascript:void(0)';
+               a.addEventListener('click', function(e) {
+                       oJobBandwidthLimit.set_value(job.bwlimit);
+                       var param = job.jobid + '|' + job.job;
+                       var cb = <%=$this->JobBandwidthCb->ActiveControl->Javascript%>;
+                       cb.setCallbackParameter(param);
+                       cb.dispatch();
+               });
+               a.title = '<%[ Set job bandwidth limit ]%>';
+               var i = document.createElement('I');
+               i.className = 'fas fa-tachometer-alt w3-large';
+               a.appendChild(i);
+               span.appendChild(a);
+
+               this.add_job_row(table, '<%[ Bandwidth limit: ]%>', span);
 
                var running_jobs_el = document.getElementById(this.ids.running_jobs);
                if (full_refresh) {
@@ -369,7 +396,11 @@ var oGraphicalClientStatus = {
                var tdl = document.createElement('TD');
                var tdr = document.createElement('TD');
                tdl.textContent = key;
-               tdr.innerHTML = value;
+               if (value instanceof HTMLElement) {
+                       tdr.appendChild(value);
+               } else {
+                       tdr.innerHTML = value;
+               }
                tr.appendChild(tdl);
                tr.appendChild(tdr);
                table.appendChild(tr);
index 86da4a80a9886c2f148925bd0508c75c3745a33d..fe60c28bd4e96c8cf8a138328fe9e8021acfcad7 100644 (file)
@@ -22,6 +22,7 @@
 
 Prado::using('System.Web.UI.ActiveControls.TActiveLabel');
 Prado::using('System.Web.UI.ActiveControls.TActiveLinkButton');
+Prado::using('System.Web.UI.ActiveControls.TCallback');
 Prado::using('Application.Web.Class.BaculumWebPage'); 
 
 class ClientView extends BaculumWebPage {
@@ -162,6 +163,14 @@ class ClientView extends BaculumWebPage {
                $this->getCallbackClient()->callClientFunction('init_graphical_client_status', array($client_status));
        }
 
+       public function setBandwidthControl($sender, $param) {
+               if ($param instanceof Prado\Web\UI\ActiveControls\TCallbackEventParameter) {
+                       list($jobid, $job_uname) = explode('|', $param->getCallbackParameter(), 2);
+                       $this->JobBandwidth->setJobId($jobid);
+                       $this->JobBandwidth->setJobUname($job_uname);
+               }
+       }
+
        private function getClientVersion($output) {
                $version = array('major' => 0, 'minor' => 0, 'release' => 0);
                for ($i = 0; $i < count($output); $i++) {
index 66f3582ec964ad996e5c4ab0b06c459a4420fa70..493d848b6f62f0217edeea693f58d674c9623274 100644 (file)
@@ -1,4 +1,4 @@
- &nbsp;<a class="w3-hover-opacity" href="javascript:void(0)" onclick="oClientBandwidthLimit.open_popup();" title="<%[ Set bandwidth ]%>"><i class="fas fa-tachometer-alt w3-large"></i></a>
+ &nbsp;<a class="w3-hover-opacity" href="javascript:void(0)" onclick="oClientBandwidthLimit.open_popup();" title="<%[ Set client bandwidth limit ]%>"><i class="fas fa-tachometer-alt w3-large"></i></a>
 <div id="client_bandwidth_limit_popup" class="w3-modal">
        <div class="w3-modal-content w3-animate-top w3-card-4">
                <header class="w3-container w3-teal">
                                CssClass="w3-button w3-section w3-green w3-padding"
                        >
                                <prop:ClientSide.OnLoading>
-                                       document.getElementById('bandwidth_limit_loading').style.visibility = 'visible';
+                                       document.getElementById('client_bandwidth_limit_loading').style.visibility = 'visible';
                                </prop:ClientSide.OnLoading>
                                <prop:ClientSide.OnComplete>
-                                       document.getElementById('bandwidth_limit_loading').style.visibility = 'hidden';
+                                       document.getElementById('client_bandwidth_limit_loading').style.visibility = 'hidden';
                                </prop:ClientSide.OnComplete>
                                <i class="fa fa-check"></i> &nbsp;<%[ Set bandwidth ]%>
                        </com:TActiveLinkButton>
-                       <i id="bandwidth_limit_loading" class="fa fa-sync w3-spin" style="visibility: hidden;"></i>
+                       <i id="client_bandwidth_limit_loading" class="fa fa-sync w3-spin" style="visibility: hidden;"></i>
                </footer>
                <div id="client_bandwidth_limit_log" class="w3-panel w3-card w3-light-grey" style="display: none; max-height: 200px; overflow-x: auto;">
                        <div class="w3-code">
diff --git a/gui/baculum/protected/Web/Portlets/JobBandwidthLimit.php b/gui/baculum/protected/Web/Portlets/JobBandwidthLimit.php
new file mode 100644 (file)
index 0000000..0f2f717
--- /dev/null
@@ -0,0 +1,136 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2019 Kern Sibbald
+ *
+ * The main author of Baculum is Marcin Haba.
+ * The original author of Bacula is Kern Sibbald, with contributions
+ * from many others, a complete list can be found in the file AUTHORS.
+ *
+ * You may use this file and others of this release according to the
+ * license defined in the LICENSE file, which includes the Affero General
+ * Public License, v3.0 ("AGPLv3") and some additional permissions and
+ * terms pursuant to its AGPLv3 Section 7.
+ *
+ * This notice must be preserved when any source code is
+ * conveyed and/or propagated.
+ *
+ * Bacula(R) is a registered trademark of Kern Sibbald.
+ */
+
+
+Prado::using('System.Web.UI.ActiveControls.TActiveLabel');
+Prado::using('System.Web.UI.ActiveControls.TActiveLinkButton');
+Prado::using('Application.Web.Portlets.DirectiveSpeed');
+Prado::using('Application.Web.Portlets.Portlets');
+
+/**
+ * Set job bandwidth limit control.
+ */
+class JobBandwidthLimit extends Portlets {
+
+       const JOBID = 'JobId';
+       const JOB_UNAME = 'JobUname';
+
+       /**
+        * Set up bandwidth limit value.
+        *
+        * @param TActiveLinkButton $sender sender
+        * @param TCallbackEventParameter $param callback parameter
+        * @return none
+        */
+       public function setupBandwidthLimit($sender, $param) {
+               $jobid = $this->getJobId();
+
+               $result = $this->getModule('api')->set(
+                       array('jobs', $jobid, 'bandwidth'),
+                       array('limit' => $this->BandwidthLimit->getValue())
+               );
+
+               // this setting to empty string is required to not cache outputs for the same values
+               $this->BandwidthLog->Text = '';
+               if ($result->error === 0) {
+                       $this->BandwidthLog->Text = implode(PHP_EOL, $result->output);
+               } else {
+                       $this->BandwidthLog->Text = $result->output;
+               }
+
+               $this->getPage()->getCallbackClient()->callClientFunction(
+                       'show_element',
+                       array('#job_bandwidth_limit_log', true)
+               );
+
+               $this->onCallback(null);
+       }
+
+       /**
+        * Callback event method.
+        *
+        * @param mixed $param callback parameter or null
+        * @return none
+        */
+       public function onCallback($param) {
+               $this->raiseEvent('OnCallback', $this, $param);
+       }
+
+       /**
+        * Set job jobid.
+        *
+        * @return none;
+        */
+       public function setJobId($jobid) {
+               $jobid = intval($jobid);
+               $this->setViewState(self::JOBID, $jobid, 0);
+               $this->JobIdLabel->Text = $jobid;
+       }
+
+       /**
+        * Get job jobid.
+        *
+        * @return integer jobid
+        */
+       public function getJobId() {
+               return $this->getViewState(self::JOBID, 0);
+       }
+
+       /**
+        * Set job uname.
+        *
+        * @return none;
+        */
+       public function setJobUname($job_uname) {
+               $this->setViewState(self::JOB_UNAME, $job_uname);
+               $this->JobUnameLabel->Text = $job_uname;
+       }
+
+       /**
+        * Get job uname.
+        *
+        * @return string job uname
+        */
+       public function getJobUname() {
+               return $this->getViewState(self::JOB_UNAME);
+       }
+
+       /**
+        * Get bandwidth limit value from field.
+        *
+        * @return mixed bandwidth limit integer value or null if bandwidth not set
+        */
+       public function getBandwidthLimit() {
+               return $this->BandwidthLimit->getValue();
+       }
+
+       /**
+        * Set bandwidth limit value in field.
+        *
+        * @param integer $bwlimit bandiwdth limit in bytes
+        * @return none
+        */
+       public function setBandwidthLimit($bwlimit) {
+               $this->BandwidthLimit->setDirectiveValue($bwlimit);
+       }
+}
+?>
diff --git a/gui/baculum/protected/Web/Portlets/JobBandwidthLimit.tpl b/gui/baculum/protected/Web/Portlets/JobBandwidthLimit.tpl
new file mode 100644 (file)
index 0000000..cc8440f
--- /dev/null
@@ -0,0 +1,71 @@
+<div id="job_bandwidth_limit_popup" class="w3-modal">
+       <div class="w3-modal-content w3-animate-top w3-card-4">
+               <header class="w3-container w3-teal">
+                       <span onclick="oJobBandwidthLimit.close_popup();" class="w3-button w3-display-topright">&times;</span>
+                       <h2><%[ Set job bandwidth limit ]%> - <%[ JobId: ]%> <com:TActiveLabel ID="JobIdLabel" /></h2>
+               </header>
+               <div class="w3-container w3-margin-left w3-margin-right">
+                       <p><%[ Job: ]%> <strong><com:TActiveLabel ID="JobUnameLabel" /></strong></p>
+                       <p><%[ Here you can set bandwidth limit for job. This change is applied on running job. ]%></p>
+                       <p><%[ Setting 0 (zero) value disables bandwidth limitation. ]%></p>
+                       <div class="w3-row w3-section w3-medium">
+                               <com:Application.Web.Portlets.DirectiveSpeed
+                                       ID="BandwidthLimit"
+                                       DirectiveName="BandwidthLimit"
+                                       DefaultValue="0"
+                                       Show="true"
+                                       Label="<%[ Bandwidth limit ]%>"
+                                       UnitType="decimal"
+                               />
+                       </div>
+               </div>
+               <footer class="w3-container w3-center">
+                       <a class="w3-button w3-red" href="javascript:void(0)" onclick="oJobBandwidthLimit.close_popup()"><i class="fas fa-times"></i> &nbsp<%[ Cancel ]%></a>
+                       <com:TActiveLinkButton
+                               ID="SetBandwidthLimit"
+                               OnCallback="setupBandwidthLimit"
+                               CssClass="w3-button w3-section w3-green w3-padding"
+                       >
+                               <prop:ClientSide.OnLoading>
+                                       document.getElementById('job_bandwidth_limit_loading').style.visibility = 'visible';
+                               </prop:ClientSide.OnLoading>
+                               <prop:ClientSide.OnComplete>
+                                       document.getElementById('job_bandwidth_limit_loading').style.visibility = 'hidden';
+                               </prop:ClientSide.OnComplete>
+                               <i class="fa fa-check"></i> &nbsp;<%[ Set bandwidth ]%>
+                       </com:TActiveLinkButton>
+                       <i id="job_bandwidth_limit_loading" class="fas fa-sync w3-spin" style="visibility: hidden;"></i>
+               </footer>
+               <div id="job_bandwidth_limit_log" class="w3-panel w3-card w3-light-grey" style="display: none; max-height: 200px; overflow-x: auto;">
+                       <div class="w3-code">
+                               <pre><com:TActiveLabel ID="BandwidthLog" /></pre>
+                       </div>
+               </div>
+       </div>
+</div>
+<script>
+var oJobBandwidthLimit = {
+       ids: {
+               popup: 'job_bandwidth_limit_popup',
+               log: 'job_bandwidth_limit_log'
+       },
+       open_popup: function() {
+               document.getElementById(this.ids.popup).style.display = 'block';
+       },
+       close_popup: function() {
+               document.getElementById(this.ids.popup).style.display = 'none';
+               this.cleanup_log();
+       },
+       cleanup_log: function() {
+               document.getElementById(this.ids.log).style.display = 'none';
+               document.getElementById('<%=$this->BandwidthLog->ClientID%>').textContent = '';
+       },
+       set_value: function(value) {
+               var bwlimit_val = document.getElementById('<%=$this->BandwidthLimit->Directive->ClientID%>');
+               var bwlimit_unit = document.getElementById('<%=$this->BandwidthLimit->SpeedFormat->ClientID%>');
+               var val = Units.format_speed(value, null, false, true);
+               bwlimit_val.value = val.value;
+               bwlimit_unit.value = Units.get_short_unit_by_long('speed', val.format) || val.format;
+       }
+};
+</script>