macros.html 15.6 KB
Newer Older
1
2
3
4
5
6
{% macro livelabel(live=None, nowlive=None) %}
{% if live or nowlive %}
<span class="label {% if nowlive %}label-danger{% else %}label-default{% endif %}">Live</span>
{% endif %}
{% endmacro %}

7
{% macro preview(lecture) %}
Andreas Valder's avatar
Andreas Valder committed
8
<li class="list-group-item">
9
	<a href="{{url_for('lecture', course=lecture.course.handle, id=lecture['id'])}}" title="{{ lecture.course.title }}" style="color: #000">
10
11
		<div class="hidden-xs">
			<div class="row">
12
				<img class="col-xs-4" style="max-height: 120px; height: auto; width:170px" src="{{ config.VIDEOPREFIX }}/thumbnail/l_{{ lecture['id'] }}.jpg" alt="Vorschaubild">
13
				<div class="col-xs-4">
Julian Rother's avatar
Julian Rother committed
14
					<span><strong>{{ lecture.course.short }}</strong> {{livelabel(lecture.live, lecture.livehandle)}}{% if ismod() %} <i>({{lecture.course_id}})</i>{% endif %}</span><br>
15
16
17
18
19
20
21
22
23
24
25
26
27
28
					<span>{% if ismod() %}ID: {{lecture.id}}{% endif %}</span><br>
					<span>{{ lecture['time'] }}</span>
					{% if lecture['speaker'] %}
						<div class="small">Gehalten von {{ lecture['speaker']|safe }} </div>
					{% endif %}
				</div>
				<div class="col-xs-4">
					<div>{{ lecture['title']|fixnl|safe  }}</div>
				</div>
			</div>
		</div>
		<div class="visible-xs">
			<ul class="list-unstyled">
				<li>
29
					<img style="width: 100%;" src="{{ config.VIDEOPREFIX }}/thumbnail/l_{{ lecture['id'] }}.jpg" alt="Vorschaubild">
30
31
				</li>
				<li>
32
					<strong>{{ lecture.course.title }}</strong>
33
					{{livelabel(lecture.live, lecture.livehandle)}}
34
				</li>
35
				<li>{{ lecture['time'] }}</li>
36
				{% if lecture['speaker'] %}
37
38
39
				<li>
					<span class="small">Gehalten von {{ lecture['speaker']|safe }} </span>
				</li>
40
				{% endif %}
41
42
43
44
				<li>
					{{ lecture['title']|fixnl|safe  }}
				</li>
			</ul>
Andreas Valder's avatar
Andreas Valder committed
45
46
		</div>
	</a>
Andreas Valder's avatar
Andreas Valder committed
47
48
</li>

Andreas Valder's avatar
Andreas Valder committed
49
50
{% endmacro %}

51
{% macro player(lecture, videos, msgs) %}
Andreas Valder's avatar
Andreas Valder committed
52
<video id="videoplayer" style="width: 100%" class="video-js vjs-default-skin vjs-big-play-centered" width="640" height="320" controls data-wasnotplayed="1"  data-setup='{ "language":"de", "plugins" : {"hotkeys": {"seekStep": 15, "enableVolumeScroll": false, "alwaysCaptureHotkeys": true}, "videoJsResolutionSwitcher": { "ui": true, "default": "720p", "dynamicLabel": false } }, "customControlsOnMobile": true, "playbackRates": [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 2.75, 3, 3.25, 3.5, 3.75, 4] }'>
53
	{% for v in videos|sort(attribute='player_prio', reverse=True) %}
54
		<source type="{{ v.mimetype }}" src="{{ config.VIDEOPREFIX }}/{{ v.path }}" label="{{ v.format_description }}"/>
Andreas Valder's avatar
Andreas Valder committed
55
	{% endfor %}
56
	<track srclang="de" kind="chapters" src="{{ url_for('chapters',lectureid=lecture.id) }}" />
Andreas Valder's avatar
Andreas Valder committed
57
</video>
Andreas Valder's avatar
Andreas Valder committed
58
<script>
Andreas Valder's avatar
Andreas Valder committed
59
$('#videoplayer').addClass("vjs-fluid");
60
$('#videoplayer').css("width");
Jan Philipp Hafer's avatar
Jan Philipp Hafer committed
61
$(function() {
Andreas Valder's avatar
Andreas Valder committed
62
63
videojs("videoplayer").ready(function() {

Andreas Valder's avatar
Andreas Valder committed
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
	//resume
	var progress_key = "progress_{{ lecture.id }}";
	var seconds_played;
	if (localStorage) {
		seconds_played = localStorage.getItem(progress_key);
		if (!seconds_played) {
			seconds_played = 0;
		} else {
			videojs('videoplayer').currentTime(seconds_played);
		}
	}
	videojs("videoplayer").on("timeupdate", function() {
		if (localStorage) {
			var player_cur_Time = Math.round(videojs("videoplayer").currentTime());
			if(Math.abs(player_cur_Time - seconds_played) >= 10) {
				seconds_played = player_cur_Time;
				localStorage.setItem( progress_key , seconds_played)
			}
		}

	});

	//autoplay
Jan Philipp Hafer's avatar
Jan Philipp Hafer committed
87
88
89
90
91
92
93
94
95
96
	var playerplay = function() {
		if ($('#videoplayer').data("wasnotplayed") == 1) {
			videojs('videoplayer').play();
			$('#videoplayer').data("wasnotplayed","0");
		}
	};
	$(window).focus(playerplay);
	if (document.hasFocus()) {
		playerplay();
	}
Andreas Valder's avatar
Andreas Valder committed
97
98

	var modals = [];
99
100
	//display errors
	{% for msg in msgs %}
Andreas Valder's avatar
Andreas Valder committed
101
102
103
		var m = videojs("videoplayer").createModal('',{"uncloseable": true });
		modals.push(m);
		m.contentEl().innerHTML='<div class="hidden-print alert alert-danger" role="alert">{{ msg|safe }}</div>';
104
105
		
	{% endfor %}
Andreas Valder's avatar
Andreas Valder committed
106
107
108
109
110
	videojs("videoplayer").on('play', function() {
		for (var i=0; i < modals.length; i++) {
			modals[i].close();
		}
	});
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129

	//markers
	$.ajax({method: "GET", url: "{{url_for('chapters',lectureid=lecture.id, json=1)}}", dataType: "json",
		success: function (data) {
			videojs("videoplayer").markers({
				markerStyle: {
					'width':'5px',
					'border-radius': '40%',
					'background-color': 'black'
				},
				markerTip:{
					display: true,
					text: function(marker) {
						return marker.text;
					}
				},
				markers: data});
		}});

Andreas Valder's avatar
Andreas Valder committed
130
});
Jan Philipp Hafer's avatar
Jan Philipp Hafer committed
131
});
Andreas Valder's avatar
Andreas Valder committed
132
</script>
Andreas Valder's avatar
Andreas Valder committed
133
{% endmacro %}
134
135

{% macro course_list_item(course,show_semester=False) %}
136
<li class="list-group-item list-group-item-condensed {% if (not course.visible) or (not course.listed) %}list-group-item-danger{% endif %}">
137
	<div class="row">
Andreas Valder's avatar
Andreas Valder committed
138
			{% if show_semester %}
139
				<span class="col-xs-2 col-md-1">
140
					{{ course.semester|semester }}
Andreas Valder's avatar
Andreas Valder committed
141
				</span>
142
				<span class="col-xs-10 col-md-6">
Andreas Valder's avatar
Andreas Valder committed
143
			{% else %}
144
				<span class="col-xs-12 col-md-7">
Andreas Valder's avatar
Andreas Valder committed
145
			{% endif %}
146
				<a href="{{url_for('course', handle=course.handle)}}">
147
					{{ course.title }}{% if ismod() %}<i> ({{course.id}})</i>{% endif %}
148
				</a>
149
			</span>
150
			<span class="col-xs-8 col-md-3">
Andreas Valder's avatar
Andreas Valder committed
151
152
				{{ course.organizer }}
			</span>
153
			<span class="col-xs-4 col-md-2">
Andreas Valder's avatar
Andreas Valder committed
154
155
				{{ course.subject }}
			</span>
156
157
158
	</div>
</li>
{% endmacro %}
Andreas Valder's avatar
Andreas Valder committed
159

160
{% macro video_download_btn(videos) %}
161
{% if not ismod() %}
162
<span class="btn btn-default dropdown-toggle{% if not videos|selectattr('downloadable')|list and not ismod() %} disabled{% endif %}" type="button" data-toggle="dropdown">Download <span class="caret"></span></span>
163
<ul class="dropdown-menu">
164
	{% for v in videos|sort(attribute='prio', reverse=True) if (v.downloadable or ismod() ) %}
165
	<li><a href="{{ config.VIDEOPREFIX }}/{{v.path}}">{{v.format_description}} ({{v.file_size|filesizeformat(true)}})</a></li>
166
167
	{% endfor %}
</ul>
168
169
{% endif %}
{% if not ismod() %}
170
	<noscript> 
171
{% endif %}
172
173
174
175
176
<ul class="pull-right list-unstyled" style="margin-left:10px;">
{% for v in videos|sort(attribute='prio', reverse=True) if (v.downloadable or ismod() ) %}
	<li>{{moderator_delete(['videos',v.id,'deleted'])}} {{ moderator_checkbox(['videos',v.id,'visible'], v.visible) }} <a href="{{ config.VIDEOPREFIX }}/{{v.path}}">{{v.format_description}} ({{v.file_size|filesizeformat(true)}})</a></li>
{% endfor %}
</ul>
177
{% if not ismod() %}
178
	</noscript> 
179
{% endif %}
180
181
{% endmacro %}

182
{%macro video_embed_btn(lectureid, course=None) %}
Andreas Valder's avatar
Andreas Valder committed
183
184
185
186
<a class="btn btn-default" id="embedcodebtn" data-container="body" data-toggle="popover" data-placement="bottom">
	<span>Einbetten</span>
</a>
<script>
187
{% set embedcode = '<iframe width="700" height="394" src="'+url_for('embed', course=course, id=lectureid, _external=True)+'" frameborder="0" allowfullscreen="true"></iframe>' %}
Andreas Valder's avatar
Andreas Valder committed
188
189
190
191
192
193
194
195
196
197
$('#embedcodebtn').popover(
		{
			html:true,
			title:'Einbettcode',
			content:'<span><input type="text" onclick="this.select()" value="{{embedcode}}"></span>'
		}
		)
</script>
{% endmacro %}

198
{% macro lecture_list_item(lecture,videos,global_permissions) %}
199
<li class="list-group-item{% if lecture.norecording %} text-muted{% endif %}" id="lecture-{{lecture.id}}">
Andreas Valder's avatar
Andreas Valder committed
200
	<div class="row">
201
202
203
204
205
206
		{% if ismod() or (videos|length > 0)  %}
			<div style="background-image: url('{{ config.VIDEOPREFIX }}/thumbnail/l_{{lecture.id}}.jpg')" class="col-sm-2 col-xs-12 thumbnailimg">
			{% if not videos|length is equalto 0 %}
				<a href="{{url_for('lecture', course=lecture.course.handle, id=lecture.id)}}">
					<span class="glyphicon glyphicon-play-circle playpreviewbtn"></span>
				</a>
207
			{% endif %}
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
			</div>
			<ul class="list-unstyled col-sm-3 col-xs-12">
				<li>{{ moderator_editor(['lectures',lecture.id,'title'], lecture.title) }}{{livelabel((lecture.live and lecture.time > datetime.now()-timedelta(days=1)), videos|selectattr("livehandle")|list|length)}}</li>
				{% if lecture.speaker or ismod() %}<li>Gehalten von {{ moderator_editor(['lectures',lecture.id,'speaker'], lecture.speaker) }}</li>{% endif %}
				<li>{{ moderator_editor(['lectures',lecture.id,'time'], lecture.time) }} </li>
				<li>Dauer: {{ moderator_editor(['lectures',lecture.id,'duration'], lecture.duration) }} min</li>
				{% if  ismod() %}
				<li>ID: <a href="{{url_for('course',handle=lecture.course.handle)}}#lecture-{{lecture.id}}">{{lecture.id}}</a></li>
				{% endif %}
			</ul>
			<ul class="list-unstyled col-sm-3 col-xs-12">
				<li>{{ moderator_editor(['lectures',lecture.id,'comment'], lecture.comment) }}</li>
				{% if  ismod() %}
				<li>{{ moderator_editor(['lectures',lecture.id,'internal'], lecture.internal) }}</li>
				<li>Sichtbar: {{ moderator_checkbox(['lectures',lecture.id,'visible'], lecture.visible) }}</li>
				<li>Livestream geplant: {{ moderator_checkbox(['lectures',lecture.id,'live'], lecture.live) }}</li>
224
				<li>Wird nicht aufgenommen: {{ moderator_checkbox(['lectures',lecture.id,'norecording'], lecture.norecording) }}</li>
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
				<li>Hörsaal: {{ moderator_editor(['lectures',lecture.id,'place'], lecture.place) }} </li>
				{% endif %}
			</ul>
			<ul class="list-inline col-sm-4 col-xs-12">
				<li class="dropdown">
					{{ video_download_btn(videos) }}
				</li>
				<li class="pull-right">
					{{ moderator_permissioneditor('lecture', lecture.id, lecture.perm, global_permissions) }}
				</li>
				<li class="pull-right">
					{{ moderator_delete(['lectures',lecture.id,'deleted']) }}
				</li>
			</ul>
		{% else %}
			<div class="col-sm-2 col-xs-12">
			</div>
			<ul class="list-unstyled col-sm-3 col-xs-12">
				<li>{{ moderator_editor(['lectures',lecture.id,'title'], lecture.title) }}{{livelabel((lecture.live and lecture.time > datetime.now()-timedelta(days=1)), videos|selectattr("livehandle")|list|length)}}</li>
			</ul>
			<ul class="list-unstyled col-sm-3 col-xs-12">
				<li>{{ moderator_editor(['lectures',lecture.id,'time'], lecture.time) }} </li>
				<li>Dauer: {{ moderator_editor(['lectures',lecture.id,'duration'], lecture.duration) }} min</li>
			</ul>
			<ul class="list-inline col-sm-4 col-xs-12">
				<li>{{ moderator_editor(['lectures',lecture.id,'comment'], lecture.comment) }}</li>
			</ul>
		{% endif %}
Andreas Valder's avatar
Andreas Valder committed
253
254
255
	</div>
</li>
{% endmacro %}
256

257
{% macro moderator_editor (path,value,reload=false) %}
258
	{% if ismod() %}
259
	<span class="moderator_editor" data-path="{{path|join('.')}}" data-reload="{{ reload|int }}" >
260
261
262
		<a class="moderator_editor_sign btn btn-default" title="{{path|join('.')}}" data-toggle="tooltip" tabindex="0" style="padding: 3px; margin-right: 5px;">
			<span class="glyphicon glyphicon-pencil"></span>
		</a>
263
		<span class="moderator_editor_value">{{ value|fixnl|safe }}</span>
264
	</span>
265
	{% else %}
266
		{{value|fixnl|safe}}
267
	{% endif %}
268
269
{% endmacro %}

270
{% macro moderator_checkbox (path,value) %}
271
	{% if ismod() %}
272
	<input title="{{path|join('.')}}" data-toggle="tooltip" type="checkbox" data-path="{{path|join('.')}}" {% if value %} checked {% endif %} onchange="moderator.editor.changeboxclick(this)"/>
273
274
	{% endif %}
{% endmacro %}
275

276
{% macro moderator_delete (path) %}
277
	{% if ismod() %}
278
	<button class="btn btn-default" style="background-color: red;" data-path="{{path|join('.')}}" onclick="moderator.editor.deletebtnclick(this)">
Andreas Valder's avatar
Andreas Valder committed
279
280
281
282
283
		<span class="glyphicon glyphicon-trash"></span>
	</button>
	{% endif %}
{% endmacro %}

284
285
286
{% macro moderator_permissioneditor(type,id,perm,global_permissions) %}
	{% set tmp = global_permissions.extend(perm) %}
	{% set permdescription = perm|permdescr %}
287
288
289
290
291
	{% set permlogos = '' %}

	{% if permdescription[0] == 'public' %}
		{% set permlogos = '<span class="fa fa-globe" aria-hidden="true"></span>' %}
	{% endif %}
Julian Rother's avatar
Julian Rother committed
292
293
294
	{% if permdescription[0] == 'none' %}
		{% set permlogos = '<span class="fa fa-ban" aria-hidden="true"></span>' %}
	{% endif %}
295
296
297
298
	{% if permdescription[0] == 'password' %}
		{% set permlogos = '<span class="fa fa-lock" aria-hidden="true"></span>' %}
	{% endif %}
	{% if permdescription[0] == 'l2p' %}
299
		{% set permlogos = '<span class="fa" aria-hidden="true" style="width: 12px; height: 14px; background-size: cover;  background-image: url(\'/static/l2p-logo.gif\');"></span>' %}
300
301
	{% endif %}
	{% if permdescription[0] == 'rwth' %}
302
		{% set permlogos = '<span class="fa" aria-hidden="true" style="width: 25px; height: 20px; background-size: cover;  background-image: url(\'/static/rwth.png\');"></span>' %}
303
	{% endif %}
304
305
306
	{% if permdescription[0] == 'fsmpi' %}
		{% set permlogos = '<span class="fa" aria-hidden="true" style="width: 25px; height: 20px; background-size: cover;  background-image: url(\'/static/fsmpi.png\');"></span>' %}
	{% endif %}
307
308

	{% if ismod() %}
309
		<button class="btn btn-default modmoderator_permissioneditor" data-type="{{ type }}" data-id="{{ id }}">
310
			{{ permlogos|safe }}	
311
		</button>
Andreas Valder's avatar
Andreas Valder committed
312
	{% else %}
Andreas Valder's avatar
Andreas Valder committed
313
		<span title="{{permdescription[1]}}">
314
			{{ permlogos|safe }}	
Andreas Valder's avatar
Andreas Valder committed
315
		</span>
316
	{% endif %}
Andreas Valder's avatar
Andreas Valder committed
317
	
318
{% endmacro %}
Andreas Valder's avatar
Andreas Valder committed
319
320

{% macro vtttime(time) %}{{ '%02d:%02d:%02d.000'|format( time//3600, (time//60)%60, time%60) }}{% endmacro %}
321

Julian Rother's avatar
Julian Rother committed
322
{% macro stats_viewsperday(id, req, title, type="scatter", param=None, maxtraces=7) %}
323
324
325
<script>
	$.ajax({
		method: "GET",
Julian Rother's avatar
Julian Rother committed
326
		url: "{{url_for('stats_viewsperday', req=req, param=param)}}",
327
328
329
330
		dataType: "json",
		error: moderator.api.handleapierror,
		success: function (data) {
			var traces = [];
Julian Rother's avatar
Julian Rother committed
331
332
333
334
335
			for (var i = 0; i < data.views.length; i++) {
				if (data.views[i].name == 'total' && data.views.length > 2)
					traces.push({"x": data.times, "y": data.views[i].vals, "type": "{{type}}", "name": "gesamt", line: {"color": "black", "width": 2}});
				else
					traces.push({"x": data.times, "y": data.views[i].vals, "type": "{{type}}", "name": data.views[i].name, line: {"width": 1}});
336
			}
Julian Rother's avatar
Julian Rother committed
337
338
339
340
341
342
343
344
345
346
347
348
			traces.sort(function (a, b) {
				amax = 0;
				bmax = 0;
				for (var i = 0; i < a.y.length; i++)
					amax = Math.max(amax, a.y[i]);
				for (var i = 0; i < b.y.length; i++)
					bmax = Math.max(bmax, b.y[i]);
				return bmax-amax;
			});
			for (var i = 0; i < traces.length; i++)
				if (i > {{maxtraces}})
					traces[i].visible = "legendonly";
349
350
351
352
353
354
355
356
357
			var layout = {
				"title": "{{title}}",
				"showlegend": (traces.length != 1)
			};
			Plotly.newPlot("{{id}}", traces, layout, { "modeBarButtonsToRemove": ['sendDataToCloud','hoverCompareCartesian'], "displaylogo": false});
		}
	});
</script>
{% endmacro %}
Julian Rother's avatar
Julian Rother committed
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400

{% macro featured_content(item) %} {# This macro is used in a panel div after the panel header #}
	{% 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 %}
		{% if item.text or ismod() %}
			<div class="panel-body">{{ moderator_editor(('featured',item.id,'text'), item.text) }}</div>
		{% endif %}
	{% elif item.type == 'courses' %}
		{% if item.text or ismod() %}
			<div class="panel-body">{{ moderator_editor(('featured',item.id,'text'), item.text) }}</div>
		{% endif %}
		<ul class="courses-list list-group">
		{% for i in item.courses %}
			{{ course_list_item(i) }}
		{% endfor %}
		</ul>
		<div class="panel-footer">
		{% if ismod() %}
			<ul class="list-inline">	
			<li><div class="dropdown">
				{% set params = {'semester': 'Semester', 'title': 'Veranstaltung', 'organizer': 'Dozent', 'subject': 'Kategorie'} %}
				<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown">{{params[item.param]}}: <span class="caret"></span></button>
				<ul class="dropdown-menu">
					{% for key, name in params.items() %}
					<li><a href="{{url_for('edit', **{'featured.'+item.id|string+'.param': key, 'ref': request.url})}}">{{name}}</a></li>
					{% endfor %}
				</ul>
			</div></li>
			<li>{{ moderator_editor(('featured',item.id,'param2'), item.param2) }}</li>
			</ul>
		{% endif %}
		Die vollständige Liste findest du <a href="{{ url_for('courses') }}">hier</a>.
		</div>
	{% else %}
		{% if item.text or ismod() %}
			<div class="panel-body">{{ moderator_editor(('featured',item.id,'text'), item.text) }}</div>
		{% endif %}
	{% endif %}
{% endmacro %}