diff --git a/migrations/versions/1f952551533_.py b/migrations/versions/1f952551533_.py new file mode 100644 index 0000000000000000000000000000000000000000..76ccf85f0616c7ab188cff1e533d44136130796a --- /dev/null +++ b/migrations/versions/1f952551533_.py @@ -0,0 +1,26 @@ +"""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 ### diff --git a/migrations/versions/53525d1450a_.py b/migrations/versions/53525d1450a_.py new file mode 100644 index 0000000000000000000000000000000000000000..b2447524b3accc788b544844b4ec06ab60d7a4a3 --- /dev/null +++ b/migrations/versions/53525d1450a_.py @@ -0,0 +1,26 @@ +"""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 ### diff --git a/models/database.py b/models/database.py index d729849bfc090dad6739da7710ff6ae002d5ea35..1299bbc63e86974f74fd8b32b6c350124410a4c4 100644 --- a/models/database.py +++ b/models/database.py @@ -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()) diff --git a/modules/admin.py b/modules/admin.py index a18f4e7a82cb1e0ea312985edd5d2bb3b4475073..2c1b1f0984aec0e04f4310f47bd2c1a6df18836a 100644 --- a/modules/admin.py +++ b/modules/admin.py @@ -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)) diff --git a/templates/admin_topic_show.html b/templates/admin_topic_show.html index d6ef4c792c4737b9f9318c4b02a9af2d205684de..887eb60d7e05aac740a1842e03ffece43eb401b3 100644 --- a/templates/admin_topic_show.html +++ b/templates/admin_topic_show.html @@ -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>