Use links as list items for corpora and jobs. Add colors for service types. Link jobs to job page.

This commit is contained in:
Patrick Jentsch 2019-08-09 10:16:31 +02:00
parent 136f2ee2b2
commit 50273ea4d1
2 changed files with 35 additions and 24 deletions

View File

@ -1,6 +1,6 @@
from flask import current_app, flash, redirect, render_template, url_for from flask import abort, current_app, flash, redirect, render_template, url_for
from flask_login import current_user, login_required from flask_login import current_user, login_required
from ..models import User, Corpus from ..models import Corpus, User, Job
from ..tables import AdminUserTable, AdminUserItem from ..tables import AdminUserTable, AdminUserItem
from . import main from . import main
from .forms import CreateCorpusForm from .forms import CreateCorpusForm
@ -14,9 +14,16 @@ def index():
return render_template('main/index.html.j2', title='Opaque') return render_template('main/index.html.j2', title='Opaque')
@main.route('/corpora/<corpus>') @main.route('/admin', methods=['GET', 'POST'])
def corpora(corpus): @login_required
return render_template('main/corpus.html.j2', title=corpus) @admin_required
def for_admins_only():
users = User.query.order_by(User.username).all()
items = [AdminUserItem(u.username, u.email, u.role_id, u.confirmed) for u in users]
table = AdminUserTable(items).__html__() # converts table object to html string
table = table.replace('tbody', 'tbody class="list"', 1) # add class list to tbody element. Needed by list.js
return render_template('main/admin.html.j2', title='Administration tools',
table=table)
@main.route('/dashboard', methods=['GET', 'POST']) @main.route('/dashboard', methods=['GET', 'POST'])
@ -54,13 +61,15 @@ def dashboard():
) )
@main.route('/admin', methods=['GET', 'POST']) @main.route('/jobs/<int:job_id>')
@login_required @login_required
@admin_required def job(job_id):
def for_admins_only(): job = Job.query.filter_by(id=job_id).first()
users = User.query.order_by(User.username).all() if not job:
items = [AdminUserItem(u.username, u.email, u.role_id, u.confirmed) for u in users] print('Job not found.')
table = AdminUserTable(items).__html__() # converts table object to html string abort(404)
table = table.replace('tbody', 'tbody class="list"', 1) # add class list to tbody element. Needed by list.js elif not job.user_id == current_user.id:
return render_template('main/admin.html.j2', title='Administration tools', print('Job does not belong to current user.')
table=table) abort(403)
print(job)
return render_template('main/corpus.html.j2', title=job.title)

View File

@ -27,16 +27,15 @@
</div> </div>
</div> </div>
</div> </div>
<ul class="collection list"> <div class="collection list">
{% for corpus in current_user.corpora.all() %} {% for corpus in current_user.corpora.all() %}
<li class="collection-item avatar"> <a href="#!" class="collection-item avatar">
<i class="material-icons circle">book</i> <i class="material-icons circle">book</i>
<span class="title">{{ corpus.title }}</span> <span class="title">{{ corpus.title }}</span>
<p>{{ corpus.description }}</p> <p>{{ corpus.description }}</p>
<a href="#!" class="secondary-content"><i class="material-icons">send</i></a> </a>
</li>
{% endfor %} {% endfor %}
</ul> </div>
</div> </div>
</div> </div>
<script> <script>
@ -78,13 +77,16 @@
</div> </div>
</div> </div>
</div> </div>
<ul class="collection list"> <div class="collection list">
{% for job in current_user.jobs.all() %} {% for job in current_user.jobs.all() %}
{% if job.service == 'nlp' %} {% if job.service == 'nlp' %}
{% set service_color = 'blue' %}
{% set service_icon = 'format_textdirection_l_to_r' %} {% set service_icon = 'format_textdirection_l_to_r' %}
{% elif job.service =='ocr' %} {% elif job.service =='ocr' %}
{% set service_color = 'green' %}
{% set service_icon = 'find_in_page' %} {% set service_icon = 'find_in_page' %}
{% else %} {% else %}
{% set service_color = 'red' %}
{% set service_icon = 'help' %} {% set service_icon = 'help' %}
{% endif %} {% endif %}
{% if job.status == 'pending' %} {% if job.status == 'pending' %}
@ -96,14 +98,14 @@
{% else %} {% else %}
{% set badge_color = 'red' %} {% set badge_color = 'red' %}
{% endif %} {% endif %}
<li class="collection-item avatar"> <a href="{{ url_for('main.job', job_id=job.id) }}" class="collection-item avatar">
<i class="material-icons circle">{{ service_icon }}</i> <i class="material-icons circle {{ service_color }}">{{ service_icon }}</i>
<span class="new badge {{ badge_color }}" data-badge-caption="">{{ job.status }}</span> <span class="new badge {{ badge_color }}" data-badge-caption="">{{ job.status }}</span>
<span class="title">{{ job.title }}</span> <span class="title">{{ job.title }}</span>
<p>{{ job.description }}</p> <p>{{ job.description }}</p>
</li> </a>
{% endfor %} {% endfor %}
</ul> </div>
</div> </div>
</div> </div>
<script> <script>