From 4370c3dc1ff65e9f0c15a2fdcc0955c00522f197 Mon Sep 17 00:00:00 2001
From: Julian Rother <julianr@fsmpi.rwth-aachen.de>
Date: Sun, 9 Apr 2017 19:29:31 +0200
Subject: [PATCH] Replaced old "featured" with a new panel-based version

---
 db_example.sql       |  2 ++
 db_schema.sql        |  3 ++
 server.py            |  6 ++--
 templates/index.html | 71 +++++++++++---------------------------------
 4 files changed, 26 insertions(+), 56 deletions(-)

diff --git a/db_example.sql b/db_example.sql
index 3c6754b..9cdcded 100644
--- a/db_example.sql
+++ b/db_example.sql
@@ -14642,10 +14642,12 @@ INSERT INTO "videos_data" VALUES(9680,7011,1,0,1,'','','','pub/16ss-dsal/16ss-ds
 INSERT INTO "videos_data" VALUES(9681,7012,1,0,1,'','','','pub/16ss-dsal/16ss-dsal-160715-1080p_1.mp4','2016-08-07 22:54:46','2016-08-07 21:02:37','2016-08-07 21:02:43',46,1402602183,4,'e036f7cbd51afd3ab7be10cf77747c00');
 INSERT INTO "videos_data" VALUES(9682,7012,1,0,1,'','','','pub/16ss-dsal/16ss-dsal-160715-360p_1.mp4','2016-08-07 22:45:34','2016-08-07 21:02:38','2016-08-07 21:02:45',46,368611109,10,'fae2bda2da55a3005aa6329a2d0227c3');
 INSERT INTO "videos_data" VALUES(9683,7012,1,0,1,'','','','pub/16ss-dsal/16ss-dsal-160715-720p_1.mp4','2016-08-07 22:46:00','2016-08-07 21:02:40','2016-08-07 21:02:44',46,721141077,5,'083c0b7693c82078c513707d1402096b');
+INSERT INTO "featured" VALUES(1,'Video AG','<p>Wir machen Vorlesungsvideos, damit du dir deine Vorlesungen angucken kannst, wann, wo und so oft <strong>du</strong> willst ;)</p><p><strong>Probleme?</strong><a href="/faq"> Hier gehts zur FAQ</a></p><p>Wenn du die Videos nützlich fandest, schreib doch bitte den Dozenten eine kurze E-Mail. Waren die Videos grauenhaft? Kritik an uns.</p><p>Wenn du mitmachen willst, Fragen oder Anregungen hast, oder nur mal schauen möchtest, komm zu unserem AG-Treffen oder schreib uns eine E-Mail. Insbesondere freuen wir uns über Studis der Mathematik und Physik, die ihre Vorlesungen filmen wollen.</p>','','plain','',0,1,0,'2017-04-09 19:00:00','2017-04-09 19:00:00',0);
 INSERT INTO "sqlite_sequence" VALUES('changelog',17859);
 INSERT INTO "sqlite_sequence" VALUES('courses_data',303);
 INSERT INTO "sqlite_sequence" VALUES('formats',30);
 INSERT INTO "sqlite_sequence" VALUES('lectures_data',7362);
 INSERT INTO "sqlite_sequence" VALUES('users',77);
 INSERT INTO "sqlite_sequence" VALUES('videos_data',9683);
+INSERT INTO "sqlite_sequence" VALUES('featured',1);
 COMMIT;
diff --git a/db_schema.sql b/db_schema.sql
index 611097a..d7ea117 100644
--- a/db_schema.sql
+++ b/db_schema.sql
@@ -220,6 +220,9 @@ CREATE TABLE IF NOT EXISTS `featured` (
 	`title` text NOT NULL DEFAULT '',
 	`text` text NOT NULL DEFAULT '',
 	`internal` text NOT NULL DEFAULT '',
+	`type` varchar(32) NOT NULL DEFAULT '',
+	`param` text NOT NULL DEFAULT '',
+	`order` INTEGER NOT NULL DEFAULT 0,
 	`visible` INTEGER NOT NULL DEFAULT 0,
 	`deleted` INTEGER NOT NULL DEFAULT 0,
   `time_created` datetime NOT NULL,
diff --git a/server.py b/server.py
index 7ecee0c..b766786 100644
--- a/server.py
+++ b/server.py
@@ -326,7 +326,7 @@ def index():
 		JOIN courses ON courses.id = lectures.course_id
 		WHERE streams.active AND (? OR (streams.visible AND courses.visible AND courses.listed AND lectures.visible))
 		''', ismod())
-	featured = query('SELECT * FROM featured WHERE NOT deleted AND (? OR visible)', ismod())
+	featured = query('SELECT * FROM featured WHERE NOT deleted AND (? OR visible) ORDER BY `order`', ismod())
 	return render_template('index.html', latestvideos=livestreams+latestvideos, upcomming=upcomming, featured=featured)
 
 @app.route('/course')
@@ -492,8 +492,8 @@ tabs = {
 	'announcements': ('announcements', 'id', ['text', 'level', 'visible',
 			'deleted', 'time_publish', 'time_expire'],
 			['created_by', 'time_created', 'time_updated']),
-	'featured': ('featured', 'id', ['title', 'text', 'internal', 'visible', 'deleted'],
-			['created_by', 'time_created', 'time_updated']),
+	'featured': ('featured', 'id', ['title', 'text', 'internal', 'visible', 'deleted', 'param', 'order'],
+			['created_by', 'time_created', 'time_updated', 'type', 'order']),
 	'perm': ('perm', 'id', ['type', 'param1', 'param2', 'deleted'],
 			['course_id', 'lecture_id', 'video_id', 'created_by', 'time_created', 'time_updated']),
 	'sorterrorlog': ('sorterrorlog_data', 'id', ['deleted'],
diff --git a/templates/index.html b/templates/index.html
index eb49e76..e38a2e5 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -62,65 +62,30 @@
 {% endif %}
 <div class="row">
 	<div class="col-md-6">
+		{% for item in featured %}
 		<div class="panel panel-default">
 			<div class="panel-heading">
-				<h1 class="panel-title">Video AG</h1>
+				<h1 class="panel-title">
+					{{ moderator_editor(('featured',item.id,'title'), item.title) }} {{ moderator_checkbox(('featured',item.id,'visible'), item.visible) }}
+					<ul class="pull-right list-inline">
+						<li>{{ moderator_delete(['featured',item.id,'deleted']) }}</li>
+					</ul>
+				</h1>
 			</div>
+			{% if item.type == 'image' %}
+				<!-- Putting image tag here makes it borderless. This should be replaced by a bootstrap-compatible solution. -->
+				<img src="{{item.param}}" style="width: 100%;"/>
+				{% if ismod() %}
+				<p>{{moderator_editor(('featured',item.id,'param'), item.param)}}</p>
+				{% endif %}
+			{% endif %}
+			{% if item.text or ismod() %}
 			<div class="panel-body">
-				<p>Wir machen Vorlesungsvideos, damit du dir deine Vorlesungen angucken kannst, wann, wo und so oft <strong>du</strong> willst ;)</p>
-				<p><strong>Probleme?</strong><a href="{{url_for('faq')}}"> Hier gehts zur FAQ</a></p>
-				<p>Wenn du die Videos nützlich fandest, schreib doch bitte den Dozenten eine kurze E-Mail. Waren die Videos grauenhaft? Kritik an uns.</p>
-				<p>Wenn du mitmachen willst, Fragen oder Anregungen hast, oder nur mal schauen möchtest, komm zu unserem AG-Treffen oder schreib uns eine E-Mail.
-				Insbesondere freuen wir uns über Studis der Mathematik und Physik, die ihre Vorlesungen filmen wollen.</p>
-				</p>
+				{{ moderator_editor(('featured',item.id,'text'), item.text) }}
 			</div>
+			{% endif %}
 		</div>
-		{% if (featured|length > 0) or ismod() %}
-			<div class="panel panel-default">
-				<div class="panel-heading">
-					<h1 class="panel-title">Featured
-						{% if ismod() %}
-							<a class="btn btn-default" href="{{ url_for('create', table='featured', title='Neuer Artikel', ref=request.url) }}">Neue Empfehlung</a>
-						{% endif %}
-					</h1>
-				</div>
-				<div class="panel-body">
-					<div id="myCarousel" class="carousel slide" data-ride="carousel" style="background-color: #EEE; min-height: 400px;" {% if ismod() %}data-interval="false"{% endif %}>
-						<ol class="carousel-indicators">
-							{% for i in featured %}
-							<li data-target="#myCarousel" data-slide-to="{{ loop.index0 }}" {% if loop.first %} class="active" {% endif %}></li>
-							{% endfor %}
-						</ol>
-							<div class="carousel-inner" role="listbox">
-						{% for i in featured %}
-								<div class="item {% if loop.first %}active{% endif %}">
-									{% if ismod() %}
-										<div class="center-block">
-											{{ moderator_editor(('featured',i.id,'text'), i.text) }}
-											{{ moderator_editor(('featured',i.id,'title'), i.title) }}
-											{{ moderator_checkbox(('featured',i.id,'visible'),i.visible) }}
-										</div>
-									{% else %}
-										{{i.text|safe}}
-									{% endif %}
-									<div class="carousel-caption">{{ i.title }}</div>
-								</div>
-						{% endfor %}
-							</div>
-							{% if not ismod() %}
-								<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
-									<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
-									<span class="sr-only">Previous</span>
-								</a>
-								<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
-									<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
-									<span class="sr-only">Next</span>
-								</a>
-							{% endif %}
-					</div>
-				</div>
-			</div>
-		{% endif %}
+		{% endfor %}
 	</div>
 	<div class="col-md-6">
 		<div class="panel panel-default">
-- 
GitLab