]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add option to show size unit values as decimal or binary bytes
authorMarcin Haba <marcin.haba@bacula.pl>
Sun, 30 Jun 2019 11:41:31 +0000 (13:41 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Sat, 14 Dec 2019 14:55:25 +0000 (15:55 +0100)
24 files changed:
gui/baculum/protected/Web/JavaScript/misc.js
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/Layouts/Main.php
gui/baculum/protected/Web/Layouts/Main.tpl
gui/baculum/protected/Web/Layouts/Wizard.php
gui/baculum/protected/Web/Layouts/Wizard.tpl
gui/baculum/protected/Web/Pages/ApplicationSettings.page
gui/baculum/protected/Web/Pages/ApplicationSettings.php
gui/baculum/protected/Web/Pages/ClientView.page
gui/baculum/protected/Web/Pages/JobHistoryList.page
gui/baculum/protected/Web/Pages/PoolView.page
gui/baculum/protected/Web/Pages/RestoreWizard.page
gui/baculum/protected/Web/Pages/RestoreWizard.php
gui/baculum/protected/Web/Pages/VolumeList.page
gui/baculum/protected/Web/Pages/VolumeView.page
gui/baculum/protected/Web/Portlets/DirectiveSize.php
gui/baculum/protected/Web/Portlets/DirectiveSpeed.php

index c7777b54a29e760440152bfb47ce8a8077538109..8995d173062acd428997322cfb815cbbce557343 100644 (file)
@@ -2,7 +2,7 @@ var Units = {
        units: {
                size: [
                        {short: '',  long: 'B', value: 1},
-                       {short: 'kb', long: 'KB', value: 1000},
+                       {short: 'kb', long: 'kB', value: 1000},
                        {short: 'k', long: 'KiB', value: 1024},
                        {short: 'mb', long: 'MB', value: 1000},
                        {short: 'm', long: 'MiB', value: 1024},
@@ -27,11 +27,11 @@ var Units = {
                        {long: 'day', value: 24}
                ]
        },
-       get_decimal_size: function(size) {
+       get_size: function(size, unit_value) {
                var dec_size;
                var units = [];
                for (var u in Units.units.size) {
-                       if ([1, 1000].indexOf(Units.units.size[u].value) !== -1) {
+                       if ([1, unit_value].indexOf(Units.units.size[u].value) !== -1) {
                                units.push(Units.units.size[u].long);
                        }
                }
@@ -48,8 +48,8 @@ var Units = {
                        size = parseInt(size, 10);
                        var unit;
                        dec_size = size.toString();
-                       while(size >= 1000) {
-                               size /= 1000;
+                       while(size >= unit_value) {
+                               size /= unit_value;
                                unit = units.shift();
                        }
                        if (unit) {
@@ -61,6 +61,23 @@ var Units = {
                }
                return dec_size;
        },
+       get_decimal_size: function(size) {
+               return this.get_size(size, 1000);
+       },
+       get_binary_size: function(size) {
+               return this.get_size(size, 1024);
+       },
+       get_formatted_size: function(size) {
+               var value = '';
+               if (typeof(SIZE_VALUES_UNIT) === 'string') {
+                       if (SIZE_VALUES_UNIT === 'decimal') {
+                               value = this.get_decimal_size(size);
+                       } else if (SIZE_VALUES_UNIT === 'binary') {
+                               value = this.get_binary_size(size);
+                       }
+               }
+               return value;
+       },
        format_size: function(size_bytes, format) {
                var reminder;
                var f = this.units.size[0].long;
@@ -157,7 +174,7 @@ var PieGraph  = {
 
 var Formatters = {
        formatter: [
-               {css_class: 'size', format_func: Units.get_decimal_size},
+               {css_class: 'size', format_func: function(val) { return Units.get_formatted_size(val); }},
                {css_class: 'time', format_func: function(val) { return Units.format_time_period(val); }}
        ],
        set_formatters: function() {
@@ -180,6 +197,10 @@ var Formatters = {
        }
 }
 
+function set_formatters() {
+       Formatters.set_formatters();
+}
+
 var Cookies = {
        default_exipration_time: 31536000000, // 1 year in miliseconds
        set_cookie: function(name, value, expiration) {
@@ -564,13 +585,13 @@ var Dashboard = {
                document.getElementById(this.ids.jobs.most_count).textContent = occupancy;
        },
        update_jobtotals: function() {
-               document.getElementById(this.ids.jobtotals.total_bytes).textContent = Units.get_decimal_size(this.stats.jobtotals.bytes);
+               document.getElementById(this.ids.jobtotals.total_bytes).textContent = Units.get_formatted_size(this.stats.jobtotals.bytes);
                document.getElementById(this.ids.jobtotals.total_files).textContent = this.stats.jobtotals.files || 0;
        },
        update_database: function() {
                if (this.stats.dbsize.dbsize) {
                        document.getElementById(this.ids.database.type).textContent = this.dbtype[this.stats.dbsize.dbtype];
-                       document.getElementById(this.ids.database.size).textContent = Units.get_decimal_size(this.stats.dbsize.dbsize);
+                       document.getElementById(this.ids.database.size).textContent = Units.get_formatted_size(this.stats.dbsize.dbsize);
                }
        },
        update_pools: function() {
index e511454596b640c855876afccaa371df0c1dc6fd..7b09f690d4ef7595979e17909e20ae39d059858b 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 e3b13f6f16d8a2e0cfc1c12c12988e7f0f951c31..e0a228d261684fde65c4606b4b6ef2c919deb298 100644 (file)
@@ -2062,3 +2062,12 @@ msgstr "Command status:"
 
 msgid "Ready"
 msgstr "Ready"
+
+msgid "Show size values as:"
+msgstr "Show size values as:"
+
+msgid "Decimal Bytes (1 mega = 10<sup>6</sup>)"
+msgstr "Decimal Bytes (1 mega = 10<sup>6</sup>)"
+
+msgid "Binary Bytes (1 mebi = 2<sup>20</sup>)"
+msgstr "Binary Bytes (1 mebi = 2<sup>20</sup>)"
index 7ccccf373317868feab4e66008ec96632440953e..0d9e97ac54e4198645e59da8d2f82db8217b9caf 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 c681f6144d9e60e7011796691ae3bc96b807403a..0777a4568fd34539a32e53c820697455ae9a460f 100644 (file)
@@ -2152,3 +2152,12 @@ msgstr "Command status:"
 
 msgid "Ready"
 msgstr "Ready"
+
+msgid "Show size values as:"
+msgstr "Show size values as:"
+
+msgid "Decimal Bytes (1 mega = 10<sup>6</sup>)"
+msgstr "Decimal Bytes (1 mega = 10<sup>6</sup>)"
+
+msgid "Binary Bytes (1 mebi = 2<sup>20</sup>)"
+msgstr "Binary Bytes (1 mebi = 2<sup>20</sup>)"
index fe0a52735ab1e7643ffdace9d6c333f09740fc67..42b7fa3ad5e3591c0e169c84351fa9f8bccb0568 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 bad09dcdf48135e051671aa785b894b4f7af743c..facf3ed2b97d8911f4022779b0a70ec0f4052aa2 100644 (file)
@@ -2069,3 +2069,12 @@ msgstr "Status komendy:"
 
 msgid "Ready"
 msgstr "Gotowy"
+
+msgid "Show size values as:"
+msgstr "Pokaż wartości rozmiaru jako:"
+
+msgid "Decimal Bytes (1 mega = 10<sup>6</sup>)"
+msgstr "Dziesiętne Bajty (1 mega = 10<sup>6</sup>)"
+
+msgid "Binary Bytes (1 mebi = 2<sup>20</sup>)"
+msgstr "Binarne Bajty (1 mebi = 2<sup>20</sup>)"
index 21a88e65d32aa74a478b8666e947357160dc7609..d186c99a45fe0e45bdcf7653ea1e47273c36cfb4 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 292b96d4023b7862aeed4b137053e52884ecc00a..3233ce22b13d0ea7491eb77dfb1224f8b0349b5c 100644 (file)
@@ -2077,3 +2077,12 @@ msgstr "Command status:"
 
 msgid "Ready"
 msgstr "Ready"
+
+msgid "Show size values as:"
+msgstr "Show size values as:"
+
+msgid "Decimal Bytes (1 mega = 10<sup>6</sup>)"
+msgstr "Decimal Bytes (1 mega = 10<sup>6</sup>)"
+
+msgid "Binary Bytes (1 mebi = 2<sup>20</sup>)"
+msgstr "Binary Bytes (1 mebi = 2<sup>20</sup>)"
index 159139341280453dedd01124e32b66ec386284be..b357f50b7dde804bb11e701b94355f14dea09835 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 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
  * Bacula(R) is a registered trademark of Kern Sibbald.
  */
  
-class Main extends TTemplateControl
-{
-       
+class Main extends TTemplateControl {
+
+       public $web_config;
+
+       public function onPreRender($param) {
+               parent::onPreRender($param);
+               $this->web_config = $this->Application->getModule('web_config')->getConfig();
+       }
 }
-?>
\ No newline at end of file
+?>
index a5e42180cb425253450c4e9544f866d05d57ee27..237fd66a4165355a1b7dca0acece4ef25f8244bf 100644 (file)
@@ -55,6 +55,7 @@
                </div>
 <script type="text/javascript">
 var is_small = $('#small').is(':visible');
+var SIZE_VALUES_UNIT = '<%=(count($this->web_config) > 0 && key_exists('size_values_unit', $this->web_config['baculum'])) ? $this->web_config['baculum']['size_values_unit'] : 'decimal'%>';
 
 var oMonitor;
 var default_refresh_interval = 60000;
index 04cbda530aac6f462e80d870fbabab004edbc2c1..c37fae98dc297a7a9664ce502262524ce3cbd998 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 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
  * Bacula(R) is a registered trademark of Kern Sibbald.
  */
  
-class Wizard extends TTemplateControl
-{
-       
+class Wizard extends TTemplateControl {
+
+       public $web_config;
+
+       public function onPreRender($param) {
+               parent::onPreRender($param);
+               $this->web_config = $this->Application->getModule('web_config')->getConfig();
+       }
 }
-?>
\ No newline at end of file
+?>
index bf043972d4f5739458123480eccf7305e606fc8a..88e6a75d715e40cf9aba078576786aa267223830 100644 (file)
@@ -6,6 +6,9 @@
        <link rel="icon" href="<%=$this->getPage()->getTheme()->getBaseUrl()%>/favicon.ico" type="image/x-icon" />
        </com:THead>
        <body  class="w3-light-grey">
+               <script type="text/javascript">
+                       var SIZE_VALUES_UNIT = '<%=(count($this->web_config) > 0 && key_exists('size_values_unit', $this->web_config['baculum'])) ? $this->web_config['baculum']['size_values_unit'] : 'decimal'%>';
+               </script>
                <com:TForm>
                        <com:TClientScript PradoScripts="ajax, effects" />
                        <com:BClientScript ScriptUrl=<%~ ../JavaScript/fontawesome-all.js %> />
index 4bdba76e4845acbc25df2790d9b763f20bebded2..7515f91c91ef9d8a69dc4f73ac0a327d9d9e4e53 100644 (file)
                        />
                </div>
        </div>
+       <div class="w3-container w3-row w3-padding">
+               <div class="w3-third w3-col"><%[ Show size values as: ]%></div>
+               <div class="w3-third w3-col">
+                       <p><com:TRadioButton
+                               ID="DecimalBytes"
+                               CssClass="w3-radio"
+                               GroupName="SizeBytes"
+                       /> <com:TLabel ForControl="DecimalBytes"><%[ Decimal Bytes (1 mega = 10<sup>6</sup>) ]%></com:TLabel></p>
+                       <p>
+                       <com:TRadioButton
+                               ID="BinaryBytes"
+                               CssClass="w3-radio"
+                               GroupName="SizeBytes"
+                       /> <com:TLabel ForControl="BinaryBytes"><%[ Binary Bytes (1 mebi = 2<sup>20</sup>) ]%></com:TLabel></p>
+               </div>
+       </div>
        <div class="w3-center">
                <com:TActiveLinkButton
                        CssClass="w3-button w3-green"
index 49a27c76625497cdafa413d55b04b6ef3736e95a..7b4c39256db2815e6c1a773c1705be540d4290f8 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
@@ -33,9 +33,14 @@ class ApplicationSettings extends BaculumWebPage {
        public function onInit($param) {
                parent::onInit($param);
                $this->web_config = $this->getModule('web_config')->getConfig();
+               $this->DecimalBytes->Checked = true;
                if(count($this->web_config) > 0) {
                        $this->Debug->Checked = ($this->web_config['baculum']['debug'] == 1);
                        $this->MaxJobs->Text = (key_exists('max_jobs', $this->web_config['baculum']) ? intval($this->web_config['baculum']['max_jobs']) : Monitor::DEFAULT_MAX_JOBS);
+                       if (key_exists('size_values_unit', $this->web_config['baculum'])) {
+                               $this->DecimalBytes->Checked = ($this->web_config['baculum']['size_values_unit'] === 'decimal');
+                               $this->BinaryBytes->Checked = ($this->web_config['baculum']['size_values_unit'] === 'binary');
+                       }
                }
        }
 
@@ -45,6 +50,7 @@ class ApplicationSettings extends BaculumWebPage {
                        $this->web_config['baculum']['debug'] = ($this->Debug->Checked === true) ? 1 : 0;
                        $max_jobs = intval($this->MaxJobs->Text);
                        $this->web_config['baculum']['max_jobs'] = $max_jobs;
+                       $this->web_config['baculum']['size_values_unit'] = $this->BinaryBytes->Checked ? 'binary' : 'decimal';
                        $this->getModule('web_config')->setConfig($this->web_config);
                }
        }
index 7f7ea6a2a331fc27c358583a6bf79bc8fefbb80d..9b981a22b7094c5efe274daa556907c445c4a5bd 100644 (file)
@@ -123,7 +123,7 @@ var oJobForClientList = {
                                        render: function (data, type, row) {
                                                var s;
                                                if (type == 'display') {
-                                                       s = Units.get_decimal_size(data)
+                                                       s = Units.get_formatted_size(data)
                                                } else {
                                                        s = data;
                                                }
index 25bd034d2dec0aea3d146b1d1ef1312fbd918efa..f074ecb91e3b5eb1caaa49da762155009d3e8abb 100644 (file)
@@ -100,7 +100,7 @@ var oJobList = {
                                        render: function (data, type, row) {
                                                var s;
                                                if (type == 'display') {
-                                                       s = Units.get_decimal_size(data)
+                                                       s = Units.get_formatted_size(data)
                                                } else {
                                                        s = data;
                                                }
index 40e1214085ef0ad5e95f55ba5e98798b8246b6ef..a68fb04c457a56b25d4c0b6f28d3047c854a0d75 100644 (file)
@@ -188,7 +188,7 @@ var oVolumeList = {
                                        render: function (data, type, row) {
                                                var s;
                                                if (type == 'display') {
-                                                       s = Units.get_decimal_size(data)
+                                                       s = Units.get_formatted_size(data)
                                                } else {
                                                        s = data;
                                                }
index 0f20b9100d4ef26f35b44259778e9ad21cf879f3..8f20e199785dcc79a759ba7cda1ec83deae086e4 100644 (file)
@@ -233,7 +233,7 @@ var oJobsToRestoreList = {
                                        render: function (data, type, row) {
                                                var s;
                                                if (type == 'display') {
-                                                       s = Units.get_decimal_size(data)
+                                                       s = Units.get_formatted_size(data)
                                                } else {
                                                        s = data;
                                                }
@@ -476,9 +476,7 @@ oJobsToRestoreList.init();
                                                <div id="restore-browser-selected" class="w3-border">
                                                        <com:TJuiDroppable ID="SelectedVersionsDropper" Height="100%" Width="100%"
                                                                Options.accept=".draggable"
-                                                               OnLoad="refreshSelectedFiles"
                                                                OnDrop="addFileToRestore"
-                                                               OnCallback="refreshSelectedFiles"
                                                                OnDeactivate="callFormatters"
                                                                >
                                                                        <com:TActiveDataGrid
index d250e482058f949fc65c5af3fc694ec03ee20b03..483d8f626e260fda4e48adbe74bf1355d62a497f 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
@@ -575,25 +575,11 @@ class RestoreWizard extends BaculumWebPage
                $this->loadSelectedFiles();
        }
 
-       /**
-        * Refresh/re-render selected files list.
-        *
-        * @param TDropContainer $sender sender object
-        * @param TEventParameter $param param object
-        * @return none
-        */
-       public function refreshSelectedFiles($sender, $param) {
-               $this->loadSelectedFiles();
-               if ($this->IsCallBack && is_object($param)) {
-                       $this->SelectedVersionsDropper->render($param->NewWriter);
-               }
-       }
-
        /**
         * Call formatters method.
         */
        public function callFormatters($sender, $param) {
-               $this->getCallbackClient()->callClientFunction('Formatters.set_formatters');
+               $this->getCallbackClient()->callClientFunction('set_formatters');
        }
 
        /*
index f453ccf2e0a80596d55630d2bf259089f4264351..eb1a05608777345633619b80b0a23ad37d856027 100644 (file)
@@ -69,7 +69,7 @@ var oVolumeList = {
                                        render: function (data, type, row) {
                                                var s;
                                                if (type == 'display') {
-                                                       s = Units.get_decimal_size(data)
+                                                       s = Units.get_formatted_size(data)
                                                } else {
                                                        s = data;
                                                }
index 4e57a989c69f094057b52756709ec72c38712388..e510637f5f7058e3456b3065910ab43c48b1b6af 100644 (file)
@@ -404,7 +404,7 @@ var oJobsOnVolumeList = {
                                        render: function (data, type, row) {
                                                var s;
                                                if (type == 'display') {
-                                                       s = Units.get_decimal_size(data)
+                                                       s = Units.get_formatted_size(data)
                                                } else {
                                                        s = data;
                                                }
index be1ced03830003db239cf8c285d376053e357bc6..65eef444c4d6ce769e2196a7c63a76f4fe08fd0c 100644 (file)
@@ -32,7 +32,7 @@ class DirectiveSize extends DirectiveTemplate {
 
        private $size_formats = array(
                array('format' => '', 'value' => 1, 'label' => 'B'),
-               array('format' => 'kb', 'value' => 1000, 'label' => 'KB'),
+               array('format' => 'kb', 'value' => 1000, 'label' => 'kB'),
                array('format' => 'k', 'value' => 1024, 'label' => 'KiB'),
                array('format' => 'mb', 'value' => 1000000, 'label' => 'MB'),
                array('format' => 'm', 'value' => 1048576, 'label' => 'MiB'),
index 1e02997c517d9814c8e2afd057cb541939c2cf3f..8aba6182c443e5af4de8ed76139c0b293981af51 100644 (file)
@@ -32,7 +32,7 @@ class DirectiveSpeed extends DirectiveTemplate {
 
        private $speed_formats = array(
                array('format' => '', 'value' => 1, 'label' => 'B/s'),
-               array('format' => 'kb/s', 'value' => 1000, 'label' => 'KB/s'),
+               array('format' => 'kb/s', 'value' => 1000, 'label' => 'kB/s'),
                array('format' => 'k/s', 'value' => 1024, 'label' => 'KiB/s'),
                array('format' => 'mb/s', 'value' => 1000000, 'label' => 'MB/s'),
                array('format' => 'm/s', 'value' => 1048576, 'label' => 'MiB/s')