Skip to content

Commit 7c90947

Browse files
authored
Merge pull request nlohmann#28 from dirtcrusher/feature/more_links
2 parents 8c27a29 + 79ec463 commit 7c90947

File tree

4 files changed

+53
-11
lines changed

4 files changed

+53
-11
lines changed

app/templates/v2_patch.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@
1414
{% endblock %}
1515

1616
{% block content %}
17+
18+
<div class="d-flex justify-content-between">
19+
{% if previous_patch is not none %}
20+
<span><a href="{{ url_for('route_v2_project_project_id_patches_patch_id', project_id=project.id, patch_id=previous_patch.id, filter_patch_state=filter_patch_state, filter_confirmation_state=filter_confirmation_state, filter_run_state=filter_run_state) }}">&laquo; Patch {{ previous_patch.id }}</a></span>
21+
{% else %}
22+
<span></span>
23+
{% endif %}
24+
25+
{% if next_patch is not none %}
26+
<span><a href="{{ url_for('route_v2_project_project_id_patches_patch_id', project_id=project.id, patch_id=next_patch.id, filter_patch_state=filter_patch_state, filter_confirmation_state=filter_confirmation_state, filter_run_state=filter_run_state) }}">Patch {{ next_patch.id }} &raquo;</a></span>
27+
{% else %}
28+
<span></span>
29+
{% endif %}
30+
</div>
31+
1732
<h1>Patch {{ patch.id }}</h1>
1833

1934
<h2>Patch</h2>

app/templates/v2_patches.html

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ <h1>Patches</h1>
2222
<thead>
2323
<tr>
2424
<th>patch</th>
25+
<th>file</th>
2526
<th>line</th>
2627
<th>kind</th>
2728
<th>state</th>
@@ -32,8 +33,9 @@ <h1>Patches</h1>
3233
{% for patch in patches.items %}
3334
<tr>
3435
<td>
35-
<a href="{{ url_for('route_v2_project_project_id_patches_patch_id', project_id=project.id, patch_id=patch.id) }}">{{ patch.id }}</a>
36+
<a href="{{ url_for('route_v2_project_project_id_patches_patch_id', project_id=project.id, patch_id=patch.id, filter_patch_state=filter_patch_state, filter_confirmation_state=filter_confirmation_state, filter_run_state=filter_run_state) }}">{{ patch.id }}</a>
3637
</td>
38+
<td>{{ patch.file.filename|basename }}</td>
3739
<td>{{ patch.line }}</td>
3840
<td><a href="{{ url_for('route_v2_mutators_mutator_id', mutator_id=patch.kind) }}">{{ patch.kind }}</a></td>
3941
<td>
@@ -66,15 +68,15 @@ <h1>Patches</h1>
6668
<ul class="pagination">
6769
<li class="page-item{% if not patches.has_prev %} disabled{% endif %}">
6870
<a class="page-link"
69-
href="{{ url_for('route_v2_project_project_id_patches', project_id=project.id, page=patches.prev_num, patch_state=request.args.get('patch_state'), confirmation_state=request.args.get('confirmation_state')) }}">
71+
href="{{ url_for('route_v2_project_project_id_patches', project_id=project.id, page=patches.prev_num, patch_state=request.args.get('patch_state'), confirmation_state=request.args.get('confirmation_state'), run_state=request.args.get('run_state')) }}">
7072
<span>&laquo;</span>
7173
</a>
7274
</li>
7375

7476
{% for page in patches.iter_pages() %}
7577
{% if page %}
7678
<li class="page-item{% if page == patches.page %} active{% endif %}">
77-
<a class="page-link" href="{{ url_for('route_v2_project_project_id_patches', project_id=project.id, page=page, patch_state=request.args.get('patch_state'), confirmation_state=request.args.get('confirmation_state')) }}">{{ page }}</a>
79+
<a class="page-link" href="{{ url_for('route_v2_project_project_id_patches', project_id=project.id, page=page, patch_state=request.args.get('patch_state'), confirmation_state=request.args.get('confirmation_state'), run_state=request.args.get('run_state')) }}">{{ page }}</a>
7880
</li>
7981
{% else %}
8082
<li class="page-item disabled">
@@ -85,11 +87,11 @@ <h1>Patches</h1>
8587

8688
<li class="page-item{% if not patches.has_next %} disabled{% endif %}">
8789
<a class="page-link"
88-
href="{{ url_for('route_v2_project_project_id_patches', project_id=project.id, page=patches.next_num, patch_state=request.args.get('patch_state'), confirmation_state=request.args.get('confirmation_state')) }}">
90+
href="{{ url_for('route_v2_project_project_id_patches', project_id=project.id, page=patches.next_num, patch_state=request.args.get('patch_state'), confirmation_state=request.args.get('confirmation_state'), run_state=request.args.get('run_state')) }}">
8991
<span>&raquo;</span>
9092
</a>
9193
</li>
9294
</ul>
9395
</nav>
9496

95-
{% endblock %}
97+
{% endblock %}

app/templates/v2_project.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,17 @@ <h2 class="pt-5">Patches</h2>
142142
<ul>
143143
{% if run_stats.run.count._all_.failure %}
144144
<li>
145-
<a class="bg-success text-white" href="">{{ run_stats.run.count._all_.failure }} failure</a>
145+
<a class="bg-success text-white" href="{{ url_for('route_v2_project_project_id_patches', project_id=project.id, patch_state='killed', run_state='failure') }}">{{ run_stats.run.count._all_.failure }} failure</a>
146146
</li>
147147
{% endif %}
148148
{% if run_stats.run.count._all_.nochange %}
149149
<li>
150-
<a class="bg-success text-white" href="">{{ run_stats.run.count._all_.nochange }} nochange</a>
150+
<a class="bg-success text-white" href="{{ url_for('route_v2_project_project_id_patches', project_id=project.id, patch_state='killed', run_state='nochange') }}">{{ run_stats.run.count._all_.nochange }} nochange</a>
151151
</li>
152152
{% endif %}
153153
{% if run_stats.run.count._all_.timeout %}
154154
<li>
155-
<a class="bg-success text-white" href="">{{ run_stats.run.count._all_.timeout }} timeout</a>
155+
<a class="bg-success text-white" href="{{ url_for('route_v2_project_project_id_patches', project_id=project.id, patch_state='killed', run_state='timeout') }}">{{ run_stats.run.count._all_.timeout }} timeout</a>
156156
</li>
157157
{% endif %}
158158
</ul>

app/views.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ def route_v2_project_project_id_patches(project_id):
226226
page = int(request.args.get('page', 1))
227227
patch_state = request.args.get('patch_state')
228228
confirmation_state = request.args.get('confirmation_state')
229+
run_state = request.args.get('run_state')
229230

230231
# initial patch query
231232
patches = Patch.query.filter(Patch.project_id == project_id)
@@ -235,23 +236,33 @@ def route_v2_project_project_id_patches(project_id):
235236
patches = patches.filter(Patch.state == patch_state)
236237
if confirmation_state:
237238
patches = patches.filter(Patch.confirmation == confirmation_state)
239+
if run_state:
240+
patches = patches.join(Run).filter(Run.log == run_state)
238241

239242
# add pagination
240243
patches = patches.paginate(page, app.config['ITEMS_PER_PAGE'], False)
241244

242-
return render_template('v2_patches.html', project=project, patches=patches)
245+
return render_template('v2_patches.html', project=project, patches=patches, filter_patch_state=patch_state,
246+
filter_confirmation_state=confirmation_state, filter_run_state=run_state)
243247

244248

245249
@app.route('/projects/<int:project_id>/patches/<int:patch_id>', methods=['GET', 'POST'])
246250
def route_v2_project_project_id_patches_patch_id(project_id, patch_id):
251+
# retrieve project
247252
project = Project.query.get(project_id)
248253
if project is None:
249254
abort(404)
250255

256+
# retrieve patch
251257
patch = Patch.query.get(patch_id)
252258
if patch is None:
253259
abort(404)
254260

261+
# retrieve parameters
262+
filter_patch_state = request.args.get('filter_patch_state')
263+
filter_confirmation_state = request.args.get('filter_confirmation_state')
264+
filter_run_state = request.args.get('filter_run_state')
265+
255266
form = SetConfirmationForm()
256267

257268
if request.method == 'GET':
@@ -260,7 +271,22 @@ def route_v2_project_project_id_patches_patch_id(project_id, patch_id):
260271
patch.confirmation = form.confirmation.data
261272
db.session.commit()
262273

263-
return render_template('v2_patch.html', project=project, patch=patch, form=form)
274+
# retrieve previous and next patch id
275+
filtered_patches = Patch.query
276+
if filter_patch_state:
277+
filtered_patches = filtered_patches.where(Patch.state == filter_patch_state)
278+
if filter_confirmation_state:
279+
filtered_patches = filtered_patches.where(Patch.confirmation == filter_confirmation_state)
280+
if filter_run_state:
281+
filtered_patches = filtered_patches.join(Run).filter(Run.log == filter_run_state)
282+
283+
previous_patch = filtered_patches.where(Patch.id < patch.id).order_by(Patch.id.desc()).first()
284+
285+
next_patch = filtered_patches.where(Patch.id > patch.id).order_by(Patch.id).first()
286+
287+
return render_template('v2_patch.html', project=project, patch=patch, form=form,
288+
filter_patch_state=filter_patch_state, filter_confirmation_state=filter_confirmation_state,
289+
filter_run_state=filter_run_state, previous_patch=previous_patch, next_patch=next_patch)
264290

265291

266292
@app.route('/projects/<int:project_id>/files/<int:file_id>/generate', methods=['GET', 'POST'])
@@ -332,4 +358,3 @@ def route_v2_mutators_mutator_id(mutator_id):
332358
abort(404)
333359

334360
return render_template('v2_mutator.html', mutator=mutator, patches=patches)
335-

0 commit comments

Comments
 (0)