From 57503c7eb52ea27aa2594c949f39e2a5c0ef9958 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sun, 2 Feb 2014 12:45:10 +0000 Subject: [PATCH] include clip conditions from smart lists in clip queries, fixes #2134 --- static/js/clipList.js | 44 +++++++++++++++++++++++++++++++------------ static/js/list.js | 18 ++++++++++-------- static/js/utils.js | 17 +++++++++++++++-- 3 files changed, 57 insertions(+), 22 deletions(-) diff --git a/static/js/clipList.js b/static/js/clipList.js index 23be749a..84e034a5 100644 --- a/static/js/clipList.js +++ b/static/js/clipList.js @@ -78,14 +78,19 @@ pandora.ui.clipList = function(videoRatio) { query = {conditions: [], operator: '&'}; // if the item query contains a layer condition, // then this condition is added to the clip query - itemsQuery.conditions.forEach(function(condition) { - if ( - condition.key == 'annotations' - || Ox.getIndexById(pandora.site.layers, condition.key) > -1 - ) { - query.conditions.push(condition); - } - }); + addConditions(query, itemsQuery.conditions); + // if a list is selected, check if its a smart list and + // add possible layer conditions from query + if (ui._list) { + pandora.api.getList({id: ui._list}, function(result) { + if (result.data.type == 'smart') { + addConditions(query, result.data.query.conditions); + } + findClips(); + }); + } else { + findClips(); + } } else { itemsQuery = { conditions:[{key: 'id', value: ui.item, operator: '=='}], @@ -99,11 +104,26 @@ pandora.ui.clipList = function(videoRatio) { }], operator: '&' }; + findClips(); + } + + function addConditions(query, conditions) { + conditions.forEach(function(condition) { + if ( + condition.key == 'annotations' + || Ox.getIndexById(pandora.site.layers, condition.key) > -1 + ) { + query.conditions.push(condition); + } + }); + } + + function findClips() { + pandora.api.findClips(Ox.extend(data, { + itemsQuery: itemsQuery, + query: query + }), callback); } - pandora.api.findClips(Ox.extend(data, { - itemsQuery: itemsQuery, - query: query - }), callback); }, keys: ['annotations', 'id', 'in', 'out'].concat( !ui.item ? ['videoRatio'] : [] diff --git a/static/js/list.js b/static/js/list.js index 6cd318aa..d807901f 100644 --- a/static/js/list.js +++ b/static/js/list.js @@ -230,14 +230,16 @@ pandora.ui.list = function() { }; }, items: function(data, callback) { - pandora.api.find(Ox.extend(data, { - query: ui.find, - clips: { - query: pandora.getClipsQuery(), - items: pandora.getClipsItems(), - keys: [] - } - }), callback); + pandora.getClipsQuery(function(clipsQuery) { + pandora.api.find(Ox.extend(data, { + query: ui.find, + clips: { + query: clipsQuery, + items: pandora.getClipsItems(), + keys: [] + } + }), callback); + }); return Ox.clone(data, true); }, keys: ['clips', 'director', 'duration', 'id', 'modified', 'posterRatio', 'title', 'videoRatio', 'year'], diff --git a/static/js/utils.js b/static/js/utils.js index 1d121ac5..8c77b121 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -847,7 +847,7 @@ pandora.getClipsItems = function(width) { return Math.floor((width - 8) / (128 + 8)) - 1; }; -pandora.getClipsQuery = function() { +pandora.getClipsQuery = function(callback) { // fixme: nice, but not needed function addClipsConditions(conditions) { conditions.forEach(function(condition) { @@ -867,7 +867,20 @@ pandora.getClipsQuery = function() { }; addClipsConditions(pandora.user.ui.find.conditions); clipsQuery.operator = clipsQuery.conditions.length ? '|' : '&'; - return clipsQuery; + if (callback) { + if (pandora.user.ui._list) { + pandora.api.getList({id: pandora.user.ui._list}, function(result) { + if (result.data.type == 'smart') { + addClipsConditions(result.data.query.conditions); + } + callback(clipsQuery) + }); + } else { + callback(clipsQuery) + } + } else { + return clipsQuery; + } }; pandora.getClipVideos = function(clip, resolution) {