From c02b7a00791d8686036874161c017780903b0f2b Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 4 Aug 2015 01:06:56 +0200 Subject: [PATCH] Fix the way the IP address modal works. Allow IP address info modal on history page. Some minor styling changes to improve layout of settings on mobile. --- data/interfaces/default/history.html | 2 + data/interfaces/default/ip_address_modal.html | 69 +++++++++++++++++++ .../default/js/tables/history_table.js | 54 ++++++++++++--- data/interfaces/default/js/tables/user_ips.js | 19 ++--- data/interfaces/default/settings.html | 34 ++++----- data/interfaces/default/user.html | 30 -------- plexpy/webserve.py | 11 +++ 7 files changed, 148 insertions(+), 71 deletions(-) create mode 100644 data/interfaces/default/ip_address_modal.html diff --git a/data/interfaces/default/history.html b/data/interfaces/default/history.html index 0f1f559a..69ccfdcf 100644 --- a/data/interfaces/default/history.html +++ b/data/interfaces/default/history.html @@ -37,6 +37,8 @@ + diff --git a/data/interfaces/default/ip_address_modal.html b/data/interfaces/default/ip_address_modal.html new file mode 100644 index 00000000..de95651a --- /dev/null +++ b/data/interfaces/default/ip_address_modal.html @@ -0,0 +1,69 @@ + + +% if data: + +% endif \ No newline at end of file diff --git a/data/interfaces/default/js/tables/history_table.js b/data/interfaces/default/js/tables/history_table.js index 9aa208db..aa05ef9a 100644 --- a/data/interfaces/default/js/tables/history_table.js +++ b/data/interfaces/default/js/tables/history_table.js @@ -32,7 +32,6 @@ history_table_options = { "data":"date", "createdCell": function (td, cellData, rowData, row, col) { if (rowData['stopped'] === null) { - $(td).addClass('currentlyWatching'); $(td).html('Currently watching...'); } else { $(td).html(moment(cellData,"X").format(date_format)); @@ -71,11 +70,21 @@ history_table_options = { "targets": [3], "data":"ip_address", "createdCell": function (td, cellData, rowData, row, col) { - if ((cellData == '') || (cellData == '0')) { + if (cellData) { + if (isPrivateIP(cellData)) { + if (cellData != '') { + $(td).html(cellData); + } else { + $(td).html('n/a'); + } + } else { + $(td).html(' ' + cellData +''); + } + } else { $(td).html('n/a'); } }, - "className": "no-wrap hidden-xs" + "className": "no-wrap hidden-xs modal-control-ip" }, { "targets": [4], @@ -99,8 +108,12 @@ history_table_options = { { "targets": [5], "data":"started", - "render": function ( data, type, full ) { - return moment(data, "X").format(time_format); + "createdCell": function (td, cellData, rowData, row, col) { + if (cellData === null) { + $(td).html('n/a'); + } else { + $(td).html(moment(cellData,"X").format(time_format)); + } }, "searchable": false, "className": "no-wrap hidden-sm hidden-xs" @@ -121,11 +134,11 @@ history_table_options = { { "targets": [7], "data":"stopped", - "render": function ( data, type, full ) { - if (data !== null) { - return moment(data, "X").format(time_format); + "createdCell": function (td, cellData, rowData, row, col) { + if (cellData === null) { + $(td).html('n/a'); } else { - return data; + $(td).html(moment(cellData,"X").format(time_format)); } }, "searchable": false, @@ -193,4 +206,27 @@ $('#history_table').on('click', 'td.modal-control', function () { }); } showStreamDetails(); +}); + +$('#history_table').on('click', 'td.modal-control-ip', function () { + var tr = $(this).parents('tr'); + var row = history_table.row( tr ); + var rowData = row.data(); + + function getUserLocation(ip_address) { + if (isPrivateIP(ip_address)) { + return "n/a" + } else { + $.ajax({ + url: 'get_ip_address_details', + data: {ip_address: ip_address}, + async: true, + complete: function(xhr, status) { + $("#ip-info-modal").html(xhr.responseText); + } + }); + } + } + + getUserLocation(rowData['ip_address']); }); \ No newline at end of file diff --git a/data/interfaces/default/js/tables/user_ips.js b/data/interfaces/default/js/tables/user_ips.js index 17eff8cb..7321e1b3 100644 --- a/data/interfaces/default/js/tables/user_ips.js +++ b/data/interfaces/default/js/tables/user_ips.js @@ -92,22 +92,11 @@ $('#user_ip_table').on('click', 'td.modal-control', function () { return "n/a" } else { $.ajax({ - url: 'http://ip-api.com/json/' + ip_address, - cache: true, + url: 'get_ip_address_details', + data: {ip_address: ip_address}, async: true, - type: 'GET', - dataType: 'json', - success: function(data) { - $('#modal_header_ip_address').html(ip_address); - $('#country').html(data.country); - $('#city').html(data.city); - $('#region').html(data.regionName); - $('#timezone').html(data.timezone); - $('#lat').html(data.lat); - $('#lon').html(data.lon); - $('#isp').html(data.isp); - $('#org').html(data.org); - $('#as').html(data.as); + complete: function(xhr, status) { + $("#ip-info-modal").html(xhr.responseText); } }); } diff --git a/data/interfaces/default/settings.html b/data/interfaces/default/settings.html index 7f7c43aa..1e6f57af 100644 --- a/data/interfaces/default/settings.html +++ b/data/interfaces/default/settings.html @@ -64,7 +64,7 @@ available_notification_agents = notifiers.available_notification_agents()
-
+
@@ -73,7 +73,7 @@ available_notification_agents = notifiers.available_notification_agents()
-
+
@@ -89,7 +89,7 @@ available_notification_agents = notifiers.available_notification_agents()
-
+
@@ -98,7 +98,7 @@ available_notification_agents = notifiers.available_notification_agents()
-
+
@@ -138,7 +138,7 @@ available_notification_agents = notifiers.available_notification_agents()
-
+
@@ -147,7 +147,7 @@ available_notification_agents = notifiers.available_notification_agents()
-
+
@@ -167,7 +167,7 @@ available_notification_agents = notifiers.available_notification_agents()
-
+
@@ -189,7 +189,7 @@ available_notification_agents = notifiers.available_notification_agents()
-
+
@@ -199,7 +199,7 @@ available_notification_agents = notifiers.available_notification_agents()
-
+
@@ -229,7 +229,7 @@ available_notification_agents = notifiers.available_notification_agents()
-
+
@@ -247,7 +247,7 @@ available_notification_agents = notifiers.available_notification_agents()
-
+
@@ -281,7 +281,7 @@ available_notification_agents = notifiers.available_notification_agents()
-
+
@@ -304,7 +304,7 @@ available_notification_agents = notifiers.available_notification_agents()
-
+
@@ -323,7 +323,7 @@ available_notification_agents = notifiers.available_notification_agents()
-
+
@@ -374,7 +374,7 @@ available_notification_agents = notifiers.available_notification_agents()
-
+
@@ -624,7 +624,7 @@ available_notification_agents = notifiers.available_notification_agents()
-
+
@@ -633,7 +633,7 @@ available_notification_agents = notifiers.available_notification_agents()
-
+
diff --git a/data/interfaces/default/user.html b/data/interfaces/default/user.html index c5f1c0c8..45c34cd2 100644 --- a/data/interfaces/default/user.html +++ b/data/interfaces/default/user.html @@ -127,36 +127,6 @@ from plexpy import helpers
diff --git a/plexpy/webserve.py b/plexpy/webserve.py index 726ee1bb..dde61268 100644 --- a/plexpy/webserve.py +++ b/plexpy/webserve.py @@ -208,6 +208,17 @@ class WebInterface(object): return serve_template(templatename="stream_data.html", title="Stream Data", data=stream_data, user=user) + @cherrypy.expose + def get_ip_address_details(self, ip_address=None, **kwargs): + import socket + + try: + socket.inet_aton(ip_address) + except socket.error: + ip_address = None + + return serve_template(templatename="ip_address_modal.html", title="IP Address Details", data=ip_address) + @cherrypy.expose def get_user_list(self, **kwargs):