Toggleable Disk Space Usage Display

This commit builds upon the previous feature of displaying disk space information by adding a toggle option in the settings to show or hide disk space usage details.

 #### Changes:
- Added a new setting under the settings section allowing users to toggle the display of disk space usage information.
- Updated the disk space display logic to check the setting before fetching and displaying disk space information.

 #### Code Additions:
- Introduced a new checkbox under the settings section to allow users to toggle the display of disk space usage.
- Implemented a check for the `show_disk_usage` setting before executing disk space calculation and display logic.

 #### Benefits:
- Provides users with the flexibility to choose whether or not to display disk space information based on their preferences or needs.
- Helps in reducing unnecessary disk space calculations when the information is not needed, potentially improving performance.
- Maintains a clean and uncluttered UI by allowing users to hide disk space information when it's not required.
This commit is contained in:
hppanpaliya 2023-10-17 21:59:18 -04:00
parent 40ebbcbbb3
commit d2e6e003a7
No known key found for this signature in database
GPG key ID: E76B4F90C2B10FAE

View file

@ -1,6 +1,6 @@
<?php
//Default Configuration
$CONFIG = '{"lang":"en","error_reporting":false,"show_hidden":false,"hide_Cols":false,"theme":"light"}';
$CONFIG = '{"lang":"en","error_reporting":false,"show_hidden":false,"hide_Cols":false,"theme":"light","show_disk_usage":true}';
/**
* H3K | Tiny File Manager V2.5.3
@ -196,6 +196,8 @@ $hide_Cols = isset($cfg->data['hide_Cols']) ? $cfg->data['hide_Cols'] : true;
// Theme
$theme = isset($cfg->data['theme']) ? $cfg->data['theme'] : 'light';
$show_disk_usage = isset($cfg->data['show_disk_usage']) ? $cfg->data['show_disk_usage'] : true;
define('FM_THEME', $theme);
//available languages
@ -539,6 +541,7 @@ if ((isset($_SESSION[FM_SESSION_ID]['logged'], $auth_users[$_SESSION[FM_SESSION_
$erp = isset($_POST['js-error-report']) && $_POST['js-error-report'] == "true" ? true : false;
$shf = isset($_POST['js-show-hidden']) && $_POST['js-show-hidden'] == "true" ? true : false;
$hco = isset($_POST['js-hide-cols']) && $_POST['js-hide-cols'] == "true" ? true : false;
$sdu = isset($_POST['js-show-usage']) && $_POST['js-show-usage'] == "true" ? true : false;
$te3 = $_POST['js-theme-3'];
if ($cfg->data['lang'] != $newLng) {
@ -557,6 +560,10 @@ if ((isset($_SESSION[FM_SESSION_ID]['logged'], $auth_users[$_SESSION[FM_SESSION_
$cfg->data['show_hidden'] = $shf;
$show_hidden_files = $shf;
}
if ($cfg->data['show_disk_usage'] != $sdu) {
$cfg->data['show_disk_usage'] = $sdu;
$show_disk_usage = $sdu;
}
if ($cfg->data['hide_Cols'] != $hco) {
$cfg->data['hide_Cols'] = $hco;
$hide_Cols = $hco;
@ -1553,6 +1560,16 @@ if (isset($_GET['settings']) && !FM_READONLY) {
</div>
</div>
<div class="mb-3 row">
<label for="js-show-hidden" class="col-sm-3 col-form-label"><?php echo lng('ShowDiskUsage') ?></label>
<div class="col-sm-9">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="js-show-usage" name="js-show-usage" value="true" <?php echo $show_disk_usage ? 'checked' : ''; ?> />
</div>
</div>
</div>
<div class="mb-3 row">
<label for="js-hide-cols" class="col-sm-3 col-form-label"><?php echo lng('HideColumns') ?></label>
<div class="col-sm-9">
@ -2202,25 +2219,31 @@ $tableTheme = (FM_THEME == "dark") ? "text-white bg-dark table-dark" : "bg-white
</tfoot>
<?php
} else { ?>
<?php
// Get total and free space
$total = disk_total_space(FM_ROOT_PATH.'/'.FM_PATH);
$free = disk_free_space(FM_ROOT_PATH.'/'.FM_PATH);
// Format sizes
$total_size = fm_get_filesize($total);
$free_size = fm_get_filesize($free);
$total_used_size = fm_get_filesize($total - $free);
<?php
// Check if show_disk_usage is true before getting disk size
if ($show_disk_usage) {
// Get total and free space
$total = disk_total_space(FM_ROOT_PATH.'/'.FM_PATH);
$free = disk_free_space(FM_ROOT_PATH.'/'.FM_PATH);
// Format sizes
$total_size = fm_get_filesize($total);
$free_size = fm_get_filesize($free);
$total_used_size = fm_get_filesize($total - $free);
}
?>
<tfoot>
<tr>
<td class="gray" colspan="<?php echo (!FM_IS_WIN && !$hide_Cols) ? (FM_READONLY ? '6' :'7') : (FM_READONLY ? '4' : '5') ?>">
<?php echo lng('FullSize').': <span class="badge text-bg-light border-radius-0">'.fm_get_filesize($all_files_size).'</span>' ?>
<?php echo lng('UsedSpace').': <span class="badge text-bg-light border-radius-0">' .$total_used_size.'</span>'; ?>
<?php echo lng('RemainingSpace').': <span class="badge text-bg-light border-radius-0">' .$free_size.'</span>'; ?>
<?php
// Check if show_disk_usage is true before displaying disk usage
if ($show_disk_usage) {
echo lng('UsedSpace').': <span class="badge text-bg-light border-radius-0">' .$total_used_size.'</span>';
echo lng('RemainingSpace').': <span class="badge text-bg-light border-radius-0">' .$free_size.'</span>';
}
?>
<?php echo lng('File').': <span class="badge text-bg-light border-radius-0">'.$num_files.'</span>' ?>
<?php echo lng('Folder').': <span class="badge text-bg-light border-radius-0">'.$num_folders.'</span>' ?>
</td>
@ -4304,6 +4327,7 @@ function lng($txt) {
$tr['en']['File or folder with this path already exists'] = 'File or folder with this path already exists';
$tr['en']['RemainingSpace'] = 'Remaining Space';
$tr['en']['UsedSpace'] = 'Used Space';
$tr['en']['ShowDiskUsage'] = 'Show Disk Usage';
$i18n = fm_get_translations($tr);
$tr = $i18n ? $i18n : $tr;