From 357e696f0d4acdf3c673ea4933c819b3e8686736 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 22 Jan 2014 18:24:21 +0000 Subject: [PATCH] add annotations to edits --- pandora/edit/models.py | 34 ++++++++++++++++++++++++++++++++++ static/js/editPanel.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/pandora/edit/models.py b/pandora/edit/models.py index ac55eb7d..82174cde 100644 --- a/pandora/edit/models.py +++ b/pandora/edit/models.py @@ -48,6 +48,13 @@ class Edit(models.Model): def __unicode__(self): return u'%s (%s)' % (self.name, self.user) + + @classmethod + def get(cls, id): + id = id.split(':') + username = id[0] + name = ":".join(id[1:]) + return cls.objects.get(user__username=username, name=name) def get_id(self): return u'%s:%s' % (self.user.username, self.name) @@ -360,8 +367,35 @@ class Clip(models.Model): data[key] = value data['duration'] = data['out'] - data['in'] data['cuts'] = tuple([c for c in self.item.get('cuts') if c > self.start and c < self.end]) + data['layers'] = self.get_layers(user) return data + def get_layers(self, user=None): + if self.annotation: + start = self.annotation.start + end = self.annotation.end + item = self.annotation.item + else: + start = self.start + end = self.end + item = self.item + layers = {} + for l in settings.CONFIG['layers']: + name = l['id'] + ll = layers.setdefault(name, []) + qs = Annotation.objects.filter(layer=name, item=item).order_by( + 'start', 'end', 'sortvalue') + if name == 'subtitles': + qs = qs.exclude(value='') + qs = qs.filter(start__lt=end, end__gt=start) + if l.get('private'): + if user and user.is_anonymous(): + user = None + qs = qs.filter(user=user) + for a in qs.order_by('start'): + ll.append(a.json(user=user)) + return layers + class Position(models.Model): class Meta: diff --git a/static/js/editPanel.js b/static/js/editPanel.js index 1fa3b6a8..54a117a9 100644 --- a/static/js/editPanel.js +++ b/static/js/editPanel.js @@ -78,6 +78,13 @@ pandora.ui.editPanel = function() { function renderEdit() { that = pandora.$ui.editPanel = Ox.VideoEditPanel({ + annotationsCalendarSize: ui.annotationsCalendarSize, + annotationsFont: ui.annotationsFont, + annotationsMapSize: ui.annotationsMapSize, + annotationsRange: ui.annotationsRange, + annotationsSize: ui.annotationsSize, + annotationsSort: ui.annotationsSort, + clickLink: pandora.clickLink, clips: Ox.clone(edit.clips), clipSize: listSize, clipSort: ui.edits[ui.edit].sort, @@ -97,6 +104,7 @@ pandora.ui.editPanel = function() { }, height: pandora.$ui.appPanel.size(1), 'in': ui.edits[ui.edit]['in'], + layers: getLayers(edit.clips), loop: ui.videoLoop, muted: ui.videoMuted, out: ui.edits[ui.edit].out, @@ -104,8 +112,12 @@ pandora.ui.editPanel = function() { resolution: ui.videoResolution, scaleToFill: ui.videoScale == 'fill', selected: ui.edits[ui.edit].selection, + showAnnotationsCalendar: ui.showAnnotationsCalendar, + showAnnotationsMap: ui.showAnnotationsMap, showClips: ui.showClips, + showLayers: ui.showLayers, showTimeline: ui.showTimeline, + showUsers: pandora.site.annotations.showUsers, smallTimelineURL: getSmallTimelineURL(), sort: ui.edits[ui.edit].sort, sortOptions: [ @@ -371,6 +383,26 @@ pandora.ui.editPanel = function() { updateVideos(); } + function getLayers(clips) { + var layers = []; + pandora.site.layers.forEach(function(layer, i) { + layers[i] = Ox.extend({}, layer, { + title: Ox._(layer.title), + item: Ox._(layer.item), + items: Ox.flatten(clips.map(function(clip) { + return clip.layers[layer.id].map(function(annotation) { + var a = Ox.clone(annotation); + ['in', 'out'].forEach(function(point) { + a[point] = a[point] - clip['in'] + clip['position']; + }); + return a; + }); + })), + }); + }); + return layers; + } + function serializeClips(clips) { // can be ids or clips return clips.map(function(clip) { @@ -394,6 +426,7 @@ pandora.ui.editPanel = function() { that.options({ clips: Ox.clone(edit.clips), duration: edit.duration, + layers: getLayers(edit.clips), smallTimelineURL: getSmallTimelineURL(), video: getVideos() });