users dialog: handle robots; statistics dialog: add colors

This commit is contained in:
rolux 2012-03-26 19:27:20 +00:00
parent a562ec428a
commit fb91217671
2 changed files with 69 additions and 36 deletions

View file

@ -5,17 +5,21 @@
pandora.ui.statisticsDialog = function() { pandora.ui.statisticsDialog = function() {
var colors = { var colors = {
firstseen: [64, 192, 64], system: {
lastseen: [64, 64, 192], 'Android': [0, 255, 0],
day: [64, 192, 192], 'iOS': [0, 128, 255],
hour: [64, 192, 192], 'Linux': [255, 128, 0],
continent: [64, 192, 64], 'Mac OS X': [0, 255, 255],
region: [64, 192, 192], 'Windows': [0, 0, 255]
country: [64, 64, 192], },
city: [192, 64, 64], browser: {
system: [64, 192, 64], 'Chrome Frame': [255, 255, 0],
browser: [64, 64, 192], 'Chrome': [0, 255, 0],
systemandbrowser: [64, 192, 192] 'Firefox': [255, 128, 8],
'Internet Explorer': [0, 0, 255],
'Opera': [255, 0, 0],
'Safari': [0, 255, 255]
}
}, },
dialogHeight = Math.round((window.innerHeight - 48) * 0.9), dialogHeight = Math.round((window.innerHeight - 48) * 0.9),
dialogWidth = Math.round(window.innerWidth * 0.9), dialogWidth = Math.round(window.innerWidth * 0.9),
@ -89,14 +93,14 @@ pandora.ui.statisticsDialog = function() {
$tabPanel; $tabPanel;
//Ox.getJSON('/static/json/deleteme.json', function(result) { Ox.getJSON('/static/json/deleteme.json', function(result) {
///* /*
pandora.api.findUsers({ pandora.api.findUsers({
keys: ['browser', 'email', 'firstseen', 'lastseen', 'level', 'location', 'system'], keys: ['browser', 'email', 'firstseen', 'lastseen', 'level', 'location', 'system'],
range: [0, 1000000], range: [0, 1000000],
sort: [{key: 'username', operator: '+'}] sort: [{key: 'username', operator: '+'}]
}, function(result) { }, function(result) {
//*/ */
var data = {}, var data = {},
flagCountry = {}, flagCountry = {},
@ -129,9 +133,11 @@ pandora.ui.statisticsDialog = function() {
month = item[key].substr(0, 7) + '-' + key, month = item[key].substr(0, 7) + '-' + key,
day = Ox.formatDate(item[key], '%u'), day = Ox.formatDate(item[key], '%u'),
hour = item[key].substr(11, 2); hour = item[key].substr(11, 2);
data[mode].year[year] = (data[mode].year[year] || 0) + 1; data[mode].year[year] = data[mode].year[year] || {};
data[mode].year[year][month] = (data[mode].year[year][month] || 0) + 1;
data[mode].month[month] = (data[mode].month[month] || 0) + 1; data[mode].month[month] = (data[mode].month[month] || 0) + 1;
data[mode].day[day] = (data[mode].day[day] || 0) + 1; data[mode].day[day] = data[mode].day[day] || {};
data[mode].day[day][hour] = (data[mode].day[day][hour] || 0) + 1;
data[mode].hour[hour] = (data[mode].hour[hour] || 0) + 1; data[mode].hour[hour] = (data[mode].hour[hour] || 0) + 1;
}); });
if (!item.location) { if (!item.location) {
@ -271,11 +277,14 @@ pandora.ui.statisticsDialog = function() {
['year', 'month', 'day', 'hour'].forEach(function(key) { ['year', 'month', 'day', 'hour'].forEach(function(key) {
var isYearOrMonth = ['year', 'month'].indexOf(key) > -1; var isYearOrMonth = ['year', 'month'].indexOf(key) > -1;
Ox.Chart({ Ox.Chart({
color: isYearOrMonth color: function(value) {
? function(value) { var split = value.split('-');
return colors[value.split('-').pop()]; return isYearOrMonth ? Ox.rgb(
} Ox.mod(8 - parseInt(split[1], 10), 12) * 30, 1, 0.5
: colors[key], ).map(Math.round) : Ox.rgb(
(Math.abs(11.5 - parseInt(split[0], 10)) - 0.5) * -11, 1, 0.5
).map(Math.round);
},
data: data[mode][key], data: data[mode][key],
formatKey: function(value) { formatKey: function(value) {
var ret, split; var ret, split;
@ -309,7 +318,11 @@ pandora.ui.statisticsDialog = function() {
} else if (id == 'locations') { } else if (id == 'locations') {
['continent', 'region', 'country', 'city'].forEach(function(key) { ['continent', 'region', 'country', 'city'].forEach(function(key) {
Ox.Chart({ Ox.Chart({
color: colors[key], color: function(value) {
return Ox.getGeoColor(
key == 'continent' ? value : value.split(', ')[1]
);
},
data: data[mode][key], data: data[mode][key],
formatKey: function(value) { formatKey: function(value) {
var city, country, split = value.split(', '); var city, country, split = value.split(', ');
@ -343,7 +356,7 @@ pandora.ui.statisticsDialog = function() {
Ox.map(Ox.COUNTRIES, function(country) { Ox.map(Ox.COUNTRIES, function(country) {
return country[key] == split[key == 'continent' ? 0 : 1] return country[key] == split[key == 'continent' ? 0 : 1]
&& country.code.length == 2 && country.code.length == 2
&& ['EU', 'UK'].indexOf(country.code) == -1 && ['AC', 'CP', 'DG', 'EA', 'EU', 'IC', 'TA', 'UK'].indexOf(country.code) == -1
&& !country.disputed && !country.disputed
&& !country.dissolved && !country.dissolved
? country.name : null; ? country.name : null;
@ -390,7 +403,18 @@ pandora.ui.statisticsDialog = function() {
['', 'version'].forEach(function(version, i) { ['', 'version'].forEach(function(version, i) {
['system', 'browser'].forEach(function(key) { ['system', 'browser'].forEach(function(key) {
Ox.Chart({ Ox.Chart({
color: colors[key], color: function(value) {
var name = value;
if (version) {
Ox.forEach(names[key], function(v) {
if (new RegExp('^' + v).test(value)) {
name = v;
return false;
}
});
}
return colors[key][name];
},
data: data[mode][key + version], data: data[mode][key + version],
formatKey: function(value) { formatKey: function(value) {
var index, var index,
@ -457,7 +481,13 @@ pandora.ui.statisticsDialog = function() {
}); });
if (i == 0) { if (i == 0) {
Ox.Chart({ Ox.Chart({
color: [64, 192, 192], color: function(value) {
return Ox.zip(value.split(' / ').map(function(v, i) {
return colors[i == 0 ? 'system' : 'browser'][v];
})).map(function(c) {
return Math.round(Ox.sum(c) / 2);
})
},
data: data[mode].systemandbrowser, data: data[mode].systemandbrowser,
formatKey: function(value) { formatKey: function(value) {
var $element = $('<div>') var $element = $('<div>')

View file

@ -136,11 +136,8 @@ pandora.ui.usersDialog = function() {
{ {
align: 'center', align: 'center',
format: function(value, data) { format: function(value, data) {
var userLevel = data.useragent.indexOf('Googlebot') > -1
|| data.useragent.indexOf('BingPreview') > -1
? 'Robot' : Ox.toTitleCase(value);
return Ox.Theme.formatColorLevel( return Ox.Theme.formatColorLevel(
userLevels.indexOf(userLevel), userLevels.indexOf(Ox.toTitleCase(value)),
userLevels, userLevels,
[0, 300] [0, 300]
); );
@ -349,7 +346,10 @@ pandora.ui.usersDialog = function() {
items: function(data, callback) { items: function(data, callback) {
pandora.api.findUsers(Ox.extend(data, { pandora.api.findUsers(Ox.extend(data, {
query: { query: {
conditions: [{key: 'level', value: 'guest', operator: '!='}], conditions: [
{key: 'level', value: 'guest', operator: '!='},
{key: 'level', value: 'robot', operator: '!='}
],
operator: '&' operator: '&'
} }
}), callback); }), callback);
@ -582,7 +582,7 @@ pandora.ui.usersDialog = function() {
return $list.options('selected').map(function(id) { return $list.options('selected').map(function(id) {
return $list.value(id); return $list.value(id);
}).filter(function(user) { }).filter(function(user) {
return user.level != 'guest' && ( return ['guest', 'robot'].indexOf(user.level) == -1 && (
$mailForm.values().include == 'users' || user.newsletter $mailForm.values().include == 'users' || user.newsletter
); );
}).map(function(user) { }).map(function(user) {
@ -805,7 +805,7 @@ pandora.ui.usersDialog = function() {
if (data.value == 'edit') { if (data.value == 'edit') {
$mailForm.detach(); $mailForm.detach();
selected = $list.options('selected'); selected = $list.options('selected');
if (selected.length == 1 && selected[0].level != 'guest') { if (selected.length == 1 && ['guest', 'robot'].indexOf(selected[0].level) == -1) {
$form.append($editForm = renderEditForm()); $form.append($editForm = renderEditForm());
} }
} else { } else {
@ -825,7 +825,7 @@ pandora.ui.usersDialog = function() {
if ($formButton.value() == 'edit') { if ($formButton.value() == 'edit') {
$form.empty(); $form.empty();
if (data.ids.length == 1) { if (data.ids.length == 1) {
if (users[0].level != 'guest') { if (['guest', 'robot'].indexOf(users[0].level) == -1) {
$form.append($editForm = renderEditForm()); $form.append($editForm = renderEditForm());
} }
} }
@ -898,8 +898,8 @@ pandora.ui.usersDialog = function() {
}), }),
title = users.length == 0 ? 'No user selected' title = users.length == 0 ? 'No user selected'
: users.length == 1 ? ( : users.length == 1 ? (
users[0].level == 'guest' ['guest', 'robot'].indexOf(users[0].level) > -1
? 'Guest' ? Ox.toTitleCase(users[0].level)
: Ox.encodeHTMLEntities(users[0].username) : Ox.encodeHTMLEntities(users[0].username)
+ ' &lt;' + users[0].email + '&gt;' + ' &lt;' + users[0].email + '&gt;'
) )
@ -944,7 +944,10 @@ pandora.ui.usersDialog = function() {
key != 'email' ? [{key: 'username', value: value, operator: '='}] : [], key != 'email' ? [{key: 'username', value: value, operator: '='}] : [],
key != 'username' ? [{key: 'email', value: value, operator: '='}] : [] key != 'username' ? [{key: 'email', value: value, operator: '='}] : []
) )
: !guests ? [{key: 'level', value: 'guest', operator: '!='}] : [], : !guests ? [
{key: 'level', value: 'guest', operator: '!='},
{key: 'level', value: 'robot', operator: '!='}
] : [],
operator: key == 'all' && value ? '|' : '&' operator: key == 'all' && value ? '|' : '&'
}; };
$list.options({ $list.options({