From 71131c699e811418265ef8611eba6dc3aab5edd4 Mon Sep 17 00:00:00 2001 From: JonnyWong16 Date: Tue, 9 Feb 2016 17:58:56 -0800 Subject: [PATCH] Add total duration to libraries and users tables --- data/interfaces/default/css/plexpy.css | 4 +++ data/interfaces/default/js/script.js | 29 +++++++++++++++---- .../interfaces/default/js/tables/libraries.js | 18 +++++++++++- data/interfaces/default/js/tables/users.js | 18 +++++++++++- data/interfaces/default/libraries.html | 6 ++++ data/interfaces/default/users.html | 6 ++++ plexpy/libraries.py | 4 +++ plexpy/users.py | 4 +++ 8 files changed, 82 insertions(+), 7 deletions(-) diff --git a/data/interfaces/default/css/plexpy.css b/data/interfaces/default/css/plexpy.css index 6c683f76..c271be54 100644 --- a/data/interfaces/default/css/plexpy.css +++ b/data/interfaces/default/css/plexpy.css @@ -2180,6 +2180,10 @@ a .home-platforms-instance-list-oval:hover, .refresh-libraries-button { float: right; } +.refresh-users-button, +.refresh-libraries-button { + margin-right: 5px; +} .nav-settings, .nav-settings ul { margin: 0px 0px 20px 0px; diff --git a/data/interfaces/default/js/script.js b/data/interfaces/default/js/script.js index 5d82f90c..1c416319 100644 --- a/data/interfaces/default/js/script.js +++ b/data/interfaces/default/js/script.js @@ -252,13 +252,13 @@ function isPrivateIP(ip_address) { function humanTime(seconds) { if (seconds >= 86400) { - text = '

' + Math.floor(moment.duration(seconds, 'seconds').asDays()) + - '

days

' + Math.floor(moment.duration((seconds % 86400), 'seconds').asHours()) + - '

hrs

' + Math.floor(moment.duration(((seconds % 86400) % 3600), 'seconds').asMinutes()) + '

mins

'; + text = '

' + Math.floor(moment.duration(seconds, 'seconds').asDays()) + '

days

' + + '

' + Math.floor(moment.duration((seconds % 86400), 'seconds').asHours()) + '

hrs

' + + '

' + Math.floor(moment.duration(((seconds % 86400) % 3600), 'seconds').asMinutes()) + '

mins

'; return text; } else if (seconds >= 3600) { - text = '

' + Math.floor(moment.duration((seconds % 86400), 'seconds').asHours()) + - '

hrs

' + Math.floor(moment.duration(((seconds % 86400) % 3600), 'seconds').asMinutes()) + '

mins

'; + text = '

' + Math.floor(moment.duration((seconds % 86400), 'seconds').asHours()) + '

hrs

' + + '

' + Math.floor(moment.duration(((seconds % 86400) % 3600), 'seconds').asMinutes()) + '

mins

'; return text; } else if (seconds >= 60) { text = '

' + Math.floor(moment.duration(((seconds % 86400) % 3600), 'seconds').asMinutes()) + '

mins

'; @@ -269,6 +269,25 @@ function humanTime(seconds) { } } +function humanTimeClean(seconds) { + if (seconds >= 86400) { + text = Math.floor(moment.duration(seconds, 'seconds').asDays()) + ' days ' + + Math.floor(moment.duration((seconds % 86400), 'seconds').asHours()) + ' hrs ' + + Math.floor(moment.duration(((seconds % 86400) % 3600), 'seconds').asMinutes()) + ' mins'; + return text; + } else if (seconds >= 3600) { + text = Math.floor(moment.duration((seconds % 86400), 'seconds').asHours()) + ' hrs ' + + Math.floor(moment.duration(((seconds % 86400) % 3600), 'seconds').asMinutes()) + ' mins'; + return text; + } else if (seconds >= 60) { + text = Math.floor(moment.duration(((seconds % 86400) % 3600), 'seconds').asMinutes()) + ' mins'; + return text; + } else { + text = '0'; + return text; + } +} + String.prototype.toProperCase = function () { return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); }; diff --git a/data/interfaces/default/js/tables/libraries.js b/data/interfaces/default/js/tables/libraries.js index 377295ae..46844506 100644 --- a/data/interfaces/default/js/tables/libraries.js +++ b/data/interfaces/default/js/tables/libraries.js @@ -161,12 +161,28 @@ libraries_list_table_options = { $(td).html('n/a'); } }, - "width": "25%", + "width": "18%", "className": "hidden-sm hidden-xs" }, { "targets": [9], "data": "plays", + "createdCell": function (td, cellData, rowData, row, col) { + if (cellData !== null && cellData !== '') { + $(td).html(cellData); + } + }, + "searchable": false, + "width": "7%" + }, + { + "targets": [10], + "data": "duration", + "createdCell": function (td, cellData, rowData, row, col) { + if (cellData !== null && cellData !== '') { + $(td).html(humanTimeClean(cellData)); + } + }, "searchable": false, "width": "10%" } diff --git a/data/interfaces/default/js/tables/users.js b/data/interfaces/default/js/tables/users.js index f7147a17..d1abb6c9 100644 --- a/data/interfaces/default/js/tables/users.js +++ b/data/interfaces/default/js/tables/users.js @@ -165,12 +165,28 @@ users_list_table_options = { $(td).html('n/a'); } }, - "width": "30%", + "width": "23%", "className": "hidden-sm hidden-xs" }, { "targets": [8], "data": "plays", + "createdCell": function (td, cellData, rowData, row, col) { + if (cellData !== null && cellData !== '') { + $(td).html(cellData); + } + }, + "searchable": false, + "width": "7%" + }, + { + "targets": [9], + "data": "duration", + "createdCell": function (td, cellData, rowData, row, col) { + if (cellData !== null && cellData !== '') { + $(td).html(humanTimeClean(cellData)); + } + }, "searchable": false, "width": "10%" } diff --git a/data/interfaces/default/libraries.html b/data/interfaces/default/libraries.html index 1e99697c..41fc9825 100644 --- a/data/interfaces/default/libraries.html +++ b/data/interfaces/default/libraries.html @@ -2,6 +2,7 @@ <%def name="headIncludes()"> + @@ -23,6 +24,7 @@ All Libraries
+ % if config['update_section_ids'] == -1: % else: @@ -48,6 +50,7 @@ Last Accessed Last Played Total Plays + Total Duration @@ -79,6 +82,7 @@ <%def name="javascriptIncludes()"> + @@ -96,6 +100,8 @@ } libraries_list_table = $('#libraries_list_table').DataTable(libraries_list_table_options); + var colvis = new $.fn.dataTable.ColVis(libraries_list_table, { buttonText: ' Select columns', buttonClass: 'btn btn-dark', exclude: [0, 1] }); + $(colvis.button()).appendTo('div.colvis-button-bar'); clearSearchButton('libraries_list_table', libraries_list_table); diff --git a/data/interfaces/default/users.html b/data/interfaces/default/users.html index 69c725a2..9b1a9dd1 100644 --- a/data/interfaces/default/users.html +++ b/data/interfaces/default/users.html @@ -2,6 +2,7 @@ <%def name="headIncludes()"> + @@ -12,6 +13,7 @@ All Users
+