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"}
],
"groups": [
{"id": "director", "title": "Director"},
{"id": "country", "title": "Country"},
{"id": "year", "title": "Year"},
{"id": "language", "title": "Language"},
{"id": "genre", "title": "Genre"},
{"id": "writer", "title": "Writer"},
{"id": "producer", "title": "Producer"},
{"id": "cinematographer", "title": "Cinematographer"},
{"id": "editor", "title": "Editor"},
{"id": "actor", "title": "Actor"},
{"id": "keyword", "title": "Keyword"}
{"id": "director", "title": "Director", "type": "string"},
{"id": "country", "title": "Country", "type": "string"},
{"id": "year", "title": "Year", "type": "integer"},
{"id": "language", "title": "Language", "type": "string"},
{"id": "genre", "title": "Genre", "type": "string"},
{"id": "writer", "title": "Writer", "type": "string"},
{"id": "producer", "title": "Producer", "type": "string"},
{"id": "cinematographer", "title": "Cinematographer", "type": "string"},
{"id": "editor", "title": "Editor", "type": "string"},
{"id": "actor", "title": "Actor", "type": "string"},
{"id": "keyword", "title": "Keyword", "type": "string"}
],
"itemKeys": [
{
@ -545,7 +545,13 @@
"ui": {
"annotationsSize": 256,
"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,
"icons": "posters",
"infoIconSize": 256,

View file

@ -39,8 +39,9 @@ pandora.Query = (function() {
// 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) {
return pandora.user.ui.groups.map(function(group) {
var index = -1,
key = group.id,
query = Ox.clone(fullQuery, true),
selected = [];
if (query.operator == '|') {

View file

@ -328,9 +328,9 @@ pandora.getSortMenu = function() {
return { id: 'sortMenu', title: 'Sort', 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) {
return Ox.extend(Ox.clone(key), {
return Ox.extend({
checked: list.sort[0].key == key.id
});
}, key);
}), {}) : [], pandora.site.sortKeys.map(function(key) {
return Ox.extend({
checked: list.sort[0].key == key.id
@ -345,7 +345,30 @@ pandora.getSortMenu = function() {
] },
{ 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) {
//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,
group: group.id,
query: pandora.user.ui.groupsData[i_].query
}), callback);
}

View file

@ -1,6 +1,8 @@
// vim: et:ts=4:sw=4:sts=4:ft=javascript
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,
title = Ox.getObjectById(pandora.site.groups, id).title,
//width = pandora.getGroupWidth(i, panelWidth),
@ -38,7 +40,7 @@ pandora.ui.group = function(id) {
)
: value
},
operator: id == 'year' ? '-' : '+',
operator: group.type == 'integer' ? '-' : '+',
title: title,
unique: true,
visible: true,
@ -69,8 +71,8 @@ pandora.ui.group = function(id) {
scrollbarVisible: true,
selected: pandora.user.ui.groupsData[i].selected,
sort: [{
key: id == 'year' ? 'name' : 'items',
operator: '-'
key: pandora.user.ui.groups[i].sort[0].key,
operator: pandora.user.ui.groups[i].sort[0].operator
}]
})
.bindEvent({
@ -124,6 +126,13 @@ pandora.ui.group = function(id) {
pandora.Query.updateGroups();
pandora.URL.push(pandora.Query.toString());
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({
@ -141,7 +150,7 @@ pandora.ui.group = function(id) {
.bindEvent('change', function(data) {
var groups = Ox.clone(pandora.user.ui.groups),
id_ = data.selected[0].id,
i_ = pandora.user.ui.groups.indexOf(id_);
i_ = Ox.getPositionById(pandora.user.ui.groups, id_);
if (i_ == -1) {
// new group was not part of old group set
if (pandora.user.ui.groupsData[i].selected.length) {
@ -151,23 +160,32 @@ pandora.ui.group = function(id) {
pandora.URL.push(pandora.Query.toString());
pandora.reloadGroups(i);
}
groups[i] = id_;
groups[i] = makeGroup(id_);
pandora.UI.set({groups: groups});
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 {
// swap two existing groups
var groupsData = Ox.clone(pandora.user.ui.groupsData[i]);
pandora.user.ui.groupsData[i] = pandora.user.ui.groupsData[i_];
pandora.user.ui.groupsData[i_] = groupsData;
groups[i] = id_;
groups[i_] = id;
groups[i] = makeGroup(id_, pandora.user.ui.groups[i_].sort);
groups[i_] = makeGroup(id, pandora.user.ui.groups[i].sort);
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
pandora.$ui.mainMenu.replaceMenu('sortMenu', pandora.getSortMenu());
function makeGroup(id, sort) {
// 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) {
// if query is passed, selected items will be derived from it
var isOuter = i % 4 == 0;
@ -184,8 +202,8 @@ pandora.ui.group = function(id) {
pandora.ui.groups = function() {
var $groups = [];
//pandora.user.queryGroups = [];
pandora.user.ui.groups.forEach(function(id, i) {
$groups[i] = pandora.ui.group(id);
pandora.user.ui.groups.forEach(function(group, i) {
$groups[i] = pandora.ui.group(group.id);
});
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: 'info', title: 'Hide Info', keyboard: 'shift i' },
{ id: 'groups', title: 'Hide Groups', keyboard: 'shift g' },
@ -146,7 +154,12 @@ pandora.ui.mainMenu = function() {
{ id: 'debugMenu', title: 'Debug', items: [
{ id: 'query', title: 'Show pandora.Query' },
{ 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});
} else if (data.id == 'movieview') {
var id = document.location.pathname.split('/')[1];
// fixme: what's this?
if (value == 'info')
url(id + '/info');
else
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') {
var key = pandora.user.ui.lists[pandora.user.ui.list].sort[0].key,
operator = value == 'ascending' ? '+' : '-';
pandora.$ui.list.options({
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.URL.push(pandora.Query.toString());
} else if (data.id == 'settheme') {
Ox.Theme(value);
pandora.UI.set('theme', value);
} else if (data.id == 'sortmovies') {
var operator = pandora.getSortOperator(value);
pandora.$ui.mainMenu.checkItem('sortMenu_ordermovies_' + (operator == '+' ? 'ascending' : 'descending'));
pandora.$ui.sortSelect.options({value: value});
pandora.$ui.list.options({
sort: [{key: value, operator: operator}]
} else if (Ox.startsWith(data.id, 'sortgroup')) {
var groups = Ox.clone(pandora.user.ui.groups),
id = data.id.replace('sortgroup', ''),
position = Ox.getPositionById(groups, id),
key = value,
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.URL.push(pandora.Query.toString());