some query fixes
This commit is contained in:
parent
09e9b5af0a
commit
95ac3ee685
4 changed files with 75 additions and 88 deletions
|
@ -89,7 +89,6 @@ pandora.Query = (function() {
|
||||||
function parseFind(str) {
|
function parseFind(str) {
|
||||||
// takes a find query string, returns useful information about the application's state
|
// takes a find query string, returns useful information about the application's state
|
||||||
// (selected lists, find input key/value (and index of the corresponding condition), query object)
|
// (selected lists, find input key/value (and index of the corresponding condition), query object)
|
||||||
str = str || '';
|
|
||||||
var conditions,
|
var conditions,
|
||||||
index, indices,
|
index, indices,
|
||||||
ret = {
|
ret = {
|
||||||
|
@ -98,61 +97,65 @@ pandora.Query = (function() {
|
||||||
query: {conditions: [], operator: ''}
|
query: {conditions: [], operator: ''}
|
||||||
},
|
},
|
||||||
subconditions = str.match(/\[.*?\]/g) || [];
|
subconditions = str.match(/\[.*?\]/g) || [];
|
||||||
// replace subconditions with placeholder,
|
if (str.length) {
|
||||||
// so we can later split by main operator
|
// replace subconditions with placeholder,
|
||||||
subconditions.forEach(function(subcondition, i) {
|
// so we can later split by main operator
|
||||||
subconditions[i] = subcondition.substr(1, subcondition.length - 2);
|
subconditions.forEach(function(subcondition, i) {
|
||||||
str = str.replace(subconditions[i], i);
|
subconditions[i] = subcondition.substr(1, subcondition.length - 2);
|
||||||
});
|
str = str.replace(subconditions[i], i);
|
||||||
if (str.indexOf(',') > -1) {
|
});
|
||||||
ret.query.operator = '&';
|
if (str.indexOf(',') > -1) {
|
||||||
} else if (str.indexOf('|') > -1) {
|
ret.query.operator = '&';
|
||||||
ret.query.operator = '|';
|
} else if (str.indexOf('|') > -1) {
|
||||||
}
|
ret.query.operator = '|';
|
||||||
ret.query.conditions = (
|
|
||||||
ret.query.operator == '' ? [str] : str.split(ret.query.operator == '&' ? ',' : '|')
|
|
||||||
).map(function(condition, i) {
|
|
||||||
var kv, ret;
|
|
||||||
if (condition[0] == '[') {
|
|
||||||
// re-insert subcondition
|
|
||||||
ret = parseFind(subconditions[parseInt(condition.substr(1, condition.length - 2))]).query;
|
|
||||||
} else {
|
|
||||||
kv = ((condition.indexOf(':') > -1 ? '' : ':') + condition).split(':');
|
|
||||||
ret = Ox.extend({key: kv[0]}, parseValue(kv[1]));
|
|
||||||
}
|
}
|
||||||
return ret;
|
ret.query.conditions = (
|
||||||
});
|
ret.query.operator == '' ? [str] : str.split(ret.query.operator == '&' ? ',' : '|')
|
||||||
// a list is selected if exactly one condition in an & query
|
).map(function(condition, i) {
|
||||||
// has "list" as key and "" as operator
|
var kv, ret;
|
||||||
if (ret.query.operator != '|') {
|
if (condition[0] == '[') {
|
||||||
index = oneCondition(ret.query.conditions, 'list', '');
|
// re-insert subcondition
|
||||||
if (index > -1 && !ret.query.conditions[index].conditions) {
|
ret = parseFind(subconditions[parseInt(condition.substr(1, condition.length - 2))]).query;
|
||||||
ret.list = ret.query.conditions[index].value;
|
} else {
|
||||||
}
|
kv = ((condition.indexOf(':') > -1 ? '' : ':') + condition).split(':');
|
||||||
}
|
ret = Ox.extend({key: kv[0]}, parseValue(kv[1]));
|
||||||
// find is populated if exactly one condition in an & query
|
|
||||||
// has a findKey as key and "" as operator
|
|
||||||
// or if all conditions in an | query have the same group id as key
|
|
||||||
if (ret.query.operator == '|') {
|
|
||||||
ret.find = {index: -1, key: 'advanced', value: ''};
|
|
||||||
Ox.map(pandora.user.ui.groups, function(key) {
|
|
||||||
if (everyCondition(ret.query.conditions, key, '=')) {
|
|
||||||
ret.find.key = '';
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
});
|
});
|
||||||
} else {
|
// a list is selected if exactly one condition in an & query
|
||||||
indices = Ox.map(pandora.site.findKeys, function(findKey) {
|
// has "list" as key and "" as operator
|
||||||
var key = findKey.id == 'all' ? '' : findKey.id,
|
if (ret.query.operator != '|') {
|
||||||
index = oneCondition(ret.query.conditions, key, '');
|
index = oneCondition(ret.query.conditions, 'list', '');
|
||||||
return index > -1 ? index : null;
|
if (index > -1 && !ret.query.conditions[index].conditions) {
|
||||||
});
|
ret.list = ret.query.conditions[index].value;
|
||||||
if (indices.length) {
|
}
|
||||||
ret.find = indices.length == 1 && !ret.query.conditions[indices[0]].conditions ? {
|
}
|
||||||
index: indices[0],
|
// find is populated if exactly one condition in an & query
|
||||||
key: ret.query.conditions[indices[0]].key,
|
// has a findKey as key and "" as operator
|
||||||
value: ret.query.conditions[indices[0]].value
|
// or if all conditions in an | query have the same group id as key
|
||||||
} : {index: -1, key: 'advanced', value: ''}
|
if (ret.query.operator == '|') {
|
||||||
|
ret.find = {index: -1, key: 'advanced', value: ''};
|
||||||
|
Ox.map(pandora.user.ui.groups, function(key) {
|
||||||
|
if (everyCondition(ret.query.conditions, key, '=')) {
|
||||||
|
ret.find.key = '';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
indices = Ox.map(pandora.site.findKeys, function(findKey) {
|
||||||
|
var key = findKey.id == 'all' ? '' : findKey.id,
|
||||||
|
index = oneCondition(ret.query.conditions, key, '');
|
||||||
|
return index > -1 ? index : null;
|
||||||
|
});
|
||||||
|
Ox.print('INDICES', indices, indices.length == 1 && !ret.query.conditions[indices[0]].conditions)
|
||||||
|
if (indices.length) {
|
||||||
|
ret.find = indices.length == 1 && !ret.query.conditions[indices[0]].conditions ? {
|
||||||
|
index: indices[0],
|
||||||
|
key: ret.query.conditions[indices[0]].key,
|
||||||
|
value: ret.query.conditions[indices[0]].value
|
||||||
|
} : {index: -1, key: 'advanced', value: ''}
|
||||||
|
}
|
||||||
|
Ox.print('FIND', ret.find)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -200,7 +203,7 @@ pandora.Query = (function() {
|
||||||
query = Ox.unserialize(str.substr(1)),
|
query = Ox.unserialize(str.substr(1)),
|
||||||
sort = []
|
sort = []
|
||||||
if ('find' in query) {
|
if ('find' in query) {
|
||||||
data = parseFind(query.find);
|
data = parseFind(query.find || '');
|
||||||
Ox.print(Ox.repeat('-', 120));
|
Ox.print(Ox.repeat('-', 120));
|
||||||
Ox.print('STATE', data);
|
Ox.print('STATE', data);
|
||||||
Ox.print(Ox.repeat('-', 120));
|
Ox.print(Ox.repeat('-', 120));
|
||||||
|
|
|
@ -58,8 +58,8 @@ pandora.ui.browser = function() {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
items: function(data, callback) {
|
items: function(data, callback) {
|
||||||
pandora.api.find($.extend(data, {
|
pandora.api.find(Ox.extend(data, {
|
||||||
query: pandora.Query.toObject()
|
query: pandora.user.ui.query
|
||||||
}), callback);
|
}), callback);
|
||||||
},
|
},
|
||||||
keys: ['director', 'id', 'posterRatio', 'title', 'year'],
|
keys: ['director', 'id', 'posterRatio', 'title', 'year'],
|
||||||
|
|
|
@ -46,10 +46,12 @@ pandora.ui.findElement = function() {
|
||||||
var key = data.selected[0].id;
|
var key = data.selected[0].id;
|
||||||
if (key == 'advanced') {
|
if (key == 'advanced') {
|
||||||
pandora.$ui.filterDialog = pandora.ui.filterDialog().open();
|
pandora.$ui.filterDialog = pandora.ui.filterDialog().open();
|
||||||
|
pandora.$ui.findInput.options({placeholder: 'Edit...'})
|
||||||
} else {
|
} else {
|
||||||
pandora.$ui.mainMenu.checkItem('findMenu_find_' + key);
|
pandora.$ui.mainMenu.checkItem('findMenu_find_' + key);
|
||||||
pandora.$ui.findInput.options({
|
pandora.$ui.findInput.options({
|
||||||
autocomplete: autocompleteFunction()
|
autocomplete: autocompleteFunction(),
|
||||||
|
placeholder: ''
|
||||||
}).focus();
|
}).focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,7 +69,7 @@ pandora.ui.findElement = function() {
|
||||||
})
|
})
|
||||||
.bindEvent({
|
.bindEvent({
|
||||||
focus: function(data) {
|
focus: function(data) {
|
||||||
if (findKey == 'advanced') {
|
if (pandora.$ui.findSelect.value() == 'advanced') {
|
||||||
pandora.$ui.filterDialog = pandora.ui.filterDialog().open();
|
pandora.$ui.filterDialog = pandora.ui.filterDialog().open();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -65,7 +65,8 @@ pandora.ui.group = function(id) {
|
||||||
} else {
|
} else {
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
index = pandora.user.ui.query.conditions.length;
|
index = pandora.user.ui.query.conditions.length;
|
||||||
pandora.user.ui.query.operator = '&'
|
pandora.user.ui.query.operator = index ? '&' : '';
|
||||||
|
Ox.print('$$$$$$$$$$$$$$$$$$$', index, pandora.user.ui.query.operator)
|
||||||
}
|
}
|
||||||
if (conditions.length == 0) {
|
if (conditions.length == 0) {
|
||||||
pandora.user.ui.query.conditions.splice(index, 1);
|
pandora.user.ui.query.conditions.splice(index, 1);
|
||||||
|
@ -82,7 +83,6 @@ pandora.ui.group = function(id) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pandora.Query.updateGroups();
|
pandora.Query.updateGroups();
|
||||||
Ox.print('---------', pandora.user.ui.query, pandora.user.ui.groupsData)
|
|
||||||
pandora.URL.push(pandora.Query.toString());
|
pandora.URL.push(pandora.Query.toString());
|
||||||
pandora.reloadGroups(i);
|
pandora.reloadGroups(i);
|
||||||
}
|
}
|
||||||
|
@ -104,55 +104,37 @@ pandora.ui.group = function(id) {
|
||||||
i_ = pandora.user.ui.groups.indexOf(id_);
|
i_ = pandora.user.ui.groups.indexOf(id_);
|
||||||
if (i_ == -1) {
|
if (i_ == -1) {
|
||||||
// new group was not part of old group set
|
// new group was not part of old group set
|
||||||
if (pandora.user.queryGroups[i].query.conditions.length) {
|
if (pandora.user.ui.groupsData[i].selected.length) {
|
||||||
// if group with selection gets replaced, reload
|
// if group with selection gets replaced, reload
|
||||||
pandora.user.queryGroups[i].query.conditions = [];
|
pandora.user.ui.query.conditions.splice(pandora.user.ui.groupsData[i].index, 1);
|
||||||
|
pandora.Query.updateGroups();
|
||||||
|
pandora.URL.push(pandora.Query.toString());
|
||||||
pandora.reloadGroups(i);
|
pandora.reloadGroups(i);
|
||||||
}
|
}
|
||||||
pandora.user.queryGroups[i] = getGroupObject(id_);
|
|
||||||
pandora.user.ui.groups[i] = id_;
|
pandora.user.ui.groups[i] = id_;
|
||||||
pandora.UI.set({groups: pandora.user.ui.groups});
|
pandora.UI.set({groups: pandora.user.ui.groups});
|
||||||
replaceGroup(i, id_);
|
replaceGroup(i, id_);
|
||||||
} else {
|
} else {
|
||||||
// swap two existing groups
|
// swap two existing groups
|
||||||
var group = $.extend({}, pandora.user.queryGroups[i]);
|
var groupsData = Ox.clone(pandora.user.ui.groupsData[i]);
|
||||||
pandora.user.queryGroups[i] = pandora.user.queryGroups[i_];
|
pandora.user.ui.groupsData[i] = pandora.user.ui.groupsData[i_];
|
||||||
pandora.user.queryGroups[i_] = group;
|
pandora.user.ui.groupsData[i_] = groupsData;
|
||||||
pandora.user.ui.groups[i] = id_;
|
pandora.user.ui.groups[i] = id_;
|
||||||
pandora.user.ui.groups[i_] = id;
|
pandora.user.ui.groups[i_] = id;
|
||||||
pandora.UI.set({groups: pandora.user.ui.groups});
|
pandora.UI.set({groups: pandora.user.ui.groups});
|
||||||
replaceGroup(i, id_, pandora.user.queryGroups[i].query);
|
replaceGroup(i, id_);
|
||||||
replaceGroup(i_, id, pandora.user.queryGroups[i_].query);
|
replaceGroup(i_, id);
|
||||||
}
|
}
|
||||||
function replaceGroup(i, id, query) {
|
function replaceGroup(i, id, query) {
|
||||||
// if query is passed, selected items will be derived from it
|
// if query is passed, selected items will be derived from it
|
||||||
var isOuter = i % 4 == 0;
|
var isOuter = i % 4 == 0;
|
||||||
pandora.$ui[isOuter ? 'browser' : 'groupsInnerPanel'].replaceElement(
|
pandora.$ui[isOuter ? 'browser' : 'groupsInnerPanel'].replaceElement(
|
||||||
isOuter ? i / 2 : i - 1,
|
isOuter ? i / 2 : i - 1,
|
||||||
pandora.$ui.groups[i] = pandora.ui.group(id, query)
|
pandora.$ui.groups[i] = pandora.ui.group(id)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.appendTo(that.$bar.$element);
|
.appendTo(that.$bar.$element);
|
||||||
if (!query) {
|
|
||||||
// if query is set, group object has already been taken care of
|
|
||||||
pandora.user.queryGroups[i] = getGroupObject(id);
|
|
||||||
}
|
|
||||||
function getGroupObject(id) {
|
|
||||||
var i = pandora.user.ui.groups.indexOf(id),
|
|
||||||
title = Ox.getObjectById(pandora.site.groups, id).title,
|
|
||||||
width = pandora.getGroupWidth(i, panelWidth);
|
|
||||||
return {
|
|
||||||
id: id,
|
|
||||||
element: that,
|
|
||||||
query: {
|
|
||||||
conditions: [],
|
|
||||||
operator: '|'
|
|
||||||
},
|
|
||||||
size: width.list,
|
|
||||||
title: title
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return that;
|
return that;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue