From: Marcin Haba Date: Sun, 30 Jun 2019 11:41:31 +0000 (+0200) Subject: baculum: Add option to show size unit values as decimal or binary bytes X-Git-Tag: Release-9.6.0~202 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c082c2fb65598f367d2c879861830b69381fba82;p=thirdparty%2Fbacula.git baculum: Add option to show size unit values as decimal or binary bytes --- diff --git a/gui/baculum/protected/Web/JavaScript/misc.js b/gui/baculum/protected/Web/JavaScript/misc.js index c7777b54a2..8995d17306 100644 --- a/gui/baculum/protected/Web/JavaScript/misc.js +++ b/gui/baculum/protected/Web/JavaScript/misc.js @@ -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() { diff --git a/gui/baculum/protected/Web/Lang/en/messages.mo b/gui/baculum/protected/Web/Lang/en/messages.mo index e511454596..7b09f690d4 100644 Binary files a/gui/baculum/protected/Web/Lang/en/messages.mo and b/gui/baculum/protected/Web/Lang/en/messages.mo differ diff --git a/gui/baculum/protected/Web/Lang/en/messages.po b/gui/baculum/protected/Web/Lang/en/messages.po index e3b13f6f16..e0a228d261 100644 --- a/gui/baculum/protected/Web/Lang/en/messages.po +++ b/gui/baculum/protected/Web/Lang/en/messages.po @@ -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 = 106)" +msgstr "Decimal Bytes (1 mega = 106)" + +msgid "Binary Bytes (1 mebi = 220)" +msgstr "Binary Bytes (1 mebi = 220)" diff --git a/gui/baculum/protected/Web/Lang/ja/messages.mo b/gui/baculum/protected/Web/Lang/ja/messages.mo index 7ccccf3733..0d9e97ac54 100644 Binary files a/gui/baculum/protected/Web/Lang/ja/messages.mo and b/gui/baculum/protected/Web/Lang/ja/messages.mo differ diff --git a/gui/baculum/protected/Web/Lang/ja/messages.po b/gui/baculum/protected/Web/Lang/ja/messages.po index c681f6144d..0777a4568f 100644 --- a/gui/baculum/protected/Web/Lang/ja/messages.po +++ b/gui/baculum/protected/Web/Lang/ja/messages.po @@ -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 = 106)" +msgstr "Decimal Bytes (1 mega = 106)" + +msgid "Binary Bytes (1 mebi = 220)" +msgstr "Binary Bytes (1 mebi = 220)" diff --git a/gui/baculum/protected/Web/Lang/pl/messages.mo b/gui/baculum/protected/Web/Lang/pl/messages.mo index fe0a52735a..42b7fa3ad5 100644 Binary files a/gui/baculum/protected/Web/Lang/pl/messages.mo and b/gui/baculum/protected/Web/Lang/pl/messages.mo differ diff --git a/gui/baculum/protected/Web/Lang/pl/messages.po b/gui/baculum/protected/Web/Lang/pl/messages.po index bad09dcdf4..facf3ed2b9 100644 --- a/gui/baculum/protected/Web/Lang/pl/messages.po +++ b/gui/baculum/protected/Web/Lang/pl/messages.po @@ -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 = 106)" +msgstr "Dziesiętne Bajty (1 mega = 106)" + +msgid "Binary Bytes (1 mebi = 220)" +msgstr "Binarne Bajty (1 mebi = 220)" diff --git a/gui/baculum/protected/Web/Lang/pt/messages.mo b/gui/baculum/protected/Web/Lang/pt/messages.mo index 21a88e65d3..d186c99a45 100644 Binary files a/gui/baculum/protected/Web/Lang/pt/messages.mo and b/gui/baculum/protected/Web/Lang/pt/messages.mo differ diff --git a/gui/baculum/protected/Web/Lang/pt/messages.po b/gui/baculum/protected/Web/Lang/pt/messages.po index 292b96d402..3233ce22b1 100644 --- a/gui/baculum/protected/Web/Lang/pt/messages.po +++ b/gui/baculum/protected/Web/Lang/pt/messages.po @@ -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 = 106)" +msgstr "Decimal Bytes (1 mega = 106)" + +msgid "Binary Bytes (1 mebi = 220)" +msgstr "Binary Bytes (1 mebi = 220)" diff --git a/gui/baculum/protected/Web/Layouts/Main.php b/gui/baculum/protected/Web/Layouts/Main.php index 1591393412..b357f50b7d 100644 --- a/gui/baculum/protected/Web/Layouts/Main.php +++ b/gui/baculum/protected/Web/Layouts/Main.php @@ -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 @@ -20,8 +20,13 @@ * 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 +?> diff --git a/gui/baculum/protected/Web/Layouts/Main.tpl b/gui/baculum/protected/Web/Layouts/Main.tpl index a5e42180cb..237fd66a41 100644 --- a/gui/baculum/protected/Web/Layouts/Main.tpl +++ b/gui/baculum/protected/Web/Layouts/Main.tpl @@ -55,6 +55,7 @@ /> diff --git a/gui/baculum/protected/Web/Pages/ApplicationSettings.page b/gui/baculum/protected/Web/Pages/ApplicationSettings.page index 4bdba76e48..7515f91c91 100644 --- a/gui/baculum/protected/Web/Pages/ApplicationSettings.page +++ b/gui/baculum/protected/Web/Pages/ApplicationSettings.page @@ -41,6 +41,22 @@ /> +
+
<%[ Show size values as: ]%>
+
+

<%[ Decimal Bytes (1 mega = 106) ]%>

+

+ <%[ Binary Bytes (1 mebi = 220) ]%>

+
+
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); } } diff --git a/gui/baculum/protected/Web/Pages/ClientView.page b/gui/baculum/protected/Web/Pages/ClientView.page index 7f7ea6a2a3..9b981a22b7 100644 --- a/gui/baculum/protected/Web/Pages/ClientView.page +++ b/gui/baculum/protected/Web/Pages/ClientView.page @@ -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; } diff --git a/gui/baculum/protected/Web/Pages/JobHistoryList.page b/gui/baculum/protected/Web/Pages/JobHistoryList.page index 25bd034d2d..f074ecb91e 100644 --- a/gui/baculum/protected/Web/Pages/JobHistoryList.page +++ b/gui/baculum/protected/Web/Pages/JobHistoryList.page @@ -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; } diff --git a/gui/baculum/protected/Web/Pages/PoolView.page b/gui/baculum/protected/Web/Pages/PoolView.page index 40e1214085..a68fb04c45 100644 --- a/gui/baculum/protected/Web/Pages/PoolView.page +++ b/gui/baculum/protected/Web/Pages/PoolView.page @@ -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; } diff --git a/gui/baculum/protected/Web/Pages/RestoreWizard.page b/gui/baculum/protected/Web/Pages/RestoreWizard.page index 0f20b9100d..8f20e19978 100644 --- a/gui/baculum/protected/Web/Pages/RestoreWizard.page +++ b/gui/baculum/protected/Web/Pages/RestoreWizard.page @@ -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();
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'); } /* diff --git a/gui/baculum/protected/Web/Pages/VolumeList.page b/gui/baculum/protected/Web/Pages/VolumeList.page index f453ccf2e0..eb1a056087 100644 --- a/gui/baculum/protected/Web/Pages/VolumeList.page +++ b/gui/baculum/protected/Web/Pages/VolumeList.page @@ -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; } diff --git a/gui/baculum/protected/Web/Pages/VolumeView.page b/gui/baculum/protected/Web/Pages/VolumeView.page index 4e57a989c6..e510637f5f 100644 --- a/gui/baculum/protected/Web/Pages/VolumeView.page +++ b/gui/baculum/protected/Web/Pages/VolumeView.page @@ -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; } diff --git a/gui/baculum/protected/Web/Portlets/DirectiveSize.php b/gui/baculum/protected/Web/Portlets/DirectiveSize.php index be1ced0383..65eef444c4 100644 --- a/gui/baculum/protected/Web/Portlets/DirectiveSize.php +++ b/gui/baculum/protected/Web/Portlets/DirectiveSize.php @@ -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'), diff --git a/gui/baculum/protected/Web/Portlets/DirectiveSpeed.php b/gui/baculum/protected/Web/Portlets/DirectiveSpeed.php index 1e02997c51..8aba6182c4 100644 --- a/gui/baculum/protected/Web/Portlets/DirectiveSpeed.php +++ b/gui/baculum/protected/Web/Portlets/DirectiveSpeed.php @@ -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')