Respect group history setting in graphs

This commit is contained in:
JonnyWong16 2018-02-18 11:04:31 -08:00
parent 07092e8aa5
commit 836c4293d6
4 changed files with 46 additions and 16 deletions

View file

@ -359,11 +359,13 @@ table.display tr.shown + tr:hover {
} }
table.display tr.shown + tr:hover a, table.display tr.shown + tr:hover a,
table.display tr.shown + tr td:hover a, table.display tr.shown + tr td:hover a,
table.display tr.shown + tr td:hover a .fa,
table.display tr.shown + tr .pagination > .active > a, table.display tr.shown + tr .pagination > .active > a,
table.display tr.shown + tr .pagination > .active > a:hover { table.display tr.shown + tr .pagination > .active > a:hover {
color: #fff; color: #fff;
} }
table.display tr.shown + tr table[id^='history_child'] td:hover a, table.display tr.shown + tr table[id^='history_child'] td:hover a,
table.display tr.shown + tr table[id^='history_child'] td:hover a .fa,
table.display tr.shown + tr table[id^='media_info_child'] > tr > td:hover a, table.display tr.shown + tr table[id^='media_info_child'] > tr > td:hover a,
table.display tr.shown + tr table[id^='media_info_child'] tr.shown + tr table[id^='media_info_child'] td:hover a { table.display tr.shown + tr table[id^='media_info_child'] tr.shown + tr table[id^='media_info_child'] td:hover a {
color: #cc7b19; color: #cc7b19;

View file

@ -5,7 +5,15 @@
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-remove"></i></button> <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-remove"></i></button>
<h4 class="modal-title" id="myModalLabel"> <h4 class="modal-title" id="myModalLabel">
<strong><span id="modal_header_ip_address"> <strong><span id="modal_header_ip_address">
% if data.get('media_type'):
<% h = {'episode': 'TV Show', 'track': 'Music'} %>
<i class="fa fa-history"></i> ${h.get(data['media_type'], data['media_type'].title())} History for <span id="date-header">${data['start_date']}</span>
% elif data.get('transcode_decision'):
<% h = {'copy': 'Direct Stream'} %>
<i class="fa fa-history"></i> ${h.get(data['transcode_decision'], data['transcode_decision'].title())} History for <span id="date-header">${data['start_date']}</span>
% else:
<i class="fa fa-history"></i> History for <span id="date-header">${data['start_date']}</span> <i class="fa fa-history"></i> History for <span id="date-header">${data['start_date']}</span>
% endif
</span></strong> </span></strong>
</h4> </h4>
</div> </div>
@ -13,11 +21,18 @@
<table class="display history_table" id="history_table_modal" width="100%"> <table class="display history_table" id="history_table_modal" width="100%">
<thead> <thead>
<tr> <tr>
<th align="left" id="started">Started</th> <th align="left" id="delete_row">Delete</th>
<th align="left" id="stopped">Stopped</th> <th align="left" id="date">Date</th>
<th align="left" id="friendly_name">User</th> <th align="left" id="friendly_name">User</th>
<th align="left" id="player">Player</th> <th align="left" id="ip_address">IP Address</th>
<th align="left" id="platform">Platform</th>
<th align="left" id="device">Player</th>
<th align="left" id="title">Title</th> <th align="left" id="title">Title</th>
<th align="left" id="started">Started</th>
<th align="left" id="paused_counter">Paused</th>
<th align="left" id="stopped">Stopped</th>
<th align="left" id="duration">Duration</th>
<th align="left" id="percent_complete"></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -28,28 +43,31 @@
</div> </div>
</div> </div>
<script src="${http_root}js/tables/history_table_modal.js${cache_param}"></script> <script src="${http_root}js/tables/history_table.js${cache_param}"></script>
<script> <script>
$(document).ready(function() { $(document).ready(function() {
$('#date-header').html(moment('${data["start_date"]}','YYYY-MM-DD').format('ddd MMM Do YYYY')); $('#date-header').html(moment('${data["start_date"]}','YYYY-MM-DD').format('ddd MMM Do YYYY'));
history_table_modal_options.ajax = { history_table_options.ajax = {
url: 'get_history', url: 'get_history',
type: 'post',
data: function ( d ) { data: function ( d ) {
return { return {
json_data: JSON.stringify(d), json_data: JSON.stringify(d),
grouping: false,
user_id: "${data['user_id']}", user_id: "${data['user_id']}",
start_date: "${data['start_date']}", start_date: "${data['start_date']}",
media_type: "${data.get('media_type')}", media_type: "${data.get('media_type')}",
transcode_decision: "${data.get('transcode_decision')}" transcode_decision: "${data.get('transcode_decision')}"
}; };
} }
} };
history_table = $('#history_table_modal').DataTable(history_table_options);
history_table.columns([0, 3, 4, 8, 10, 11]).visible(false);
history_table = $('#history_table_modal').DataTable(history_table_modal_options);
clearSearchButton('history_table_modal', history_table); clearSearchButton('history_table_modal', history_table);
$('#history-modal').on('shown.bs.modal', function() {
history_table.columns.adjust().draw();
});
}); });
</script> </script>
% else: % else:

View file

@ -27,7 +27,7 @@ class Graphs(object):
def __init__(self): def __init__(self):
pass pass
def get_total_plays_per_day(self, time_range='30', y_axis='plays', user_id=None): def get_total_plays_per_day(self, time_range='30', y_axis='plays', user_id=None, grouping=None):
monitor_db = database.MonitorDatabase() monitor_db = database.MonitorDatabase()
if not time_range.isdigit(): if not time_range.isdigit():
@ -38,17 +38,22 @@ class Graphs(object):
user_cond = 'AND session_history.user_id = %s ' % session.get_session_user_id() user_cond = 'AND session_history.user_id = %s ' % session.get_session_user_id()
elif user_id and user_id.isdigit(): elif user_id and user_id.isdigit():
user_cond = 'AND session_history.user_id = %s ' % user_id user_cond = 'AND session_history.user_id = %s ' % user_id
if grouping is None:
grouping = plexpy.CONFIG.GROUP_HISTORY_TABLES
group_by = 'reference_id' if grouping else 'id'
try: try:
if y_axis == 'plays': if y_axis == 'plays':
query = 'SELECT date(started, "unixepoch", "localtime") AS date_played, ' \ query = 'SELECT date(started, "unixepoch", "localtime") AS date_played, ' \
'SUM(CASE WHEN media_type = "episode" THEN 1 ELSE 0 END) AS tv_count, ' \ 'SUM(CASE WHEN media_type = "episode" THEN 1 ELSE 0 END) AS tv_count, ' \
'SUM(CASE WHEN media_type = "movie" THEN 1 ELSE 0 END) AS movie_count, ' \ 'SUM(CASE WHEN media_type = "movie" THEN 1 ELSE 0 END) AS movie_count, ' \
'SUM(CASE WHEN media_type = "track" THEN 1 ELSE 0 END) AS music_count ' \ 'SUM(CASE WHEN media_type = "track" THEN 1 ELSE 0 END) AS music_count ' \
'FROM session_history ' \ 'FROM (SELECT * FROM session_history GROUP BY %s) ' \
'WHERE datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") %s' \ 'WHERE datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") %s' \
'GROUP BY date_played ' \ 'GROUP BY date_played ' \
'ORDER BY started ASC' % (time_range, user_cond) 'ORDER BY started ASC' % (group_by, time_range, user_cond)
result = monitor_db.select(query) result = monitor_db.select(query)
else: else:

View file

@ -1799,7 +1799,7 @@ class WebInterface(object):
@cherrypy.tools.json_out() @cherrypy.tools.json_out()
@requireAuth() @requireAuth()
@addtoapi() @addtoapi()
def get_plays_by_date(self, time_range='30', user_id=None, y_axis='plays', **kwargs): def get_plays_by_date(self, time_range='30', user_id=None, y_axis='plays', grouping=None, **kwargs):
""" Get graph data by date. """ Get graph data by date.
``` ```
@ -1823,8 +1823,13 @@ class WebInterface(object):
} }
``` ```
""" """
if grouping and str(grouping).isdigit():
grouping = int(grouping)
elif grouping == 'false':
grouping = 0
graph = graphs.Graphs() graph = graphs.Graphs()
result = graph.get_total_plays_per_day(time_range=time_range, user_id=user_id, y_axis=y_axis) result = graph.get_total_plays_per_day(time_range=time_range, user_id=user_id, y_axis=y_axis, grouping=grouping)
if result: if result:
return result return result