restructure file access
This commit is contained in:
parent
007ad4581b
commit
d4605b952e
55
analytics.py
55
analytics.py
@ -727,6 +727,8 @@ def file_access():
|
||||
if 'timeframe' not in session:
|
||||
session['timeframe'] = 'last24hours'
|
||||
session['timeframe'] = request.args.get('timeframe', session['timeframe'])
|
||||
if 'file_access_category' not in session:
|
||||
session['file_access_category'] = None
|
||||
|
||||
now = datetime.now()
|
||||
|
||||
@ -775,25 +777,56 @@ def file_access():
|
||||
'category': hf.extract_structure_from_string(rel_path)[0]
|
||||
})
|
||||
|
||||
# Get possible categories from the rows
|
||||
categories = sorted({r['category'] for r in rows if r['category'] is not None})
|
||||
all_categories = [None] + categories
|
||||
top20 = []
|
||||
for category in all_categories:
|
||||
label = category if category is not None else 'Keine Kategorie gefunden !'
|
||||
files = [r for r in rows if r['category'] == category][:20]
|
||||
top20.append({
|
||||
'category': label,
|
||||
'files': files
|
||||
# Build a list of selectable categories for the dropdown
|
||||
category_options = []
|
||||
has_uncategorized = any(r['category'] is None for r in rows)
|
||||
if has_uncategorized:
|
||||
category_options.append({
|
||||
'value': 'uncategorized',
|
||||
'label': 'Keine Kategorie gefunden !'
|
||||
})
|
||||
|
||||
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_long = app_config.get('TITLE_LONG' , 'Default Title')
|
||||
|
||||
return render_template(
|
||||
"file_access.html",
|
||||
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(),
|
||||
title_short=title_short,
|
||||
title_long=title_long
|
||||
|
||||
@ -34,47 +34,63 @@
|
||||
<ul class="dropdown-menu" aria-labelledby="timeframeDropdown">
|
||||
<li>
|
||||
<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
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<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
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<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
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<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
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<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
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</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>
|
||||
|
||||
|
||||
<!-- Detailed Table of Top File Accesses -->
|
||||
{% for top20_item in top20 %}
|
||||
<div class="card mb-4">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<span>{{ top20_item['category'] }}</span>
|
||||
<span class="toggle-icon" aria-label="collapse" role="button" tabindex="0">+</span>
|
||||
</div>
|
||||
<div class="card-body collapsable">
|
||||
<div class="card-header">{{ selected_category_label }}</div>
|
||||
<div class="card-body">
|
||||
{% if top20_files %}
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
@ -84,23 +100,20 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for row in top20_item['files'] %}
|
||||
{% for row in top20_files %}
|
||||
<tr>
|
||||
<td>{{ row.access_count }}</td>
|
||||
<td>{{ row.rel_path }}</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr>
|
||||
<td colspan="2">No data available for the selected timeframe.</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% else %}
|
||||
<p class="mb-0">No data available for the selected timeframe and category.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user