Add link type to facet browser.

This commit is contained in:
Edward Betts 2018-05-31 20:28:03 +01:00
parent bd9dd70877
commit aa3b42c918
2 changed files with 40 additions and 18 deletions

View file

@ -1,11 +1,24 @@
{% extends "base.html" %}
{% macro new_buttons() %}
<p>
<a href="{{ url_for('.new_sourcedoc') }}" class="btn btn-primary">new source document</a>
<a href="{{ url_for('.new_xanalink') }}" class="btn btn-primary">new xanalink</a>
<a href="{{ url_for('.new_xanadoc') }}" class="btn btn-primary">new xanadoc</a>
</p>
{% endmacro %}
{% block title %}perma.pub{% endblock %}
{% block content %}
<h1>{{ self.title() }}</h1>
<div class="container-fluid">
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-10">
<h1>{{ self.title() }}</h1>
{{ new_buttons() }}
</div>
</div>
<div class="row">
<div class="col-md-2">
item type<br>
@ -13,15 +26,20 @@
<input type="checkbox" checked="checked" id="type_{{ item_type }}">
<label for="type_{{ item_type }}"> {{ item_type }}</label><br/>
{% endfor %}
users<br>
user<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 %}
link type<br>
{% for link_type in link_types %}
<input type="checkbox" checked="checked" id="link_type_{{ link_type }}">
<label for="link_type_{{ link_type }}">{{ link_type }}</label><br/>
{% endfor %}
</div>
<div class="col-md-10">
{% for doc in docs %}
<div data-id="{{ doc.id }}" class="card border-primary w-50 my-2">
<div data-id="{{ doc.id }}" class="card border-primary my-2">
<h5 class="card-header"><a href="{{ doc.url }}">{{ doc.title() }}</a>
&mdash; {{ doc.user.username }} &mdash; {{ doc.created | datetime }}</h5>
<div class="card-body">
@ -33,18 +51,10 @@
</div>
</div>
{% endfor %}
</div>
</div>
</div>
{{ new_buttons() }}
<p>
<a href="{{ url_for('.new_sourcedoc') }}" class="btn btn-primary">new source document</a>
<a href="{{ url_for('.new_xanalink') }}" class="btn btn-primary">new xanalink</a>
<a href="{{ url_for('.new_xanadoc') }}" class="btn btn-primary">new xanadoc</a>
{#
<a href="#" class="btn btn-default">upload a source document</a>
#}
</p>
</div>
</div>
{% endblock %}
{% block scripts %}
@ -56,10 +66,13 @@
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);
var show_link_type = doc['type'] != 'xanalink' || document.getElementById('link_type_' + doc['link_type']).checked;
element.toggle(show_type && show_user && show_link_type);
});
}
$(update_list());
$('input').change(update_list);
</script>

View file

@ -62,11 +62,20 @@ def show_errors(f):
@bp.route('/')
def home():
docs = Item.query.order_by(Item.created)
docs_info = [{'user': doc.user.username, 'id': doc.id, 'type': doc.type}
for doc in docs]
docs_info = []
for item in docs:
cur = {'user': item.user.username, 'id': item.id, 'type': item.type}
if item.type == 'xanalink':
cur['link_type'] = item.link_type
docs_info.append(cur)
users = [item_user.username for item_user in User.query]
link_types = {item['link_type'] for item in docs_info if item.get('link_type')}
return render_template('home.html',
docs=docs,
link_types=link_types,
docs_info=docs_info,
nbsp_at_start=nbsp_at_start,
users=users)