Merge pull request #256 from JonnyWong16/miscellaneous-fixes

Miscellaneous fixes
This commit is contained in:
drzoidberg33 2015-10-20 13:15:49 +02:00
commit 1ef9d72534
7 changed files with 182 additions and 121 deletions

View file

@ -76,19 +76,50 @@
<script src="interfaces/default/js/moment-with-locale.js"></script>
<script src="interfaces/default/js/tables/history_table.js"></script>
<script>
$(document).ready(function() {
history_table_options.ajax = {
"url": "get_history",
type: "post",
data: function ( d ) {
return { 'json_data': JSON.stringify( d ) };
$(document).ready(function () {
function loadHistoryTable(media_type) {
history_table_options.ajax = {
url: 'get_history',
type: 'post',
data: function (d) {
return {
'json_data': JSON.stringify(d),
'media_type': media_type
};
}
}
}
history_table = $('#history_table').DataTable(history_table_options);
var colvis = new $.fn.dataTable.ColVis(history_table, { buttonText: '<i class="fa fa-columns"></i> Select columns', buttonClass: 'btn btn-dark', exclude: [0, 11] });
$(colvis.button()).appendTo('div.colvis-button-bar');
history_table = $('#history_table').DataTable(history_table_options);
var colvis = new $.fn.dataTable.ColVis(history_table, { buttonText: '<i class="fa fa-columns"></i> Select columns', buttonClass: 'btn btn-dark', exclude: [0, 11] });
$(colvis.button()).appendTo('div.colvis-button-bar');
clearSearchButton('history_table', history_table);
clearSearchButton('history_table', history_table);
$('#history_table_filter').prepend('<div class="btn-group" data-toggle="buttons" id="media_type-selection" style="padding-right: 15px;"> \
<label class="btn btn-dark active"> \
<input type="radio" name="media_type-filter" id="history-all" value="all" autocomplete="off"> All \
</label> \
<label class="btn btn-dark"> \
<input type="radio" name="media_type-filter" id="history-movies" value="movie" autocomplete="off"> Movies \
</label> \
<label class="btn btn-dark"> \
<input type="radio" name="media_type-filter" id="history-tv_shows" value="episode" autocomplete="off"> TV Shows \
</label> \
<label class="btn btn-dark"> \
<input type="radio" name="media_type-filter" id="history-music" value="track" autocomplete="off"> Music \
</label> \
</div>');
$('#media_type-selection').on('change', function () {
$('#media_type-selection > label').removeClass('active');
selected_filter = $('input[name=media_type-filter]:checked', '#media_type-selection');
$(selected_filter).closest('label').addClass('active');
media_type = $(selected_filter).val();
history_table.draw();
});
}
var media_type = 'all';
loadHistoryTable(media_type);
$('#row-edit-mode').on('click', function() {
$('#row-edit-mode-alert').fadeIn(200);

View file

@ -382,49 +382,38 @@ DOCUMENTATION :: END
<div class="summary-navbar">
<div class="col-md-12">
<div class="summary-navbar-list">
% if query:
% if query['media_type'] == 'movie':
<span>Movies</span>
<span class="hidden-xs hidden-sm"><i class="fa fa-chevron-right"></i></span>
<span>${query['title']}</span>
% elif query['media_type'] == 'show':
<span>TV Shows</span>
<span class="hidden-xs hidden-sm"><i class="fa fa-chevron-right"></i></span>
<span>${query['grandparent_title']}</span>
% elif query['media_type'] == 'season':
<span class="hidden-xs hidden-sm">TV Shows</span>
<span class="hidden-xs hidden-sm"><i class="fa fa-chevron-right"></i></span>
<span class="hidden-xs hidden-sm">${query['grandparent_title']}</span>
<span class="hidden-xs hidden-sm"><i class="fa fa-chevron-right"></i></span>
<span>Season ${query['parent_media_index']}</span>
% elif query['media_type'] == 'episode':
<span class="hidden-xs hidden-sm">TV Shows</span>
<span class="hidden-xs hidden-sm"><i class="fa fa-chevron-right"></i></span>
<span class="hidden-xs hidden-sm">${query['grandparent_title']}</span>
<span class="hidden-xs hidden-sm"><i class="fa fa-chevron-right"></i></span>
<span>Season ${query['parent_media_index']}</span>
<span><i class="fa fa-chevron-right"></i></span>
<span>Episode ${query['media_index']} - ${query['title']}</span>
% elif query['media_type'] == 'artist':
<span>Music</span>
<span><i class="fa fa-chevron-right"></i></span>
<span>${query['grandparent_title']}</span>
% elif query['media_type'] == 'album':
<span class="hidden-xs hidden-sm">Music</span>
<span class="hidden-xs hidden-sm"><i class="fa fa-chevron-right"></i></span>
<span>${query['grandparent_title']}</span>
<span><i class="fa fa-chevron-right"></i></span>
<span>${query['parent_title']}</span>
% elif query['media_type'] == 'track':
<span class="hidden-xs hidden-sm">Music</span>
<span class="hidden-xs hidden-sm"><i class="fa fa-chevron-right"></i></span>
<span class="hidden-xs hidden-sm">${query['grandparent_title']}</span>
<span class="hidden-xs hidden-sm"><i class="fa fa-chevron-right"></i></span>
<span>${query['parent_title']}</span>
<span><i class="fa fa-chevron-right"></i></span>
<span>Track ${query['media_index']} - ${query['title']}</span>
% endif
% endif
<ul class="list-unstyled breadcrumb">
% if query:
% if query['media_type'] == 'movie':
<li><a href="info?item_id=movie">Movies</a></li>
<li class="active">${query['title']}</li>
% elif query['media_type'] == 'show':
<li><a href="info?item_id=show">TV Shows</a></li>
<li class="active">${query['grandparent_title']}</li>
% elif query['media_type'] == 'season':
<li class="hidden-xs hidden-sm"><a href="info?item_id=show">TV Shows</a></li>
<li class="hidden-xs hidden-sm">${query['grandparent_title']}</li>
<li class="active">Season ${query['parent_media_index']}</li>
% elif query['media_type'] == 'episode':
<li class="hidden-xs hidden-sm"><a href="info?item_id=show">TV Shows</a></li>
<li class="hidden-xs hidden-sm">${query['grandparent_title']}</li>
<li>Season ${query['parent_media_index']}</li>
<li class="active">Episode ${query['media_index']} - ${query['title']}</li>
% elif query['media_type'] == 'artist':
<li><a href="info?item_id=artist">Music</a></li>
<li class="active">${query['grandparent_title']}</li>
% elif query['media_type'] == 'album':
<li class="hidden-xs hidden-sm"><a href="info?item_id=artist">Music</a></li>
<li>${query['grandparent_title']}</li>
<li class="active">${query['parent_title']}</li>
% elif query['media_type'] == 'track':
<li class="hidden-xs hidden-sm"><a href="info?item_id=artist">Music</a></li>
<li class="hidden-xs hidden-sm">${query['grandparent_title']}</li>
<li>${query['parent_title']}</li>
<li class="active">Track ${query['media_index']} - ${query['title']}</li>
% endif
% endif
</ul>
</div>
</div>
</div>
@ -514,11 +503,11 @@ DOCUMENTATION :: END
<script>
function get_history() {
history_table_options.ajax = {
"url": "get_history",
url: 'get_history',
type: 'post',
data: function ( d ) {
return { 'json_data': JSON.stringify( d ),
'media_type': '${data['media_type']}' };
'media_type': "${data['media_type']}" };
}
}
}
@ -527,11 +516,11 @@ DOCUMENTATION :: END
<script>
function get_history() {
history_table_options.ajax = {
"url": "get_history",
url: 'get_history',
type: 'post',
data: function ( d ) {
return { 'json_data': JSON.stringify( d ),
'grandparent_rating_key': ${data['rating_key']} };
'grandparent_rating_key': "${data['rating_key']}" };
}
}
}
@ -540,11 +529,11 @@ DOCUMENTATION :: END
<script>
function get_history() {
history_table_options.ajax = {
"url": "get_history",
url: 'get_history',
type: 'post',
data: function ( d ) {
return { 'json_data': JSON.stringify( d ),
'parent_rating_key': ${data['rating_key']} };
'parent_rating_key': "${data['rating_key']}" };
}
}
}
@ -553,11 +542,11 @@ DOCUMENTATION :: END
<script>
function get_history() {
history_table_options.ajax = {
"url": "get_history",
url: 'get_history',
type: 'post',
data: function ( d ) {
return { 'json_data': JSON.stringify( d ),
'rating_key': ${data['rating_key']} };
'rating_key': "${data['rating_key']}" };
}
}
}
@ -614,7 +603,7 @@ DOCUMENTATION :: END
<script>
$.ajax({
url: 'get_item_children',
type: "GET",
type: 'GET',
async: true,
data: { rating_key : ${data['rating_key']} },
complete: function(xhr, status) {
@ -622,6 +611,13 @@ DOCUMENTATION :: END
});
</script>
% endif
% if data['type'] != 'library':
<script>
$('#row-edit-mode').after('<a href="info?item_id=${data['rating_key']}" class="btn btn-danger btn-edit" id="fix-metadata" \
data-toggle="tooltip" data-placement="left" title="Fix metadata if the item was moved in Plex"><i class="fa fa-wrench"></i> Fix Metadata</a>');
$('#fix-metadata').tooltip();
</script>
% endif
% if data['type'] != 'library' and data['rating']:
<script>
// Convert rating to 5 star rating type
@ -638,7 +634,7 @@ DOCUMENTATION :: END
<script>
$.ajax({
url: 'get_search_results_children',
type: "GET",
type: 'GET',
async: true,
data: {'query': "${query['query_string']}",
'media_type': "${query['media_type']}",

View file

@ -26,7 +26,7 @@
<%def name="javascriptIncludes()">
<script>
$('#search_button').removeClass('btn-inactive');
$('#search_query').val('${query}').css({ right: '0', width: '250px' }).addClass('active');
$('#search_query').val("${query}").css({ right: '0', width: '250px' }).addClass('active');
$.ajax({
url: 'get_search_results_children',

View file

@ -319,15 +319,17 @@ from plexpy import helpers
}
});
$( "#history-tab-btn" ).one( "click", function() {
function loadHistoryTable(media_type) {
// Build watch history table
history_table_options.ajax = {
"url": "get_history",
url: 'get_history',
type: 'post',
data: function ( d ) {
return { 'json_data': JSON.stringify( d ),
'user_id': user_id,
'user': "${data['username']}"
return {
'json_data': JSON.stringify( d ),
'user_id': user_id,
'user': "${data['username']}",
'media_type': media_type
};
}
}
@ -338,6 +340,34 @@ from plexpy import helpers
$(colvis.button()).appendTo('#button-bar-history');
clearSearchButton('history_table', history_table);
$('#history_table_filter').prepend('<div class="btn-group" data-toggle="buttons" id="media_type-selection" style="padding-right: 15px;"> \
<label class="btn btn-dark active"> \
<input type="radio" name="media_type-filter" id="history-all" value="all" autocomplete="off"> All \
</label> \
<label class="btn btn-dark"> \
<input type="radio" name="media_type-filter" id="history-movies" value="movie" autocomplete="off"> Movies \
</label> \
<label class="btn btn-dark"> \
<input type="radio" name="media_type-filter" id="history-tv_shows" value="episode" autocomplete="off"> TV Shows \
</label> \
<label class="btn btn-dark"> \
<input type="radio" name="media_type-filter" id="history-music" value="track" autocomplete="off"> Music \
</label> \
</div>');
$('#media_type-selection').on('change', function () {
$('#media_type-selection > label').removeClass('active');
selected_filter = $('input[name=media_type-filter]:checked', '#media_type-selection');
$(selected_filter).closest('label').addClass('active');
media_type = $(selected_filter).val();
history_table.draw();
});
}
$( "#history-tab-btn" ).one( "click", function() {
var media_type = 'all';
loadHistoryTable(media_type);
});
$( "#ip-tab-btn" ).one( "click", function() {

View file

@ -182,7 +182,7 @@ class DataFactory(object):
'ORDER BY %s DESC LIMIT %s' % (time_range, sort_type, stats_count)
result = monitor_db.select(query)
except:
logger.warn("Unable to execute database query.")
logger.warn("Unable to execute database query for get_home_stats: top_tv.")
return None
for item in result:
@ -230,7 +230,7 @@ class DataFactory(object):
'LIMIT %s' % (time_range, sort_type, stats_count)
result = monitor_db.select(query)
except:
logger.warn("Unable to execute database query.")
logger.warn("Unable to execute database query for get_home_stats: popular_tv.")
return None
for item in result:
@ -274,7 +274,7 @@ class DataFactory(object):
'ORDER BY %s DESC LIMIT %s' % (time_range, sort_type, stats_count)
result = monitor_db.select(query)
except:
logger.warn("Unable to execute database query.")
logger.warn("Unable to execute database query for get_home_stats: top_movies.")
return None
for item in result:
@ -322,7 +322,7 @@ class DataFactory(object):
'LIMIT %s' % (time_range, sort_type, stats_count)
result = monitor_db.select(query)
except:
logger.warn("Unable to execute database query.")
logger.warn("Unable to execute database query for get_home_stats: popular_movies.")
return None
for item in result:
@ -366,7 +366,7 @@ class DataFactory(object):
'ORDER BY %s DESC LIMIT %s' % (time_range, sort_type, stats_count)
result = monitor_db.select(query)
except:
logger.warn("Unable to execute database query.")
logger.warn("Unable to execute database query for get_home_stats: top_music.")
return None
for item in result:
@ -414,7 +414,7 @@ class DataFactory(object):
'LIMIT %s' % (time_range, sort_type, stats_count)
result = monitor_db.select(query)
except:
logger.warn("Unable to execute database query.")
logger.warn("Unable to execute database query for get_home_stats: popular_music.")
return None
for item in result:
@ -459,7 +459,7 @@ class DataFactory(object):
'ORDER BY %s DESC LIMIT %s' % (time_range, sort_type, stats_count)
result = monitor_db.select(query)
except:
logger.warn("Unable to execute database query.")
logger.warn("Unable to execute database query for get_home_stats: top_users.")
return None
for item in result:
@ -507,7 +507,7 @@ class DataFactory(object):
'ORDER BY %s DESC LIMIT %s' % (time_range, sort_type, stats_count)
result = monitor_db.select(query)
except:
logger.warn("Unable to execute database query.")
logger.warn("Unable to execute database query for get_home_stats: top_platforms.")
return None
for item in result:
@ -564,12 +564,12 @@ class DataFactory(object):
'AND (session_history_metadata.media_type = "movie" ' \
'OR session_history_metadata.media_type = "episode") ' \
'AND percent_complete >= %s ' \
'GROUP BY session_history_metadata.full_title ' \
'GROUP BY session_history.id ' \
'ORDER BY last_watch DESC ' \
'LIMIT %s' % (time_range, notify_watched_percent, stats_count)
result = monitor_db.select(query)
except:
logger.warn("Unable to execute database query.")
logger.warn("Unable to execute database query for get_home_stats: last_watched.")
return None
for item in result:
@ -680,7 +680,7 @@ class DataFactory(object):
'ORDER BY started DESC LIMIT ?'
result = monitor_db.select(query, args=[limit])
except:
logger.warn("Unable to execute database query.")
logger.warn("Unable to execute database query for get_recently_watched.")
return None
for row in result:
@ -894,7 +894,7 @@ class DataFactory(object):
grandparent_rating_key = result[0]['grandparent_rating_key']
except:
logger.warn("Unable to execute database query.")
logger.warn("Unable to execute database query for get_rating_keys_list.")
return {}
query = 'SELECT rating_key, parent_rating_key, grandparent_rating_key, title, parent_title, grandparent_title, ' \

View file

@ -1,4 +1,4 @@
# This file is part of PlexPy.
# This file is part of PlexPy.
#
# PlexPy is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -70,6 +70,39 @@ class DataTables(object):
else:
grouping = False
# Build join parameters
if join_types:
counter = 0
for join_type in join_types:
if join_type.upper() == 'LEFT OUTER JOIN':
join_item = 'LEFT OUTER JOIN %s ON %s = %s ' % \
(join_tables[counter], join_evals[counter][0], join_evals[counter][1])
elif join_type.upper() == 'JOIN' or join_type.upper() == 'INNER JOIN':
join_item = 'JOIN %s ON %s = %s ' % \
(join_tables[counter], join_evals[counter][0], join_evals[counter][1])
else:
join_item = ''
counter += 1
join += join_item
# Build custom where parameters
if custom_where:
for w in custom_where:
c_where += w[0] + ' = ? AND '
# The order of our args changes if we are grouping
#if grouping:
# args.insert(0, w[1])
#else:
# args.append(w[1])
# My testing shows that order of args doesn't change
args.append(w[1])
if c_where:
c_where = 'WHERE ' + c_where.rstrip(' AND ')
# Build ordering
for o in parameters['order']:
sort_order = ' COLLATE NOCASE'
@ -119,36 +152,6 @@ class DataTables(object):
if where:
where = 'WHERE ' + where.rstrip(' OR ')
# Build join parameters
if join_types:
counter = 0
for join_type in join_types:
if join_type.upper() == 'LEFT OUTER JOIN':
join_item = 'LEFT OUTER JOIN %s ON %s = %s ' % \
(join_tables[counter], join_evals[counter][0], join_evals[counter][1])
elif join_type.upper() == 'JOIN' or join_type.upper() == 'INNER JOIN':
join_item = 'JOIN %s ON %s = %s ' % \
(join_tables[counter], join_evals[counter][0], join_evals[counter][1])
else:
join_item = ''
counter += 1
join += join_item
# Build custom where parameters
if custom_where:
for w in custom_where:
c_where += w[0] + ' = ? AND '
# The order of our args changes if we are grouping
if grouping:
args.insert(0, w[1])
else:
args.append(w[1])
if c_where:
c_where = 'WHERE ' + c_where.rstrip(' AND ')
# Build our queries
if grouping:
if c_where == '':

View file

@ -571,27 +571,28 @@ class WebInterface(object):
custom_where = []
if user_id:
custom_where = [['session_history.user_id', user_id]]
custom_where.append(['session_history.user_id', user_id])
elif user:
custom_where = [['session_history.user', user]]
custom_where.append(['session_history.user', user])
if 'rating_key' in kwargs:
rating_key = kwargs.get('rating_key', "")
custom_where = [['session_history.rating_key', rating_key]]
custom_where.append(['session_history.rating_key', rating_key])
if 'parent_rating_key' in kwargs:
rating_key = kwargs.get('parent_rating_key', "")
custom_where = [['session_history.parent_rating_key', rating_key]]
custom_where.append(['session_history.parent_rating_key', rating_key])
if 'grandparent_rating_key' in kwargs:
rating_key = kwargs.get('grandparent_rating_key', "")
custom_where = [['session_history.grandparent_rating_key', rating_key]]
custom_where.append(['session_history.grandparent_rating_key', rating_key])
if 'start_date' in kwargs:
start_date = kwargs.get('start_date', "")
custom_where = [['strftime("%Y-%m-%d", datetime(date, "unixepoch", "localtime"))', start_date]]
custom_where.append(['strftime("%Y-%m-%d", datetime(date, "unixepoch", "localtime"))', start_date])
if 'reference_id' in kwargs:
reference_id = kwargs.get('reference_id', "")
custom_where = [['session_history.reference_id', reference_id]]
custom_where.append(['session_history.reference_id', reference_id])
if 'media_type' in kwargs:
media_type = kwargs.get('media_type', "")
custom_where = [['session_history_metadata.media_type', media_type]]
if media_type != 'all':
custom_where.append(['session_history_metadata.media_type', media_type])
data_factory = datafactory.DataFactory()
history = data_factory.get_history(kwargs=kwargs, custom_where=custom_where, grouping=grouping, watched_percent=watched_percent)