support deeper nesting of brackets in url find query
This commit is contained in:
parent
e7a0195b9d
commit
a373d423eb
7 changed files with 56 additions and 25 deletions
|
@ -459,7 +459,7 @@ def setUI(request):
|
|||
if key not in p:
|
||||
p[key] = {}
|
||||
p = p[key]
|
||||
if value == None:
|
||||
if value == None and keys[0] in p:
|
||||
del p[keys[0]]
|
||||
else:
|
||||
p[keys[0]] = value
|
||||
|
|
|
@ -97,13 +97,24 @@ pandora.Query = (function() {
|
|||
list: '',
|
||||
query: {conditions: [], operator: ''}
|
||||
},
|
||||
subconditions = str.match(/\[.*?\]/g) || [];
|
||||
subconditions = [];
|
||||
if (str.length) {
|
||||
// replace subconditions with placeholder,
|
||||
// so we can later split by main operator
|
||||
var counter = 0;
|
||||
Ox.forEach(str, function(c, i) {
|
||||
if (c == ']') {
|
||||
counter--;
|
||||
}
|
||||
if (counter >= 1) {
|
||||
subconditions[subconditions.length - 1] += c;
|
||||
}
|
||||
if (c == '[') {
|
||||
(++counter == 1) && subconditions.push('');
|
||||
}
|
||||
});
|
||||
subconditions.forEach(function(subcondition, i) {
|
||||
subconditions[i] = subcondition.substr(1, subcondition.length - 2);
|
||||
str = str.replace(subconditions[i], i);
|
||||
str = str.replace(subcondition, i);
|
||||
});
|
||||
if (str.indexOf(',') > -1) {
|
||||
ret.query.operator = '&';
|
||||
|
@ -116,7 +127,7 @@ pandora.Query = (function() {
|
|||
var kv, ret;
|
||||
if (condition[0] == '[') {
|
||||
// re-insert subcondition
|
||||
ret = parseFind(subconditions[parseInt(condition.substr(1, condition.length - 2))]).query;
|
||||
ret = parseFind(subconditions[parseInt(Ox.sub(condition, 1, -1))]).query;
|
||||
} else {
|
||||
kv = ((condition.indexOf(':') > -1 ? '' : ':') + condition).split(':');
|
||||
ret = Ox.extend({key: kv[0]}, parseValue(kv[1]));
|
||||
|
|
|
@ -3,17 +3,21 @@ pandora.UI = (function() {
|
|||
return {
|
||||
set: function(/*{key: val} or key, val*/) {
|
||||
var obj = Ox.makeObject(arguments);
|
||||
$.each(obj, function(key, val) {
|
||||
Ox.forEach(obj, function(val, key) {
|
||||
Ox.print('key', key, 'val', val);
|
||||
var i = 0,
|
||||
keys = key.split('|'),
|
||||
old = pandora.user.ui;
|
||||
ui = pandora.user.ui;
|
||||
while (i < keys.length - 1) {
|
||||
old = old[keys[i]];
|
||||
ui = ui[keys[i]];
|
||||
i++;
|
||||
}
|
||||
if (old[keys[i]] !== val) {
|
||||
old[keys[i]] = val;
|
||||
if (ui[keys[i]] !== val) {
|
||||
if (val === null) {
|
||||
delete ui[keys[i]]
|
||||
} else {
|
||||
ui[keys[i]] = val;
|
||||
}
|
||||
} else {
|
||||
delete obj[key];
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@ pandora.URL = (function() {
|
|||
return prev + (parseFloat(curr) || 0) * Math.pow(60, i);
|
||||
}, 0);
|
||||
i == 0 && pandora.UI.set(['videoPosition', item].join('|'), point);
|
||||
return Ox.formatDuration(point, 2).replace(/\.00$/, '');
|
||||
return Ox.formatDuration(point, 3).replace(/\.000$/, '');
|
||||
}).join('-');
|
||||
pandora.URL.replace(split.join('/'))
|
||||
}
|
||||
|
|
|
@ -175,7 +175,7 @@ pandora.ui.folderList = function(id) {
|
|||
click: function(event, data) {
|
||||
var $list = pandora.$ui.folderList[id];
|
||||
if (data.key == 'type') {
|
||||
pandora.$ui.filterDialog = ui.filterDialog().open();
|
||||
pandora.$ui.filterDialog = pandora.ui.filterDialog().open();
|
||||
} else if (data.key == 'status') {
|
||||
pandora.api.editList({
|
||||
id: data.id,
|
||||
|
|
|
@ -7,16 +7,39 @@ pandora.ui.item = function() {
|
|||
}, pandora.user.level == 'admin' && pandora.user.ui.itemView == 'info' ? 0 : -1, function(result) {
|
||||
if (result.status.code != 200) {
|
||||
// fixme: this is quite a hack
|
||||
var title = decodeURI(pandora.user.ui.item).toLowerCase(),
|
||||
videoPosition;
|
||||
if (pandora.user.ui.item in pandora.user.ui.videoPosition) {
|
||||
videoPosition = pandora.user.ui.videoPosition[pandora.user.ui.item];
|
||||
pandora.UI.set(['videoPosition', pandora.user.ui.item].join('|'), null);
|
||||
}
|
||||
pandora.api.find({
|
||||
query: {
|
||||
conditions: [{key: 'title', value: decodeURI(pandora.user.ui.item), operator: '='}],
|
||||
conditions: [{key: 'title', value: title, operator: ''}],
|
||||
operator: ''
|
||||
},
|
||||
keys: ['id']
|
||||
sort: [{key: 'votes', operator: '-'}], // fixme: operator '' should work as well
|
||||
range: [0, 100],
|
||||
keys: ['id', 'title', 'votes']
|
||||
}, function(result) {
|
||||
if (result.data.items.length) {
|
||||
Ox.print(result.data.items)
|
||||
var re = {
|
||||
exact: new RegExp('^' + title + '$', 'i'),
|
||||
word: new RegExp('\\b' + title + '\\b', 'i')
|
||||
},
|
||||
id = result.data.items.sort(function(a, b) {
|
||||
return (parseInt(b.votes) || 0)
|
||||
+ re.word.test(b.title) * 1000000
|
||||
+ re.exact.test(b.title) * 2000000
|
||||
- (parseInt(a.votes) || 0)
|
||||
- re.word.test(a.title) * 1000000
|
||||
- re.exact.test(a.title) * 2000000;
|
||||
})[0].id;
|
||||
pandora.user.ui.item = '';
|
||||
pandora.URL.set(result.data.items[0].id);
|
||||
!Ox.isUndefined(videoPosition)
|
||||
&& pandora.UI.set(['videoPosition', id].join('|'), videoPosition);
|
||||
pandora.URL.set(id);
|
||||
} else {
|
||||
pandora.$ui.contentPanel.replaceElement(1,
|
||||
Ox.Element()
|
||||
|
@ -404,7 +427,7 @@ pandora.ui.item = function() {
|
|||
);
|
||||
}
|
||||
if (result.data) {
|
||||
var director = result.data.director?' ('+result.data.director.join(', ')+')':'';
|
||||
var director = result.data.director ? ' ('+result.data.director.join(', ') + ')' : '';
|
||||
pandora.$ui.total.html(result.data.title + director);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -28,13 +28,6 @@ pandora.ui.preferencesDialog = function() {
|
|||
});
|
||||
},
|
||||
tabs: tabs
|
||||
})
|
||||
.bindEvent({
|
||||
change: function(data) {
|
||||
$dialog.options({
|
||||
title: Ox.getObjectById(tabs, data.selected).title
|
||||
});
|
||||
}
|
||||
});
|
||||
var $dialog = Ox.Dialog({
|
||||
buttons: [
|
||||
|
@ -49,12 +42,12 @@ pandora.ui.preferencesDialog = function() {
|
|||
],
|
||||
//closeButton: true,
|
||||
content: $tabPanel,
|
||||
height: Math.round((window.innerHeight - 24) * 0.75),
|
||||
height: Math.round((window.innerHeight - 24) * 0.5),
|
||||
//maximizeButton: true,
|
||||
minHeight: 256,
|
||||
minWidth: 640,
|
||||
title: 'Preferences',
|
||||
width: Math.round(window.innerWidth * 0.75),
|
||||
width: Math.round(window.innerWidth * 0.5),
|
||||
});
|
||||
|
||||
return $dialog;
|
||||
|
|
Loading…
Reference in a new issue