]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add component start/stop/restart actions to Web
authorMarcin Haba <marcin.haba@bacula.pl>
Thu, 1 Aug 2019 18:50:21 +0000 (20:50 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Sat, 14 Dec 2019 14:55:28 +0000 (15:55 +0100)
14 files changed:
gui/baculum/protected/API/Pages/Panel/APIInstallWizard.php
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/Portlets/BaculaConfigComponents.php
gui/baculum/protected/Web/Portlets/BaculaConfigComponents.tpl
gui/baculum/protected/Web/Portlets/ComponentActionsMenu.php [new file with mode: 0644]
gui/baculum/protected/Web/Portlets/ComponentActionsMenu.tpl [new file with mode: 0644]
gui/baculum/themes/Baculum-v2/css/baculum.css

index 7a507e21cd1427bc775a5a2c31a243b468e2178d..0ce83b3e4a1ee741bbcdbb2dd39ff06e023f0902 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2018 Kern Sibbald
+ * Copyright (C) 2013-2019 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
index a6bacfbbc90eed6d7d2ef21be35ddfe4699aa64a..38f61a6c6af42c30e1640fcbc909130f5ff2f5e7 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 5a0ba22c25b3558dae88b77385b9125237d7e7e4..bcb9c304ef989287283ca936d50df22ec114e7e8 100644 (file)
@@ -2293,3 +2293,24 @@ msgstr "Graphical client status is supported for Bacula clients version 9.0 and
 
 msgid "Status request timed out. The most probably the Bacula client is not available or it is not running."
 msgstr "Status request timed out. The most probably the Bacula client is not available or it is not running."
+
+msgid "Start"
+msgstr "Start"
+
+msgid "Stop"
+msgstr "Stop"
+
+msgid "Restart"
+msgstr "Restart"
+
+msgid "Component action result"
+msgstr "Component action result"
+
+msgid "Component start finished successfully."
+msgstr "Component start finished successfully."
+
+msgid "Component stop finished successfully."
+msgstr "Component stop finished successfully."
+
+msgid "Component restart finished successfully."
+msgstr "Component restart finished successfully."
index b3572ed1c13b3f0a1f6b71eabdfec23758a48355..74b32786e53ed7ce53cc9c07c930b014277f0cef 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 96bc28b992340dd3901039a4ddcd1b0a9bf4ac62..ec31065550634856850914da7e20570968b15e09 100644 (file)
@@ -2379,3 +2379,24 @@ msgstr "Graphical client status is supported for Bacula clients version 9.0 and
 
 msgid "Status request timed out. The most probably the Bacula client is not available or it is not running."
 msgstr "Status request timed out. The most probably the Bacula client is not available or it is not running."
+
+msgid "Start"
+msgstr "Start"
+
+msgid "Stop"
+msgstr "Stop"
+
+msgid "Restart"
+msgstr "Restart"
+
+msgid "Component action result"
+msgstr "Component action result"
+
+msgid "Component start finished successfully."
+msgstr "Component start finished successfully."
+
+msgid "Component stop finished successfully."
+msgstr "Component stop finished successfully."
+
+msgid "Component restart finished successfully."
+msgstr "Component restart finished successfully."
index b974331756a0dd93183b643a24657f355cb29796..c19d884d3847d5039a205b092b6c003ec49fa648 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 44160a81bab2225ad7ef3558a7d77e009e5f9161..6a9f5d410219a38c0c83aff3548a747cc6076969 100644 (file)
@@ -2300,3 +2300,24 @@ msgstr "Graficzny status klienta jest wspierany dla klientów Bacula w wersji 9.
 
 msgid "Status request timed out. The most probably the Bacula client is not available or it is not running."
 msgstr "Upłynął limit czasu żądania statusu. Najprawdopodobniej klient Bacula nie jest dostępny lub nie jest uruchomiony."
+
+msgid "Start"
+msgstr "Start"
+
+msgid "Stop"
+msgstr "Stop"
+
+msgid "Restart"
+msgstr "Restart"
+
+msgid "Component action result"
+msgstr "Rezultat akcji na komponencie"
+
+msgid "Component start finished successfully."
+msgstr "Uruchomienie komponentu zakończyło się pomyślnie."
+
+msgid "Component stop finished successfully."
+msgstr "Zatrzymanie komponentu zakończyło się pomyślnie."
+
+msgid "Component restart finished successfully."
+msgstr "Restart komponentu zakończył się pomyślnie."
index bf215332452a06eb927200b7b64801c05dc57096..d3e2b03f4155d43b9ccc7f41618fd7fb2b8fc0b6 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 bed1c3cdd929d016b2a5491caff334445ec0fe1c..9156b9c99782b078136d45e9c3d7ccb894f66118 100644 (file)
@@ -2308,3 +2308,24 @@ msgstr "Graphical client status is supported for Bacula clients version 9.0 and
 
 msgid "Status request timed out. The most probably the Bacula client is not available or it is not running."
 msgstr "Status request timed out. The most probably the Bacula client is not available or it is not running."
+
+msgid "Start"
+msgstr "Start"
+
+msgid "Stop"
+msgstr "Stop"
+
+msgid "Restart"
+msgstr "Restart"
+
+msgid "Component action result"
+msgstr "Component action result"
+
+msgid "Component start finished successfully."
+msgstr "Component start finished successfully."
+
+msgid "Component stop finished successfully."
+msgstr "Component stop finished successfully."
+
+msgid "Component restart finished successfully."
+msgstr "Component restart finished successfully."
index dba176a42e53f07448c351c02aa72db6f5e0962b..f707fd18d023b725864c92d20287c8758c49520b 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2017 Kern Sibbald
+ * Copyright (C) 2013-2019 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
@@ -32,6 +32,8 @@ class BaculaConfigComponents extends ComponentListTemplate {
 
        const MENU_CONTROL = 'NewResourceMenu';
 
+       const ACTIONS_CONTROL = 'ComponentActionsMenu';
+
        private function getConfigData($host) {
                $params = array('config');
                $result = $this->Application->getModule('api')->get($params, $host, false);
@@ -63,13 +65,16 @@ class BaculaConfigComponents extends ComponentListTemplate {
        }
 
        public function createComponentListElement($sender, $param) {
-               $controls = array(self::CHILD_CONTROL, self::MENU_CONTROL);
-               for ($i = 0; $i < count($controls); $i++) {
-                       $control = $this->getChildControl($param->Item, $controls[$i]);
-                       if (is_object($control)) {
-                               $control->setHost($param->Item->Data['host']);
-                               $control->setComponentType($param->Item->Data['component_type']);
-                               $control->setComponentName($param->Item->Data['component_name']);
+               $conts = array(self::MENU_CONTROL, self::ACTIONS_CONTROL);
+               for ($i = 0; $i < count($conts); $i++) {
+                       $controls = array(self::CHILD_CONTROL, $conts[$i]);
+                       for ($j = 0; $j < count($controls); $j++) {
+                               $control = $this->getChildControl($param->Item, $controls[$j]);
+                               if (is_object($control)) {
+                                       $control->setHost($param->Item->Data['host']);
+                                       $control->setComponentType($param->Item->Data['component_type']);
+                                       $control->setComponentName($param->Item->Data['component_name']);
+                               }
                        }
                }
        }
index 5367cc5b69af266c2ca26b6db198f0eec9078d10..81678206a70585d0d0d1f5afd832218a35585b5a 100644 (file)
@@ -18,8 +18,9 @@
                                                        <i class="fa fa-sync w3-spin" style="display: none"><i/>
                                                </td>
                                                <td class="right" style="width: 20%">
+                                                       <com:Application.Web.Portlets.ComponentActionsMenu ID="CompActions" Visible="<%=$this->CompActions->getComponentType() !== 'bcons'%>" />
                                                        <a class="w3-button w3-green w3-right button_fixed" href="javascript:void(0)" onmousedown="openElementOnCursor(event, '<%=$this->ResourcesMenu->ClientID%>_new_resource', -80, 20);"><i class="fa fa-plus"></i> &nbsp;<%[ Add ]%></a>
-                                                       <com:Application.Web.Portlets.NewResourceMenu ID="ResourcesMenu" />
+                                                       <com:Application.Web.Portlets.NewResourceMenu ID="ResourcesMenu"/>
                                                </td>
                                        </tr>
                                </table>
diff --git a/gui/baculum/protected/Web/Portlets/ComponentActionsMenu.php b/gui/baculum/protected/Web/Portlets/ComponentActionsMenu.php
new file mode 100644 (file)
index 0000000..4b62671
--- /dev/null
@@ -0,0 +1,60 @@
+<?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.TActiveLinkButton');
+Prado::using('Application.Web.Portlets.DirectiveListTemplate');
+
+/**
+ * Component actions control responsible for start,
+ * stop and restart components.
+ */
+class ComponentActionsMenu extends DirectiveListTemplate {
+
+       /**
+        * Allowed actions to do with components.
+        */
+       private $allowed_actions = array('start', 'stop', 'restart');
+
+       /**
+        * Do action on component.
+        *
+        * @param TActiveLinkButton $sender sender object
+        * @param TCommandEventParameter $param command parameter
+        * @return none
+        */
+       public function componentAction($sender, $param) {
+               $action = $param->getCommandParameter();
+               if (in_array($action, $this->allowed_actions)) {
+                       $host = $this->getHost();
+                       $component_type = $this->getComponentType();
+                       $component = $this->getModule('misc')->getComponentUrlName($component_type);
+                       $result = $this->getModule('api')->get(
+                               array('actions', $component, $action),
+                               $host
+                       );
+                       $this->getPage()->getCallbackClient()->callClientFunction(
+                               $this->ClientID . '_component_action_set_result',
+                               array($action, $result)
+                       );
+               }
+       }
+}
diff --git a/gui/baculum/protected/Web/Portlets/ComponentActionsMenu.tpl b/gui/baculum/protected/Web/Portlets/ComponentActionsMenu.tpl
new file mode 100644 (file)
index 0000000..e5d8c5f
--- /dev/null
@@ -0,0 +1,120 @@
+<a href="javascript:void(0);" onmousedown="openElementOnCursor(event, '<%=$this->ClientID%>_component_actions', -80, 20);"><i class="fas fa-ellipsis-v fa-lg"></i></a>
+<div id="<%=$this->ClientID%>_component_actions" class="w3-card w3-white w3-padding left" style="display: none">
+       <i class="fa fa-times w3-right" onclick="$('#<%=$this->ClientID%>_component_actions').hide();" style="cursor: pointer"></i>
+       <ul class="w3-ul new_element_menu">
+               <li><com:TActiveLinkButton
+                       OnCommand="componentAction"
+                       CommandParameter="start"
+                       ClientSide.OnLoading="$('#<%=$this->ClientID%>_component_actions').hide();"
+                       >
+                       <i class='fas fa-play'></i> &nbsp;<%[ Start ]%>
+               </com:TActiveLinkButton>
+               </li>
+               <li><com:TActiveLinkButton
+                       OnCommand="componentAction"
+                       CommandParameter="stop"
+                       ClientSide.OnLoading="$('#<%=$this->ClientID%>_component_actions').hide();"
+                       >
+                       <i class='fas fa-stop'></i> &nbsp;<%[ Stop ]%>
+               </com:TActiveLinkButton>
+               </li>
+               <li><com:TActiveLinkButton
+                       OnCommand="componentAction"
+                       CommandParameter="restart"
+                       ClientSide.OnLoading="$('#<%=$this->ClientID%>_component_actions').hide();"
+                       >
+                       <i class='fas fa-sync'></i> &nbsp;<%[ Restart ]%>
+               </com:TActiveLinkButton>
+               </li>
+       </ul>
+</div>
+<div id="<%=$this->ClientID%>_component_action_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 marked">
+                       <span onclick="$('#<%=$this->ClientID%>_component_action_message_box').hide();" class="w3-button w3-display-topright">×</span>
+                       <h2><%[ Component action result ]%></h2>
+               </header>
+               <div class="w3-panel w3-padding">
+                       <p><strong><%[ Message: ]%></strong> <span id="<%=$this->ClientID%>_component_action_output"></span></p>
+                       <p onclick="$('#<%=$this->ClientID%>_component_action_details').slideToggle('fast'); $('#<%=$this->ClientID%>_component_action_arrow').toggleClass(function() { return $(this).is('.fa-chevron-down') ? 'fa-chevron-up' : 'fa-chevron-down';});" style="cursor: pointer"><i id="<%=$this->ClientID%>_component_action_arrow" class="fas fa-chevron-down"></i> &nbsp;<%[ Details ]%></p>
+                       <p id="<%=$this->ClientID%>_component_action_details" style="display: none"><strong><%[ Error code: ]%></strong> <span id="<%=$this->ClientID%>_component_action_message_exit_code"></span></p>
+               </div>
+               <footer class="w3-container w3-center w3-border-top">
+                       <button type="button" class="w3-button w3-section w3-red marked" onclick="$('#<%=$this->ClientID%>_component_action_message_box').hide()"><i class="fa fa-check"></i> &nbsp;<%[ OK ]%></button>
+               </footer>
+       </div>
+</div>
+<script type="text/javascript">
+oComponentAction<%=$this->ClientID%> = {
+       ids: {
+               message_box: '<%=$this->ClientID%>_component_action_message_box',
+               error_code: '<%=$this->ClientID%>_component_action_message_exit_code',
+               output: '<%=$this->ClientID%>_component_action_output'
+       },
+       msgs: {
+               start_ok: '<%[ Component start finished successfully. ]%>',
+               stop_ok: '<%[ Component stop finished successfully. ]%>',
+               restart_ok: '<%[ Component restart finished successfully. ]%>',
+       },
+       actions: {
+               start: 'start',
+               stop: 'stop',
+               restart: 'restart'
+       },
+       set_result: function(action, result) {
+               if (result.error === 0) {
+                       this.set_info_view();
+               } else {
+                       this.set_error_view();
+               }
+               this.set_output(action, result);
+               this.set_error_code(result.error);
+               this.show_box();
+       },
+       set_info_view: function() {
+               this.switch_box_view('w3-red', 'w3-green');
+       },
+       set_error_view: function() {
+               this.switch_box_view('w3-green', 'w3-red');
+       },
+       switch_box_view: function(old_class, new_class) {
+               var msgbox = document.getElementById(this.ids.message_box);
+               var containers = msgbox.querySelectorAll('.marked');
+               for (var i = 0; i < containers.length; i++) {
+                       if (containers[i].classList.contains(old_class)) {
+                               containers[i].classList.remove(old_class);
+                       }
+                       containers[i].classList.add(new_class);
+               }
+       },
+       set_error_code: function(error_code) {
+               document.getElementById(this.ids.error_code).textContent = error_code;
+       },
+       set_output: function(action, result) {
+               var out = document.getElementById(this.ids.output);
+               if (Array.isArray(result.output)) {
+                       out.innerHTML = result.output.join('<br />');
+               } else if (result.output) {
+                       out.textContent = result.output;
+               } else if (result.error === 0) {
+                       switch (action) {
+                               case this.actions.start:
+                                       out.textContent = this.msgs.start_ok;
+                                       break;
+                               case this.actions.stop:
+                                       out.textContent = this.msgs.stop_ok;
+                                       break;
+                               case this.actions.restart:
+                                       out.textContent = this.msgs.restart_ok;
+                                       break;
+                       }
+               }
+       },
+       show_box: function() {
+               document.getElementById(this.ids.message_box).style.display = 'block';
+       }
+};
+function <%=$this->ClientID%>_component_action_set_result(action, result) {
+       oComponentAction<%=$this->ClientID%>.set_result(action, result);
+}
+</script>
index 414f1e7c492d3a79404614ba584dc8b8019e1276..7843fcbc79975fd16e5e5daba13fc0548e652d7e 100644 (file)
@@ -239,3 +239,15 @@ table.status_table td:nth-of-type(1) {
 table.status_table td, table.status_table td svg {
        vertical-align: middle;
 }
+
+.fa-ellipsis-v {
+       width: 43px !important;
+       height: 43px;
+       padding: 10px;
+       border-radius: 50%;
+       background-color: transparent;
+}
+
+.fa-ellipsis-v:hover {
+       background-color: #efeff0;
+}