Facet browser is working.

This commit is contained in:
Edward Betts 2018-05-31 17:00:57 +01:00
parent a619df8e66
commit 359af31aa8
2 changed files with 34 additions and 3 deletions

View file

@ -10,12 +10,18 @@
<div class="col-md-2"> <div class="col-md-2">
item type<br> item type<br>
{% for item_type in 'xanadoc', 'xanalink', 'sourcedoc' %} {% for item_type in 'xanadoc', 'xanalink', 'sourcedoc' %}
<input type="checkbox" checked="checked" id="{{ item_type }}" value="{{ item_type }}"> <label for="{{ item_type }}"> {{ item_type }}</label><br> <input type="checkbox" checked="checked" id="type_{{ item_type }}">
<label for="type_{{ item_type }}"> {{ item_type }}</label><br/>
{% endfor %}
users<br>
{% for item_user in users %}
<input type="checkbox" checked="checked" id="user_{{ item_user }}">
<label for="user_{{ item_user }}">{{ item_user }}</label><br/>
{% endfor %} {% endfor %}
</div> </div>
<div class="col-md-10"> <div class="col-md-10">
{% for doc in docs %} {% for doc in docs %}
<div class="card border-primary w-50 my-2"> <div data-id="{{ doc.id }}" class="card border-primary w-50 my-2">
<h5 class="card-header"><a href="{{ doc.url }}">{{ doc.title() }}</a> <h5 class="card-header"><a href="{{ doc.url }}">{{ doc.title() }}</a>
&mdash; {{ doc.user.username }} &mdash; {{ doc.created | datetime }}</h5> &mdash; {{ doc.user.username }} &mdash; {{ doc.created | datetime }}</h5>
<div class="card-body"> <div class="card-body">
@ -40,3 +46,21 @@
#} #}
</p> </p>
{% endblock %} {% endblock %}
{% block scripts %}
<script>
var docs_info = {{ docs_info | tojson }};
function update_list() {
docs_info.forEach(function(doc) {
var element = $('[data-id=' + doc['id'] + ']');
var show_type = document.getElementById('type_' + doc['type']).checked;
var show_user = document.getElementById('user_' + doc['user']).checked;
element.toggle(show_type && show_user);
});
}
$('input').change(update_list);
</script>
{% endblock %}

View file

@ -62,7 +62,14 @@ def show_errors(f):
@bp.route('/') @bp.route('/')
def home(): def home():
docs = Item.query.order_by(Item.created) docs = Item.query.order_by(Item.created)
return render_template('home.html', docs=docs, nbsp_at_start=nbsp_at_start) docs_info = [{'user': doc.user.username, 'id': doc.id, 'type': doc.type}
for doc in docs]
users = [item_user.username for item_user in User.query]
return render_template('home.html',
docs=docs,
docs_info=docs_info,
nbsp_at_start=nbsp_at_start,
users=users)
@bp.route('/password_reset', methods=['GET', 'POST']) @bp.route('/password_reset', methods=['GET', 'POST'])
def password_reset(): def password_reset():