some query fixes
This commit is contained in:
parent
cc4df21897
commit
ab3098f847
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,6 +97,7 @@ pandora.Query = (function() {
|
||||||
query: {conditions: [], operator: ''}
|
query: {conditions: [], operator: ''}
|
||||||
},
|
},
|
||||||
subconditions = str.match(/\[.*?\]/g) || [];
|
subconditions = str.match(/\[.*?\]/g) || [];
|
||||||
|
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
|
||||||
subconditions.forEach(function(subcondition, i) {
|
subconditions.forEach(function(subcondition, i) {
|
||||||
|
@ -147,6 +147,7 @@ pandora.Query = (function() {
|
||||||
index = oneCondition(ret.query.conditions, key, '');
|
index = oneCondition(ret.query.conditions, key, '');
|
||||||
return index > -1 ? index : null;
|
return index > -1 ? index : null;
|
||||||
});
|
});
|
||||||
|
Ox.print('INDICES', indices, indices.length == 1 && !ret.query.conditions[indices[0]].conditions)
|
||||||
if (indices.length) {
|
if (indices.length) {
|
||||||
ret.find = indices.length == 1 && !ret.query.conditions[indices[0]].conditions ? {
|
ret.find = indices.length == 1 && !ret.query.conditions[indices[0]].conditions ? {
|
||||||
index: indices[0],
|
index: indices[0],
|
||||||
|
@ -154,6 +155,8 @@ pandora.Query = (function() {
|
||||||
value: ret.query.conditions[indices[0]].value
|
value: ret.query.conditions[indices[0]].value
|
||||||
} : {index: -1, key: 'advanced', 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