Commit 6f6953e7 authored by Robin Sonnabend's avatar Robin Sonnabend

Implemented pauses with a linear timeslider

parent 9ad58988
"""empty message
Revision ID: 1f952551533
Revises: 53525d1450a
Create Date: 2015-11-07 23:03:51.647356
"""
# revision identifiers, used by Alembic.
revision = '1f952551533'
down_revision = '53525d1450a'
from alembic import op
import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.add_column('events', sa.Column('paused_until', sa.DateTime(), nullable=True))
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('events', 'paused_until')
### end Alembic commands ###
"""empty message
Revision ID: 53525d1450a
Revises: 497c76393f9
Create Date: 2015-11-07 22:26:09.145955
"""
# revision identifiers, used by Alembic.
revision = '53525d1450a'
down_revision = '497c76393f9'
from alembic import op
import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.add_column('events', sa.Column('paused', sa.Boolean(), nullable=True))
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('events', 'paused')
### end Alembic commands ###
......@@ -39,12 +39,21 @@ class Event(db.Model):
__tablename__ = "events"
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String, unique=True)
paused = db.Column(db.Boolean)
paused_until = db.Column(db.DateTime)
def __init__(self, name):
def __init__(self, name, paused=False):
self.name = name
self.paused = paused
self.paused_until = datetime(1970, 1, 1)
def __repr__(self):
return "<Event(id={}, name={})>".format(self.id, self.name)
return "<Event(id={}, name={}, paused={}, paused_until={})>".format(
self.id,
self.name,
self.paused,
self.paused_until
)
def sorted_topics(self):
return sorted(self.topics, key=lambda tp: tp.get_index())
......
......@@ -2,6 +2,8 @@ from flask import Blueprint, redirect, url_for, request, flash, abort, send_file
from flask.ext.login import login_required
from passlib.hash import pbkdf2_sha256
from datetime import datetime, timedelta
from models.database import User, Topic, Event, Speaker, Statement
from models.forms import AdminUserForm, NewUserForm, NewTopicForm, NewEventForm, AddStatementForm, EditSpeakerForm
......@@ -325,3 +327,22 @@ def statement_undo():
db.session.commit()
return redirect(url_for(".topic_show", id=topic_id))
@admin.route("/pause", methods=["GET", "POST"])
@login_required
@admin_permission.require()
def pause():
event_id = request.args.get("id", None)
if event_id is not None:
event = Event.query.filter_by(id=event_id).first()
if event is not None:
if event.paused_until == None:
event.paused_until = datetime(1970, 1, 1)
event.paused = not event.paused
if event.paused:
rawtime = float(request.form["timeslider"])
delta = timedelta(seconds=rawtime)
print(delta)
event.paused_until += delta
db.session.commit()
topic_id = request.args.get("original", None)
return redirect(url_for(".topic_show", id=topic_id))
......@@ -57,7 +57,40 @@
{% endif %}
<li><a href="{{ url_for(".statement_undo") }}" class="rede-href"><i class="material-icons" role="presentation">undo</i> Previous</a></li>
<li><a href="{{ url_for(".topic_show", id=topic.get_next_index()) }}"><i class="material-icons">arrow_forward</i> Next Topic</a></li>
<li><a href="{{ url_for(".topic_show", id=topic.get_previous_index()) }}"><i class="material-icons">arrow_backward</i> Previous Topic</a></li>
<li><a href="{{ url_for(".topic_show", id=topic.get_previous_index()) }}"><i class="material-icons">arrow_backward</i>Previous Topic</a></li>
<li>
<form action="{{ url_for(".pause", id=topic.event.id, original=topic.id) }}" method="POST">
<button class="mdl-button">
{% if topic.event.paused %}
<i class="material-icons">play_arrow</i>
Resume
{% else %}
<i class="material-icons">pause</i>
Pause
{% endif %}
</button>
{% if not topic.event.paused %}
<input name="timeslider" class="mdl-slider mdl-js-slider" type="range" min="0" max="3600" value="300" step="30" onchange="settimesliderresult(this);">
<script>
function settimesliderresult(slider) {
var div = document.getElementById("timesliderresult");
var time = slider.value;
var text = "";
if (Math.floor(time / 3600) > 0) {
text += Math.floor(time / 3600) + "h";
time %= 3600;
}
if (Math.floor(time / 60) > 0) {
text += Math.floor(time / 60) + "m";
time %= 60;
}
text += time + "s";
div.innerHTML = text;
}
</script>
<div id="timesliderresult"></div>
{% endif %}
</li>
</ul>
</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