forked from 0x2620/pandora
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:
|
if key not in p:
|
||||||
p[key] = {}
|
p[key] = {}
|
||||||
p = p[key]
|
p = p[key]
|
||||||
if value == None:
|
if value == None and keys[0] in p:
|
||||||
del p[keys[0]]
|
del p[keys[0]]
|
||||||
else:
|
else:
|
||||||
p[keys[0]] = value
|
p[keys[0]] = value
|
||||||
|
|
|
@ -97,13 +97,24 @@ pandora.Query = (function() {
|
||||||
list: '',
|
list: '',
|
||||||
query: {conditions: [], operator: ''}
|
query: {conditions: [], operator: ''}
|
||||||
},
|
},
|
||||||
subconditions = str.match(/\[.*?\]/g) || [];
|
subconditions = [];
|
||||||
if (str.length) {
|
if (str.length) {
|
||||||
// replace subconditions with placeholder,
|
// replace subconditions with placeholder,
|
||||||
// so we can later split by main operator
|
// 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.forEach(function(subcondition, i) {
|
||||||
subconditions[i] = subcondition.substr(1, subcondition.length - 2);
|
str = str.replace(subcondition, i);
|
||||||
str = str.replace(subconditions[i], i);
|
|
||||||
});
|
});
|
||||||
if (str.indexOf(',') > -1) {
|
if (str.indexOf(',') > -1) {
|
||||||
ret.query.operator = '&';
|
ret.query.operator = '&';
|
||||||
|
@ -116,7 +127,7 @@ pandora.Query = (function() {
|
||||||
var kv, ret;
|
var kv, ret;
|
||||||
if (condition[0] == '[') {
|
if (condition[0] == '[') {
|
||||||
// re-insert subcondition
|
// 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 {
|
} else {
|
||||||
kv = ((condition.indexOf(':') > -1 ? '' : ':') + condition).split(':');
|
kv = ((condition.indexOf(':') > -1 ? '' : ':') + condition).split(':');
|
||||||
ret = Ox.extend({key: kv[0]}, parseValue(kv[1]));
|
ret = Ox.extend({key: kv[0]}, parseValue(kv[1]));
|
||||||
|
|
|
@ -3,17 +3,21 @@ pandora.UI = (function() {
|
||||||
return {
|
return {
|
||||||
set: function(/*{key: val} or key, val*/) {
|
set: function(/*{key: val} or key, val*/) {
|
||||||
var obj = Ox.makeObject(arguments);
|
var obj = Ox.makeObject(arguments);
|
||||||
$.each(obj, function(key, val) {
|
Ox.forEach(obj, function(val, key) {
|
||||||
Ox.print('key', key, 'val', val);
|
Ox.print('key', key, 'val', val);
|
||||||
var i = 0,
|
var i = 0,
|
||||||
keys = key.split('|'),
|
keys = key.split('|'),
|
||||||
old = pandora.user.ui;
|
ui = pandora.user.ui;
|
||||||
while (i < keys.length - 1) {
|
while (i < keys.length - 1) {
|
||||||
old = old[keys[i]];
|
ui = ui[keys[i]];
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if (old[keys[i]] !== val) {
|
if (ui[keys[i]] !== val) {
|
||||||
old[keys[i]] = val;
|
if (val === null) {
|
||||||
|
delete ui[keys[i]]
|
||||||
|
} else {
|
||||||
|
ui[keys[i]] = val;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
delete obj[key];
|
delete obj[key];
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,7 +108,7 @@ pandora.URL = (function() {
|
||||||
return prev + (parseFloat(curr) || 0) * Math.pow(60, i);
|
return prev + (parseFloat(curr) || 0) * Math.pow(60, i);
|
||||||
}, 0);
|
}, 0);
|
||||||
i == 0 && pandora.UI.set(['videoPosition', item].join('|'), point);
|
i == 0 && pandora.UI.set(['videoPosition', item].join('|'), point);
|
||||||
return Ox.formatDuration(point, 2).replace(/\.00$/, '');
|
return Ox.formatDuration(point, 3).replace(/\.000$/, '');
|
||||||
}).join('-');
|
}).join('-');
|
||||||
pandora.URL.replace(split.join('/'))
|
pandora.URL.replace(split.join('/'))
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,7 +175,7 @@ pandora.ui.folderList = function(id) {
|
||||||
click: function(event, data) {
|
click: function(event, data) {
|
||||||
var $list = pandora.$ui.folderList[id];
|
var $list = pandora.$ui.folderList[id];
|
||||||
if (data.key == 'type') {
|
if (data.key == 'type') {
|
||||||
pandora.$ui.filterDialog = ui.filterDialog().open();
|
pandora.$ui.filterDialog = pandora.ui.filterDialog().open();
|
||||||
} else if (data.key == 'status') {
|
} else if (data.key == 'status') {
|
||||||
pandora.api.editList({
|
pandora.api.editList({
|
||||||
id: data.id,
|
id: data.id,
|
||||||
|
|
|
@ -7,16 +7,39 @@ pandora.ui.item = function() {
|
||||||
}, pandora.user.level == 'admin' && pandora.user.ui.itemView == 'info' ? 0 : -1, function(result) {
|
}, pandora.user.level == 'admin' && pandora.user.ui.itemView == 'info' ? 0 : -1, function(result) {
|
||||||
if (result.status.code != 200) {
|
if (result.status.code != 200) {
|
||||||
// fixme: this is quite a hack
|
// 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({
|
pandora.api.find({
|
||||||
query: {
|
query: {
|
||||||
conditions: [{key: 'title', value: decodeURI(pandora.user.ui.item), operator: '='}],
|
conditions: [{key: 'title', value: title, operator: ''}],
|
||||||
operator: ''
|
operator: ''
|
||||||
},
|
},
|
||||||
keys: ['id']
|
sort: [{key: 'votes', operator: '-'}], // fixme: operator '' should work as well
|
||||||
|
range: [0, 100],
|
||||||
|
keys: ['id', 'title', 'votes']
|
||||||
}, function(result) {
|
}, function(result) {
|
||||||
if (result.data.items.length) {
|
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.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 {
|
} else {
|
||||||
pandora.$ui.contentPanel.replaceElement(1,
|
pandora.$ui.contentPanel.replaceElement(1,
|
||||||
Ox.Element()
|
Ox.Element()
|
||||||
|
|
|
@ -28,13 +28,6 @@ pandora.ui.preferencesDialog = function() {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
tabs: tabs
|
tabs: tabs
|
||||||
})
|
|
||||||
.bindEvent({
|
|
||||||
change: function(data) {
|
|
||||||
$dialog.options({
|
|
||||||
title: Ox.getObjectById(tabs, data.selected).title
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
var $dialog = Ox.Dialog({
|
var $dialog = Ox.Dialog({
|
||||||
buttons: [
|
buttons: [
|
||||||
|
@ -49,12 +42,12 @@ pandora.ui.preferencesDialog = function() {
|
||||||
],
|
],
|
||||||
//closeButton: true,
|
//closeButton: true,
|
||||||
content: $tabPanel,
|
content: $tabPanel,
|
||||||
height: Math.round((window.innerHeight - 24) * 0.75),
|
height: Math.round((window.innerHeight - 24) * 0.5),
|
||||||
//maximizeButton: true,
|
//maximizeButton: true,
|
||||||
minHeight: 256,
|
minHeight: 256,
|
||||||
minWidth: 640,
|
minWidth: 640,
|
||||||
title: 'Preferences',
|
title: 'Preferences',
|
||||||
width: Math.round(window.innerWidth * 0.75),
|
width: Math.round(window.innerWidth * 0.5),
|
||||||
});
|
});
|
||||||
|
|
||||||
return $dialog;
|
return $dialog;
|
||||||
|
|
Loading…
Reference in a new issue