include clip conditions from smart lists in clip queries, fixes #2134

This commit is contained in:
j 2014-02-02 12:45:10 +00:00 committed by rolux
parent 522af49a73
commit 57503c7eb5
3 changed files with 57 additions and 22 deletions

View file

@ -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'] : []

View file

@ -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'],

View file

@ -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) {