From 8831c3d8dd0034a7caafbb329a9303b0039b1da7 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Mon, 20 Jun 2011 17:02:53 +0200 Subject: [PATCH] clips next to map --- pandora/annotation/managers.py | 1 + pandora/place/models.py | 9 +++++-- static/js/pandora/ui/item.js | 46 +++++++++++++++++++++++++++++++++- static/js/pandora/ui/list.js | 42 ++++++++++++++++++++++++++++++- 4 files changed, 94 insertions(+), 4 deletions(-) diff --git a/pandora/annotation/managers.py b/pandora/annotation/managers.py index 119fe5d..b0447a6 100644 --- a/pandora/annotation/managers.py +++ b/pandora/annotation/managers.py @@ -20,6 +20,7 @@ def parseCondition(condition, user): k = condition.get('key', 'name') k = { 'user': 'user__username', + 'place': 'places__id', }.get(k, k) if not k: k = 'name' diff --git a/pandora/place/models.py b/pandora/place/models.py index 6d6424e..6baed31 100644 --- a/pandora/place/models.py +++ b/pandora/place/models.py @@ -43,6 +43,7 @@ class Place(models.Model): matches = models.IntegerField(default=0) items = models.ManyToManyField(Item, blank=True, related_name='places') + annotations = models.ManyToManyField(Annotation, blank=True, related_name='places') objects = managers.PlaceManager() @@ -74,14 +75,18 @@ class Place(models.Model): return j def get_matches(self): - q = Q(value__icontains=" " + self.name)|Q(value__startswith=self.name) + q = Q(value__contains=" " + self.name)|Q(value__startswith=self.name) for name in self.alternativeNames: - q = q|Q(value__icontains=" " + name)|Q(value__startswith=name) + q = q|Q(value__contains=" " + name)|Q(value__startswith=name) return Annotation.objects.filter(q) 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 3c9d184..d68c385 100644 --- a/static/js/pandora/ui/item.js +++ b/static/js/pandora/ui/item.js @@ -117,10 +117,54 @@ pandora.ui.item = function() { showTypes: true, toolbar: true, width: window.innerWidth - pandora.user.ui.showSidebar * pandora.user.ui.sidebarSize - 2 - 144 - Ox.UI.SCROLLBAR_SIZE + }).bindEvent({ + selectplace: function(event, place) { + if(place) { + pandora.$ui.clips.options({ + items: function(data, callback) { + return pandora.api.findAnnotations($.extend(data, { + query: { + conditions:[{key: 'place', value: place.id, operator:'='}] + }, + itemQuery: {conditions: [{ + key: 'id', + value: pandora.user.ui.item, + operator: '=' + }]} + }), callback); + } + }); + } else { + pandora.$ui.clips.options({ + items: [] + }); + } + } }) }, { - element: Ox.Element(), + element: pandora.$ui.clips = Ox.IconList({ + item: function(data, sort, size) { + size = size || 128; + var ratio = data.aspectRatio, + width = size, + height = size/ratio, + url = '/' + data.item + '/frame/' + size + '/'+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', 'aspectRatio', 'item'], + size: 128, + sort: pandora.user.ui.lists[pandora.user.ui.list].sort, + unique: 'id' + }), id: 'place', size: 144 + Ox.UI.SCROLLBAR_SIZE } diff --git a/static/js/pandora/ui/list.js b/static/js/pandora/ui/list.js index 86fe56c..d563997 100644 --- a/static/js/pandora/ui/list.js +++ b/static/js/pandora/ui/list.js @@ -148,10 +148,50 @@ pandora.ui.list = function(view) { // fixme: remove view argument showTypes: true, toolbar: true, width: window.innerWidth - pandora.user.ui.showSidebar * pandora.user.ui.sidebarSize - 2 - 144 - Ox.UI.SCROLLBAR_SIZE, + }).bindEvent({ + selectplace: function(event, place) { + if(place) { + pandora.$ui.clips.options({ + items: function(data, callback) { + return pandora.api.findAnnotations($.extend(data, { + query: { + conditions:[{key: 'place', value: place.id, operator:'='}] + }, + itemQuery: pandora.Query.toObject() + }), callback); + } + }); + } else { + pandora.$ui.clips.options({ + items: [] + }); + } + } }) }, { - element: Ox.Element(), + element: pandora.$ui.clips = Ox.IconList({ + item: function(data, sort, size) { + size = size || 128; + var ratio = data.aspectRatio, + width = size, + height = size/ratio, + url = '/' + data.item + '/frame/' + size + '/'+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', 'aspectRatio', 'item'], + size: 128, + sort: pandora.user.ui.lists[pandora.user.ui.list].sort, + unique: 'id' + }), id: 'place', size: 144 + Ox.UI.SCROLLBAR_SIZE }