Add setting to selectively hide library statistics cards on the homepage

This commit is contained in:
Jonathan Wong 2015-09-18 23:42:16 -07:00
parent 8a989d71ca
commit 078f4babf5
5 changed files with 89 additions and 7 deletions

View file

@ -29,6 +29,7 @@
</div> </div>
</div> </div>
% endif % endif
% if config['home_library_cards'] > 'library_statistics':
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
<div class="padded-header" id="library-statistics-header"> <div class="padded-header" id="library-statistics-header">
@ -40,6 +41,7 @@
</div> </div>
</div> </div>
</div> </div>
% endif
<div class='row'> <div class='row'>
<div class="col-md-12"> <div class="col-md-12">
<div class="padded-header"> <div class="padded-header">

View file

@ -93,7 +93,7 @@ available_notification_agents = notifiers.available_notification_agents()
<div class="form-group"> <div class="form-group">
<label for="home_stats_cards">Cards</label> <label for="home_stats_cards">Cards</label>
<p class="help-block">Select the cards to show in the watch statistics on the home page.</p> <p class="help-block">Select the cards to show in the watch statistics on the home page. Select none to disable.</p>
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<select multiple class="form-control" id="home_stats_cards" name="home_stats_cards" data-parsley-trigger="change"> <select multiple class="form-control" id="home_stats_cards" name="home_stats_cards" data-parsley-trigger="change">
@ -137,7 +137,24 @@ available_notification_agents = notifiers.available_notification_agents()
</label> </label>
<p class="help-block">Use play duration instead of play count to generate statistics.</p> <p class="help-block">Use play duration instead of play count to generate statistics.</p>
</div> </div>
<div class="padded-header">
<h3>Library Statistics</h3>
</div>
<div class="form-group">
<label for="home_library_cards">Cards</label>
<p class="help-block">Select the cards to show in the library statistics on the home page. Select none to disable.</p>
<div class="row">
<div class="col-md-6">
<select multiple class="form-control" id="home_library_cards" name="home_library_cards" data-parsley-trigger="change">
<option id="card-library_statistics" value="library_statistics" class="hidden" selected>Library Statistics</option>
</select>
</div>
</div>
</div>
<p><input type="button" class="btn btn-bright save-button" value="Save" data-success="Changes saved successfully"></p> <p><input type="button" class="btn btn-bright save-button" value="Save" data-success="Changes saved successfully"></p>
</div> </div>
<div role="tabpanel" class="tab-pane" id="tabs-3"> <div role="tabpanel" class="tab-pane" id="tabs-3">
<div class="padded-header"> <div class="padded-header">
@ -1215,6 +1232,34 @@ $(document).ready(function() {
}).on('mousemove', function(e) { }).on('mousemove', function(e) {
e.preventDefault() e.preventDefault()
}); });
$.ajax({
url: 'get_server_children',
data: { },
async: true,
complete: function (xhr, status) {
server_children_info = $.parseJSON(xhr.responseText);
libraries_list = server_children_info.libraries_list;
for (var i in libraries_list) {
title = libraries_list[i].title;
key = libraries_list[i].key;
$('#home_library_cards').append('<option id="card-' + key + '" value="' + key + '">' + title + '</option>')
}
var cards = "${config['home_library_cards']}".split(/[\s,]+/);
cards.forEach(function (item) {
$('#card-'+item).prop('selected', !$(this).prop('selected'));
});
}
});
$('#home_library_cards').on('mousedown', function(e) {
e.preventDefault();
var scroll = this.scrollTop;
e.target.selected = !e.target.selected;
this.scrollTop = scroll;
}).on('mousemove', function(e) {
e.preventDefault()
});
}); });
</script> </script>
</%def> </%def>

View file

@ -82,10 +82,11 @@ _CONFIG_DEFINITIONS = {
'GROWL_ON_RESUME': (int, 'Growl', 0), 'GROWL_ON_RESUME': (int, 'Growl', 0),
'GROWL_ON_BUFFER': (int, 'Growl', 0), 'GROWL_ON_BUFFER': (int, 'Growl', 0),
'GROWL_ON_WATCHED': (int, 'Growl', 0), 'GROWL_ON_WATCHED': (int, 'Growl', 0),
'HOME_LIBRARY_CARDS': (str, 'General', 'library_statistics_first'),
'HOME_STATS_LENGTH': (int, 'General', 30), 'HOME_STATS_LENGTH': (int, 'General', 30),
'HOME_STATS_TYPE': (int, 'General', 0), 'HOME_STATS_TYPE': (int, 'General', 0),
'HOME_STATS_COUNT': (int, 'General', 5), 'HOME_STATS_COUNT': (int, 'General', 5),
'HOME_STATS_CARDS': (str, 'General', 'top_tv, popular_tv, top_movies, popular_movies, top_music, popular_music, top_users, top_platforms, last_watched'), 'HOME_STATS_CARDS': (str, 'General', 'watch_statistics_first'),
'HTTPS_CERT': (str, 'General', ''), 'HTTPS_CERT': (str, 'General', ''),
'HTTPS_KEY': (str, 'General', ''), 'HTTPS_KEY': (str, 'General', ''),
'HTTP_HOST': (str, 'General', '0.0.0.0'), 'HTTP_HOST': (str, 'General', '0.0.0.0'),

View file

@ -1270,13 +1270,15 @@ class PmsConnect(object):
return output return output
""" """
Return processed and validated server statistics. Return processed and validated library statistics.
Output: array Output: array
""" """
def get_library_stats(self): def get_library_stats(self, library_cards=''):
server_libraries = self.get_server_children() server_libraries = self.get_server_children()
library_keys = library_cards.split(', ')
server_library_stats = [] server_library_stats = []
if server_libraries['libraries_count'] != '0': if server_libraries['libraries_count'] != '0':
@ -1285,7 +1287,10 @@ class PmsConnect(object):
for library in libraries_list: for library in libraries_list:
library_type = library['type'] library_type = library['type']
section_key = library['key'] section_key = library['key']
if section_key in library_keys:
library_list = self.get_library_children(library_type, section_key) library_list = self.get_library_children(library_type, section_key)
else:
continue
if library_list['library_count'] != '0': if library_list['library_count'] != '0':
library_stats = {'title': library['title'], library_stats = {'title': library['title'],

View file

@ -67,6 +67,7 @@ class WebInterface(object):
config = { config = {
"home_stats_length": plexpy.CONFIG.HOME_STATS_LENGTH, "home_stats_length": plexpy.CONFIG.HOME_STATS_LENGTH,
"home_stats_cards": plexpy.CONFIG.HOME_STATS_CARDS, "home_stats_cards": plexpy.CONFIG.HOME_STATS_CARDS,
"home_library_cards": plexpy.CONFIG.HOME_LIBRARY_CARDS,
"pms_identifier": plexpy.CONFIG.PMS_IDENTIFIER "pms_identifier": plexpy.CONFIG.PMS_IDENTIFIER
} }
return serve_template(templatename="index.html", title="Home", config=config) return serve_template(templatename="index.html", title="Home", config=config)
@ -140,7 +141,10 @@ class WebInterface(object):
@cherrypy.expose @cherrypy.expose
def library_stats(self, **kwargs): def library_stats(self, **kwargs):
pms_connect = pmsconnect.PmsConnect() pms_connect = pmsconnect.PmsConnect()
stats_data = pms_connect.get_library_stats()
library_cards = plexpy.CONFIG.HOME_LIBRARY_CARDS
stats_data = pms_connect.get_library_stats(library_cards=library_cards)
return serve_template(templatename="library_stats.html", title="Library Stats", data=stats_data) return serve_template(templatename="library_stats.html", title="Library Stats", data=stats_data)
@ -479,6 +483,7 @@ class WebInterface(object):
"home_stats_type": checked(plexpy.CONFIG.HOME_STATS_TYPE), "home_stats_type": checked(plexpy.CONFIG.HOME_STATS_TYPE),
"home_stats_count": plexpy.CONFIG.HOME_STATS_COUNT, "home_stats_count": plexpy.CONFIG.HOME_STATS_COUNT,
"home_stats_cards": plexpy.CONFIG.HOME_STATS_CARDS, "home_stats_cards": plexpy.CONFIG.HOME_STATS_CARDS,
"home_library_cards": plexpy.CONFIG.HOME_LIBRARY_CARDS,
"buffer_threshold": plexpy.CONFIG.BUFFER_THRESHOLD, "buffer_threshold": plexpy.CONFIG.BUFFER_THRESHOLD,
"buffer_wait": plexpy.CONFIG.BUFFER_WAIT "buffer_wait": plexpy.CONFIG.BUFFER_WAIT
} }
@ -535,6 +540,10 @@ class WebInterface(object):
if kwargs['home_stats_cards'] != 'watch_statistics': if kwargs['home_stats_cards'] != 'watch_statistics':
kwargs['home_stats_cards'] = ', '.join(kwargs['home_stats_cards']) kwargs['home_stats_cards'] = ', '.join(kwargs['home_stats_cards'])
if 'home_library_cards' in kwargs:
if kwargs['home_library_cards'] != 'library_statistics':
kwargs['home_library_cards'] = ', '.join(kwargs['home_library_cards'])
plexpy.CONFIG.process_kwargs(kwargs) plexpy.CONFIG.process_kwargs(kwargs)
# Write the config # Write the config
@ -1132,6 +1141,26 @@ class WebInterface(object):
else: else:
logger.warn('Unable to retrieve data.') logger.warn('Unable to retrieve data.')
@cherrypy.expose
def get_server_children(self, **kwargs):
pms_connect = pmsconnect.PmsConnect()
result = pms_connect.get_server_children()
if plexpy.CONFIG.HOME_LIBRARY_CARDS == '':
library_keys = ['library_statistics']
for library in result['libraries_list']:
library_keys.append(library['key'])
plexpy.CONFIG.HOME_LIBRARY_CARDS = ', '.join(library_keys)
plexpy.CONFIG.write()
if result:
cherrypy.response.headers['Content-type'] = 'application/json'
return json.dumps(result)
else:
logger.warn('Unable to retrieve data.')
@cherrypy.expose @cherrypy.expose
def get_activity(self, **kwargs): def get_activity(self, **kwargs):