diff --git a/app/static/css/partials/_film.scss b/app/static/css/partials/_film.scss index ab5acee..748512a 100755 --- a/app/static/css/partials/_film.scss +++ b/app/static/css/partials/_film.scss @@ -8,6 +8,10 @@ text-decoration: none; } + .actions { + text-align: right; + } + select { font-size: 18px; font-family: "noto_sans", sans-serif; diff --git a/app/static/css/partials/_player.scss b/app/static/css/partials/_player.scss index 2be4aa2..74405cc 100644 --- a/app/static/css/partials/_player.scss +++ b/app/static/css/partials/_player.scss @@ -31,6 +31,7 @@ @media screen and (max-width: 1100px) { h1 { display: block; + font-size: 16px; } } diff --git a/app/static/js/films.js b/app/static/js/films.js index 54a18a7..727298f 100644 --- a/app/static/js/films.js +++ b/app/static/js/films.js @@ -5,10 +5,14 @@ function isNumeric (str) { !isNaN(parseFloat(str)) // ...and ensure strings of whitespace fail } -function selectChanged() { +var options = parseHash(); + +function sortChanged() { const sortValue = document.getElementById('sort-select').value const $films = [...document.querySelectorAll('.film')] - location.hash = sortValue + + options.sort = sortValue + updateHash() $films.sort((a, b) => { let aVal = a.dataset[sortValue] let bVal = b.dataset[sortValue] @@ -24,12 +28,43 @@ function selectChanged() { }) } -//document.getElementById('sort-select').addEventListener('change', selectChanged) +function filterChanged() { + const filterValue = document.getElementById('filter-select').value + options.filter = filterValue + document.querySelectorAll('.film').forEach(film => { + if (!options.filter || film.dataset.type.split(',').indexOf(options.filter) > -1) { + console.log(film.dataset.type.split(','), film.dataset.type.split(',').indexOf(options.filter)) + film.style.display = '' + } else { + film.style.display = 'none' + } + }) + updateHash() +} -const locationHash = location.hash.replace('#', '') -if (locationHash !== '') { - document.getElementById('sort-select').value = locationHash - selectChanged() +function parseHash() { + var options = {} + location.hash.slice(1).split('&').forEach(kv => { + kv = kv.split('=') + options[kv.shift()] = kv.join('=') + }) + return options; +} + +function updateHash() { + location.hash = '#' + Object.keys(options).map(key => { return key + '=' + options[key]; }).join('&') +} + +document.getElementById('sort-select').addEventListener('change', sortChanged) +document.getElementById('filter-select').addEventListener('change', filterChanged) + +if (options.sort) { + document.getElementById('sort-select').value = options.sort + sortChanged() +} +document.getElementById('filter-select').value = options.filter +if (options.filter) { + filterChanged() } document.querySelectorAll('.films .film figure').forEach(figure => { diff --git a/app/templates/films.html b/app/templates/films.html index ee5267b..299ede7 100644 --- a/app/templates/films.html +++ b/app/templates/films.html @@ -3,28 +3,29 @@ {% block main %}
-
{% for film in films %}
diff --git a/app/video/management/commands/load_titles.py b/app/video/management/commands/load_titles.py index 9e5d61f..8ca234b 100644 --- a/app/video/management/commands/load_titles.py +++ b/app/video/management/commands/load_titles.py @@ -24,7 +24,7 @@ class Command(BaseCommand): keys = [ 'id', 'title', 'director', 'summary', 'source', 'sourcedescription', 'date', 'location', - 'country', 'type', + 'country', 'type', 'year', 'duration', 'featuring', 'cinematographer', 'hue', 'saturation', 'lightness', 'folder', 'folderdescription', 'rightslevel' @@ -50,6 +50,7 @@ class Command(BaseCommand): folders[item['folder']] = { 'title': item['folder'], 'date': item.get('date', ''), + 'year': item.get('year', ''), 'country': item.get('country', []), 'featuring': item.get('featuring', []), 'type': item['type'], diff --git a/app/video/models.py b/app/video/models.py index 47bcddf..8357530 100644 --- a/app/video/models.py +++ b/app/video/models.py @@ -37,6 +37,12 @@ class Film(models.Model): if folder: return Text.objects.filter(Q(data__folder=folder) | Q(data__related=folder)) + def duration_seconds(self): + duration = 0 + for item in self.data.get('items', []): + duration += item['duration'] + return duration + def duration(self): return ox.format_duration(self.data['duration'] * 1000, verbosity=1, milliseconds=False) diff --git a/app/video/views.py b/app/video/views.py index 0d87bc3..0d4432c 100644 --- a/app/video/views.py +++ b/app/video/views.py @@ -1,5 +1,6 @@ import logging import json +from collections import Counter from django.shortcuts import render, redirect, get_object_or_404 from django.views.decorators.csrf import csrf_exempt @@ -56,6 +57,16 @@ def get_stream_prefix(request): def films(request): context = {} context['films'] = models.Film.objects.filter(public=True).order_by('position', 'data__title') + types = [] + for f in context['films']: + types += f.data['type'] + types = Counter(types) + context['types'] = [] + for t in sorted(types): + context['types'].append({ + 'title': '%s (%s)' % (t, types[t]), 'value': t + }) + context['stream_prefix'] = get_stream_prefix(request) context['settings'] = settings return render(request, 'films.html', context)