From bb728c9369fc32365504ed850f5d4b8e42167187 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sun, 9 Oct 2011 12:02:16 +0000 Subject: [PATCH 1/5] sort clips --- pandora/clip/models.py | 3 ++- pandora/clip/views.py | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pandora/clip/models.py b/pandora/clip/models.py index 656170fda..756090ac4 100644 --- a/pandora/clip/models.py +++ b/pandora/clip/models.py @@ -50,13 +50,14 @@ class Clip(models.Model): def json(self, keys=None): j = {} - clip_keys = ('id', 'in', 'out', 'created', 'modified', + clip_keys = ('id', 'in', 'out', 'position', 'created', 'modified', 'hue', 'saturation', 'lightness', 'volume') for key in clip_keys: j[key] = getattr(self, { 'id': 'public_id', 'in': 'start', 'out': 'end', + 'position': 'start', }.get(key, key)) if keys: for key in j.keys(): diff --git a/pandora/clip/views.py b/pandora/clip/views.py index cd5aefae9..3147ae192 100644 --- a/pandora/clip/views.py +++ b/pandora/clip/views.py @@ -31,9 +31,13 @@ def order_query(qs, sort): operator = e['operator'] if operator != '-': operator = '' + clip_keys = ('start', 'end', 'hue', 'saturation', 'lightness', 'volume' + 'annotations__value') key = { 'in': 'start', 'out': 'end', + 'position': 'start', + 'text': 'annotations__value', }.get(e['key'], e['key']) if key.startswith('clip:'): key = e['key'][len('clip:'):] @@ -41,7 +45,7 @@ def order_query(qs, sort): 'text': 'annotations__value', 'position': 'start', }.get(key, key) - elif key not in ('start', 'end', 'annotations__value'): + elif key not in clip_keys: #key mgith need to be changed, see order_sort in item/views.py key = "item__sort__%s" % key order = '%s%s' % (operator, key) From 7fd64740aac6b4e0614887505ac42f5b6538c953 Mon Sep 17 00:00:00 2001 From: rolux Date: Sun, 9 Oct 2011 12:46:35 +0000 Subject: [PATCH 2/5] new clip sort key scheme; fix for info line(s) in icon lists --- pandora/0xdb.json | 19 ++++++++++--------- pandora/clip/views.py | 3 ++- static/js/pandora.js | 4 ++-- static/js/pandora/URL.js | 2 +- static/js/pandora/ui/clipList.js | 21 ++++++++++++++------- static/js/pandora/ui/list.js | 23 ++++++++++++++++------- static/js/pandora/ui/sortSelect.js | 20 ++++++++++++-------- static/js/pandora/utils.js | 18 +++++++----------- 8 files changed, 64 insertions(+), 46 deletions(-) diff --git a/pandora/0xdb.json b/pandora/0xdb.json index da87e1d94..cc09cc30d 100644 --- a/pandora/0xdb.json +++ b/pandora/0xdb.json @@ -10,13 +10,13 @@ "canSeeExtraItemViews": {"friend": true, "staff": true, "admin": true} }, "clipKeys": [ - {"id": "clip:text", "title": "Text", "type": "string"}, - {"id": "clip:position", "title": "Position", "type": "float"}, - {"id": "clip:duration", "title": "Duration", "type": "float"}, - {"id": "clip:hue", "title": "Hue", "type": "hue"}, - {"id": "clip:saturation", "title": "Saturation", "type": "float"}, - {"id": "clip:lightness", "title": "Lightness", "type": "float"}, - {"id": "clip:volume", "title": "Volume", "type": "float"} + {"id": "text", "title": "Text", "type": "string"}, + {"id": "position", "title": "Position", "type": "float", "sortOperator": "-"}, + {"id": "duration", "title": "Duration", "type": "float"}, + {"id": "hue", "title": "Hue", "type": "float", "sortOperator": "-"}, + {"id": "saturation", "title": "Saturation", "type": "float"}, + {"id": "lightness", "title": "Lightness", "type": "float"}, + {"id": "volume", "title": "Volume", "type": "float"} ], "groups": [ {"id": "director", "title": "Director", "type": "string"}, @@ -298,9 +298,10 @@ { "id": "hue", "title": "Hue", - "type": "hue", + "type": "float", "columnWidth": 90, - "format": {"type": "color", "args": ["hue"]} + "format": {"type": "color", "args": ["hue"]}, + "sortOperator": "-" }, { "id": "saturation", diff --git a/pandora/clip/views.py b/pandora/clip/views.py index 3147ae192..e63361722 100644 --- a/pandora/clip/views.py +++ b/pandora/clip/views.py @@ -31,9 +31,10 @@ def order_query(qs, sort): operator = e['operator'] if operator != '-': operator = '' - clip_keys = ('start', 'end', 'hue', 'saturation', 'lightness', 'volume' + clip_keys = ('public_id', 'start', 'end', 'hue', 'saturation', 'lightness', 'volume' 'annotations__value') key = { + 'id': 'public_id', 'in': 'start', 'out': 'end', 'position': 'start', diff --git a/static/js/pandora.js b/static/js/pandora.js index cc7130aa2..90d7f115f 100644 --- a/static/js/pandora.js +++ b/static/js/pandora.js @@ -73,7 +73,7 @@ Ox.load({ Ox.extend(pandora.site, { clipKeys: Ox.map(data.site.clipKeys, function(key) { return Ox.extend(key, { - operator: pandora._getSortOperator(key.type) + operator: pandora.getSortOperator(key.id) }); }), findKeys: Ox.map(data.site.itemKeys, function(key) { @@ -100,7 +100,7 @@ Ox.load({ }, sortKeys: Ox.map(pandora.site.itemKeys, function(key) { return key.columnWidth ? Ox.extend(key, { - operator: pandora._getSortOperator(key.type) + operator: pandora.getSortOperator(key.id) }) : null; }) }); diff --git a/static/js/pandora/URL.js b/static/js/pandora/URL.js index a1e5b6afb..bb3be4e19 100644 --- a/static/js/pandora/URL.js +++ b/static/js/pandora/URL.js @@ -414,7 +414,7 @@ pandora.URL = (function() { } else { action = 'push'; } - self.URL[action](getState(), pandora.getPageTitle(), getState(keys)); + self.URL[action](getState(), pandora.getPageTitle(), getState(/*keys*/)); } }; diff --git a/static/js/pandora/ui/clipList.js b/static/js/pandora/ui/clipList.js index cd8673089..7eb33ee74 100644 --- a/static/js/pandora/ui/clipList.js +++ b/static/js/pandora/ui/clipList.js @@ -10,7 +10,8 @@ pandora.ui.clipList = function(videoRatio) { fixedRatio: fixedRatio, item: function(data, sort, size) { size = size || 128; // fixme: is this needed? - var ratio, width, height, url, sortKey, info; + var ratio, width, height, + format, info, sortKey, url; if (!ui.item) { ratio = data.videoRatio; width = ratio > fixedRatio ? size : Math.round(size * ratio / fixedRatio); @@ -19,13 +20,19 @@ pandora.ui.clipList = function(videoRatio) { width = fixedRatio > 1 ? size : Math.round(size * fixedRatio); height = fixedRatio > 1 ? Math.round(size / fixedRatio) : size; } - url = '/' + data.id.split('/')[0] + '/' + height + 'p' + data['in'] + '.jpg'; - sortKey = sort[0].key.split(':').pop(); - info = ['hue', 'saturation', 'lightness'].indexOf(sortKey) > -1 - ? Ox.formatColor(data[sortKey], sortKey) - : Ox.formatDuration(data['in'], 'short') + ' - ' - + Ox.formatDuration(data['out'], 'short'), title = data.subtitles[0]; //fixme: could be other layer + url = '/' + data.id.split('/')[0] + '/' + height + 'p' + data['in'] + '.jpg'; + sortKey = sort[0].key; + if (['text', 'position', 'duration'].indexOf(sortKey) > -1) { + info = Ox.formatDuration(data['in'], 'short') + ' - ' + + Ox.formatDuration(data.out, 'short'); + } else { + format = pandora.getSortKeyData(sortKey).format; + info = format + ? Ox['format' + Ox.toTitleCase(format.type)] + .apply(this, Ox.merge([data[sortKey]], format.args || [])) + : data[sortKey]; + } return { height: height, id: data.id, diff --git a/static/js/pandora/ui/list.js b/static/js/pandora/ui/list.js index 699c81cc3..0706d5bb2 100644 --- a/static/js/pandora/ui/list.js +++ b/static/js/pandora/ui/list.js @@ -145,19 +145,28 @@ pandora.ui.list = function() { var ui = pandora.user.ui, ratio = ui.icons == 'posters' ? (ui.showSitePoster ? 5/8 : data.posterRatio) : 1, - info = ['hue', 'saturation', 'lightness'].indexOf(sort[0].key) > -1 - ? Ox.formatColor(data[sort[0].key], sort[0].key) - : data[['title', 'director'].indexOf(sort[0].key) > -1 ? 'year' : sort[0].key]; + url = '/' + data.id + '/' + ( + ui.icons == 'posters' + ? (ui.showSitePoster ? 'siteposter' : 'poster') : 'icon' + ) + size + '.jpg', + format, info, sortKey; + if (['title', 'director'].indexOf(sort[0].key) > -1) { + info = data['year'] + } else { + sortKey = sort[0].key, + format = pandora.getSortKeyData(sortKey).format, + info = format + ? Ox['format' + Ox.toTitleCase(format.type)] + .apply(this, Ox.merge([data[sortKey]], format.args || [])) + : data[sortKey]; + } size = size || 128; return { height: Math.round(ratio <= 1 ? size : size / ratio), id: data.id, info: info, title: data.title + (data.director.length ? ' (' + data.director.join(', ') + ')' : ''), - url: '/' + data.id + '/' + ( - ui.icons == 'posters' - ? (ui.showSitePoster ? 'siteposter' : 'poster') : 'icon' - ) + size + '.jpg', + url: url, width: Math.round(ratio >= 1 ? size : size * ratio) }; }, diff --git a/static/js/pandora/ui/sortSelect.js b/static/js/pandora/ui/sortSelect.js index ac7f7060d..b73010dbe 100644 --- a/static/js/pandora/ui/sortSelect.js +++ b/static/js/pandora/ui/sortSelect.js @@ -1,23 +1,27 @@ // vim: et:ts=4:sw=4:sts=4:ft=javascript pandora.ui.sortSelect = function() { - var items = [], + var isClipView = pandora.isClipView(), + items = [], sortKey = !pandora.user.ui.item ? 'listSort' : 'itemSort', that; - if (pandora.isClipView()) { + if (isClipView) { items = pandora.site.clipKeys.map(function(key) { return Ox.extend(Ox.clone(key), { checked: key.id == pandora.user.ui[sortKey][0].key, title: 'Sort by ' + (!pandora.user.ui.item ? 'Clip ' : '') + key.title }); }); - //!pandora.user.ui.item && items.push({}); + // fixme: a separator would be good + // !pandora.user.ui.item && items.push({}); } if (!pandora.user.ui.item) { - items = Ox.merge(items, pandora.site.sortKeys.map(function(key) { - return Ox.extend(Ox.clone(key), { - checked: key.id == pandora.user.ui[sortKey][0].key, - title: 'Sort by ' + key.title - }); + items = Ox.merge(items, Ox.map(pandora.site.sortKeys, function(key) { + return Ox.getPositionById(items, key.id) == -1 + ? Ox.extend(Ox.clone(key), { + checked: key.id == pandora.user.ui[sortKey][0].key, + title: 'Sort by ' + key.title + }) + : null; })); } that = Ox.Select({ diff --git a/static/js/pandora/utils.js b/static/js/pandora/utils.js index bf186cc68..4d93984d4 100644 --- a/static/js/pandora/utils.js +++ b/static/js/pandora/utils.js @@ -592,19 +592,15 @@ pandora.getMetadataByIdOrName = function(item, view, str, callback) { }; }()); -pandora._getSortOperator = function(type) { - return ['hue', 'string', 'text'].indexOf( - Ox.isArray(type) ? type[0] : type - ) > -1 ? '+' : '-'; +pandora.getSortKeyData = function(key) { + return Ox.getObjectById(pandora.site.itemKeys, key) + || Ox.getObjectById(pandora.site.clipKeys, key); } -pandora.getSortOperator = function(key) { // fixme: remove? - var type = Ox.getObjectById( - /^clip:/.test(key) ? pandora.site.clipKeys : pandora.site.itemKeys, - key - ).type; - return ['hue', 'string', 'text'].indexOf( - Ox.isArray(type) ? type[0] : type +pandora.getSortOperator = function(key) { + var data = pandora.getSortKeyData(key); + return data.sortOperator || ['string', 'text'].indexOf( + Ox.isArray(data.type) ? data.type[0] : data.type ) > -1 ? '+' : '-'; }; From d066835061144046f00b8269ac2a17ef377ebdf5 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sun, 9 Oct 2011 13:01:16 +0000 Subject: [PATCH 3/5] , --- pandora/clip/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora/clip/views.py b/pandora/clip/views.py index e63361722..889efc8d9 100644 --- a/pandora/clip/views.py +++ b/pandora/clip/views.py @@ -31,7 +31,7 @@ def order_query(qs, sort): operator = e['operator'] if operator != '-': operator = '' - clip_keys = ('public_id', 'start', 'end', 'hue', 'saturation', 'lightness', 'volume' + clip_keys = ('public_id', 'start', 'end', 'hue', 'saturation', 'lightness', 'volume', 'annotations__value') key = { 'id': 'public_id', From 55b517b54bf9fd5bb00b9658c7166c2140a69630 Mon Sep 17 00:00:00 2001 From: rolux Date: Sun, 9 Oct 2011 13:13:11 +0000 Subject: [PATCH 4/5] fix bug when switching to a view that doesn't have the current sort key; update view movies menu when switching view --- static/js/pandora/ui/list.js | 7 ++++--- static/js/pandora/ui/menu.js | 10 +++++++++- static/js/pandora/ui/viewSelect.js | 14 ++++++++++++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/static/js/pandora/ui/list.js b/static/js/pandora/ui/list.js index 0706d5bb2..2328c07f7 100644 --- a/static/js/pandora/ui/list.js +++ b/static/js/pandora/ui/list.js @@ -149,9 +149,10 @@ pandora.ui.list = function() { ui.icons == 'posters' ? (ui.showSitePoster ? 'siteposter' : 'poster') : 'icon' ) + size + '.jpg', - format, info, sortKey; - if (['title', 'director'].indexOf(sort[0].key) > -1) { - info = data['year'] + sortKey = sort[0].key, + format, info; + if (['title', 'director'].indexOf(sortKey) > -1) { + info = data['year']; } else { sortKey = sort[0].key, format = pandora.getSortKeyData(sortKey).format, diff --git a/static/js/pandora/ui/menu.js b/static/js/pandora/ui/menu.js index a0958682e..9b340d553 100644 --- a/static/js/pandora/ui/menu.js +++ b/static/js/pandora/ui/menu.js @@ -210,7 +210,14 @@ pandora.ui.mainMenu = function() { } else if (data.id == 'viewicons') { pandora.UI.set({icons: value}); } else if (data.id == 'viewmovies') { - pandora.UI.set('listView', value); + var set = {listView: value}; + if ( + !pandora.isClipView(key, pandora.user.ui.item) + && ['title', 'position'].indexOf(pandora.user.ui.listSort[0].key) > -1 + ) { + set.listSort = pandora.site.user.ui.listSort; + } + pandora.UI.set(set); } else if (['personallists', 'favoritelists', 'featuredlists'].indexOf(value) > -1) { pandora.UI.set({list: value.substr(8)}); } @@ -277,6 +284,7 @@ pandora.ui.mainMenu = function() { that[data.value.length ? 'enableItem' : 'disableItem']('newlistfromselection'); }, pandora_listview: function(data) { + pandora.$ui.mainMenu.checkItem('viewMenu_movies_' + data.value); if (pandora.isClipView() != pandora.isClipView(data.previousValue)) { that.replaceMenu('sortMenu', getSortMenu()); } diff --git a/static/js/pandora/ui/viewSelect.js b/static/js/pandora/ui/viewSelect.js index 7e46b440a..6deca0cac 100644 --- a/static/js/pandora/ui/viewSelect.js +++ b/static/js/pandora/ui/viewSelect.js @@ -1,7 +1,8 @@ // vim: et:ts=4:sw=4:sts=4:ft=javascript pandora.ui.viewSelect = function() { - var viewKey = !pandora.user.ui.item ? 'listView' : 'itemView', + var sortKey = !pandora.user.ui.item ? 'listSort' : 'itemSort', + viewKey = !pandora.user.ui.item ? 'listView' : 'itemView', that = Ox.Select({ id: 'viewSelect', items: Ox.map(pandora.site[viewKey + 's'], function(view) { @@ -22,7 +23,16 @@ pandora.ui.viewSelect = function() { }) .bindEvent({ change: function(data) { - pandora.UI.set(viewKey, data.selected[0].id); + var key = data.selected[0].id, + set = {}; + set[viewKey] = key + if ( + !pandora.isClipView(key, pandora.user.ui.item) + && ['title', 'position'].indexOf(pandora.user.ui[sortKey][0].key) > -1 + ) { + set[sortKey] = pandora.site.user.ui.listSort; + } + pandora.UI.set(set); }, pandora_listview: function(data) { that.selectItem(data.value); From 460a4217ea2a6af4308d493f9881d86e45d01eff Mon Sep 17 00:00:00 2001 From: rolux Date: Sun, 9 Oct 2011 13:31:46 +0000 Subject: [PATCH 5/5] fix default item sort in config json --- pandora/0xdb.json | 2 +- static/js/pandora/URL.js | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pandora/0xdb.json b/pandora/0xdb.json index cc09cc30d..400cf51f6 100644 --- a/pandora/0xdb.json +++ b/pandora/0xdb.json @@ -568,7 +568,7 @@ "icons": "posters", "infoIconSize": 256, "item": "", - "itemSort": [{"key": "clip:position", "operator": "+"}], + "itemSort": [{"key": "position", "operator": "+"}], "itemView": "info", "listColumns": ["title", "director", "country", "year", "language", "runtime", "genre"], "listColumnWidth": {}, diff --git a/static/js/pandora/URL.js b/static/js/pandora/URL.js index bb3be4e19..49a0acb77 100644 --- a/static/js/pandora/URL.js +++ b/static/js/pandora/URL.js @@ -79,10 +79,12 @@ pandora.URL = (function() { state.view = pandora.user.ui.itemView; state.sort = pandora.user.ui.itemSort; } - if (pandora.user.ui.mapSelection) { - state.span = '@' + pandora.user.ui.mapSelection; - } else if (pandora.user.ui.mapFind) { - state.span = '@' + pandora.user.ui.mapFind; + if (state.view == 'map') { + if (pandora.user.ui.mapSelection) { + state.span = '@' + pandora.user.ui.mapSelection; + } else if (pandora.user.ui.mapFind) { + state.span = '@' + pandora.user.ui.mapFind; + } } /* : pandora.isClipView(pandora.user.ui.itemView)