Add platform stats to user page

Re-add user gravatars
Some error catching
Some code clean-up
This commit is contained in:
Tim 2015-06-21 17:19:19 +02:00
commit 9364b06c99
12 changed files with 275 additions and 76 deletions

View file

@ -7635,6 +7635,7 @@ button.close {
}
.user-info-poster-face img {
bottom: 0;
margin-right: 15px;
overflow: hidden;
float: left;
background-color: #323232;
@ -7651,12 +7652,11 @@ button.close {
color: #fff;
position: relative;
top: 27px;
left: 15px;
}
.user-info-nav {
position: relative;
top: 15px;
left: 3px;
left: -5px;
}
.user-info-nav > .active > a, .nav-tabs > .active > a:hover, .nav-tabs > .active > a:focus {
color: #F9AA03;

View file

@ -210,13 +210,17 @@ function getPlatformImagePath(platformName) {
}
function isPrivateIP(ip_address) {
var parts = ip_address.split('.');
if (parts[0] === '10' ||
(parts[0] === '172' && (parseInt(parts[1], 10) >= 16 && parseInt(parts[1], 10) <= 31)) ||
(parts[0] === '192' && parts[1] === '168')) {
if (ip_address.indexOf(".") > -1) {
var parts = ip_address.split('.');
if (parts[0] === '10' ||
(parts[0] === '172' && (parseInt(parts[1], 10) >= 16 && parseInt(parts[1], 10) <= 31)) ||
(parts[0] === '192' && parts[1] === '168')) {
return true;
}
return false;
} else {
return true;
}
return false;
}
function humanTime(seconds) {

View file

@ -32,7 +32,11 @@ user_ip_table_options = {
"className": "modal-control",
"createdCell": function (td, cellData, rowData, row, col) {
if (isPrivateIP(cellData)) {
$(td).html(cellData);
if (cellData != '') {
$(td).html(cellData);
} else {
$(td).html('n/a');
}
} else {
$(td).html('<a href="#ip-info-modal" data-toggle="modal"><span data-toggle="ip-tooltip" data-placement="left" title="IP Address Info" id="ip-info"><i class="icon-map-marker icon-white"></i></span>&nbsp' + cellData +'</a>');
}

View file

@ -25,13 +25,13 @@ users_list_table_options = {
"columnDefs": [
{
"targets": [0],
"data": null,
"data": "thumb",
"createdCell": function (td, cellData, rowData, row, col) {
//if (rowData['user_thumb'] === '') {
if (cellData === '') {
$(td).html('<img src="interfaces/default/images/gravatar-default-80x80.png" alt="User Logo"/>');
//} else {
// $(td).html('<img src="' + rowData['user_thumb'] + '" alt="User Logo"/>');
//}
} else {
$(td).html('<img src="' + cellData + '" alt="User Logo"/>');
}
},
"orderable": false,
"className": "users-poster-face",

View file

@ -13,7 +13,7 @@
<div class="row-fluid">
<div class="span12">
<div class="user-info-wrapper">
<div class="user-info-poster-face">
<div class="user-info-poster-face" id="user-gravatar">
<img src="interfaces/default/images/gravatar-default-80x80.png">
</div>
<div class="user-info-username">
@ -42,7 +42,7 @@
</div>
</div>
<div id="user-time-stats" class="user-overview-stats-wrapper">
<div id="user-stats-spinner" class="spinner"></div>
<div class='muted'><i class="fa fa-refresh fa-spin"></i> Loading data...</div><br>
</div>
</div>
</div>
@ -58,7 +58,7 @@
</div>
</div>
<div id="user-platform-stats" class="user-platforms">
<div id="user-platform-spinner" class="spinner"></div>
<div class='muted'><i class="fa fa-refresh fa-spin"></i> Loading data...</div><br>
</div>
</div>
</div>
@ -73,8 +73,8 @@
<h3>Recently watched</h3>
</div>
</div>
<div id="user-recently-watched" class="dashboard-recent-media-row">
<div id="user-watched-spinner" class="spinner"></div>
<div id="user-recently-watched">
<div class='muted'><i class="fa fa-refresh fa-spin"></i> Loading data...</div><br>
</div>
</div>
</div>
@ -88,7 +88,7 @@
<div class="wellbg">
<div class="wellheader">
<div class="dashboard-wellheader">
<h3>Public IP Addresses for <strong>
<h3>IP Addresses for <strong>
${user}
</strong></h3>
</div>
@ -190,6 +190,7 @@
<script>
$(document).ready(function () {
// Populate watch time stats
$.ajax({
url: 'get_user_watch_time_stats',
async: true,
@ -199,6 +200,17 @@
}
});
// Populate platform stats
$.ajax({
url: 'get_user_platform_stats',
async: true,
data: { user: '${user}' },
complete: function(xhr, status) {
$("#user-platform-stats").html(xhr.responseText);
}
});
// Populate recently watched
$.ajax({
url: 'get_user_recently_watched',
async: true,
@ -208,6 +220,7 @@
}
});
// Build watch history table
history_table_options.ajax = {
"url": "get_history",
"data": function(d) {
@ -217,6 +230,7 @@
history_table = $('#history_table').DataTable(history_table_options);
history_table.column(2).visible(false); // Hide the title column
// Build user IP table
user_ip_table_options.ajax = {
"url": "get_user_ips",
"data": function(d) {
@ -225,6 +239,18 @@
}
user_ip_table = $('#user_ip_table').DataTable(user_ip_table_options);
// Load user gravatar image
$.ajax({
url: 'get_user_gravatar_image',
async: true,
data: { user: '${user}' },
success: function(data) {
if (data.user_thumb !== '') {
thumb = data.user_thumb;
$('#user-gravatar').html('<img src="' + thumb + '">');
}
}
});
});
</script>
</%def>

View file

@ -0,0 +1,22 @@
% if platform_stats != None:
% for a in platform_stats:
<ul>
<div class="user-platforms-instance">
<li>
<span id="user-platform-image-${a['result_id']}"></span>
<div class="user-platforms-instance-name">
${a['platform_name']}
</div>
<div class="user-platforms-instance-playcount">
<h3>${a['total_plays']}</h3><p> plays</p>
</div>
</li>
</div>
</ul>
<script>
$("#user-platform-image-${a['result_id']}").html("<img class='user-platforms-instance-poster' src='" + getPlatformImagePath('${a['platform_type']}') + "'>");
</script>
% endfor
% else:
<div class="muted">There was an error loading your PlexWatch data. Please check your <a href="config">settings</a>.</div><br>
% endif

View file

@ -32,5 +32,5 @@
</ul>
</div>
% else:
<div class="muted">There was an error retrieving some data. Please check your <a href="config">settings</a>.</div><br>
<div class="muted">There was an error loading your PlexWatch data. Please check your <a href="config">settings</a>.</div><br>
% endif

View file

@ -9,7 +9,7 @@
% elif a['query_days'] == 1:
<h4>Last 24 hours</h4>
% else:
<h4>Last ${a['query_days']} day(s)</h4>
<h4>Last ${a['query_days']} days</h4>
% endif
<h3>${a['total_plays']}</h3><p>plays</p>
<span id="total-time-${a['query_days']}"></span>
@ -21,4 +21,6 @@
</script>
% endfor
</ul>
% else:
<div class="muted">There was an error loading your PlexWatch data. Please check your <a href="config">settings</a>.</div><br>
% endif