]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Move resource monitor and error message box to separate modules
authorMarcin Haba <marcin.haba@bacula.pl>
Fri, 9 Jul 2021 19:20:16 +0000 (21:20 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:03:25 +0000 (09:03 +0100)
gui/baculum/protected/Web/Layouts/Main.tpl
gui/baculum/protected/Web/Portlets/ErrorMessageBox.php [new file with mode: 0644]
gui/baculum/protected/Web/Portlets/ErrorMessageBox.tpl [new file with mode: 0644]
gui/baculum/protected/Web/Portlets/ResourceMonitor.php [new file with mode: 0644]
gui/baculum/protected/Web/Portlets/ResourceMonitor.tpl [new file with mode: 0644]

index f7c4f33c9a343d9def3abc9d35cbcb9a343c1100..6bee6960103a881b13d8506a717289a55cd10289 100644 (file)
                        </div>
                </com:TForm>
                <div id="small" class="w3-hide-large"></div>
-               <div id="error_message_box" class="w3-modal" style="display: none">
-                       <div class="w3-modal-content w3-card-4 w3-animate-zoom" style="width:600px">
-                               <header class="w3-container w3-red">
-                                       <span onclick="document.getElementById('error_message_box').style.display='none'" class="w3-button w3-display-topright">×</span>
-                                       <h2><%[ Error ]%></h2>
-                               </header>
-                               <div class="w3-panel w3-padding">
-                                       <p><strong><%[ Error code: ]%></strong> <span id="error_message_error_code"></span></p>
-                                       <p><strong><%[ Message: ]%></strong> <span id="error_message_error_msg"></span></p>
-                               </div>
-                               <footer class="w3-container w3-center">
-                                       <button type="button" class="w3-button w3-section w3-red" onclick="document.getElementById('error_message_box').style.display='none'"><i class="fa fa-check"></i> &nbsp;<%[ OK ]%></button>
-                               </footer>
-                       </div>
-               </div>
-<script type="text/javascript">
+<com:Application.Web.Portlets.ErrorMessageBox />
+<com:Application.Web.Portlets.ResourceMonitor />
+<com:Application.Web.Portlets.MsgEnvelope Visible="<%=$this->User->isInRole(WebUserRoles::ADMIN)%>" />
+<script>
 var is_small = $('#small').is(':visible');
-
-var oMonitor;
-var default_refresh_interval = 60000;
-var default_fast_refresh_interval = 10000;
-var timeout_handler;
-var last_callback_time = 0;
-var callback_time_offset = 0;
-var oData;
-var MonitorCalls = [];
-var MonitorCallsInterval = [];
 $(function() {
        if (is_small) {
                W3SideBar.close();
        }
-       oMonitor = function() {
-               return $.ajax('<%=$this->Service->constructUrl("Monitor")%>', {
-                       dataType: 'json',
-                       type: 'post',
-                       data: {
-                               'params': (typeof(MonitorParams) == 'object' ? MonitorParams : []),
-                               'use_limit' : <%=$this->Service->getRequestedPagePath() == "Dashboard" ? '0' : '1'%>,
-                       },
-                       beforeSend: function() {
-                               last_callback_time = new Date().getTime();
-                       },
-                       success: function(response) {
-                               if (timeout_handler) {
-                                       clearTimeout(timeout_handler);
-                               }
-                               if (response && response.hasOwnProperty('error') && response.error.error !== 0) {
-                                       show_error(response.error.output, response.error.error);
-                               }
-
-                               oData = response;
-                               if ('<%=get_class($this->Service->getRequestedPage())%>' == 'Dashboard') {
-                                       Statistics.grab_statistics(oData, JobStatus.get_states());
-                                       Dashboard.set_text({
-                                               js_sum_title: '<%[ Job status summary ]%>'
-                                       });
-                                       Dashboard.update_all(Statistics);
-                               }
-
-                               if (oData.running_jobs.length > 0) {
-                                       refreshInterval =  callback_time_offset + default_fast_refresh_interval;
-                               } else {
-                                       refreshInterval = default_refresh_interval;
-                               }
-                               if (typeof(job_callback_func) == 'function') {
-                                       job_callback_func();
-                               }
-                               document.getElementById('running_jobs').textContent = oData.running_jobs.length;
-                               timeout_handler = setTimeout("oMonitor()", refreshInterval);
-
-                               var calls_len = MonitorCalls.length;
-                               for (var i = 0; i < calls_len; i++) {
-                                       MonitorCalls[i]();
-                               }
-                               var calls_interval_len = MonitorCallsInterval.length;
-                               for (var i = 0; i < calls_interval_len; i++) {
-                                       MonitorCallsInterval[i]();
-                               }
-                               if (calls_len > 0) {
-                                       Formatters.set_formatters();
-                               }
-                               MonitorCalls = [];
-                       }
-               });
-       };
-       oMonitor();
 });
-function show_error(output, error) {
-       var err_box = document.getElementById('error_message_box');
-       var err_code = document.getElementById('error_message_error_code');
-       var err_msg = document.getElementById('error_message_error_msg');
-       err_code.textContent = error;
-       err_msg.innerHTML = output;
-       err_box.style.display = 'block';
-}
-       </script>
-       <com:Application.Web.Portlets.MsgEnvelope Visible="<%=$this->User->isInRole(WebUserRoles::ADMIN)%>" />
+</script>
        </body>
 </html>
diff --git a/gui/baculum/protected/Web/Portlets/ErrorMessageBox.php b/gui/baculum/protected/Web/Portlets/ErrorMessageBox.php
new file mode 100644 (file)
index 0000000..272b595
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2021 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('Application.Web.Portlets.Portlets');
+
+/**
+ * Error message box - displays global errors and problems.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @category Control
+ * @package Baculum Web
+ */
+class ErrorMessageBox extends Portlets {
+}
diff --git a/gui/baculum/protected/Web/Portlets/ErrorMessageBox.tpl b/gui/baculum/protected/Web/Portlets/ErrorMessageBox.tpl
new file mode 100644 (file)
index 0000000..f7e3ad4
--- /dev/null
@@ -0,0 +1,25 @@
+<div id="error_message_box" class="w3-modal" style="display: none">
+       <div class="w3-modal-content w3-card-4 w3-animate-zoom" style="width:600px">
+               <header class="w3-container w3-red">
+                       <span onclick="document.getElementById('error_message_box').style.display='none'" class="w3-button w3-display-topright">×</span>
+                       <h2><%[ Error ]%></h2>
+               </header>
+               <div class="w3-panel w3-padding">
+                       <p><strong><%[ Error code: ]%></strong> <span id="error_message_error_code"></span></p>
+                       <p><strong><%[ Message: ]%></strong> <span id="error_message_error_msg"></span></p>
+               </div>
+               <footer class="w3-container w3-center">
+                       <button type="button" class="w3-button w3-section w3-red" onclick="document.getElementById('error_message_box').style.display='none'"><i class="fa fa-check"></i> &nbsp;<%[ OK ]%></button>
+               </footer>
+       </div>
+</div>
+<script>
+function show_error(output, error) {
+       var err_box = document.getElementById('error_message_box');
+       var err_code = document.getElementById('error_message_error_code');
+       var err_msg = document.getElementById('error_message_error_msg');
+       err_code.textContent = error;
+       err_msg.innerHTML = output;
+       err_box.style.display = 'block';
+}
+</script>
diff --git a/gui/baculum/protected/Web/Portlets/ResourceMonitor.php b/gui/baculum/protected/Web/Portlets/ResourceMonitor.php
new file mode 100644 (file)
index 0000000..deecb79
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2021 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('Application.Web.Portlets.Portlets');
+
+/**
+ * Resource monitor.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @category Control
+ * @package Baculum Web
+ */
+class ResourceMonitor extends Portlets {
+}
diff --git a/gui/baculum/protected/Web/Portlets/ResourceMonitor.tpl b/gui/baculum/protected/Web/Portlets/ResourceMonitor.tpl
new file mode 100644 (file)
index 0000000..7fa8def
--- /dev/null
@@ -0,0 +1,68 @@
+<script>
+var oMonitor;
+var default_refresh_interval = 60000;
+var default_fast_refresh_interval = 10000;
+var timeout_handler;
+var last_callback_time = 0;
+var callback_time_offset = 0;
+var oData;
+var MonitorCalls = [];
+var MonitorCallsInterval = [];
+$(function() {
+       oMonitor = function() {
+               return $.ajax('<%=$this->Service->constructUrl("Monitor")%>', {
+                       dataType: 'json',
+                       type: 'post',
+                       data: {
+                               'params': (typeof(MonitorParams) == 'object' ? MonitorParams : []),
+                               'use_limit' : <%=$this->Service->getRequestedPagePath() == "Dashboard" ? '0' : '1'%>,
+                       },
+                       beforeSend: function() {
+                               last_callback_time = new Date().getTime();
+                       },
+                       success: function(response) {
+                               if (timeout_handler) {
+                                       clearTimeout(timeout_handler);
+                               }
+                               if (response && response.hasOwnProperty('error') && response.error.error !== 0) {
+                                       show_error(response.error.output, response.error.error);
+                               }
+
+                               oData = response;
+                               if ('<%=get_class($this->Service->getRequestedPage())%>' == 'Dashboard') {
+                                       Statistics.grab_statistics(oData, JobStatus.get_states());
+                                       Dashboard.set_text({
+                                               js_sum_title: '<%[ Job status summary ]%>'
+                                       });
+                                       Dashboard.update_all(Statistics);
+                               }
+
+                               if (oData.running_jobs.length > 0) {
+                                       refreshInterval =  callback_time_offset + default_fast_refresh_interval;
+                               } else {
+                                       refreshInterval = default_refresh_interval;
+                               }
+                               if (typeof(job_callback_func) == 'function') {
+                                       job_callback_func();
+                               }
+                               document.getElementById('running_jobs').textContent = oData.running_jobs.length;
+                               timeout_handler = setTimeout("oMonitor()", refreshInterval);
+
+                               var calls_len = MonitorCalls.length;
+                               for (var i = 0; i < calls_len; i++) {
+                                       MonitorCalls[i]();
+                               }
+                               var calls_interval_len = MonitorCallsInterval.length;
+                               for (var i = 0; i < calls_interval_len; i++) {
+                                       MonitorCallsInterval[i]();
+                               }
+                               if (calls_len > 0) {
+                                       Formatters.set_formatters();
+                               }
+                               MonitorCalls = [];
+                       }
+               });
+       };
+       oMonitor();
+});
+</script>