Skip to content
Snippets Groups Projects
Commit 99a26435 authored by Julian's avatar Julian
Browse files

Location selection UI

parent 47de8bcf
Branches
No related tags found
No related merge requests found
...@@ -174,7 +174,19 @@ def item_upload_photo(item_id): ...@@ -174,7 +174,19 @@ def item_upload_photo(item_id):
def item_locate(item_id): def item_locate(item_id):
item = Item.query.get_or_404(item_id) item = Item.query.get_or_404(item_id)
if request.method == 'GET': if request.method == 'GET':
return render_template('item/locate.html', item=item, all_locations=Location.query.all()) query = Location.query
if 'search' in request.values:
keywords = request.values['search'].strip().split()
for keyword in keywords:
query = query.filter(db.or_(Location.name.contains(keyword), Location.description.contains(keyword)))
locations = query.all()
def include_parents_r(location):
if location.parent and location.parent not in locations:
locations.append(location.parent)
include_parents_r(location.parent)
for location in list(locations):
include_parents_r(location)
return render_template('item/locate.html', item=item, locations=locations)
item.location = Location.query.get(request.form['location_id']) item.location = Location.query.get(request.form['location_id'])
db.session.commit() db.session.commit()
return redirect(url_for('item_view', item_id=item_id)) return redirect(url_for('item_view', item_id=item_id))
......
{% extends 'layout.html' %} {% extends 'layout.html' %}
{% macro location_recursive(location, indent=0) %}
<tr>
<td>{{ ('&emsp;'*indent)|safe }}{{ location.name }}</td>
<td>
{% if not location.children %}
<button type="submit" name="location_id" value="{{ location.id }}" class="float-end btn btn-sm btn-primary">Select</button>
{% else %}
<button type="submit" name="location_id" value="{{ location.id }}" class="float-end btn btn-sm btn-secondary">Select</button>
{% endif %}
</td>
</tr>
{% for item in locations if item in location.children %}
{{ location_recursive(item, indent+1) }}
{% endfor %}
{% endmacro %}
{% block body %} {% block body %}
<h1>Set location for {{ item.name }}</h1>
<div class="d-flex justify-content-end gap-1">
<form class="form-inline">
<div class="input-group">
<input type="text" class="form-control" name="search" value="{{ request.args.search }}" placeholder="Search" autofocus>
<button class="btn btn-outline-secondary" type="submit">Search</button>
</div>
</form>
</div>
<form method="POST"> <form method="POST">
<input type="hidden" name="csrf_token" value="{{ request.csrf_token }}"> <input type="hidden" name="csrf_token" value="{{ request.csrf_token }}">
{% for location in all_locations %} <table class="table table-hover">
<div class="clearfix w-100 my-2"> <thead>
{{ location.name }} <tr>
<button type="submit" name="location_id" value="{{ location.id }}" class="float-end btn btn-primary">Select</button> <th scope="col">Location</th>
</div> <th scope="col"></th>
</tr>
</thead>
<tbody>
{% for location in locations if not location.parent %}
{{ location_recursive(location) }}
{% endfor %} {% endfor %}
</tbody>
</table>
</form> </form>
{% endblock %} {% endblock %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment