better mapping between find query string and lists, find input, groups
This commit is contained in:
parent
3ff1d186c0
commit
1238ad2370
9 changed files with 347 additions and 329 deletions
|
@ -513,17 +513,14 @@
|
|||
"preferences": {},
|
||||
"ui": {
|
||||
"annotationsSize": 256,
|
||||
"findKey": "",
|
||||
"findQuery": {"conditions": [], "operator": ""},
|
||||
"find": {"index": -1, "key": "", "value": ""},
|
||||
"groups": ["director", "country", "year", "language", "genre"],
|
||||
"groupsQuery": {"conditions": [], "operator": "|"},
|
||||
"groupsSize": 176,
|
||||
"icons": "posters",
|
||||
"infoIconSize": 256,
|
||||
"item": "",
|
||||
"itemView": "info",
|
||||
"list": "",
|
||||
"listQuery": {"conditions": [], "operator": ""},
|
||||
"lists": {
|
||||
"": {
|
||||
"columns": ["title", "director", "country", "year", "language", "runtime", "genre"],
|
||||
|
@ -535,6 +532,7 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
"query": {"conditions": [], "operator": ""},
|
||||
"section": "items",
|
||||
"showAnnotations": true,
|
||||
"showControls": true,
|
||||
|
|
|
@ -1,16 +1,100 @@
|
|||
// vim: et:ts=4:sw=4:sts=4:ft=javascript
|
||||
pandora.Query = (function() {
|
||||
|
||||
function parseFind2(str) {
|
||||
function constructFind(query) {
|
||||
return /*encodeURI(*/query.conditions.map(function(condition) {
|
||||
var ret;
|
||||
if (condition.conditions) {
|
||||
ret = '[' + constructFind(condition) + ']';
|
||||
} else {
|
||||
ret = condition.value !== ''
|
||||
? condition.key + (condition.key ? ':' : '')
|
||||
+ constructValue(condition.value, condition.operator)
|
||||
: null;
|
||||
}
|
||||
return ret;
|
||||
}).join(query.operator == '&' ? ',' : '|')/*)*/;
|
||||
}
|
||||
|
||||
function constructValue(value, operator) {
|
||||
operator = operator.replace('=', '^$');
|
||||
if (operator.indexOf('$') > -1) {
|
||||
value = operator.substr(0, operator.length - 1) + value + '$';
|
||||
} else {
|
||||
value = operator + value;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function everyCondition(conditions, key, operator) {
|
||||
// if every condition has the given key and operator
|
||||
// (excluding conditions where all subconditions match)
|
||||
// returns true, otherwise false
|
||||
return Ox.every(conditions, function(condition) {
|
||||
return condition.key == key && condition.operator == operator;
|
||||
});
|
||||
}
|
||||
|
||||
function getGroupsData() {
|
||||
// a group is selected if exactly one condition in an & query
|
||||
// or every condition in an | query
|
||||
// has the group id as key and "=" as operator
|
||||
return pandora.user.ui.groups.map(function(key) {
|
||||
var index = -1,
|
||||
query = Ox.clone(pandora.user.ui.query, true),
|
||||
selected = [];
|
||||
if (query.operator == '|') {
|
||||
if (everyCondition(query.conditions, key, '=')) {
|
||||
index = Ox.range(query.conditions.length);
|
||||
selected = query.conditions.map(function(condition) {
|
||||
return condition.value;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
index = oneCondition(query.conditions, key, '=');
|
||||
if (index > -1) {
|
||||
selected = query.conditions[index].conditions
|
||||
? query.conditions[index].conditions.map(function(condition) {
|
||||
return condition.value;
|
||||
})
|
||||
: [query.conditions[index].value];
|
||||
}
|
||||
}
|
||||
if (selected.length) {
|
||||
if (Ox.isArray(index)) {
|
||||
query = {conditions: [], operator: ''};
|
||||
} else {
|
||||
query.conditions.splice(index, 1);
|
||||
if (query.conditions.length == 1) {
|
||||
if (query.conditions[0].conditions) {
|
||||
// unwrap single remaining bracketed query
|
||||
query = {
|
||||
conditions: query.conditions[0].conditions,
|
||||
operator: query.conditions[0].operator
|
||||
}
|
||||
} else {
|
||||
query.operator = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
index: index,
|
||||
query: query,
|
||||
selected: selected
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function parseFind(str) {
|
||||
// takes a find query string, returns useful information about the application's state
|
||||
// (selected lists, find input key/value, group queries and selection, query object)
|
||||
Ox.print('parseFind2', str)
|
||||
// (selected lists, find input key/value (and index of the corresponding condition), query object)
|
||||
str = str || '';
|
||||
var conditions,
|
||||
index, indices,
|
||||
ret = {
|
||||
find: {key: '', value: ''},
|
||||
groups: [],
|
||||
lists: [],
|
||||
find: {index: -1, key: '', value: ''},
|
||||
list: '',
|
||||
query: {conditions: [], operator: ''}
|
||||
},
|
||||
subconditions = str.match(/\[.*?\]/g) || [];
|
||||
|
@ -31,161 +115,61 @@ pandora.Query = (function() {
|
|||
var kv, ret;
|
||||
if (condition[0] == '[') {
|
||||
// re-insert subcondition
|
||||
ret = parseFind2(subconditions[parseInt(condition.substr(1, condition.length - 2))]).query;
|
||||
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;
|
||||
});
|
||||
// lists are selected if exactly one condition in an & query
|
||||
// or every condition in an | query
|
||||
// a list is selected if exactly one condition in an & query
|
||||
// has "list" as key and "" as operator
|
||||
ret.lists = ret.query.operator == '|'
|
||||
? everyCondition(ret.query.conditions, 'list', '')
|
||||
: oneCondition(ret.query.conditions, 'list', '');
|
||||
if (ret.query.operator != '|') {
|
||||
index = oneCondition(ret.query.conditions, 'list', '');
|
||||
if (index > -1 && !ret.query.conditions[index].conditions) {
|
||||
ret.list = ret.query.conditions[index].value;
|
||||
}
|
||||
}
|
||||
// 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 = {key: 'advanced', value: ''};
|
||||
} else {
|
||||
conditions = Ox.map(pandora.site.findKeys, function(findKey) {
|
||||
var values = oneCondition(ret.query.conditions, findKey.id, '');
|
||||
return values.length ? {key: findKey.id, values: values} : null;
|
||||
});
|
||||
ret.find = conditions.length == 0 ? {key: '', value: ''}
|
||||
: conditions.length == 1 && conditions[0].values.length == 1
|
||||
? {key: conditions[0].key, value: conditions[0].values[0]}
|
||||
: {key: 'advanced', value: ''}
|
||||
}
|
||||
// a group is selected if exactly one condition in an & query
|
||||
// or every condition in an | query
|
||||
// has the group id as key and "=" as operator
|
||||
ret.groups = pandora.user.ui.groups.map(function(key) {
|
||||
var selected = ret.query.operator == '|'
|
||||
? everyCondition(ret.query.conditions, key, '=')
|
||||
: oneCondition(ret.query.conditions, key, '='),
|
||||
query = ret.query;
|
||||
if (selected.length) {
|
||||
query = {
|
||||
conditions: Ox.map(ret.query.conditions, function(condition) {
|
||||
var ret;
|
||||
if (condition.conditions) {
|
||||
ret = condition.conditions[0].key != key ? condition : null; // fixme: correct? see below...
|
||||
} else {
|
||||
ret = condition.key != key ? condition : null;
|
||||
}
|
||||
return ret;
|
||||
}),
|
||||
operator: ''
|
||||
};
|
||||
if (query.conditions.length == 1) {
|
||||
if (query.conditions[0].conditions) {
|
||||
// unwrap single remaining bracketed query
|
||||
query = {
|
||||
conditions: query.conditions[0].conditions,
|
||||
operator: query.conditions[0].operator
|
||||
}
|
||||
} else {
|
||||
query.operator = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
query: query,
|
||||
selected: selected
|
||||
};
|
||||
});
|
||||
function oneCondition(conditions, key, operator) {
|
||||
// if exactly one condition has the given key and operator
|
||||
// (including conditions where all subconditions match)
|
||||
// returns the corresponding value(s), otherwise returns []
|
||||
var values = Ox.map(conditions, function(condition) {
|
||||
var ret, same;
|
||||
if (condition.conditions) {
|
||||
var every = everyCondition(condition.conditions, key, operator); // fixme: what if [key|key],[key|other]?
|
||||
ret = every.length ? every : null;
|
||||
} else {
|
||||
ret = condition.key == key && condition.operator == operator ? [condition.value] : null
|
||||
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;
|
||||
});
|
||||
return values.length == 1 ? values[0] : [];
|
||||
}
|
||||
function everyCondition(conditions, key, operator) {
|
||||
// if every condition has the given key and operator
|
||||
// (excluding conditions where all subconditions match)
|
||||
// returns the corresponding value(s), otherwise returns []
|
||||
var values = Ox.map(conditions, function(condition) {
|
||||
return condition.key == key && condition.operator == operator ? condition.value : null
|
||||
} 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;
|
||||
});
|
||||
return values.length == conditions.length ? values : [];
|
||||
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: ''}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
function constructFind(query) {
|
||||
//Ox.print('cF', query)
|
||||
return /*encodeURI(*/$.map(query.conditions, function(v, i) {
|
||||
if (!Ox.isUndefined(v.conditions)) {
|
||||
return '[' + constructFind(v) + ']';
|
||||
} else {
|
||||
return v.value !== '' ? v.key + (v.key ? ':' : '') + constructValue(v.value, v.operator) : null;
|
||||
}
|
||||
}).join(query.operator)/*)*/;
|
||||
}
|
||||
|
||||
function constructValue(value, operator) {
|
||||
operator = operator.replace('=', '^$');
|
||||
if (operator.indexOf('$') > -1) {
|
||||
value = operator.substr(0, operator.length - 1) + value + '$';
|
||||
} else {
|
||||
value = operator + value;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function mergeFind() {
|
||||
}
|
||||
|
||||
function parseFind(str) {
|
||||
str = str || '';
|
||||
var find = {
|
||||
conditions: [],
|
||||
operator: ''
|
||||
},
|
||||
subconditions = str.match(/\[.*?\]/g) || [];
|
||||
$.each(subconditions, function(i, v) {
|
||||
subconditions[i] = v.substr(1, v.length - 2);
|
||||
str = str.replace(v, '[' + i + ']');
|
||||
function oneCondition(conditions, key, operator) {
|
||||
// if exactly one condition has the given key and operator
|
||||
// (including conditions where all subconditions match)
|
||||
// returns the corresponding index, otherwise returns -1
|
||||
var indices = Ox.map(conditions, function(condition, i) {
|
||||
return (
|
||||
condition.conditions
|
||||
? everyCondition(condition.conditions, key, operator)
|
||||
: condition.key == key && condition.operator == operator
|
||||
) ? i : null;
|
||||
});
|
||||
if (str.indexOf(',') > -1) {
|
||||
find.operator = '&';
|
||||
} else if (str.indexOf('|') > -1) {
|
||||
find.operator = '|';
|
||||
}
|
||||
//Ox.print('pF', str, find.operator)
|
||||
find.conditions = $.map(find.operator === '' ? [str] : str.split(find.operator == '&' ? ',' : '|'), function(v, i) {
|
||||
//Ox.print('v', v)
|
||||
var ret, kv;
|
||||
if (v[0] == '[') {
|
||||
//Ox.print('recursion', subconditions)
|
||||
ret = parseFind(subconditions[parseInt(v.substr(1, v.length - 2))]);
|
||||
} else {
|
||||
kv = ((v.indexOf(':') > - 1 ? '' : ':') + v).split(':');
|
||||
if (kv[0] == 'list') { // fixme: this is just a hack
|
||||
pandora.user.ui.listQuery = {conditions: [$.extend({
|
||||
key: kv[0]
|
||||
}, parseValue(kv[1]))], operator: ''};
|
||||
} else {
|
||||
ret = $.extend({
|
||||
key: kv[0]
|
||||
}, parseValue(kv[1]));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
});
|
||||
return find;
|
||||
return indices.length == 1 ? indices[0] : -1;
|
||||
}
|
||||
|
||||
function parseValue(str) {
|
||||
|
@ -212,23 +196,21 @@ pandora.Query = (function() {
|
|||
return {
|
||||
|
||||
fromString: function(str) {
|
||||
var list = '',
|
||||
var data
|
||||
query = Ox.unserialize(str.substr(1)),
|
||||
sort = [];
|
||||
sort = []
|
||||
if ('find' in query) {
|
||||
Ox.print(Ox.repeat('-', 80));
|
||||
Ox.print('parseFind2', parseFind2(query.find));
|
||||
Ox.print(Ox.repeat('-', 80));
|
||||
pandora.user.ui.listQuery = {conditions: [], operator: ''}; // fixme: hackish
|
||||
pandora.user.ui.findQuery = parseFind(query.find);
|
||||
if (pandora.user.ui.listQuery.conditions.length) {
|
||||
list = pandora.user.ui.listQuery.conditions[0].value;
|
||||
!pandora.user.ui.lists[list] && pandora.UI.set(
|
||||
['lists', list].join('|'), pandora.site.user.ui.lists['']
|
||||
);
|
||||
}
|
||||
pandora.UI.set({list: list});
|
||||
//Ox.print('user.ui.findQuery', pandora.user.ui.findQuery)
|
||||
data = parseFind(query.find);
|
||||
Ox.print(Ox.repeat('-', 120));
|
||||
Ox.print('STATE', data);
|
||||
Ox.print(Ox.repeat('-', 120));
|
||||
!pandora.user.ui.lists[data.list] && pandora.UI.set(
|
||||
['lists', data.list].join('|'), pandora.site.user.ui.lists['']
|
||||
);
|
||||
pandora.UI.set({list: data.list});
|
||||
pandora.user.ui.find = data.find;
|
||||
pandora.user.ui.query = data.query;
|
||||
pandora.user.ui.groupsData = getGroupsData();
|
||||
}
|
||||
if ('sort' in query) {
|
||||
sort = query.sort.split(',');
|
||||
|
@ -247,6 +229,7 @@ pandora.Query = (function() {
|
|||
}
|
||||
},
|
||||
|
||||
/*
|
||||
toObject: function(groupId) {
|
||||
//Ox.print('tO', pandora.user.ui.findQuery.conditions)
|
||||
// the inner $.merge() creates a clone
|
||||
|
@ -268,6 +251,7 @@ pandora.Query = (function() {
|
|||
operator: operator
|
||||
};
|
||||
},
|
||||
*/
|
||||
|
||||
toString: function() {
|
||||
//Ox.print('tS', pandora.user.ui.find)
|
||||
|
@ -275,10 +259,14 @@ pandora.Query = (function() {
|
|||
key = sort.key,
|
||||
operator = sort.operator;
|
||||
return '?' + Ox.serialize({
|
||||
find: constructFind(pandora.Query.toObject()),
|
||||
find: constructFind(pandora.user.ui.query),
|
||||
sort: (operator == pandora.getSortOperator(key) ? '' : operator) + key,
|
||||
view: pandora.user.ui.lists[pandora.user.ui.list].listView
|
||||
});
|
||||
},
|
||||
|
||||
updateGroups: function() {
|
||||
pandora.user.ui.groupsData = getGroupsData();
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -54,83 +54,10 @@ pandora.getFoldersWidth = function() {
|
|||
return width;
|
||||
};
|
||||
|
||||
pandora.getGroupWidth = function(pos, panelWidth) { // fixme: don't pass panelWidth
|
||||
var width = {};
|
||||
width.list = Math.floor(panelWidth / 5) + (panelWidth % 5 > pos);
|
||||
width.column = width.list - 40 - Ox.UI.SCROLLBAR_SIZE;
|
||||
return width;
|
||||
};
|
||||
|
||||
pandora.getSortOperator = function(key) { // fixme: make static
|
||||
var type = Ox.getObjectById(pandora.site.itemKeys, key).type;
|
||||
return ['hue', 'string', 'text'].indexOf(
|
||||
Ox.isArray(type) ? type[0] : type
|
||||
) > -1 ? '+' : '-';
|
||||
};
|
||||
|
||||
pandora.login = function(data) {
|
||||
pandora.user = data.user;
|
||||
Ox.Theme(pandora.user.ui.theme);
|
||||
pandora.$ui.appPanel.reload();
|
||||
};
|
||||
|
||||
pandora.logout = function(data) {
|
||||
pandora.user = data.user;
|
||||
Ox.Theme(pandora.site.user.ui.theme);
|
||||
pandora.$ui.appPanel.reload();
|
||||
};
|
||||
|
||||
pandora.reloadGroups = function(i) {
|
||||
var query = pandora.Query.toObject(),
|
||||
view = pandora.user.ui.lists[pandora.user.ui.list].listView;
|
||||
if(view == 'clip') {
|
||||
pandora.$ui.list.options({
|
||||
items: function(data, callback) {
|
||||
return pandora.api.findAnnotations($.extend(data, {
|
||||
itemQuery: query
|
||||
}), callback);
|
||||
}
|
||||
});
|
||||
} else if (view == 'map') {
|
||||
pandora.$ui.map.options({
|
||||
places: function(data, callback) {
|
||||
return pandora.api.findPlaces($.extend(data, {
|
||||
itemQuery: query
|
||||
}), callback);
|
||||
}
|
||||
});
|
||||
} else if (view == 'calendar') {
|
||||
pandora.$ui.list.options({
|
||||
items: function(data, callback) {
|
||||
return pandora.api.findEvents($.extend(data, {
|
||||
itemQuery: query
|
||||
}), callback);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
pandora.$ui.list.options({
|
||||
items: function(data, callback) {
|
||||
return pandora.api.find($.extend(data, {
|
||||
query: query
|
||||
}), callback);
|
||||
}
|
||||
});
|
||||
}
|
||||
$.each(pandora.user.queryGroups, function(i_, group_) {
|
||||
if (i_ != i) {
|
||||
//Ox.print('setting groups request', i, i_)
|
||||
pandora.$ui.groups[i_].options({
|
||||
items: function(data, callback) {
|
||||
delete data.keys;
|
||||
return pandora.api.find($.extend(data, {
|
||||
group: group_.id,
|
||||
query: pandora.Query.toObject(group_.id)
|
||||
}), callback);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
pandora.URL.push(pandora.Query.toString());
|
||||
pandora.getGroupsSizes = function() {
|
||||
return Ox.divideInt(
|
||||
window.innerWidth - pandora.user.ui.showSidebar * pandora.user.ui.sidebarSize - 1, 5
|
||||
)
|
||||
};
|
||||
|
||||
pandora.getListData = function() {
|
||||
|
@ -144,6 +71,13 @@ pandora.getListData = function() {
|
|||
return data;
|
||||
};
|
||||
|
||||
pandora.getSortOperator = function(key) { // fixme: make static
|
||||
var type = Ox.getObjectById(pandora.site.itemKeys, key).type;
|
||||
return ['hue', 'string', 'text'].indexOf(
|
||||
Ox.isArray(type) ? type[0] : type
|
||||
) > -1 ? '+' : '-';
|
||||
};
|
||||
|
||||
pandora.getVideoPartsAndPoints = function(durations, points) {
|
||||
var parts = durations.length,
|
||||
offsets = Ox.range(parts).map(function(i) {
|
||||
|
@ -168,6 +102,70 @@ pandora.getVideoPartsAndPoints = function(durations, points) {
|
|||
return ret;
|
||||
};
|
||||
|
||||
pandora.login = function(data) {
|
||||
pandora.user = data.user;
|
||||
Ox.Theme(pandora.user.ui.theme);
|
||||
pandora.$ui.appPanel.reload();
|
||||
};
|
||||
|
||||
pandora.logout = function(data) {
|
||||
pandora.user = data.user;
|
||||
Ox.Theme(pandora.site.user.ui.theme);
|
||||
pandora.$ui.appPanel.reload();
|
||||
};
|
||||
|
||||
pandora.reloadGroups = function(i) {
|
||||
var query = pandora.user.ui.query,
|
||||
view = pandora.user.ui.lists[pandora.user.ui.list].listView;
|
||||
if (view == 'clip') {
|
||||
pandora.$ui.list.options({
|
||||
items: function(data, callback) {
|
||||
return pandora.api.findAnnotations(Ox.extend(data, {
|
||||
itemQuery: query
|
||||
}), callback);
|
||||
}
|
||||
});
|
||||
} else if (view == 'map') {
|
||||
pandora.$ui.map.options({
|
||||
places: function(data, callback) {
|
||||
return pandora.api.findPlaces(Ox.extend(data, {
|
||||
itemQuery: query
|
||||
}), callback);
|
||||
}
|
||||
});
|
||||
} else if (view == 'calendar') {
|
||||
pandora.$ui.list.options({
|
||||
items: function(data, callback) {
|
||||
return pandora.api.findEvents(Ox.extend(data, {
|
||||
itemQuery: query
|
||||
}), callback);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
pandora.$ui.list.options({
|
||||
items: function(data, callback) {
|
||||
return pandora.api.find(Ox.extend(data, {
|
||||
query: query
|
||||
}), callback);
|
||||
}
|
||||
});
|
||||
}
|
||||
$.each(pandora.user.ui.groups, function(i_, id) {
|
||||
if (i_ != i) {
|
||||
//Ox.print('setting groups request', i, i_)
|
||||
pandora.$ui.groups[i_].options({
|
||||
items: function(data, callback) {
|
||||
delete data.keys;
|
||||
return pandora.api.find(Ox.extend(data, {
|
||||
group: id,
|
||||
query: pandora.user.ui.groupsData[i_].query
|
||||
}), callback);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
pandora.reloadList = function() {
|
||||
Ox.print('reloadList')
|
||||
var listData = pandora.getListData();
|
||||
|
@ -191,14 +189,16 @@ pandora.reloadList = function() {
|
|||
};
|
||||
|
||||
pandora.resizeGroups = function(width) {
|
||||
var widths = $.map(pandora.user.queryGroups, function(v, i) {
|
||||
return pandora.getGroupWidth(i, width);
|
||||
});
|
||||
//Ox.print('widths', widths);
|
||||
pandora.$ui.browser.size(0, widths[0].list).size(2, widths[4].list);
|
||||
pandora.$ui.groupsInnerPanel.size(0, widths[1].list).size(2, widths[3].list);
|
||||
$.each(pandora.$ui.groups, function(i, list) {
|
||||
list.resizeColumn('name', widths[i].column);
|
||||
pandora.user.ui.groupsSizes = pandora.getGroupsSizes();
|
||||
Ox.print('{}{}{}', window.innerWidth, window.innerWidth - pandora.user.ui.showSidebar * pandora.user.ui.sidebarSize - 1, pandora.user.ui.groupsSizes)
|
||||
pandora.$ui.browser
|
||||
.size(0, pandora.user.ui.groupsSizes[0])
|
||||
.size(2, pandora.user.ui.groupsSizes[4]);
|
||||
pandora.$ui.groupsInnerPanel
|
||||
.size(0, pandora.user.ui.groupsSizes[1])
|
||||
.size(2, pandora.user.ui.groupsSizes[3]);
|
||||
pandora.$ui.groups.forEach(function(list, i) {
|
||||
list.resizeColumn('name', pandora.user.ui.groupsSizes[i] - 40 - Ox.UI.SCROLLBAR_SIZE);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -1,20 +1,21 @@
|
|||
// vim: et:ts=4:sw=4:sts=4:ft=javascript
|
||||
pandora.ui.browser = function() {
|
||||
var that;
|
||||
var sizes, that;
|
||||
if (!pandora.user.ui.item) {
|
||||
pandora.user.ui.groupsSizes = pandora.getGroupsSizes();
|
||||
pandora.$ui.groups = pandora.ui.groups();
|
||||
that = Ox.SplitPanel({
|
||||
elements: [
|
||||
{
|
||||
element: pandora.$ui.groups[0],
|
||||
size: pandora.user.queryGroups[0].size
|
||||
size: pandora.user.ui.groupsSizes[0]
|
||||
},
|
||||
{
|
||||
element: pandora.$ui.groupsInnerPanel = pandora.ui.groupsInnerPanel()
|
||||
},
|
||||
{
|
||||
element: pandora.$ui.groups[4],
|
||||
size: pandora.user.queryGroups[4].size
|
||||
size: pandora.user.ui.groupsSizes[4]
|
||||
},
|
||||
],
|
||||
id: 'browser',
|
||||
|
|
|
@ -1,17 +1,14 @@
|
|||
// vim: et:ts=4:sw=4:sts=4:ft=javascript
|
||||
pandora.ui.findElement = function() {
|
||||
var findKey = '',
|
||||
findValue = '';
|
||||
if (pandora.user.ui.findQuery.conditions.length == 1) {
|
||||
findKey = pandora.user.ui.findQuery.conditions[0].key;
|
||||
findValue = pandora.user.ui.findQuery.conditions[0].value;
|
||||
}
|
||||
var findIndex = pandora.user.ui.find.index,
|
||||
findKey = pandora.user.ui.find.key,
|
||||
findValue = pandora.user.ui.find.value;
|
||||
var that = Ox.FormElementGroup({
|
||||
elements: $.merge(pandora.user.ui.list ? [
|
||||
pandora.$ui.findListSelect = Ox.Select({
|
||||
items: [
|
||||
{id: 'all', title: 'Find: All ' + pandora.site.itemName.plural},
|
||||
{id: 'list', title: 'Find: This List'}
|
||||
{id: 'list', title: 'Find: This List', checked: true}
|
||||
],
|
||||
overlap: 'right',
|
||||
type: 'image'
|
||||
|
@ -27,17 +24,20 @@ pandora.ui.findElement = function() {
|
|||
] : [], [
|
||||
pandora.$ui.findSelect = Ox.Select({
|
||||
id: 'select',
|
||||
items: $.merge($.map(pandora.site.findKeys,
|
||||
function(key, i) {
|
||||
return {
|
||||
id: key.id,
|
||||
checked: key.id == findKey,
|
||||
title: 'Find: ' + key.title
|
||||
};
|
||||
}), [{}, {
|
||||
id: 'advanced',
|
||||
title: 'Find: Advanced'
|
||||
}]),
|
||||
items: Ox.merge(
|
||||
pandora.site.findKeys.map(function(key, i) {
|
||||
return {
|
||||
id: key.id,
|
||||
title: 'Find: ' + key.title,
|
||||
checked: findKey == key.id
|
||||
};
|
||||
}),
|
||||
[{}, {
|
||||
id: 'advanced',
|
||||
title: 'Find: Advanced',
|
||||
checked: findKey == 'advanced'
|
||||
}]
|
||||
),
|
||||
overlap: 'right',
|
||||
width: 112
|
||||
})
|
||||
|
@ -47,11 +47,6 @@ pandora.ui.findElement = function() {
|
|||
if (key == 'advanced') {
|
||||
pandora.$ui.filterDialog = pandora.ui.filterDialog().open();
|
||||
} else {
|
||||
if (!pandora.user.ui.findQuery.conditions.length) { // fixme: can this case happen at all?
|
||||
pandora.user.ui.findQuery.conditions = [{key: key, value: '', operator: ''}];
|
||||
} else {
|
||||
pandora.user.ui.findQuery.conditions[0].key = key;
|
||||
}
|
||||
pandora.$ui.mainMenu.checkItem('findMenu_find_' + key);
|
||||
pandora.$ui.findInput.options({
|
||||
autocomplete: autocompleteFunction()
|
||||
|
@ -66,25 +61,47 @@ pandora.ui.findElement = function() {
|
|||
autocompleteSelectSubmit: true,
|
||||
clear: true,
|
||||
id: 'input',
|
||||
placeholder: findKey == 'advanced' ? 'Edit...' : '',
|
||||
value: findValue,
|
||||
width: 192
|
||||
})
|
||||
.bindEvent({
|
||||
submit: function(event, data) {
|
||||
var key = pandora.user.ui.findQuery.conditions.length ?
|
||||
pandora.user.ui.findQuery.conditions[0].key : '';
|
||||
if (pandora.user.ui.list && that.value()[0].id == 'all') {
|
||||
$.each(pandora.$ui.folderList, function(k, $list) {
|
||||
$list.options({selected: []});
|
||||
});
|
||||
pandora.UI.set({list: ''});
|
||||
pandora.user.ui.listQuery = {conditions: [], operator: ''};
|
||||
focus: function(data) {
|
||||
if (findKey == 'advanced') {
|
||||
pandora.$ui.filterDialog = pandora.ui.filterDialog().open();
|
||||
}
|
||||
},
|
||||
submit: function(data) {
|
||||
var findInList = pandora.user.ui.list
|
||||
&& pandora.$ui.findListSelect.value() == 'list',
|
||||
key = pandora.$ui.findSelect.value(),
|
||||
condition = {
|
||||
key: key == 'all' ? '' : key,
|
||||
value: data.value,
|
||||
operator: ''
|
||||
};
|
||||
if (findInList) {
|
||||
pandora.user.ui.query = {
|
||||
conditions: [{
|
||||
key: 'list',
|
||||
value: pandora.user.ui.list,
|
||||
operator: ''
|
||||
}, condition],
|
||||
operator: '&'
|
||||
}
|
||||
findIndex == 0 && pandora.user.ui.query.conditions.reverse();
|
||||
} else {
|
||||
if (pandora.user.ui.list) {
|
||||
Ox.forEach(pandora.$ui.folderList, function($list) {
|
||||
$list.options({selected: []});
|
||||
});
|
||||
pandora.UI.set({list: ''});
|
||||
}
|
||||
pandora.user.ui.query = {
|
||||
conditions: [condition],
|
||||
operator: ''
|
||||
}
|
||||
}
|
||||
pandora.user.ui.findQuery.conditions = [{
|
||||
key: key == 'all' ? '' : key,
|
||||
value: data.value,
|
||||
operator: ''
|
||||
}];
|
||||
pandora.URL.set(pandora.Query.toString());
|
||||
}
|
||||
})
|
||||
|
@ -96,7 +113,7 @@ pandora.ui.findElement = function() {
|
|||
margin: '4px'
|
||||
});
|
||||
function autocompleteFunction() {
|
||||
return pandora.user.ui.findQuery.conditions.length ? function(value, callback) {
|
||||
return pandora.user.ui.query.conditions.length ? function(value, callback) {
|
||||
var elementValue = that.value(),
|
||||
key = elementValue[pandora.user.ui.list ? 1 : 0],
|
||||
findKey = Ox.getObjectById(pandora.site.findKeys, key);
|
||||
|
|
|
@ -1,16 +1,9 @@
|
|||
// vim: et:ts=4:sw=4:sts=4:ft=javascript
|
||||
pandora.ui.group = function(id, query) {
|
||||
//Ox.print('group', id, query);
|
||||
/*
|
||||
query && query.conditions.length && alert($.map(query.conditions, function(v) {
|
||||
return v.value;
|
||||
}));
|
||||
*/
|
||||
//alert(id + ' ' + JSON.stringify(pandora.Query.toObject(id)))
|
||||
pandora.ui.group = function(id) {
|
||||
var i = pandora.user.ui.groups.indexOf(id),
|
||||
panelWidth = pandora.$ui.document.width() - (pandora.user.ui.showSidebar * pandora.user.ui.sidebarSize) - 1,
|
||||
title = Ox.getObjectById(pandora.site.groups, id).title,
|
||||
width = pandora.getGroupWidth(i, panelWidth),
|
||||
//width = pandora.getGroupWidth(i, panelWidth),
|
||||
that = Ox.TextList({
|
||||
columns: [
|
||||
{
|
||||
|
@ -20,7 +13,7 @@ pandora.ui.group = function(id, query) {
|
|||
title: title,
|
||||
unique: true,
|
||||
visible: true,
|
||||
width: width.column
|
||||
width: pandora.user.ui.groupsSizes[i] - 40 - Ox.UI.SCROLLBAR_SIZE
|
||||
},
|
||||
{
|
||||
align: 'right',
|
||||
|
@ -36,40 +29,61 @@ pandora.ui.group = function(id, query) {
|
|||
items: function(data, callback) {
|
||||
//if (pandora.user.ui.showGroups) {
|
||||
delete data.keys;
|
||||
//alert(id + " pandora.Query.toObject " + JSON.stringify(pandora.Query.toObject(id)) + ' ' + JSON.stringify(data))
|
||||
return pandora.api.find($.extend(data, {
|
||||
group: id,
|
||||
query: pandora.Query.toObject(id)
|
||||
query: pandora.user.ui.groupsData[i].query
|
||||
}), callback);
|
||||
//} else {
|
||||
// callback({data: {items: data.keys ? [] : 0}});
|
||||
//}
|
||||
},
|
||||
scrollbarVisible: true,
|
||||
selected: query ? $.map(query.conditions, function(v) {
|
||||
return v.value;
|
||||
}) : [],
|
||||
sort: [
|
||||
{
|
||||
key: id == 'year' ? 'name' : 'items',
|
||||
operator: '-'
|
||||
}
|
||||
]
|
||||
selected: pandora.user.ui.groupsData[i].selected,
|
||||
sort: [{
|
||||
key: id == 'year' ? 'name' : 'items',
|
||||
operator: '-'
|
||||
}]
|
||||
})
|
||||
.bindEvent({
|
||||
paste: function(event, data) {
|
||||
pandora.$ui.list.triggerEvent('paste', data);
|
||||
},
|
||||
select: function(event, data) {
|
||||
var group = pandora.user.queryGroups[i],
|
||||
query;
|
||||
pandora.user.queryGroups[i].query.conditions = $.map(data.ids, function(v) {
|
||||
return {
|
||||
key: id,
|
||||
value: v,
|
||||
operator: '='
|
||||
};
|
||||
});
|
||||
var conditions = data.ids.map(function(value) {
|
||||
return {
|
||||
key: id,
|
||||
value: value,
|
||||
operator: '='
|
||||
};
|
||||
}),
|
||||
index = pandora.user.ui.groupsData[i].index;
|
||||
if (Ox.isArray(index)) {
|
||||
pandora.user.ui.query = {
|
||||
conditions: conditions,
|
||||
operator: conditions.length > 1 ? '|' : ''
|
||||
}
|
||||
} else {
|
||||
if (index == -1) {
|
||||
index = pandora.user.ui.query.conditions.length;
|
||||
pandora.user.ui.query.operator = '&'
|
||||
}
|
||||
if (conditions.length == 0) {
|
||||
pandora.user.ui.query.conditions.splice(index, 1);
|
||||
if (pandora.user.ui.query.conditions.length == 1) {
|
||||
pandora.user.ui.query.operator = '';
|
||||
}
|
||||
} else if (conditions.length == 1) {
|
||||
pandora.user.ui.query.conditions[index] = conditions[0];
|
||||
} else {
|
||||
pandora.user.ui.query.conditions[index].conditions = conditions;
|
||||
pandora.user.ui.query.conditions[index].operator = '|';
|
||||
delete pandora.user.ui.query.conditions[index].key;
|
||||
delete pandora.user.ui.query.conditions[index].value;
|
||||
}
|
||||
}
|
||||
pandora.Query.updateGroups();
|
||||
Ox.print('---------', pandora.user.ui.query, pandora.user.ui.groupsData)
|
||||
pandora.URL.push(pandora.Query.toString());
|
||||
pandora.reloadGroups(i);
|
||||
}
|
||||
});
|
||||
|
@ -156,14 +170,14 @@ pandora.ui.groupsInnerPanel = function() {
|
|||
elements: [
|
||||
{
|
||||
element: pandora.$ui.groups[1],
|
||||
size: pandora.user.queryGroups[1].size
|
||||
size: pandora.user.ui.groupsSizes[1]
|
||||
},
|
||||
{
|
||||
element: pandora.$ui.groups[2],
|
||||
},
|
||||
{
|
||||
element: pandora.$ui.groups[3],
|
||||
size: pandora.user.queryGroups[3].size
|
||||
size: pandora.user.ui.groupsSizes[3]
|
||||
}
|
||||
],
|
||||
orientation: 'horizontal'
|
||||
|
|
|
@ -89,20 +89,20 @@ pandora.ui.list = function() { // fixme: remove view argument
|
|||
ratio = icons == 'posters' ? data.posterRatio : 1;
|
||||
size = size || 128;
|
||||
return {
|
||||
height: ratio <= 1 ? size : size / ratio,
|
||||
height: Math.round(ratio <= 1 ? size : size / ratio),
|
||||
id: data.id,
|
||||
info: data[['title', 'director'].indexOf(sort[0].key) > -1 ? 'year' : sort[0].key],
|
||||
title: data.title + (data.director.length ? ' (' + data.director.join(', ') + ')' : ''),
|
||||
url: icons == 'posters'
|
||||
? '/' + data.id + '/poster' + size + '.jpg'
|
||||
: '/' + data.id + '/icon' + size + '.jpg',
|
||||
width: ratio >= 1 ? size : size * ratio
|
||||
width: Math.round(ratio >= 1 ? size : size * ratio)
|
||||
};
|
||||
},
|
||||
items: function(data, callback) {
|
||||
//Ox.print('data, pandora.Query.toObject', data, pandora.Query.toObject())
|
||||
pandora.api.find($.extend(data, {
|
||||
query: pandora.Query.toObject()
|
||||
query: pandora.user.ui.query
|
||||
}), callback);
|
||||
},
|
||||
keys: ['director', 'id', 'posterRatio', 'title', 'year'],
|
||||
|
|
|
@ -120,11 +120,11 @@ pandora.ui.mainMenu = function() {
|
|||
{ id: 'findMenu', title: 'Find', items: [
|
||||
{ id: 'find', title: 'Find', items: [
|
||||
{ group: 'find', min: 1, max: 1, items: pandora.site.findKeys.map(function(key, i) {
|
||||
var index = pandora.user.ui.find.index;
|
||||
return Ox.extend({
|
||||
checked: pandora.user.ui.findQuery.conditions.length ? (
|
||||
pandora.user.ui.findQuery.conditions[0].key == key.id ||
|
||||
(pandora.user.ui.findQuery.conditions[0].key === '' && key.id == 'all')
|
||||
) : key.id == 'all',
|
||||
checked: index > -1 && pandora.user.ui.query.conditions[index].key
|
||||
? pandora.user.ui.query.conditions[index].key == key.id
|
||||
: key.id == 'all'
|
||||
}, key);
|
||||
}) }
|
||||
] },
|
||||
|
|
|
@ -37,7 +37,7 @@ pandora.ui.rightPanel = function() {
|
|||
.bindEvent({
|
||||
resize: function(event, data) {
|
||||
if (!pandora.user.ui.item) {
|
||||
pandora.resizeGroups(data);
|
||||
pandora.resizeGroups();
|
||||
pandora.$ui.list.size();
|
||||
if (pandora.user.ui.lists[pandora.user.ui.list].listView == 'timelines') {
|
||||
pandora.$ui.list.options({
|
||||
|
|
Loading…
Reference in a new issue