From 6f0393d12c72d28cc3862dd22645f5c23c91a14a Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 28 Sep 2011 03:40:36 +0200 Subject: [PATCH] events and places --- pandora/annotation/managers.py | 5 ++- pandora/event/models.py | 5 +++ static/js/pandora/ui/item.js | 82 ++++++++++++++++++++++++++++++---- static/js/pandora/ui/list.js | 81 ++++++++++++++++++++++++++++----- 4 files changed, 150 insertions(+), 23 deletions(-) diff --git a/pandora/annotation/managers.py b/pandora/annotation/managers.py index 787ad04b3..872bc9b1a 100644 --- a/pandora/annotation/managers.py +++ b/pandora/annotation/managers.py @@ -20,6 +20,7 @@ def parseCondition(condition, user): k = { 'user': 'user__username', 'place': 'places__id', + 'event': 'events__id', }.get(k, k) if not k: k = 'name' @@ -41,12 +42,12 @@ def parseCondition(condition, user): return q if k == 'id': v = ox.from32(v.split('/')[-1]) - elif k in ('places__id', ): + elif k in ('places__id', 'events__id'): v = ox.from32(v) if isinstance(v, bool): #featured and public flag key = k elif k in ('lat', 'lng', 'area', 'south', 'west', 'north', 'east', 'matches', - 'id', 'places__id'): + 'id', 'places__id', 'events__id'): key = "%s%s" % (k, { '>': '__gt', '>=': '__gte', diff --git a/pandora/event/models.py b/pandora/event/models.py index 954a31aff..e3d94b1a8 100644 --- a/pandora/event/models.py +++ b/pandora/event/models.py @@ -51,6 +51,7 @@ class Event(models.Model): matches = models.IntegerField(default=0) items = models.ManyToManyField(Item, blank=True, related_name='events') + annotations = models.ManyToManyField(Annotation, blank=True, related_name='events') def __unicode__(self): return self.name @@ -64,6 +65,10 @@ class Event(models.Model): def update_matches(self): matches = self.get_matches() self.matches = matches.count() + for i in self.annotations.exclude(id__in=matches): + self.annotations.remove(i) + for i in matches.exclude(id__in=self.annotations.all()): + self.annotations.add(i) ids = list(set([a.item.id for a in matches])) for i in self.items.exclude(id__in=ids): self.items.remove(i) diff --git a/static/js/pandora/ui/item.js b/static/js/pandora/ui/item.js index 6729629bd..3716003a9 100644 --- a/static/js/pandora/ui/item.js +++ b/static/js/pandora/ui/item.js @@ -39,6 +39,7 @@ pandora.ui.item = function() { ); } else if (pandora.user.ui.itemView == 'calendar') { + var video = result.data.stream; pandora.api.findEvents({ itemQuery: {conditions: [{key: 'id', value: pandora.user.ui.item, operator:'='}]}, keys: ['id', 'name', 'start', 'end'], @@ -55,10 +56,68 @@ pandora.ui.item = function() { range: [-5000, 5000], width: window.innerWidth - pandora.user.ui.showSidebar * pandora.user.ui.sidebarSize - 2 - 144 - Ox.UI.SCROLLBAR_SIZE, zoom: 4 + }).bindEvent({ + select: function(event) { + pandora.$ui.clips.options({ + items: function(data, callback) { + pandora.api.findAnnotations(Ox.extend(data, { + query: { + conditions:[{ + key: 'event', + value: event.id, + operator:'==' + }] + }, + itemQuery: {conditions: [{ + key: 'id', + value: pandora.user.ui.item, + operator: '==' + }]} + }), callback); + } + }); + + } }) }, { element: Ox.Element(), + element: pandora.$ui.clips = Ox.IconList({ + fixedRatio: video.aspectRatio, + item: function(data, sort, size) { + size = size || 128; + var width = size, + height = Math.round(size / video.aspectRatio), + itemId = data.id.split('/')[0], + url = '/' + itemId + '/' + height + 'p' + data['in'] + '.jpg'; + return { + height: height, + id: data['id'], + info: Ox.formatDuration(data['in'], 'short') +' - '+ Ox.formatDuration(data['out'], 'short'), + title: data.value, + url: url, + width: width + }; + }, + items: [], + keys: ['id', 'value', 'in', 'out'], + size: 128, + sort: pandora.user.ui.itemSort, + unique: 'id' + }).bindEvent({ + open: function(data) { + var id = data.ids[0], + item = pandora.user.ui.item, + points = { + 'in': pandora.$ui.clips.value(id, 'in'), + out: pandora.$ui.clips.value(id, 'out') + }; + pandora.UI.set('videoPoints.' + item, Ox.extend(points, { + position: points['in'] + })); + pandora.UI.set('itemView', 'timeline'); + } + }), id: 'place', size: 144 + Ox.UI.SCROLLBAR_SIZE } @@ -449,18 +508,22 @@ pandora.ui.item = function() { toolbar: true, width: window.innerWidth - pandora.user.ui.showSidebar * pandora.user.ui.sidebarSize - 2 - 144 - Ox.UI.SCROLLBAR_SIZE }).bindEvent({ - selectplace: function(event, place) { + selectplace: function(place) { if(place) { pandora.$ui.clips.options({ items: function(data, callback) { return pandora.api.findAnnotations(Ox.extend(data, { query: { - conditions:[{key: 'place', value: place.id, operator:'='}] + conditions:[{ + key: 'place', + value: place.id, + operator:'==' + }] }, itemQuery: {conditions: [{ key: 'id', value: pandora.user.ui.item, - operator: '=' + operator: '==' }]} }), callback); } @@ -478,10 +541,11 @@ pandora.ui.item = function() { fixedRatio: video.aspectRatio, item: function(data, sort, size) { size = size || 128; - var ratio = data.aspectRatio, - width = size, - height = Math.round(size / ratio), - url = '/' + data.item + '/' + height + 'p' + data['in'] + '.jpg'; + Ox.print('DATA', data); + var width = size, + height = Math.round(size / video.aspectRatio), + itemId = data.id.split('/')[0], + url = '/' + itemId + '/' + height + 'p' + data['in'] + '.jpg'; return { height: height, id: data['id'], @@ -492,7 +556,7 @@ pandora.ui.item = function() { }; }, items: [], - keys: ['id', 'value', 'in', 'out', 'aspectRatio', 'item'], + keys: ['id', 'value', 'in', 'out'], size: 128, sort: pandora.user.ui.itemSort, unique: 'id' @@ -507,7 +571,7 @@ pandora.ui.item = function() { pandora.UI.set('videoPoints.' + item, Ox.extend(points, { position: points['in'] })); - pandora.URL.set(item + '/timeline'); + pandora.UI.set('itemView', 'timeline'); } }), id: 'place', diff --git a/static/js/pandora/ui/list.js b/static/js/pandora/ui/list.js index 85d7bcad9..c92668944 100644 --- a/static/js/pandora/ui/list.js +++ b/static/js/pandora/ui/list.js @@ -422,13 +422,16 @@ pandora.ui.list = function() { toolbar: true, width: window.innerWidth - pandora.user.ui.showSidebar * pandora.user.ui.sidebarSize - 2 - 144 - Ox.UI.SCROLLBAR_SIZE, }).bindEvent({ - selectplace: function(event, place) { + selectplace: function(place) { if(place && place.id[0] != '_') { pandora.$ui.clips.options({ items: function(data, callback) { return pandora.api.findAnnotations(Ox.extend(data, { query: { - conditions:[{key: 'place', value: place.id, operator:'='}] + conditions:[{key: 'place', + value: place.id, + operator:'==' + }] }, itemQuery: pandora.user.ui.find }), callback); @@ -446,11 +449,11 @@ pandora.ui.list = function() { element: pandora.$ui.clips = Ox.IconList({ fixedRatio: fixedRatio, item: function(data, sort, size) { - Ox.print('RATIO', data.videoRatio); size = size || 128; var width = data.videoRatio < fixedRatio ? size : size * data.videoRatio / fixedRatio, - height = width / data.videoRatio, - url = '/' + data.item + '/' + height + 'p' + data['in'] + '.jpg'; + height = Math.round(width / data.videoRatio), + itemId = data.id.split('/')[0], + url = '/' + itemId + '/' + height + 'p' + data['in'] + '.jpg'; return { height: height, id: data.id, @@ -462,7 +465,7 @@ pandora.ui.list = function() { }; }, items: [], - keys: ['id', 'value', 'in', 'out', 'videoRatio', 'item'], + keys: ['id', 'value', 'in', 'out', 'videoRatio'], size: 128, sort: pandora.user.ui.listSort, unique: 'id' @@ -477,10 +480,10 @@ pandora.ui.list = function() { pandora.UI.set('videoPoints.' + item, Ox.extend(points, { position: points['in'] })); - pandora.URL.set(item + '/timeline'); + pandora.UI.set('itemView', 'timeline'); } }), - id: 'place', + id: 'clips', size: 144 + Ox.UI.SCROLLBAR_SIZE } ], @@ -490,14 +493,52 @@ pandora.ui.list = function() { pandora.$ui.map.resizeMap(); }); } else if (view == 'calendar') { + var fixedRatio = 16/9; that = Ox.SplitPanel({ elements: [ { element: pandora.$ui.calendar = Ox.Element() }, { - element: Ox.Element(), - id: 'place', + element: pandora.$ui.clips = Ox.IconList({ + fixedRatio: fixedRatio, + item: function(data, sort, size) { + size = size || 128; + var width = data.videoRatio < fixedRatio ? size : size * data.videoRatio / fixedRatio, + height = Math.round(width / data.videoRatio), + itemId = data.id.split('/')[0], + url = '/' + itemId + '/' + height + 'p' + data['in'] + '.jpg'; + Ox.print(data.videoRatio, size, fixedRatio, width, height); + return { + height: height, + id: data.id, + info: Ox.formatDuration(data['in'], 'short') + ' - ' + + Ox.formatDuration(data['out'], 'short'), + title: data.value, + url: url, + width: width + }; + }, + items: [], + keys: ['id', 'value', 'in', 'out', 'videoRatio'], + size: 128, + sort: pandora.user.ui.listSort, + unique: 'id' + }).bindEvent({ + open: function(data) { + var id = data.ids[0], + item = pandora.$ui.clips.value(id, 'item'), + points = { + 'in': pandora.$ui.clips.value(id, 'in'), + out: pandora.$ui.clips.value(id, 'out') + }; + pandora.UI.set('videoPoints.' + item, Ox.extend(points, { + position: points['in'] + })); + pandora.UI.set('itemView', 'timeline'); + } + }), + id: 'clips', size: 144 + Ox.UI.SCROLLBAR_SIZE } ], @@ -518,6 +559,22 @@ pandora.ui.list = function() { range: [-5000, 5000], width: window.innerWidth - pandora.user.ui.showSidebar * pandora.user.ui.sidebarSize - 2 - 144 - Ox.UI.SCROLLBAR_SIZE, zoom: 4 + }).bindEvent({ + select: function(event) { + pandora.$ui.clips.options({ + items: function(data, callback) { + return pandora.api.findAnnotations(Ox.extend(data, { + query: { + conditions:[{key: 'event', + value: event.id, + operator:'==' + }] + }, + itemQuery: pandora.user.ui.find + }), callback); + } + }); + } })); }); } else { @@ -574,7 +631,7 @@ pandora.ui.list = function() { return { key: 'id', value: id, - operator: '=' + operator: '==' } }), operator: '|' @@ -662,7 +719,7 @@ pandora.ui.list = function() { return { key: 'id', value: id, - operator: '=' + operator: '==' } }), operator: '|'