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