Add Breadcrumbs and UserList to admin package

This commit is contained in:
Patrick Jentsch 2021-01-13 11:57:46 +01:00
parent 3d53b673fd
commit a8643aa9f4
6 changed files with 58 additions and 19 deletions

View File

@ -8,11 +8,19 @@ from ..models import Role, User
from ..settings import tasks as settings_tasks from ..settings import tasks as settings_tasks
@admin.route('/')
@login_required
@admin_required
def index():
return redirect(url_for('.users'))
@admin.route('/users') @admin.route('/users')
@login_required @login_required
@admin_required @admin_required
def users(): def users():
users = [user.to_dict() for user in User.query.all()] # users = [user.to_dict() for user in User.query.all()]
users = {user.id: user.to_dict() for user in User.query.all()}
return render_template('admin/users.html.j2', title='Users', users=users) return render_template('admin/users.html.j2', title='Users', users=users)
@ -33,10 +41,10 @@ def delete_user(user_id):
return redirect(url_for('.users')) return redirect(url_for('.users'))
@admin.route('/users/<int:user_id>/edit_general_settings', methods=['GET', 'POST']) # noqa @admin.route('/users/<int:user_id>/edit', methods=['GET', 'POST']) # noqa
@login_required @login_required
@admin_required @admin_required
def edit_general_settings(user_id): def edit_user(user_id):
user = User.query.get_or_404(user_id) user = User.query.get_or_404(user_id)
form = EditGeneralSettingsAdminForm(user=user) form = EditGeneralSettingsAdminForm(user=user)
if form.validate_on_submit(): if form.validate_on_submit():
@ -47,11 +55,11 @@ def edit_general_settings(user_id):
user.role = Role.query.get(form.role.data) user.role = Role.query.get(form.role.data)
db.session.commit() db.session.commit()
flash('Settings have been updated.') flash('Settings have been updated.')
return redirect(url_for('.edit_general_settings', user_id=user.id)) return redirect(url_for('.edit_user', user_id=user.id))
form.confirmed.data = user.confirmed form.confirmed.data = user.confirmed
form.dark_mode.data = user.setting_dark_mode form.dark_mode.data = user.setting_dark_mode
form.email.data = user.email form.email.data = user.email
form.role.data = user.role_id form.role.data = user.role_id
form.username.data = user.username form.username.data = user.username
return render_template('admin/edit_general_settings.html.j2', return render_template('admin/edit_user.html.j2', form=form,
form=form, title='General settings', user=user) title='Edit user', user=user)

View File

@ -0,0 +1,19 @@
<ul class="tabs tabs-transparent">
<li class="tab"><a href="{{ url_for('main.index') }}" target="_self"><i class="material-icons">home</i></a></li>
<li class="tab disabled"><i class="material-icons">navigate_next</i></li>
<li class="tab"><a href="{{ url_for('.index') }}" target="_self">Administration</a></li>
<li class="tab disabled"><i class="material-icons">navigate_next</i></li>
{% if request.path == url_for('.users') %}
<li class="tab"><a class="active" href="{{ url_for('.users') }}" target="_self">Users</a></li>
{% elif request.path == url_for('.user', user_id=user.id) %}
<li class="tab"><a href="{{ url_for('.users') }}" target="_self">Users</a></li>
<li class="tab disabled"><i class="material-icons">navigate_next</i></li>
<li class="tab"><a class="active" href="{{ url_for('.user', user_id=user.id) }}" target="_self">{{ user.username }}</a></li>
{% elif request.path == url_for('.edit_user', user_id=user.id) %}
<li class="tab"><a href="{{ url_for('.users') }}" target="_self">Users</a></li>
<li class="tab disabled"><i class="material-icons">navigate_next</i></li>
<li class="tab"><a href="{{ url_for('.user', user_id=user.id) }}" target="_self">{{ user.username }}</a></li>
<li class="tab disabled"><i class="material-icons">navigate_next</i></li>
<li class="tab"><a class="active" href="{{ url_for('.edit_user', user_id=user.id) }}" target="_self">Edit</a></li>
{% endif %}
</ul>

View File

@ -1,6 +1,10 @@
{% extends "nopaque.html.j2" %} {% extends "nopaque.html.j2" %}
{% import 'materialize/wtf.html.j2' as wtf %} {% import 'materialize/wtf.html.j2' as wtf %}
{% block nav_content %}
{% include 'admin/_breadcrumbs.html.j2' %}
{% endblock nav_content %}
{% block page_content %} {% block page_content %}
<div class="container"> <div class="container">
<div class="row"> <div class="row">

View File

@ -1,5 +1,9 @@
{% extends "nopaque.html.j2" %} {% extends "nopaque.html.j2" %}
{% block nav_content %}
{% include 'admin/_breadcrumbs.html.j2' %}
{% endblock nav_content %}
{% block page_content %} {% block page_content %}
<div class="container"> <div class="container">
<div class="row"> <div class="row">
@ -30,7 +34,7 @@
</ul> </ul>
</div> </div>
<div class="card-action right-align"> <div class="card-action right-align">
<a href="{{ url_for('.edit_general_settings', user_id=user.id) }}" class="waves-effect waves-light btn"><i class="material-icons left">edit</i>Edit</a> <a href="{{ url_for('.edit_user', user_id=user.id) }}" class="waves-effect waves-light btn"><i class="material-icons left">edit</i>Edit</a>
<a data-target="delete-user-modal" class="waves-effect waves-light btn red modal-trigger"><i class="material-icons left">delete</i>Delete</a> <a data-target="delete-user-modal" class="waves-effect waves-light btn red modal-trigger"><i class="material-icons left">delete</i>Delete</a>
</div> </div>
</div> </div>

View File

@ -1,5 +1,9 @@
{% extends "nopaque.html.j2" %} {% extends "nopaque.html.j2" %}
{% block nav_content %}
{% include 'admin/_breadcrumbs.html.j2' %}
{% endblock nav_content %}
{% block page_content %} {% block page_content %}
<div class="container"> <div class="container">
<div class="row"> <div class="row">
@ -7,28 +11,28 @@
<h1 id="title">{{ title }}</h1> <h1 id="title">{{ title }}</h1>
</div> </div>
<div class="col s12"> <div class="col s12" id="users">
<div class="card"> <div class="card">
<div class="card-content" id="users"> <div class="card-content">
<div class="input-field"> <div class="input-field">
<i class="material-icons prefix">search</i> <i class="material-icons prefix">search</i>
<input id="search-user" class="search" type="text"></input> <input id="search-user" class="search" type="text"></input>
<label for="search-user">Search user</label> <label for="search-user">Search user</label>
</div> </div>
<ul class="pagination paginationTop"></ul> <table class="highlight ressource-list">
<table class="highlight responsive-table">
<thead> <thead>
<tr> <tr>
<th class="sort" data-sort="id">Id</th> <th class="sort" data-sort="id">Id</th>
<th class="sort" data-sort="username">Username</th> <th class="sort" data-sort="username">Username</th>
<th class="sort" data-sort="email">Email</th> <th class="sort" data-sort="email">Email</th>
<th class="sort" data-sort="role_id">Role</th> <th class="sort" data-sort="last_seen">Last seen</th>
<th>{# Actions #}</th> <th class="sort" data-sort="role">Role</th>
<th></th>
</tr> </tr>
</thead> </thead>
<tbody class="list"></tbody> <tbody class="list"></tbody>
</table> </table>
<ul class="pagination paginationBottom"></ul> <ul class="pagination"></ul>
</div> </div>
</div> </div>
</div> </div>
@ -38,9 +42,8 @@
{% block scripts %} {% block scripts %}
{{ super() }} {{ super() }}
<script type="module"> <script>
import {RessourceList} from '{{ url_for('static', filename='js/nopaque.lists.js') }}'; let userList = new UserList(document.querySelector('#users'), {page: 10});
let userList = new RessourceList('users', null, "User", RessourceList.options.extended); userList.init({{ users|tojson }});
userList._add({{ users|tojson }});
</script> </script>
{% endblock scripts %} {% endblock scripts %}

View File

@ -150,7 +150,7 @@
{% if current_user.is_administrator() %} {% if current_user.is_administrator() %}
<li><div class="divider"></div></li> <li><div class="divider"></div></li>
<li><a class="subheader">Administration</a></li> <li><a class="subheader">Administration</a></li>
<li><a href="{{ url_for('admin.users') }}"><i class="material-icons">build</i>Administration tools</a></li> <li><a href="{{ url_for('admin.index') }}"><i class="material-icons">build</i>Administration</a></li>
{% endif %} {% endif %}
</ul> </ul>
{% endblock sidenav %} {% endblock sidenav %}
@ -264,6 +264,7 @@
<script src="{{ url_for('static', filename='js/nopaque/lists/JobInputList.js') }}"></script> <script src="{{ url_for('static', filename='js/nopaque/lists/JobInputList.js') }}"></script>
<script src="{{ url_for('static', filename='js/nopaque/lists/JobResultList.js') }}"></script> <script src="{{ url_for('static', filename='js/nopaque/lists/JobResultList.js') }}"></script>
<script src="{{ url_for('static', filename='js/nopaque/lists/QueryResultList.js') }}"></script> <script src="{{ url_for('static', filename='js/nopaque/lists/QueryResultList.js') }}"></script>
<script src="{{ url_for('static', filename='js/nopaque/lists/UserList.js') }}"></script>
<script> <script>
// Disable all option elements with no value // Disable all option elements with no value
for (let optionElement of document.querySelectorAll('option[value=""]')) {optionElement.disabled = true;} for (let optionElement of document.querySelectorAll('option[value=""]')) {optionElement.disabled = true;}