forked from 0x2620/pandora
use common map & filter
This commit is contained in:
parent
98af37696f
commit
c0851b5a7f
16 changed files with 90 additions and 79 deletions
|
@ -177,7 +177,7 @@ appPanel
|
|||
var prefix = '/static/';
|
||||
if (localStorage && localStorage['pandora.debug']) {
|
||||
Ox.getJSON(prefix + 'json/pandora.json?' + Ox.random(1000), function(files) {
|
||||
Ox.loadFiles(Ox.map(files, function(file) {
|
||||
Ox.loadFiles(files.map(function(file) {
|
||||
return prefix + file;
|
||||
}), callback);
|
||||
});
|
||||
|
@ -227,13 +227,13 @@ appPanel
|
|||
}) ? 'manual' : data.site.layers.some(function(layer) {
|
||||
return layer.hasEvents;
|
||||
}) ? 'auto' : 'none',
|
||||
clipKeys: Ox.map(data.site.clipKeys, function(key) {
|
||||
clipKeys: data.site.clipKeys.map(function(key) {
|
||||
return Ox.extend(key, {
|
||||
operator: pandora.getSortOperator(key.id)
|
||||
});
|
||||
}),
|
||||
findKeys: Ox.map(data.site.itemKeys, function(key) {
|
||||
return key.find ? key : null;
|
||||
findKeys: data.site.itemKeys.filter(function(key) {
|
||||
return key.find;
|
||||
}),
|
||||
itemsSection: pandora.site.itemName.plural.toLowerCase(),
|
||||
map: data.site.layers.some(function(layer) {
|
||||
|
@ -259,14 +259,16 @@ appPanel
|
|||
{id: 'featured', title: 'Featured Texts', showBrowser: false}
|
||||
]
|
||||
},
|
||||
sortKeys: Ox.map(pandora.site.itemKeys, function(key) {
|
||||
return key.sort ? Ox.extend(key, {
|
||||
sortKeys: pandora.site.itemKeys.filter(function(key) {
|
||||
return key.sort;
|
||||
}).map(function(key) {
|
||||
return Ox.extend(key, {
|
||||
operator: pandora.getSortOperator(key.id)
|
||||
}) : null;
|
||||
});
|
||||
})
|
||||
});
|
||||
pandora.site.listSettings = {};
|
||||
Ox.map(pandora.site.user.ui, function(val, key) {
|
||||
Ox.forEach(pandora.site.user.ui, function(val, key) {
|
||||
if (/^list[A-Z]/.test(key)) {
|
||||
pandora.site.listSettings[key] = key[4].toLowerCase() + key.substr(5);
|
||||
}
|
||||
|
|
|
@ -176,18 +176,22 @@ pandora.URL = (function() {
|
|||
list: Ox.merge(
|
||||
// listView is the default view
|
||||
[pandora.user.ui.listView],
|
||||
Ox.map(pandora.site.listViews, function(view) {
|
||||
return view.id == pandora.user.ui.listView ? null : view.id;
|
||||
pandora.site.listViews.filter(function(view) {
|
||||
return view.id == pandora.user.ui.listView
|
||||
}).map(function(view) {
|
||||
return view.id;
|
||||
})
|
||||
),
|
||||
item: Ox.merge(
|
||||
// itemView is the default view,
|
||||
// videoView is the default view if there is a duration
|
||||
[pandora.user.ui.itemView, pandora.user.ui.videoView],
|
||||
Ox.map(pandora.site.itemViews, function(view) {
|
||||
pandora.site.itemViews.filter(function(view) {
|
||||
return [
|
||||
pandora.user.ui.itemView, pandora.user.ui.videoView
|
||||
].indexOf(view.id) > -1 ? null : view.id;
|
||||
].indexOf(view.id) > -1;
|
||||
}).map(function(view) {
|
||||
return view.id;
|
||||
})
|
||||
)
|
||||
};
|
||||
|
@ -200,11 +204,11 @@ pandora.URL = (function() {
|
|||
|| pandora.isClipView(view)
|
||||
&& Ox.getObjectById(pandora.site.clipKeys, pandora.user.ui.listSort[0].key)
|
||||
|| [],
|
||||
pandora.isClipView(view) ? Ox.map(pandora.site.clipKeys, function(key) {
|
||||
return key.id == pandora.user.ui.listSort[0].key ? null : key;
|
||||
pandora.isClipView(view) ? pandora.site.clipKeys.filter(function(key) {
|
||||
return key.id == pandora.user.ui.listSort[0].key;
|
||||
}) : [],
|
||||
Ox.map(pandora.site.sortKeys, function(key) {
|
||||
return key.id == pandora.user.ui.listSort[0].key ? null : key;
|
||||
pandora.site.sortKeys.filter(function(key) {
|
||||
return key.id == pandora.user.ui.listSort[0].key;
|
||||
})
|
||||
);
|
||||
});
|
||||
|
@ -213,8 +217,8 @@ pandora.URL = (function() {
|
|||
sortKeys[itemsSection].item[view] = Ox.merge(
|
||||
// itemSort[0].key is the default sort key
|
||||
[Ox.getObjectById(pandora.site.clipKeys, pandora.user.ui.itemSort[0].key)],
|
||||
Ox.map(pandora.site.clipKeys, function(key) {
|
||||
return key.id == pandora.user.ui.itemSort[0].key ? null : key;
|
||||
pandora.site.clipKeys.filter(function(key) {
|
||||
return key.id == pandora.user.ui.itemSort[0].key;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
|
@ -311,9 +311,9 @@ pandora.ui.filesView = function(options, self) {
|
|||
}, function(result) {
|
||||
*/
|
||||
conditions = {};
|
||||
Ox.map(['id', 'title', 'director', 'year'], function(key) {
|
||||
['id', 'title', 'director', 'year'].map(function(key) {
|
||||
var value = self['$' + key + 'Input'].value();
|
||||
if(value.length) {
|
||||
if (value.length) {
|
||||
conditions[key] = key == 'director' ? value.split(', ') : value;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -15,7 +15,7 @@ pandora.ui.filterForm = function(list) {
|
|||
}, function(result) {
|
||||
that.append(
|
||||
that.$filter = Ox.Filter({
|
||||
findKeys: Ox.merge(Ox.map(pandora.site.itemKeys, function(itemKey) {
|
||||
findKeys: Ox.merge(pandora.site.itemKeys.map(function(itemKey) {
|
||||
var key = Ox.clone(itemKey);
|
||||
key.type = key.type == 'layer'
|
||||
? Ox.getObjectById(pandora.site.layers, key.id).type
|
||||
|
|
|
@ -28,13 +28,14 @@ pandora.ui.findElement = function() {
|
|||
pandora.$ui.findSelect = Ox.Select({
|
||||
id: 'select',
|
||||
items: Ox.merge(
|
||||
Ox.map(pandora.site.findKeys, function(key, i) {
|
||||
pandora.site.findKeys.filter(function(key, i) {
|
||||
return !key.capability
|
||||
|| pandora.site.capabilities[key.capability][pandora.user.level]
|
||||
? {
|
||||
|| pandora.site.capabilities[key.capability][pandora.user.level];
|
||||
}).map(function(key) {
|
||||
return {
|
||||
id: key.id,
|
||||
title: 'Find: ' + key.title,
|
||||
} : null;
|
||||
};
|
||||
}),
|
||||
[{}, {
|
||||
id: 'advanced',
|
||||
|
|
|
@ -643,9 +643,9 @@ pandora.ui.infoView = function(data) {
|
|||
Ox.Button({
|
||||
tooltip: (canEdit ? Ox.toTitleCase(userLevel) : 'You') + ' '
|
||||
+ (hasCapability ? 'can' : 'can\'t') + ' '
|
||||
+ Ox.map(Ox.toSlashes(capability.name).split('/'), function(word, i) {
|
||||
return i == 0 ? null : word.toLowerCase();
|
||||
}).join(' ')
|
||||
+ Ox.toSlashes(capability.name)
|
||||
.split('/').slice(1).join(' ')
|
||||
.toLowerCase()
|
||||
.replace('see item', 'see the item')
|
||||
.replace('play video', 'play the full video')
|
||||
.replace('download video', 'download the video'),
|
||||
|
|
|
@ -616,9 +616,9 @@ pandora.ui.infoView = function(data) {
|
|||
Ox.Button({
|
||||
tooltip: (canEdit ? Ox.toTitleCase(userLevel) : 'You') + ' '
|
||||
+ (hasCapability ? 'can' : 'can\'t') + ' '
|
||||
+ Ox.map(Ox.toSlashes(capability.name).split('/'), function(word, i) {
|
||||
return i == 0 ? null : word.toLowerCase();
|
||||
}).join(' '),
|
||||
+ Ox.toSlashes(capability.name)
|
||||
.split('/').slice(1).join(' ')
|
||||
.toLowerCase(),
|
||||
title: capability.symbol,
|
||||
type: 'image'
|
||||
})
|
||||
|
|
|
@ -616,9 +616,9 @@ pandora.ui.infoView = function(data) {
|
|||
Ox.Button({
|
||||
tooltip: (canEdit ? Ox.toTitleCase(userLevel) : 'You') + ' '
|
||||
+ (hasCapability ? 'can' : 'can\'t') + ' '
|
||||
+ Ox.map(Ox.toSlashes(capability.name).split('/'), function(word, i) {
|
||||
return i == 0 ? null : word.toLowerCase();
|
||||
}).join(' '),
|
||||
+ Ox.toSlashes(capability.name)
|
||||
.split('/').slice(1).join(' ')
|
||||
.toLowerCase(),
|
||||
title: capability.symbol,
|
||||
type: 'image'
|
||||
})
|
||||
|
|
|
@ -52,27 +52,27 @@ pandora.ui.list = function() {
|
|||
titleImage: pandora.user.ui.icons == 'posters' ? 'SetPoster' : 'Icon',
|
||||
visible: pandora.user.ui.listColumns.indexOf('posterRatio') > -1,
|
||||
width: 16
|
||||
}], Ox.map(pandora.site.sortKeys, function(key) {
|
||||
var position = pandora.user.ui.listColumns.indexOf(key.id);
|
||||
}], pandora.site.sortKeys.filter(function(key) {
|
||||
return !key.capability
|
||||
|| pandora.site.capabilities[key.capability][pandora.user.level]
|
||||
? {
|
||||
align: ['string', 'text'].indexOf(
|
||||
Ox.isArray(key.type) ? key.type[0]: key.type
|
||||
) > -1 ? 'left' : key.type == 'list' ? 'center' : 'right',
|
||||
defaultWidth: key.columnWidth,
|
||||
format: key.format,
|
||||
id: key.id,
|
||||
operator: pandora.getSortOperator(key.id),
|
||||
position: position,
|
||||
removable: !key.columnRequired,
|
||||
title: key.title,
|
||||
type: key.type,
|
||||
unique: key.id == 'id',
|
||||
visible: position > -1,
|
||||
width: pandora.user.ui.listColumnWidth[key.id] || key.columnWidth
|
||||
}
|
||||
: null;
|
||||
|| pandora.site.capabilities[key.capability][pandora.user.level];
|
||||
}).map(function(key) {
|
||||
var position = pandora.user.ui.listColumns.indexOf(key.id);
|
||||
return {
|
||||
align: ['string', 'text'].indexOf(
|
||||
Ox.isArray(key.type) ? key.type[0]: key.type
|
||||
) > -1 ? 'left' : key.type == 'list' ? 'center' : 'right',
|
||||
defaultWidth: key.columnWidth,
|
||||
format: key.format,
|
||||
id: key.id,
|
||||
operator: pandora.getSortOperator(key.id),
|
||||
position: position,
|
||||
removable: !key.columnRequired,
|
||||
title: key.title,
|
||||
type: key.type,
|
||||
unique: key.id == 'id',
|
||||
visible: position > -1,
|
||||
width: pandora.user.ui.listColumnWidth[key.id] || key.columnWidth
|
||||
};
|
||||
})),
|
||||
columnsMovable: true,
|
||||
columnsRemovable: true,
|
||||
|
|
|
@ -602,13 +602,15 @@ pandora.ui.mainMenu = function() {
|
|||
{ id: 'sortitems', title: 'Sort ' + (isClipView || ui.item ? 'Clips' : pandora.site.itemName.plural) + ' by', items: [
|
||||
{ group: 'listsort', min: 1, max: 1, items: Ox.merge(
|
||||
items,
|
||||
Ox.map(pandora.site.sortKeys, function(key) {
|
||||
pandora.site.sortKeys.filter(function(key) {
|
||||
return Ox.getIndexById(items, key.id) == -1 && (
|
||||
!key.capability
|
||||
|| pandora.site.capabilities[key.capability][pandora.user.level]
|
||||
) ? Ox.extend({
|
||||
);
|
||||
}).map(function(key) {
|
||||
return Ox.extend({
|
||||
checked: ui.listSort[0].key == key.id
|
||||
}, key) : null;
|
||||
}, key);
|
||||
})
|
||||
) }
|
||||
] },
|
||||
|
|
|
@ -15,13 +15,14 @@ pandora.ui.sortSelect = function(isNavigationView) {
|
|||
if (!pandora.user.ui.item) {
|
||||
items = Ox.merge(
|
||||
items,
|
||||
Ox.map(pandora.site.sortKeys, function(key) {
|
||||
pandora.site.sortKeys.filter(function(key) {
|
||||
return Ox.getIndexById(items, key.id) == -1 && (
|
||||
!key.capability
|
||||
|| pandora.site.capabilities[key.capability][pandora.user.level]
|
||||
) ? Ox.extend(Ox.clone(key), {
|
||||
|| pandora.site.capabilities[key.capability][pandora.user.level];
|
||||
}).map(function(key) {
|
||||
return Ox.extend(Ox.clone(key), {
|
||||
title: 'Sort by ' + key.title
|
||||
}) : null;
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
|
@ -353,13 +353,14 @@ pandora.ui.statisticsDialog = function() {
|
|||
element: '<img>',
|
||||
tooltip: mode == 'all' && (key == 'continent' || key == 'region')
|
||||
? Ox.wordwrap(
|
||||
Ox.map(Ox.COUNTRIES, function(country) {
|
||||
Ox.COUNTRIES.filter(function(country) {
|
||||
return country[key] == split[key == 'continent' ? 0 : 1]
|
||||
&& country.code.length == 2
|
||||
&& ['AC', 'CP', 'DG', 'EA', 'EU', 'IC', 'TA', 'UK'].indexOf(country.code) == -1
|
||||
&& !country.exception
|
||||
&& !country.disputed
|
||||
&& !country.dissolved
|
||||
? country.name : null;
|
||||
&& !country.dissolved;
|
||||
}).map(function(country) {
|
||||
return country.name;
|
||||
}).sort().join(', '),
|
||||
64, '<br>', true
|
||||
).split(', ').map(function(country) {
|
||||
|
|
|
@ -659,11 +659,11 @@ pandora.ui.usersDialog = function() {
|
|||
}),
|
||||
Ox.Select({
|
||||
id: 'level',
|
||||
items: Ox.map(pandora.site.userLevels, function(level, i) {
|
||||
return i ? {
|
||||
items: pandora.site.userLevels.slice(1).map(function(level) {
|
||||
return {
|
||||
id: level,
|
||||
title: Ox.toTitleCase(level)
|
||||
} : null;
|
||||
};
|
||||
}),
|
||||
label: 'Level',
|
||||
labelWidth: 80,
|
||||
|
|
|
@ -596,13 +596,13 @@ pandora.getItemByIdOrTitle = function(str, callback) {
|
|||
}, function(result) {
|
||||
var id = '';
|
||||
if (result.data.items.length) {
|
||||
var items = Ox.map(result.data.items, function(item) {
|
||||
var items = Ox.filter(Ox.map(result.data.items, function(item) {
|
||||
// test if exact match or word match
|
||||
var sort = new RegExp('^' + str + '$', 'i').test(item.title) ? 2000000
|
||||
: new RegExp('\\b' + str + '\\b', 'i').test(item.title) ? 1000000 : 0;
|
||||
return sort ? {id: item.id, sort: sort + (parseInt(item[sortKey]) || 0)} : null;
|
||||
// fixme: remove the (...|| 0) check once the backend sends correct data
|
||||
});
|
||||
}));
|
||||
if (items.length) {
|
||||
id = items.sort(function(a, b) {
|
||||
return b.sort - a.sort;
|
||||
|
@ -1170,12 +1170,12 @@ pandora.unloadWindow = function() {
|
|||
// If exactly one condition has the given key and operator
|
||||
// (including or excluding conditions where all subconditions match)
|
||||
// returns the corresponding index, otherwise returns -1
|
||||
var indices = Ox.map(conditions, function(condition, i) {
|
||||
var indices = Ox.indicesOf(conditions, function(condition) {
|
||||
return (
|
||||
condition.conditions
|
||||
? includeSubconditions && everyCondition(condition.conditions, key, operator)
|
||||
: condition.key == key && condition.operator == operator
|
||||
) ? i : null;
|
||||
);
|
||||
});
|
||||
return indices.length == 1 ? indices[0] : -1;
|
||||
}
|
||||
|
@ -1245,9 +1245,9 @@ pandora.unloadWindow = function() {
|
|||
return filter.index > -1;
|
||||
}).length;
|
||||
// indices of non-advanced find queries
|
||||
indices = Ox.map(pandora.site.findKeys, function(findKey) {
|
||||
indices = Ox.indicesOf(pandora.site.findKeys, function(findKey) {
|
||||
var index = oneCondition(find.conditions, findKey.id, '=');
|
||||
return index > -1 ? index : null;
|
||||
return index > -1;
|
||||
});
|
||||
state = conditions == 1 && indices.length == 1 ? {
|
||||
index: indices[0],
|
||||
|
|
|
@ -6,7 +6,7 @@ pandora.ui.videoPreview = function(data) {
|
|||
var that = Ox.VideoPreview({
|
||||
duration: data.duration,
|
||||
getFrame: function(position) {
|
||||
var resolutions = Ox.filter(pandora.site.video.resolutions, function(resolution, i) {
|
||||
var resolutions = pandora.site.video.resolutions.filter(function(resolution, i) {
|
||||
return resolution >= data.height;
|
||||
}),
|
||||
resolution = resolutions.length
|
||||
|
|
|
@ -6,10 +6,10 @@ pandora.ui.viewSelect = function() {
|
|||
var ui = pandora.user.ui,
|
||||
sortKey = !ui.item ? 'listSort' : 'itemSort',
|
||||
viewKey = !ui.item ? 'listView' : 'itemView',
|
||||
items = Ox.map(pandora.site[viewKey + 's'], function(view) {
|
||||
return ['data', 'files'].indexOf(view.id) == -1
|
||||
? {id: view.id, title: 'View ' + view.title}
|
||||
: null;
|
||||
items = pandora.site[viewKey + 's'].filter(function(view) {
|
||||
return ['data', 'files'].indexOf(view.id) == -1;
|
||||
}).map(function(view) {
|
||||
return {id: view.id, title: 'View ' + view.title};
|
||||
}),
|
||||
that;
|
||||
if (
|
||||
|
|
Loading…
Reference in a new issue