From daaabba0712d55e7417b591f4cfd532d32852b9c Mon Sep 17 00:00:00 2001 From: rolux Date: Wed, 1 Feb 2012 12:01:39 +0000 Subject: [PATCH] highlight matches in clips --- pandora/0xdb.jsonc | 2 +- pandora/annotation/models.py | 2 +- pandora/item/models.py | 2 +- pandora/padma.jsonc | 4 ++-- static/js/pandora/UI.js | 4 +--- static/js/pandora/clipList.js | 24 +++++++++++++++++++++--- static/js/pandora/clipsView.js | 8 ++------ static/js/pandora/contentPanel.js | 6 +++--- static/js/pandora/item.js | 16 ++++------------ static/js/pandora/itemClips.js | 1 + static/js/pandora/mainPanel.js | 4 ++++ static/js/pandora/utils.js | 25 ++++++++++++++++++------- 12 files changed, 59 insertions(+), 39 deletions(-) diff --git a/pandora/0xdb.jsonc b/pandora/0xdb.jsonc index 542420bf..981b200e 100644 --- a/pandora/0xdb.jsonc +++ b/pandora/0xdb.jsonc @@ -642,7 +642,7 @@ "icons": "posters", "infoIconSize": 256, "item": "", - "itemFind": {"conditions": [], "operator": "&"}, + "itemFind": "", "itemSort": [{"key": "position", "operator": "+"}], "itemView": "info", "listColumns": ["title", "director", "country", "year", "language", "runtime", "genre"], diff --git a/pandora/annotation/models.py b/pandora/annotation/models.py index a4f9260c..a4220f8b 100644 --- a/pandora/annotation/models.py +++ b/pandora/annotation/models.py @@ -124,7 +124,7 @@ class Annotation(models.Model): layer = self.get_layer() if self.value: self.value = utils.cleanup_value(self.value, layer['type']) - self.findvalue = ox.stripTags(self.value).strip() + self.findvalue = ox.decodeHtml(ox.stripTags(self.value).strip()) sortvalue = sort_string(self.findvalue) if sortvalue: self.sortvalue = sortvalue[:1000] diff --git a/pandora/item/models.py b/pandora/item/models.py index 9cc67692..6133a976 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -552,7 +552,7 @@ class Item(models.Model): if isinstance(value, bool): value = value and 'true' or 'false' if isinstance(value, basestring): - value = value.strip() + value = ox.decodeHtml(ox.stripTags(value.strip())) f.value = value f.save() else: diff --git a/pandora/padma.jsonc b/pandora/padma.jsonc index 5f8c1d99..fea5ee42 100644 --- a/pandora/padma.jsonc +++ b/pandora/padma.jsonc @@ -53,7 +53,7 @@ /* clipLayers is the ordered list of public layers that will appear as the text of clips. Excluding a layer from this list means it will not be - included in find annotations. + included in find annotations. // FIXME: the last bit is not implemented. */ "clipLayers": ["transcripts", "keywords", "places", "events", "descriptions"], // fixme: either this, or filter: true in itemKeys, but not both @@ -221,7 +221,7 @@ }, { "id": "annotations", - "title": "Annotation", + "title": "Annotations", "type": "string", "find": true }, diff --git a/static/js/pandora/UI.js b/static/js/pandora/UI.js index be8a48e6..f820a0ca 100644 --- a/static/js/pandora/UI.js +++ b/static/js/pandora/UI.js @@ -64,7 +64,6 @@ pandora.UI = (function() { // switch from item view to list view args['item'] = ''; } - add.itemFind = pandora.site.user.ui.itemFind; if (list != self.previousUI._list) { Ox.Log('UI', 'FIND HAS CHANGED LIST') // if find has changed list @@ -79,8 +78,7 @@ pandora.UI = (function() { } }); } - add.itemFind = pandora.isItemFind(args.find) - ? args.find : pandora.site.user.ui.itemFind; + add.itemFind = pandora.getItemFind(args.find); } else { list = self.previousUI._list; } diff --git a/static/js/pandora/clipList.js b/static/js/pandora/clipList.js index 801f21f9..9f033c34 100644 --- a/static/js/pandora/clipList.js +++ b/static/js/pandora/clipList.js @@ -4,10 +4,13 @@ pandora.ui.clipList = function(videoRatio) { + Ox.print('CLIP LIST FIND', !pandora.user.ui.item ? pandora.getItemFind(pandora.user.ui.find) : pandora.user.ui.itemFind); + var ui = pandora.user.ui, fixedRatio = !ui.item ? 16/9 : videoRatio, isClipView = !ui.item ? ui.listView == 'clip' : ui.itemView == 'clips', that = Ox.IconList({ + find: !ui.item ? pandora.getItemFind(ui.find) : ui.itemFind, fixedRatio: fixedRatio, item: function(data, sort, size) { size = size || 128; // fixme: is this needed? @@ -21,9 +24,17 @@ pandora.ui.clipList = function(videoRatio) { width = fixedRatio > 1 ? size : Math.round(size * fixedRatio); height = fixedRatio > 1 ? Math.round(size / fixedRatio) : size; } - title = data.annotations ? data.annotations.map(function(annotation) { + title = data.annotations ? data.annotations.sort(function(a, b) { + var layerA = pandora.site.clipLayers.indexOf(a.layer), + layerB = pandora.site.clipLayers.indexOf(b.layer); + return layerA < layerB ? -1 + : layerA > layerB ? 1 + : a.value < b.value ? -1 + : a.value > b.value ? 1 + : 0; + }).map(function(annotation) { return Ox.stripTags(annotation.value); - }).join('; ') : '', + }).join('; ') : ''; url = '/' + data.id.split('/')[0] + '/' + height + 'p' + data['in'] + '.jpg'; sortKey = sort[0].key; if (['text', 'position', 'duration'].indexOf(sortKey) > -1) { @@ -73,7 +84,14 @@ pandora.ui.clipList = function(videoRatio) { conditions:[{key: 'id', value: ui.item, operator: '=='}], operator: '&' }; - query = pandora.user.ui.itemFind; + query = { + conditions: ui.itemFind === '' ? [] : [{ + key: 'annotations', + value: ui.itemFind, + operator: '=' + }], + operator: '&' + }; } pandora.api.findClips(Ox.extend({ itemsQuery: itemsQuery, diff --git a/static/js/pandora/clipsView.js b/static/js/pandora/clipsView.js index d7e7cfa1..d47b90ef 100644 --- a/static/js/pandora/clipsView.js +++ b/static/js/pandora/clipsView.js @@ -18,17 +18,13 @@ pandora.ui.clipsView = function(videoRatio) { Ox.Input({ clear: true, placeholder: 'Find Clips', - value: pandora.user.ui.itemFind.conditions[0] - ? pandora.user.ui.itemFind.conditions[0].value : '', + value: pandora.user.ui.itemFind, width: 192 }) .css({float: 'right', margin: '4px'}) .bindEvent({ submit: function(data) { - pandora.UI.set('itemFind', data.value ? { - conditions: [{key: 'annotations', value: data.value, operator: '='}], - operator: '&' - } : pandora.site.user.ui.itemFind); + pandora.UI.set('itemFind', data.value); // since this is the only way itemFind can change, // there's no need for an event handler that.replaceElement(1, diff --git a/static/js/pandora/contentPanel.js b/static/js/pandora/contentPanel.js index f6b412ed..e480a6d9 100644 --- a/static/js/pandora/contentPanel.js +++ b/static/js/pandora/contentPanel.js @@ -34,9 +34,6 @@ pandora.ui.contentPanel = function() { orientation: 'vertical' }) .bindEvent({ - pandora_listview: function() { - that.replaceElement(1, pandora.$ui.list = pandora.ui.list()); - }, pandora_item: function(data) { if (data.value && data.previousValue) { that.replaceElement(1, pandora.$ui.item = pandora.ui.item()); @@ -45,6 +42,9 @@ pandora.ui.contentPanel = function() { pandora_itemview: function() { that.replaceElement(1, pandora.$ui.item = pandora.ui.item()); }, + pandora_listview: function() { + that.replaceElement(1, pandora.$ui.list = pandora.ui.list()); + }, pandora_showbrowser: function(data) { data.value == that.options('elements')[0].collapsed && that.toggle(0); }, diff --git a/static/js/pandora/item.js b/static/js/pandora/item.js index a7d4739a..467a2b9a 100644 --- a/static/js/pandora/item.js +++ b/static/js/pandora/item.js @@ -132,8 +132,7 @@ pandora.ui.item = function() { cuts: result.data.cuts || [], duration: result.data.duration, enableSubtitles: pandora.user.ui.videoSubtitles, - find: pandora.user.ui.itemFind.conditions[0] - ? pandora.user.ui.itemFind.conditions[0].value : '', + find: pandora.user.ui.itemFind, getTimelineImageURL: function(i) { return '/' + pandora.user.ui.item + '/timeline64p' + i + '.png'; }, @@ -172,10 +171,7 @@ pandora.ui.item = function() { pandora.UI.set({annotationsSort: data.sort}); }, find: function(data) { - pandora.UI.set('itemFind', data.find ? { - conditions: [{key: 'annotations', value: data.find, operator: '='}], - operator: '&' - } : pandora.site.user.ui.itemFind); + pandora.UI.set('itemFind', data.find); }, muted: function(data) { pandora.UI.set('videoMuted', data.muted); @@ -245,8 +241,7 @@ pandora.ui.item = function() { duration: result.data.duration, enableDownload: pandora.site.capabilities.canDownloadVideo[pandora.user.level] >= result.data.rightslevel, enableSubtitles: pandora.user.ui.videoSubtitles, - find: pandora.user.ui.itemFind.conditions[0] - ? pandora.user.ui.itemFind.conditions[0].value : '', + find: pandora.user.ui.itemFind, getFrameURL: function(position) { return '/' + pandora.user.ui.item + '/' + pandora.user.ui.videoResolution + 'p' + position + '.jpg'; }, @@ -359,10 +354,7 @@ pandora.ui.item = function() { pandora.$ui.embedDialog = pandora.ui.embedDialog(data).open(); }, find: function(data) { - pandora.UI.set('itemFind', data.find ? { - conditions: [{key: 'annotations', value: data.find, operator: '='}], - operator: '&' - } : pandora.site.user.ui.itemFind); + pandora.UI.set('itemFind', data.find); }, info: function(data) { pandora.ui.annotationDialog(data.layer).open(); diff --git a/static/js/pandora/itemClips.js b/static/js/pandora/itemClips.js index 1a231ef8..3f45ab08 100644 --- a/static/js/pandora/itemClips.js +++ b/static/js/pandora/itemClips.js @@ -37,6 +37,7 @@ pandora.ui.itemClips = function(options) { }), url = '/' + self.options.id + '/' + self.height + 'p' + clip['in'] + '.jpg', $item = Ox.IconItem({ + find: pandora.user.ui.itemFind, imageHeight: self.height, imageWidth: self.width, id: clip.id, diff --git a/static/js/pandora/mainPanel.js b/static/js/pandora/mainPanel.js index cf4fe8a5..82fc13f0 100644 --- a/static/js/pandora/mainPanel.js +++ b/static/js/pandora/mainPanel.js @@ -28,6 +28,10 @@ pandora.ui.mainPanel = function() { pandora.ui.navigationView(pandora.user.ui.listView) ); } else { + if (['clips', 'clip'].indexOf(pandora.user.ui.listView) > -1) { + Ox.print('HELLO????', pandora.user.ui.itemFind) + pandora.$ui.list.options({find: pandora.user.ui.itemFind}); + } pandora.$ui.list.reloadList(); } // FIXME: why is this being handled _here_? diff --git a/static/js/pandora/utils.js b/static/js/pandora/utils.js index f4cd3cb9..098cd2a0 100644 --- a/static/js/pandora/utils.js +++ b/static/js/pandora/utils.js @@ -602,6 +602,24 @@ pandora.getItemByIdOrTitle = function(str, callback) { }); } +pandora.getItemFind = function(find) { + var itemFind = ''; + Ox.forEach(find.conditions, function(condition) { + if ( + ( + condition.key == '*' || condition.key == 'annotations' + || Ox.getIndexById(pandora.site.layers, condition.key) > -1 + ) + && condition.value.length + && ['=', '=='].indexOf(condition.operator) > -1 + ) { + itemFind = condition.value; + return false; + } + }) + return itemFind; +}; + pandora.getListData = function(list) { var data = {}, folder; list = Ox.isUndefined(list) ? pandora.user.ui._list : list; @@ -854,13 +872,6 @@ pandora.isClipView = function(view, item) { ).indexOf(view) > -1; }; -pandora.isItemFind = function(find) { - return find.conditions.length == 1 - && (find.conditions[0].key == 'annotations' - ||Ox.getIndexById(pandora.site.layers, find.conditions[0].key) > -1) - && find.conditions[0].operator == '='; -}; - pandora.signin = function(data) { pandora.user = data.user; pandora.user.ui._list = pandora.getListState(pandora.user.ui.find);