0001-misc-keep-logs-tab-open-when-using-pagination-64834.patch
passerelle/templates/passerelle/includes/resource-logs-table.html | ||
---|---|---|
1 | 1 |
{% load i18n passerelle tz gadjo %} |
2 | 2 | |
3 | 3 |
{% if logrecords %} |
4 |
<table class="main" data-log-base-url="{% url 'view-logs-connector' connector=object.get_connector_slug slug=object.slug %}" > |
|
4 |
<table class="main" id="table-logs" data-log-base-url="{% url 'view-logs-connector' connector=object.get_connector_slug slug=object.slug %}" >
|
|
5 | 5 |
<thead> |
6 | 6 |
<th>{% trans 'Timestamp' %}</th> |
7 | 7 |
<th>{% trans 'Source IP' %}</th> |
... | ... | |
21 | 21 |
</tbody> |
22 | 22 |
</table> |
23 | 23 | |
24 |
{% with page_obj=logrecords anchor="#logs" without_key="log_id" page_key=page_key|default:"page" %} |
|
24 |
{% with page_obj=logrecords anchor="#table-logs" without_key="log_id" page_key=page_key|default:"page" %}
|
|
25 | 25 |
{% if page_obj.has_next or page_obj.has_previous %} |
26 | 26 |
{% spaceless %} |
27 | 27 |
<p class="paginator"> |
passerelle/templates/passerelle/manage/service_view.html | ||
---|---|---|
61 | 61 | |
62 | 62 |
<div class="pk-tabs connector-tabs"> |
63 | 63 |
<div class="pk-tabs--tab-list" role="tablist"> |
64 |
<button role="tab" aria-selected="true" aria-controls="panel-endpoints" id="tab-endpoints" tabindex="0">{% trans "Endpoints" %}</button>
|
|
64 |
<button role="tab" {% if default_tab_page == 'endpoints' %}aria-selected="true" tabindex="0"{% else %}aria-selected="false" tabindex="-1"{% endif %}aria-controls="panel-endpoints" id="tab-endpoints">{% trans "Endpoints" %}</button>
|
|
65 | 65 |
{% if object|can_edit:request.user and object.queries is not None %} |
66 | 66 |
<button role="tab" aria-selected="false" aria-controls="panel-queries" id="tab-queries" tabindex="-1">{% trans "Queries" %}</button> |
67 | 67 |
{% endif %} |
... | ... | |
70 | 70 |
<button role="tab" aria-selected="false" aria-controls="panel-security" id="tab-security" tabindex="-1">{% trans "Security" %}</button> |
71 | 71 |
{% endif %} |
72 | 72 |
{% if perms.base.see_resourcelog %} |
73 |
<button role="tab" aria-selected="false" aria-controls="panel-logs" id="tab-logs" tabindex="-1">{% trans "Logs" %}</button>
|
|
73 |
<button role="tab" {% if default_tab_page == 'logs' %}aria-selected="true" tabindex="0"{% else %}aria-selected="false" tabindex="-1"{% endif %} aria-controls="panel-logs" id="tab-logs">{% trans "Logs" %}</button>
|
|
74 | 74 |
{% endif %} |
75 | 75 |
{% if perms.base.view_job and object.jobs_set.all %} |
76 | 76 |
<button role="tab" aria-selected="false" aria-controls="panel-jobs" id="tab-jobs" tabindex="-1">{% trans "Jobs" %}</button> |
... | ... | |
78 | 78 |
</div> |
79 | 79 |
<div class="pk-tabs--container"> |
80 | 80 | |
81 |
<div id="panel-endpoints" role="tabpanel" tabindex="0" aria-labelledby="tab-endpoints"> |
|
81 |
<div id="panel-endpoints" role="tabpanel" tabindex="0" aria-labelledby="tab-endpoints" {% if default_tab_page != 'endpoints' %}hidden{% endif %}>
|
|
82 | 82 |
{% if object.documentation_url %} |
83 | 83 |
<div class="pk-information documentation"><a href="{{ object.documentation_url }}">{% trans "Documentation" %}</a></div> |
84 | 84 |
{% endif %} |
... | ... | |
145 | 145 |
{% endif %} |
146 | 146 | |
147 | 147 |
{% if perms.base.see_resourcelog %} |
148 |
<div id="panel-logs" role="tabpanel" tabindex="-1" aria-labelledby="tab-logs" hidden>
|
|
148 |
<div id="panel-logs" role="tabpanel" tabindex="-1" aria-labelledby="tab-logs" {% if not default_tab_page == 'logs' %}hidden{% endif %}>
|
|
149 | 149 |
<div> |
150 | 150 |
{% block logs %} |
151 | 151 |
{% resource_logs_table resource=object %} |
passerelle/views.py | ||
---|---|---|
178 | 178 |
def get_context_data(self, slug=None, **kwargs): |
179 | 179 |
context = super().get_context_data(**kwargs) |
180 | 180 |
context['has_check_status'] = not hasattr(context['object'].check_status, 'not_implemented') |
181 |
context['default_tab_page'] = 'endpoints' |
|
182 |
if 'page' in self.request.GET: |
|
183 |
context['default_tab_page'] = 'logs' |
|
181 | 184 |
return context |
182 | 185 | |
183 | 186 |
def get_template_names(self): |
tests/test_manager.py | ||
---|---|---|
253 | 253 |
assert 'title="Level 42 - Oct. 6, 2020 14:08:12"' in resp.text |
254 | 254 | |
255 | 255 | |
256 |
def test_logs_tab_pagination(app, admin_user): |
|
257 |
data = StringIO('1;Foo\n2;Bar\n3;Baz') |
|
258 |
csv = CsvDataSource.objects.create( |
|
259 |
csv_file=File(data, 't.csv'), |
|
260 |
columns_keynames='id, text', |
|
261 |
slug='test', |
|
262 |
title='a title', |
|
263 |
description='a description', |
|
264 |
) |
|
265 | ||
266 |
query = Query(slug='fooba', resource=csv, structure='array') |
|
267 |
query.projections = '\n'.join(['id:int(id)', 'text:text']) |
|
268 |
query.save() |
|
269 | ||
270 |
api = ApiUser.objects.create( |
|
271 |
username='public', fullname='public', description='access for all', keytype='', key='' |
|
272 |
) |
|
273 |
obj_type = ContentType.objects.get_for_model(csv) |
|
274 |
AccessRight.objects.create( |
|
275 |
codename='can_access', |
|
276 |
apiuser=api, |
|
277 |
resource_type=obj_type, |
|
278 |
resource_pk=csv.pk, |
|
279 |
) |
|
280 | ||
281 |
app = login(app) |
|
282 |
resp = app.get(csv.get_absolute_url()) |
|
283 |
assert '<p>No records found</p>' in resp.text |
|
284 | ||
285 |
for i in range(20): |
|
286 |
app.get('/csvdatasource/test/query/foobar/?q=toto%s' % i) |
|
287 | ||
288 |
resp = app.get(csv.get_absolute_url()) |
|
289 |
assert resp.pyquery('#panel-logs[hidden]') |
|
290 |
assert resp.pyquery('#panel-endpoints:not([hidden])') |
|
291 |
assert resp.pyquery('#table-logs tr').length == 10 |
|
292 |
assert resp.pyquery('#panel-logs .paginator a:first').text() == '2' |
|
293 |
resp = resp.click('2') |
|
294 |
assert resp.pyquery('#panel-logs:not([hidden])') |
|
295 |
assert resp.pyquery('#panel-endpoints[hidden]') |
|
296 |
assert resp.pyquery('#table-logs tr').length == 10 |
|
297 |
resp.pyquery('#panel-logs .paginator a:first').text() |
|
298 |
assert resp.pyquery('#panel-logs .paginator a:first').text() == '1' |
|
299 | ||
300 | ||
256 | 301 |
def test_logs_search(app, admin_user): |
257 | 302 |
csv = CsvDataSource.objects.create(csv_file=File(StringIO('1;t\n'), 't.csv'), slug='t', title='t') |
258 | 303 |
app = login(app) |
259 |
- |