Skip to content

Commit 65ec2ef

Browse files
committed
Add folder size in tree view
1 parent 8dd156d commit 65ec2ef

File tree

4 files changed

+43
-12
lines changed

4 files changed

+43
-12
lines changed

assets/css/styles.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,9 @@
520520
.py-\[0\.4rem\] {
521521
padding-block: 0.4rem;
522522
}
523+
.pe-1 {
524+
padding-inline-end: calc(0.25rem * 1);
525+
}
523526
.pe-5 {
524527
padding-inline-end: calc(0.25rem * 5);
525528
}

assets/js/scripts.js

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -398,21 +398,48 @@ if (treeview) {
398398
init_expand_state();
399399
}
400400

401-
function update_folder_counts() {
402-
const folders = document.querySelectorAll('.tree-toggle[data-path]');
401+
function number_format(number, decimals = 0) {
402+
let parts = parseFloat(number).toFixed(decimals).split('.');
403+
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, thousandssep);
404+
return parts.join(decimalsep);
405+
}
406+
407+
function format_bytes(bytes, decimals = 2) {
408+
if (bytes > 1048576) {
409+
return number_format(bytes / 1048576, decimals) + 'MB';
410+
}
411+
412+
if (bytes > 1024) {
413+
return number_format(bytes / 1024, decimals) + 'KB';
414+
}
403415

404-
folders.forEach(folder => {
405-
const path = folder.getAttribute('data-path');
406-
const tree_children = document.querySelector(`.tree-children[data-path="${path}"]`);
407-
const children_count = tree_children ? tree_children.querySelectorAll('.keywrapper').length : 0;
408-
const items_count = folder.parentElement.querySelector('.items-count');
416+
return number_format(bytes, decimals) + 'B';
417+
}
409418

410-
if (items_count) {
411-
items_count.textContent = `(${children_count})`;
419+
function update_folder_counts() {
420+
document.querySelectorAll('.tree-toggle').forEach(folder => {
421+
const children_wrapper = folder.closest('.tree-group').querySelector('.tree-children');
422+
423+
if (children_wrapper) {
424+
const total_items = children_wrapper.querySelectorAll('.keywrapper').length;
425+
let total_bytes = 0;
426+
children_wrapper.querySelectorAll('.file-size').forEach(el => {
427+
const bytes = parseFloat(el.getAttribute('data-bytes')) || 0;
428+
total_bytes += bytes;
429+
});
430+
431+
const items_count_span = folder.parentElement.querySelector('.items-count');
432+
if (items_count_span) {
433+
items_count_span.textContent = `(${total_items} items, ${format_bytes(total_bytes)})`;
434+
}
412435
}
413436
});
414437
}
415438

439+
document.addEventListener('DOMContentLoaded', () => {
440+
update_folder_counts();
441+
});
442+
416443
/**
417444
* Light / Dark mode
418445
*/

templates/layout.twig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
3131
const panels_refresh_interval = {{ config('panelrefresh', 30) * 1000 }};
3232
const ajax_panels = {{ ajax_panels is defined and ajax_panels == true ? 'true' : 'false' }};
33-
const metrics_refresh_interval = {{ config('metricsrefresh', 60) * 1000 }};
3433
let metrics_active_filter = {{ config('metricstab', 1440) }};
34+
const decimalsep = '{{ config('decimalsep', ',') }}';
35+
const thousandssep = '{{ config('thousandssep', ' ') }}';
3536
</script>
3637
</head>
3738
<body class="flex flex-col min-h-screen text-gray-900 bg-gray-100 dark:text-gray-200 dark:bg-gray-900" data-dashboard="{{ current }}">

templates/partials/tree_view.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{% if item.type == 'folder' %}
77
<div class="tree-group border-t border-gray-200 dark:border-gray-700" style="--level: {{ level }}">
88
<div class="flex gap-1 items-center py-1 px-6 hover:bg-gray-50 dark:hover:bg-white/5" style="padding-left: calc({{ level }} * 20px + 1.5rem)">
9-
<div>{{ components.checkbox('check-all') }}</div>
9+
<div class="pe-1" title="Check all">{{ components.checkbox('check-all') }}</div>
1010
<button class="flex gap-1 items-center tree-toggle" data-path="{{ item.path }}">
1111
{{ svg('down', 10, '-rotate-90') }}
1212
<span class="tree">{{ item.name }}{{ separator }}*</span>
@@ -47,7 +47,7 @@
4747
{% elseif item_key starts with 'timediff_' and kitem is not empty %}
4848
<span title="{{ kitem|time }}">{{- kitem|timediff -}}</span>
4949
{% elseif item_key starts with 'bytes_' %}
50-
{{- kitem|bytes -}}
50+
<span class="file-size" data-bytes="{{ kitem }}">{{- kitem|bytes -}}</span>
5151
{% else %}
5252
{{- kitem -}}
5353
{% endif %}

0 commit comments

Comments
 (0)