Commit a4d0d865 authored by Robin Sonnabend's avatar Robin Sonnabend

Admin overview

parent bca7b24c
......@@ -32,4 +32,4 @@ class NewEventForm(Form):
class NewTopicForm(Form):
name = StringField("Name", validators=[InputRequired("Entering the name is required.")])
mode = StringField("Mode", validators=[InputRequired("Entering the mode is required."), AnyOf(values=["balanced", "fifo"], message="Must be 'balanced' or 'fifo' atm.")])
event_id = HiddenField("Event_ID")
event_id = HiddenField("Event_id")
......@@ -15,8 +15,8 @@ admin = Blueprint("admin", __name__)
@admin_permission.require()
def index():
users = User.query.limit(10).all()
topics = Topic.query.limit(10).all()
return render_layout("admin_index.html", users=users, topics=topics)
events = Event.query.limit(10).all()
return render_layout("admin_index.html", users=users, events=events)
@admin.route("/user/")
@login_required
......@@ -74,6 +74,16 @@ def user_new():
def event():
events = Event.query.all()
return render_layout("admin_event_index.html", events=events)
@admin.route("/even/show")
@login_required
@admin_permission.require()
def event_show():
event_id = request.args.get("id", None)
if event_id is not None:
event = Event.query.filter_by(id=event_id).first()
return render_layout("admin_event_show.html", event=event)
@admin.route("/event/new", methods=["GET", "POST"])
......@@ -98,7 +108,7 @@ def event_new():
def event_delete():
event_id = request.args.get("id", None)
if event_id is not None:
event = Event.query.filter_by(id=event_id).first()
event = Event.query.filter_by(id=event_id).first()
db.session.delete(event)
db.session.commit()
flash("Event deleted.", "alert-success")
......@@ -111,9 +121,9 @@ def event_edit():
event_id = request.args.get("id", None)
if event_id is not None:
event = db.session.query(Event).filter_by(id=event_id).first()
form = NewEventForm(obj=topic)
form = NewEventForm(obj=event)
if form.validate_on_submit():
form.populate_obj(topic)
form.populate_obj(event)
db.session.commit()
return redirect(url_for(".index"))
else:
......@@ -135,6 +145,10 @@ def topic_new():
db.session.add(topic)
db.session.commit()
return redirect(url_for(".topic"))
event_id = request.args.get("event_id", None)
if event_id is None:
return redirect(url_for(".index"))
form.event_id.data = event_id
return render_layout("admin_topic_new.html", form=form)
@admin.route("/topic/delete")
......
......@@ -7,13 +7,19 @@
<thead>
<tr>
<th class="mdl-data-table__cell--non-numeric">Name</th>
<th class="mdl-data-table__cell--non-numeric">Edit</th>
<th class="mdl-data-table__cell--non-numeric">Delete</th>
</tr>
</thead>
<tbody>
{% for event in events %}
<tr>
<td class="mdl-data-table__cell--non-numeric"><a href="{{ url_for(".event_edit", id=event.id) }}">{{ event.name }}</a></td>
<td class="mdl-data-table__cell--non-numeric"><a href="{{ url_for(".event_show", id=event.id) }}">{{ event.name }}</a></td>
<td class="mdl-data-table__cell--non-numeric">
<a href="{{ url_for(".event_edit", id=event.id) }}">
<i class="material-icons">edit</i>
</a>
</td>
<td class="mdl-data-table__cell--non-numeric">
<a href="{{ url_for('.event_delete', id=event.id) }}">
<i class="material-icons">delete</i>
......
{% extends "admin_index.html" %}
{% block admin_title %}Event - {{ event.name }}{% endblock %}
{% block content %}
<div class="mdl-cell mdl-cell--3-col mdl-grid mdl-grid--no-spacing">
<table class="mdl-data-table mdl-js-table mdl-shadow--2dp mdl-cell mdl-cell--3-col">
<thead>
<tr>
<th class="mdl-data-table__cell--non-numeric">Name</th>
<th class="mdl-data-table__cell--non-numeric">Mode</th>
<th class="mdl-data-table__cell--non-numeric">Edit</th>
<th class="mdl-data-table__cell--non-numeric">Delete</th>
</tr>
</thead>
<tbody>
{% for topic in event.topics %}
<tr>
<td class="mdl-data-table__cell--non-numeric"><a href="{{ url_for(".topic_show", id=topic.id) }}">{{ topic.name }}</a></td>
<td class="mdl-data-table__cell--non-numeric">
<a href="{{ url_for(".topic_edit", id=topic.id) }}">
<i class="material-icons">edit</i>
</a>
</td>
<td class="mdl-data-table__cell--non-numeric">
<a href="{{ url_for('.topic_delete', id=topic.id) }}">
<i class="material-icons">delete</i>
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="rede-separator">
<div class="mdl-cell mdl-cell--1-col">
<a class="mdl-button mdl-button--colored mdl-js-button mdl-button--fab mdl-js-ripple-effect" href="{{ url_for('.topic_new', event_id=event.id) }}">
<i class="material-icons">add</i>
</a>
</div>
</div>
</div>
{% endblock %}
......@@ -32,21 +32,31 @@
<thead>
<tr>
<th class="mdl-data-table__cell--non-numeric">Name</th>
<th class="mdl-data-table__cell--non-numeric">Mode</th>
<th class="mdl-data-table__cell--non-numeric">Edit</th>
<th class="mdl-data-table__cell--non-numeric">Delete</th>
</tr>
</thead>
<tbody>
{% for topic in events %}
{% for event in events %}
<tr>
<td class="mdl-data-table__cell--non-numeric"><a href="{{ url_for(".topic_edit", id=event.id) }}">{{ event.name }}</a></td>
<td class="mdl-data-table__cell--non-numeric">{{ topic.mode }}</td>
<td class="mdl-data-table__cell--non-numeric"><a href="{{ url_for(".event_show", id=event.id) }}">{{ event.name }}</a></td>
<td class="mdl-data-table__cell--non-numeric">
<a href="{{ url_for(".event_edit", id=event.id) }}">
<i class="material-icons">edit</i>
</a>
</td>
<td class="mdl-data-table__cell--non-numeric">
<a href="{{ url_for(".event_delete", id=event.id) }}">
<i class="material-icons">delete</i>
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="mdl-cell mdl-cell--3-col mdl-cell--3-col-tablet mdl-cell--2-col-phone">
<a class="mdl-button mdl-button--colored mdl-js-button" href="{{ url_for(".topic") }}">
All topics
<a class="mdl-button mdl-button--colored mdl-js-button" href="{{ url_for(".event") }}">
All events
</a>
</div>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment