restructure file access

This commit is contained in:
lelo 2026-01-18 19:00:53 +00:00
parent 007ad4581b
commit d4605b952e
2 changed files with 75 additions and 29 deletions

View File

@ -727,6 +727,8 @@ def file_access():
if 'timeframe' not in session: if 'timeframe' not in session:
session['timeframe'] = 'last24hours' session['timeframe'] = 'last24hours'
session['timeframe'] = request.args.get('timeframe', session['timeframe']) session['timeframe'] = request.args.get('timeframe', session['timeframe'])
if 'file_access_category' not in session:
session['file_access_category'] = None
now = datetime.now() now = datetime.now()
@ -775,25 +777,56 @@ def file_access():
'category': hf.extract_structure_from_string(rel_path)[0] 'category': hf.extract_structure_from_string(rel_path)[0]
}) })
# Get possible categories from the rows # Build a list of selectable categories for the dropdown
categories = sorted({r['category'] for r in rows if r['category'] is not None}) category_options = []
all_categories = [None] + categories has_uncategorized = any(r['category'] is None for r in rows)
top20 = [] if has_uncategorized:
for category in all_categories: category_options.append({
label = category if category is not None else 'Keine Kategorie gefunden !' 'value': 'uncategorized',
files = [r for r in rows if r['category'] == category][:20] 'label': 'Keine Kategorie gefunden !'
top20.append({
'category': label,
'files': files
}) })
unique_categories = sorted({r['category'] for r in rows if r['category'] is not None})
for category in unique_categories:
category_options.append({
'value': category,
'label': category
})
default_category_value = category_options[0]['value'] if category_options else None
requested_category = request.args.get('category')
stored_category = session.get('file_access_category')
selected_category = requested_category or stored_category or default_category_value
valid_values = {opt['value'] for opt in category_options}
if selected_category not in valid_values:
selected_category = default_category_value
session['file_access_category'] = selected_category
def matches_category(row):
if selected_category == 'uncategorized':
return row['category'] is None
return row['category'] == selected_category
filtered_rows = [r for r in rows if matches_category(r)] if selected_category is not None else []
top20_files = filtered_rows[:20]
selected_category_label = next(
(opt['label'] for opt in category_options if opt['value'] == selected_category),
'Keine Daten verfügbar'
)
title_short = app_config.get('TITLE_SHORT', 'Default Title') title_short = app_config.get('TITLE_SHORT', 'Default Title')
title_long = app_config.get('TITLE_LONG' , 'Default Title') title_long = app_config.get('TITLE_LONG' , 'Default Title')
return render_template( return render_template(
"file_access.html", "file_access.html",
timeframe=session['timeframe'], timeframe=session['timeframe'],
top20 = top20, categories=category_options,
selected_category=selected_category,
selected_category_label=selected_category_label,
top20_files=top20_files,
admin_enabled=auth.is_admin(), admin_enabled=auth.is_admin(),
title_short=title_short, title_short=title_short,
title_long=title_long title_long=title_long

View File

@ -34,47 +34,63 @@
<ul class="dropdown-menu" aria-labelledby="timeframeDropdown"> <ul class="dropdown-menu" aria-labelledby="timeframeDropdown">
<li> <li>
<a class="dropdown-item {% if session['timeframe'] == 'last24hours' %}active{% endif %}" <a class="dropdown-item {% if session['timeframe'] == 'last24hours' %}active{% endif %}"
href="{{ url_for('file_access', timeframe='last24hours') }}"> href="{{ url_for('file_access', timeframe='last24hours', category=selected_category) }}">
Last 24 Hours Last 24 Hours
</a> </a>
</li> </li>
<li> <li>
<a class="dropdown-item {% if session['timeframe'] == '7days' %}active{% endif %}" <a class="dropdown-item {% if session['timeframe'] == '7days' %}active{% endif %}"
href="{{ url_for('file_access', timeframe='7days') }}"> href="{{ url_for('file_access', timeframe='7days', category=selected_category) }}">
Last 7 Days Last 7 Days
</a> </a>
</li> </li>
<li> <li>
<a class="dropdown-item {% if session['timeframe'] == '14days' %}active{% endif %}" <a class="dropdown-item {% if session['timeframe'] == '14days' %}active{% endif %}"
href="{{ url_for('file_access', timeframe='14days') }}"> href="{{ url_for('file_access', timeframe='14days', category=selected_category) }}">
Last 14 Days Last 14 Days
</a> </a>
</li> </li>
<li> <li>
<a class="dropdown-item {% if session['timeframe'] == '30days' %}active{% endif %}" <a class="dropdown-item {% if session['timeframe'] == '30days' %}active{% endif %}"
href="{{ url_for('file_access', timeframe='30days') }}"> href="{{ url_for('file_access', timeframe='30days', category=selected_category) }}">
Last 30 Days Last 30 Days
</a> </a>
</li> </li>
<li> <li>
<a class="dropdown-item {% if session['timeframe'] == '365days' %}active{% endif %}" <a class="dropdown-item {% if session['timeframe'] == '365days' %}active{% endif %}"
href="{{ url_for('file_access', timeframe='365days') }}"> href="{{ url_for('file_access', timeframe='365days', category=selected_category) }}">
Last 365 Days Last 365 Days
</a> </a>
</li> </li>
</ul> </ul>
</div> </div>
<!-- Category Dropdown -->
{% if categories %}
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle"
type="button" id="categoryDropdown" data-bs-toggle="dropdown" aria-expanded="false">
{{ selected_category_label }}
</button>
<ul class="dropdown-menu" aria-labelledby="categoryDropdown">
{% for option in categories %}
<li>
<a class="dropdown-item {% if selected_category == option.value %}active{% endif %}"
href="{{ url_for('file_access', timeframe=session['timeframe'], category=option.value) }}">
{{ option.label }}
</a>
</li>
{% endfor %}
</ul>
</div>
{% endif %}
</div> </div>
<!-- Detailed Table of Top File Accesses --> <!-- Detailed Table of Top File Accesses -->
{% for top20_item in top20 %}
<div class="card mb-4"> <div class="card mb-4">
<div class="card-header d-flex justify-content-between align-items-center"> <div class="card-header">{{ selected_category_label }}</div>
<span>{{ top20_item['category'] }}</span> <div class="card-body">
<span class="toggle-icon" aria-label="collapse" role="button" tabindex="0">+</span> {% if top20_files %}
</div>
<div class="card-body collapsable">
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
@ -84,23 +100,20 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for row in top20_item['files'] %} {% for row in top20_files %}
<tr> <tr>
<td>{{ row.access_count }}</td> <td>{{ row.access_count }}</td>
<td>{{ row.rel_path }}</td> <td>{{ row.rel_path }}</td>
</tr> </tr>
{% else %}
<tr>
<td colspan="2">No data available for the selected timeframe.</td>
</tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
</div> </div>
{% else %}
<p class="mb-0">No data available for the selected timeframe and category.</p>
{% endif %}
</div> </div>
</div> </div>
{% endfor %}
</div> </div>
{% endblock %} {% endblock %}