Add first_seen to user ips and add title attr with full date/time

This commit is contained in:
Sam Edwards 2020-07-11 15:23:26 -07:00
parent 40ecf56904
commit 63656b73c2
No known key found for this signature in database
GPG key ID: 7E45576E3D00CD64
5 changed files with 48 additions and 12 deletions

5
API.md
View file

@ -2267,8 +2267,8 @@ Required parameters:
user_id (str): The id of the Plex user user_id (str): The id of the Plex user
Optional parameters: Optional parameters:
order_column (str): "last_seen", "ip_address", "platform", "player", order_column (str): "last_seen", "first_seen", "ip_address", "platform",
"last_played", "play_count" "player", "last_played", "play_count"
order_dir (str): "desc" or "asc" order_dir (str): "desc" or "asc"
start (int): Row to start from, 0 start (int): Row to start from, 0
length (int): Number of items to return, 25 length (int): Number of items to return, 25
@ -2286,6 +2286,7 @@ Returns:
"ip_address": "xxx.xxx.xxx.xxx", "ip_address": "xxx.xxx.xxx.xxx",
"last_played": "Game of Thrones - The Red Woman", "last_played": "Game of Thrones - The Red Woman",
"last_seen": 1462591869, "last_seen": 1462591869,
"first_seen": 1583968210,
"live": 0, "live": 0,
"media_index": 1, "media_index": 1,
"media_type": "episode", "media_type": "episode",

View file

@ -1,3 +1,25 @@
var date_format = 'YYYY-MM-DD';
var time_format = 'hh:mm a';
$.ajax({
url: 'get_date_formats',
type: 'GET',
success: function(data) {
date_format = data.date_format;
time_format = data.time_format;
}
});
var seenRender = function (data, type, full) {
return moment(data, "X").fromNow();
};
var seenCreatedCell = function (td, cellData, rowData, row, col) {
if (cellData !== null) {
$(td).attr('title', moment(cellData, "X").format(date_format + ' ' + time_format));
}
};
user_ip_table_options = { user_ip_table_options = {
"destroy": true, "destroy": true,
"language": { "language": {
@ -21,16 +43,24 @@ user_ip_table_options = {
"columnDefs": [ "columnDefs": [
{ {
"targets": [0], "targets": [0],
"data":"last_seen", "data": "last_seen",
"render": function ( data, type, full ) { "render": seenRender,
return moment(data, "X").fromNow(); "createdCell": seenCreatedCell,
},
"searchable": false, "searchable": false,
"width": "15%", "width": "15%",
"className": "no-wrap" "className": "no-wrap"
}, },
{ {
"targets": [1], "targets": [1],
"data": "first_seen",
"render": seenRender,
"createdCell": seenCreatedCell,
"searchable": false,
"width": "15%",
"className": "no-wrap"
},
{
"targets": [2],
"data": "ip_address", "data": "ip_address",
"createdCell": function (td, cellData, rowData, row, col) { "createdCell": function (td, cellData, rowData, row, col) {
if (cellData) { if (cellData) {
@ -48,7 +78,7 @@ user_ip_table_options = {
"className": "no-wrap modal-control-ip" "className": "no-wrap modal-control-ip"
}, },
{ {
"targets": [2], "targets": [3],
"data": "platform", "data": "platform",
"createdCell": function (td, cellData, rowData, row, col) { "createdCell": function (td, cellData, rowData, row, col) {
if (cellData !== '') { if (cellData !== '') {
@ -59,7 +89,7 @@ user_ip_table_options = {
"className": "no-wrap" "className": "no-wrap"
}, },
{ {
"targets": [3], "targets": [4],
"data": "player", "data": "player",
"createdCell": function (td, cellData, rowData, row, col) { "createdCell": function (td, cellData, rowData, row, col) {
if (cellData !== '') { if (cellData !== '') {
@ -78,7 +108,7 @@ user_ip_table_options = {
"className": "no-wrap modal-control" "className": "no-wrap modal-control"
}, },
{ {
"targets": [4], "targets": [5],
"data": "last_played", "data": "last_played",
"createdCell": function (td, cellData, rowData, row, col) { "createdCell": function (td, cellData, rowData, row, col) {
if (cellData !== '') { if (cellData !== '') {
@ -119,7 +149,7 @@ user_ip_table_options = {
"className": "datatable-wrap" "className": "datatable-wrap"
}, },
{ {
"targets": [5], "targets": [6],
"data": "play_count", "data": "play_count",
"searchable": false, "searchable": false,
"width": "10%", "width": "10%",

View file

@ -285,6 +285,7 @@ DOCUMENTATION :: END
<thead> <thead>
<tr> <tr>
<th align="left" id="last_seen">Last Streamed</th> <th align="left" id="last_seen">Last Streamed</th>
<th align="left" id="first_seen">First Streamed</th>
<th align="left" id="ip_address">IP Address</th> <th align="left" id="ip_address">IP Address</th>
<th align="left" id="platform">Last Platform</th> <th align="left" id="platform">Last Platform</th>
<th align="left" id="player">Last Player</th> <th align="left" id="player">Last Player</th>

View file

@ -246,6 +246,7 @@ class Users(object):
columns = ['session_history.id AS history_row_id', columns = ['session_history.id AS history_row_id',
'MAX(session_history.started) AS last_seen', 'MAX(session_history.started) AS last_seen',
'MIN(session_history.started) AS first_seen',
'session_history.ip_address', 'session_history.ip_address',
'COUNT(session_history.id) AS play_count', 'COUNT(session_history.id) AS play_count',
'session_history.platform', 'session_history.platform',
@ -306,6 +307,7 @@ class Users(object):
row = {'history_row_id': item['history_row_id'], row = {'history_row_id': item['history_row_id'],
'last_seen': item['last_seen'], 'last_seen': item['last_seen'],
'first_seen': item['first_seen'],
'ip_address': item['ip_address'], 'ip_address': item['ip_address'],
'play_count': item['play_count'], 'play_count': item['play_count'],
'platform': platform, 'platform': platform,

View file

@ -1378,8 +1378,8 @@ class WebInterface(object):
user_id (str): The id of the Plex user user_id (str): The id of the Plex user
Optional parameters: Optional parameters:
order_column (str): "last_seen", "ip_address", "platform", "player", order_column (str): "last_seen", "first_seen", "ip_address", "platform",
"last_played", "play_count" "player", "last_played", "play_count"
order_dir (str): "desc" or "asc" order_dir (str): "desc" or "asc"
start (int): Row to start from, 0 start (int): Row to start from, 0
length (int): Number of items to return, 25 length (int): Number of items to return, 25
@ -1397,6 +1397,7 @@ class WebInterface(object):
"ip_address": "xxx.xxx.xxx.xxx", "ip_address": "xxx.xxx.xxx.xxx",
"last_played": "Game of Thrones - The Red Woman", "last_played": "Game of Thrones - The Red Woman",
"last_seen": 1462591869, "last_seen": 1462591869,
"first_seen": 1583968210,
"live": 0, "live": 0,
"media_index": 1, "media_index": 1,
"media_type": "episode", "media_type": "episode",
@ -1423,6 +1424,7 @@ class WebInterface(object):
if not kwargs.get('json_data'): if not kwargs.get('json_data'):
# TODO: Find some one way to automatically get the columns # TODO: Find some one way to automatically get the columns
dt_columns = [("last_seen", True, False), dt_columns = [("last_seen", True, False),
("first_seen", True, False),
("ip_address", True, True), ("ip_address", True, True),
("platform", True, True), ("platform", True, True),
("player", True, True), ("player", True, True),