diff --git a/pandora/annotation/managers.py b/pandora/annotation/managers.py index 119fe5db2..b0447a676 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 6d6424ef2..6baed3139 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 3c9d18413..d68c38538 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 86fe56c63..d56399777 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 }