mirror of
https://github.com/shouptech/humulus.git
synced 2026-02-03 16:09:44 +00:00
Add sort by volume
This commit is contained in:
parent
a7e04c4ec6
commit
c036e6f6f8
4 changed files with 38 additions and 3 deletions
|
|
@ -7,6 +7,9 @@
|
|||
},
|
||||
"by-name": {
|
||||
"map": "function (doc) {\n if (doc.$type == \"recipe\" && doc.name) {\n emit(doc.name, doc.name)\n }\n}"
|
||||
},
|
||||
"by-volume": {
|
||||
"map": "function (doc) {\n if (doc.$type == \"recipe\" && doc.volume && doc.name) {\n emit(doc.volume, doc.name)\n }\n}"
|
||||
}
|
||||
},
|
||||
"lists": {},
|
||||
|
|
|
|||
|
|
@ -257,6 +257,8 @@ def index():
|
|||
sort_by = request.args.get('sort_by', default='name', type=str)
|
||||
if sort_by == 'date':
|
||||
view = get_view('_design/recipes', 'by-date')
|
||||
elif sort_by == 'volume':
|
||||
view = get_view('_design/recipes', 'by-volume')
|
||||
else:
|
||||
view = get_view('_design/recipes', 'by-name')
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,15 @@
|
|||
<a class="text-dark" href="{{ url_for('recipes.index', descending='false', sort_by='name') }}">Name</a>
|
||||
{% endif %}
|
||||
</th>
|
||||
<th>Batch Size</th>
|
||||
<th>
|
||||
{% if sort_by == 'volume' and descending %}
|
||||
<a class="text-dark" href="{{ url_for('recipes.index', descending='false', sort_by='volume') }}">Batch Size ↓</a>
|
||||
{% elif sort_by == 'volume' %}
|
||||
<a class="text-dark" href="{{ url_for('recipes.index', descending='true', sort_by='volume') }}">Batch Size ↑</a>
|
||||
{% else %}
|
||||
<a class="text-dark" href="{{ url_for('recipes.index', descending='false', sort_by='volume') }}">Batch Size</a>
|
||||
{% endif %}
|
||||
</th>
|
||||
<th>
|
||||
{% if sort_by == 'date' and descending %}
|
||||
<a class="text-dark" href="{{ url_for('recipes.index', descending='false', sort_by='date') }}">Created On ↓</a>
|
||||
|
|
@ -55,7 +63,7 @@
|
|||
{% for row in rows %}
|
||||
<tr>
|
||||
<td><a href="{{ url_for('recipes.info', id=row.id) }}">{{ row.doc.name }}</a></td>
|
||||
<td>{{ row.doc.volume }}</td>
|
||||
<td>{{ row.doc.volume }} gal.</td>
|
||||
<td>{{ moment(row.doc.created) }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
|
|
|||
|
|
@ -71,6 +71,28 @@ def test_index(client):
|
|||
response.data
|
||||
)
|
||||
|
||||
# Test sort by volume ascending
|
||||
response = client.get('/recipes/?descending=false&sort_by=volume')
|
||||
assert (
|
||||
b'"/recipes/?descending=false&sort_by=name">Name' in
|
||||
response.data
|
||||
)
|
||||
assert (
|
||||
b'"/recipes/?descending=true&sort_by=volume">Batch Size ↑' in
|
||||
response.data
|
||||
)
|
||||
|
||||
# Test sort by volume descending
|
||||
response = client.get('/recipes/?descending=true&sort_by=volume')
|
||||
assert (
|
||||
b'"/recipes/?descending=false&sort_by=name">Name' in
|
||||
response.data
|
||||
)
|
||||
assert (
|
||||
b'"/recipes/?descending=false&sort_by=volume">Batch Size ↓' in
|
||||
response.data
|
||||
)
|
||||
|
||||
|
||||
def test_create(client, app, auth):
|
||||
"""Test success in creating a recipe document."""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue