make group sort sticky

This commit is contained in:
rolux 2011-09-17 23:24:53 +00:00
parent 69c12f990c
commit 0f64867884
5 changed files with 125 additions and 40 deletions

View file

@ -15,17 +15,17 @@
{"id": "clip:volume", "title": "Clip Volume", "type": "float"} {"id": "clip:volume", "title": "Clip Volume", "type": "float"}
], ],
"groups": [ "groups": [
{"id": "director", "title": "Director"}, {"id": "director", "title": "Director", "type": "string"},
{"id": "country", "title": "Country"}, {"id": "country", "title": "Country", "type": "string"},
{"id": "year", "title": "Year"}, {"id": "year", "title": "Year", "type": "integer"},
{"id": "language", "title": "Language"}, {"id": "language", "title": "Language", "type": "string"},
{"id": "genre", "title": "Genre"}, {"id": "genre", "title": "Genre", "type": "string"},
{"id": "writer", "title": "Writer"}, {"id": "writer", "title": "Writer", "type": "string"},
{"id": "producer", "title": "Producer"}, {"id": "producer", "title": "Producer", "type": "string"},
{"id": "cinematographer", "title": "Cinematographer"}, {"id": "cinematographer", "title": "Cinematographer", "type": "string"},
{"id": "editor", "title": "Editor"}, {"id": "editor", "title": "Editor", "type": "string"},
{"id": "actor", "title": "Actor"}, {"id": "actor", "title": "Actor", "type": "string"},
{"id": "keyword", "title": "Keyword"} {"id": "keyword", "title": "Keyword", "type": "string"}
], ],
"itemKeys": [ "itemKeys": [
{ {
@ -545,7 +545,13 @@
"ui": { "ui": {
"annotationsSize": 256, "annotationsSize": 256,
"find": {"index": -1, "key": "", "value": ""}, "find": {"index": -1, "key": "", "value": ""},
"groups": ["director", "country", "year", "language", "genre"], "groups": [
{"id": "director", "sort": [{"key": "items", "operator": "-"}]},
{"id": "country", "sort": [{"key": "items", "operator": "-"}]},
{"id": "year", "sort": [{"key": "name", "operator": "-"}]},
{"id": "language", "sort": [{"key": "items", "operator": "-"}]},
{"id": "genre", "sort": [{"key": "items", "operator": "-"}]}
],
"groupsSize": 176, "groupsSize": 176,
"icons": "posters", "icons": "posters",
"infoIconSize": 256, "infoIconSize": 256,

View file

@ -39,8 +39,9 @@ pandora.Query = (function() {
// a group is selected if exactly one condition in an & query // a group is selected if exactly one condition in an & query
// or every condition in an | query // or every condition in an | query
// has the group id as key and "=" as operator // has the group id as key and "=" as operator
return pandora.user.ui.groups.map(function(key) { return pandora.user.ui.groups.map(function(group) {
var index = -1, var index = -1,
key = group.id,
query = Ox.clone(fullQuery, true), query = Ox.clone(fullQuery, true),
selected = []; selected = [];
if (query.operator == '|') { if (query.operator == '|') {

View file

@ -328,9 +328,9 @@ pandora.getSortMenu = function() {
return { id: 'sortMenu', title: 'Sort', items: [ return { id: 'sortMenu', title: 'Sort', items: [
{ id: 'sortmovies', title: 'Sort ' + (isClipView ? 'Clips' : pandora.site.itemName.plural) + ' by', items: [ { id: 'sortmovies', title: 'Sort ' + (isClipView ? 'Clips' : pandora.site.itemName.plural) + ' by', items: [
{ group: 'sortmovies', min: 1, max: 1, items: Ox.merge(isClipView ? Ox.merge(pandora.site.clipKeys.map(function(key) { { group: 'sortmovies', min: 1, max: 1, items: Ox.merge(isClipView ? Ox.merge(pandora.site.clipKeys.map(function(key) {
return Ox.extend(Ox.clone(key), { return Ox.extend({
checked: list.sort[0].key == key.id checked: list.sort[0].key == key.id
}); }, key);
}), {}) : [], pandora.site.sortKeys.map(function(key) { }), {}) : [], pandora.site.sortKeys.map(function(key) {
return Ox.extend({ return Ox.extend({
checked: list.sort[0].key == key.id checked: list.sort[0].key == key.id
@ -345,7 +345,30 @@ pandora.getSortMenu = function() {
] }, ] },
{ id: 'advancedsort', title: 'Advanced Sort...', keyboard: 'shift control s' }, { id: 'advancedsort', title: 'Advanced Sort...', keyboard: 'shift control s' },
{}, {},
{ id: 'groupsstuff', title: 'Groups Stuff' } { id: 'sortgroups', title: 'Sort Groups', items: pandora.user.ui.groups.map(function(group) {
return {
id: 'sortgroup' + group.id,
title: 'Sort ' + Ox.getObjectById(pandora.site.groups, group.id).title + ' Group by',
items: [
{ group: 'sortgroup' + group.id, min: 1, max: 1, items: [
{ id: 'name', title: 'Name', checked: group.sort[0].key == 'name' },
{ id: 'items', title: 'Items', checked: group.sort[0].key == 'items' }
] }
]
}
}) },
{ id: 'ordergroups', title: 'Order Groups', items: pandora.user.ui.groups.map(function(group) {
return {
id: 'ordergroup' + group.id,
title: 'Order ' + Ox.getObjectById(pandora.site.groups, group.id).title + ' Group',
items: [
{ group: 'ordergroup' + group.id, min: 1, max: 1, items: [
{ id: 'ascending', title: 'Ascending', checked: group.sort[0].operator == '+' },
{ id: 'descending', title: 'Descending', checked: group.sort[0].operator == '-' }
] }
]
}
}) }
] }; ] };
}; };
@ -438,14 +461,14 @@ pandora.reloadGroups = function(i) {
} }
}); });
} }
Ox.forEach(pandora.user.ui.groups, function(id, i_) { Ox.forEach(pandora.user.ui.groups, function(group, i_) {
if (i_ != i) { if (i_ != i) {
//Ox.print('setting groups request', i, i_) //Ox.print('setting groups request', i, i_)
pandora.$ui.groups[i_].options({ pandora.$ui.groups[i_].options({
items: function(data, callback) { items: function(data, callback) {
delete data.keys; delete data.keys;
return pandora.api.find(Ox.extend(data, { return pandora.api.find(Ox.extend(data, {
group: id, group: group.id,
query: pandora.user.ui.groupsData[i_].query query: pandora.user.ui.groupsData[i_].query
}), callback); }), callback);
} }

View file

@ -1,6 +1,8 @@
// vim: et:ts=4:sw=4:sts=4:ft=javascript // vim: et:ts=4:sw=4:sts=4:ft=javascript
pandora.ui.group = function(id) { pandora.ui.group = function(id) {
var i = pandora.user.ui.groups.indexOf(id), //Ox.print('group', id, Ox.getPositionById(pandora.user.ui.groups, id))
var i = Ox.getPositionById(pandora.user.ui.groups, id),
group = Ox.getObjectById(pandora.site.groups, id),
panelWidth = pandora.$ui.document.width() - (pandora.user.ui.showSidebar * pandora.user.ui.sidebarSize) - 1, panelWidth = pandora.$ui.document.width() - (pandora.user.ui.showSidebar * pandora.user.ui.sidebarSize) - 1,
title = Ox.getObjectById(pandora.site.groups, id).title, title = Ox.getObjectById(pandora.site.groups, id).title,
//width = pandora.getGroupWidth(i, panelWidth), //width = pandora.getGroupWidth(i, panelWidth),
@ -38,7 +40,7 @@ pandora.ui.group = function(id) {
) )
: value : value
}, },
operator: id == 'year' ? '-' : '+', operator: group.type == 'integer' ? '-' : '+',
title: title, title: title,
unique: true, unique: true,
visible: true, visible: true,
@ -69,8 +71,8 @@ pandora.ui.group = function(id) {
scrollbarVisible: true, scrollbarVisible: true,
selected: pandora.user.ui.groupsData[i].selected, selected: pandora.user.ui.groupsData[i].selected,
sort: [{ sort: [{
key: id == 'year' ? 'name' : 'items', key: pandora.user.ui.groups[i].sort[0].key,
operator: '-' operator: pandora.user.ui.groups[i].sort[0].operator
}] }]
}) })
.bindEvent({ .bindEvent({
@ -124,6 +126,13 @@ pandora.ui.group = function(id) {
pandora.Query.updateGroups(); pandora.Query.updateGroups();
pandora.URL.push(pandora.Query.toString()); pandora.URL.push(pandora.Query.toString());
pandora.reloadGroups(i); pandora.reloadGroups(i);
},
sort: function(data) {
var groups = Ox.clone(pandora.user.ui.groups);
pandora.$ui.mainMenu.checkItem('sortMenu_sortgroups_sortgroup' + id + '_' + data.key);
pandora.$ui.mainMenu.checkItem('sortMenu_ordergroups_ordergroup' + id + '_' + (data.operator == '+' ? 'ascending' : 'descending'));
groups[i].sort = [{key: data.key, operator: data.operator}];
pandora.UI.set({groups: groups});
} }
}); });
Ox.Select({ Ox.Select({
@ -141,7 +150,7 @@ pandora.ui.group = function(id) {
.bindEvent('change', function(data) { .bindEvent('change', function(data) {
var groups = Ox.clone(pandora.user.ui.groups), var groups = Ox.clone(pandora.user.ui.groups),
id_ = data.selected[0].id, id_ = data.selected[0].id,
i_ = pandora.user.ui.groups.indexOf(id_); i_ = Ox.getPositionById(pandora.user.ui.groups, 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.ui.groupsData[i].selected.length) { if (pandora.user.ui.groupsData[i].selected.length) {
@ -151,23 +160,32 @@ pandora.ui.group = function(id) {
pandora.URL.push(pandora.Query.toString()); pandora.URL.push(pandora.Query.toString());
pandora.reloadGroups(i); pandora.reloadGroups(i);
} }
groups[i] = id_; groups[i] = makeGroup(id_);
pandora.UI.set({groups: groups}); pandora.UI.set({groups: groups});
replaceGroup(i, id_); replaceGroup(i, id_);
// fixme: there is an obscure special case not yet covered:
// switching to a new group may change find from advanced to not advanced
// if part of the existing query works as a group selection in the new group
} else { } else {
// swap two existing groups // swap two existing groups
var groupsData = Ox.clone(pandora.user.ui.groupsData[i]); var groupsData = Ox.clone(pandora.user.ui.groupsData[i]);
pandora.user.ui.groupsData[i] = pandora.user.ui.groupsData[i_]; pandora.user.ui.groupsData[i] = pandora.user.ui.groupsData[i_];
pandora.user.ui.groupsData[i_] = groupsData; pandora.user.ui.groupsData[i_] = groupsData;
groups[i] = id_; groups[i] = makeGroup(id_, pandora.user.ui.groups[i_].sort);
groups[i_] = id; groups[i_] = makeGroup(id, pandora.user.ui.groups[i].sort);
pandora.UI.set({groups: groups}); pandora.UI.set({groups: groups});
replaceGroup(i, id_); replaceGroup(i, id_);
replaceGroup(i_, id); replaceGroup(i_, id);
} }
// fixme: there is an obscure special case not yet covered: pandora.$ui.mainMenu.replaceMenu('sortMenu', pandora.getSortMenu());
// switching to a new group may change find from advanced to not advanced function makeGroup(id, sort) {
// if part of the existing query works as a group selection in the new group // makes user.ui.groups object from site.groups object
var group = Ox.getObjectById(pandora.site.groups, id);
return {
id: group.id,
sort: sort || [{key: group.type == 'integer' ? 'name' : 'items', operator: '-'}]
};
}
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;
@ -184,8 +202,8 @@ pandora.ui.group = function(id) {
pandora.ui.groups = function() { pandora.ui.groups = function() {
var $groups = []; var $groups = [];
//pandora.user.queryGroups = []; //pandora.user.queryGroups = [];
pandora.user.ui.groups.forEach(function(id, i) { pandora.user.ui.groups.forEach(function(group, i) {
$groups[i] = pandora.ui.group(id); $groups[i] = pandora.ui.group(group.id);
}); });
return $groups; return $groups;
}; };

View file

@ -101,6 +101,14 @@ pandora.ui.mainMenu = function() {
}) } }) }
] }, ] },
{}, {},
{ id: 'groups', title: 'Groups', items: [
{ group: 'groups', min: 5, max: 5, items: pandora.site.groups.map(function(group) {
return Ox.extend({
checked: Ox.getPositionById(pandora.user.ui.groups, group.id) > -1
}, group);
}) }
] },
{},
{ id: 'lists', title: 'Hide Lists', keyboard: 'shift l' }, { id: 'lists', title: 'Hide Lists', keyboard: 'shift l' },
{ id: 'info', title: 'Hide Info', keyboard: 'shift i' }, { id: 'info', title: 'Hide Info', keyboard: 'shift i' },
{ id: 'groups', title: 'Hide Groups', keyboard: 'shift g' }, { id: 'groups', title: 'Hide Groups', keyboard: 'shift g' },
@ -146,7 +154,12 @@ pandora.ui.mainMenu = function() {
{ id: 'debugMenu', title: 'Debug', items: [ { id: 'debugMenu', title: 'Debug', items: [
{ id: 'query', title: 'Show pandora.Query' }, { id: 'query', title: 'Show pandora.Query' },
{ id: 'resetui', title: 'Reset UI Settings'}, { id: 'resetui', title: 'Reset UI Settings'},
{ id: 'clearcache', title: 'Clear cache'} { id: 'clearcache', title: 'Clear cache'},
{ id: 'nestedone', title: 'Some Nesting', items: [
{ id: 'nestedtwo', title: 'Some More Nesting', items: [
{ id: 'nestedthree', title: 'Even More Nesting' }
] }
] }
] } ] }
] ]
}) })
@ -157,30 +170,54 @@ pandora.ui.mainMenu = function() {
pandora.$ui.findSelect.options({value: value}); pandora.$ui.findSelect.options({value: value});
} else if (data.id == 'movieview') { } else if (data.id == 'movieview') {
var id = document.location.pathname.split('/')[1]; var id = document.location.pathname.split('/')[1];
// fixme: what's this?
if (value == 'info') if (value == 'info')
url(id + '/info'); url(id + '/info');
else else
url(id); url(id);
} else if (Ox.startsWith(data.id, 'ordergroup')) {
var groups = Ox.clone(pandora.user.ui.groups),
id = data.id.replace('ordergroup', ''),
position = Ox.getPositionById(groups, id),
key = groups[position].sort[0].key,
operator = value == 'ascending' ? '+' : '-';
pandora.$ui.groups[position].options({
sort: [{key: key, operator: operator}]
});
groups[position].sort[0].operator = operator;
pandora.UI.set({groups: groups});
} else if (data.id == 'ordermovies') { } else if (data.id == 'ordermovies') {
var key = pandora.user.ui.lists[pandora.user.ui.list].sort[0].key, var key = pandora.user.ui.lists[pandora.user.ui.list].sort[0].key,
operator = value == 'ascending' ? '+' : '-'; operator = value == 'ascending' ? '+' : '-';
pandora.$ui.list.options({ pandora.$ui.list.options({
sort: [{key: key, operator: operator}] sort: [{key: key, operator: operator}]
}); });
pandora.UI.set(['lists', pandora.user.ui.list, 'sort'].join('|'), [{key: key, operator: operator}]); pandora.UI.set('lists|' + pandora.user.ui.list + '|sort', [{key: key, operator: operator}]);
//pandora.user.ui.lists[pandora.user.ui.list].sort[0] = {key: key, operator: operator}; //pandora.user.ui.lists[pandora.user.ui.list].sort[0] = {key: key, operator: operator};
pandora.URL.push(pandora.Query.toString()); pandora.URL.push(pandora.Query.toString());
} else if (data.id == 'settheme') { } else if (data.id == 'settheme') {
Ox.Theme(value); Ox.Theme(value);
pandora.UI.set('theme', value); pandora.UI.set('theme', value);
} else if (data.id == 'sortmovies') { } else if (Ox.startsWith(data.id, 'sortgroup')) {
var operator = pandora.getSortOperator(value); var groups = Ox.clone(pandora.user.ui.groups),
pandora.$ui.mainMenu.checkItem('sortMenu_ordermovies_' + (operator == '+' ? 'ascending' : 'descending')); id = data.id.replace('sortgroup', ''),
pandora.$ui.sortSelect.options({value: value}); position = Ox.getPositionById(groups, id),
pandora.$ui.list.options({ key = value,
sort: [{key: value, operator: operator}] operator = '-';
pandora.$ui.groups[position].options({
sort: [{key: key, operator: operator}]
}); });
pandora.UI.set(['lists', pandora.user.ui.list, 'sort'].join('|'), [{key: value, operator: operator}]); groups[position].sort[0].key = key;
pandora.UI.set({groups: groups});
} else if (data.id == 'sortmovies') {
var key = value,
operator = pandora.getSortOperator(key);
pandora.$ui.mainMenu.checkItem('sortMenu_ordermovies_' + (operator == '+' ? 'ascending' : 'descending'));
pandora.$ui.sortSelect.options({value: key});
pandora.$ui.list.options({
sort: [{key: key, operator: operator}]
});
pandora.UI.set('lists|' + pandora.user.ui.list + '|sort', [{key: key, operator: operator}]);
//pandora.user.ui.lists[pandora.user.ui.list].sort[0] = {key: key, operator: operator}; //pandora.user.ui.lists[pandora.user.ui.list].sort[0] = {key: key, operator: operator};
pandora.URL.push(pandora.Query.toString()); pandora.URL.push(pandora.Query.toString());