Add filtering of media_type from history table

This commit is contained in:
Jonathan Wong 2015-10-18 11:50:01 -07:00
parent 1ff58a85dc
commit 2243cd1de9
4 changed files with 98 additions and 29 deletions

View file

@ -76,19 +76,52 @@
<script src="interfaces/default/js/moment-with-locale.js"></script> <script src="interfaces/default/js/moment-with-locale.js"></script>
<script src="interfaces/default/js/tables/history_table.js"></script> <script src="interfaces/default/js/tables/history_table.js"></script>
<script> <script>
$(document).ready(function() { $(document).ready(function () {
history_table_options.ajax = { function loadHistoryTable(media_type) {
"url": "get_history", history_table_options.ajax = {
type: "post", url: 'get_history',
data: function ( d ) { type: 'post',
return { 'json_data': JSON.stringify( d ) }; data: function (d) {
return {
'json_data': JSON.stringify(d),
'media_type': media_type
};
}
} }
} history_table = $('#history_table').DataTable(history_table_options);
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] });
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');
$(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"> \
<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 = $('input[name=media_type-filter]:checked', '#media_type-selection').val();
loadHistoryTable(media_type)
});
$('#media_type-selection > label').removeClass('active');
if (media_type == 'all') { $('#history-all').closest('label').addClass('active'); }
if (media_type == 'movie') { $('#history-movies').closest('label').addClass('active'); }
if (media_type == 'episode') { $('#history-tv_shows').closest('label').addClass('active'); }
if (media_type == 'track') { $('#history-music').closest('label').addClass('active'); }
}
var media_type = 'all';
loadHistoryTable(media_type)
$('#row-edit-mode').on('click', function() { $('#row-edit-mode').on('click', function() {
$('#row-edit-mode-alert').fadeIn(200); $('#row-edit-mode-alert').fadeIn(200);

View file

@ -319,15 +319,17 @@ from plexpy import helpers
} }
}); });
$( "#history-tab-btn" ).one( "click", function() { function loadHistoryTable(media_type) {
// Build watch history table // Build watch history table
history_table_options.ajax = { history_table_options.ajax = {
"url": "get_history", url: 'get_history',
type: 'post', type: 'post',
data: function ( d ) { data: function ( d ) {
return { 'json_data': JSON.stringify( d ), return {
'user_id': user_id, 'json_data': JSON.stringify( d ),
'user': "${data['username']}" 'user_id': user_id,
'user': "${data['username']}",
'media_type': media_type
}; };
} }
} }
@ -338,6 +340,36 @@ from plexpy import helpers
$(colvis.button()).appendTo('#button-bar-history'); $(colvis.button()).appendTo('#button-bar-history');
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"> \
<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 = $('input[name=media_type-filter]:checked', '#media_type-selection').val();
loadHistoryTable(media_type)
});
$('#media_type-selection > label').removeClass('active');
if (media_type == 'all') { $('#history-all').closest('label').addClass('active'); }
if (media_type == 'movie') { $('#history-movies').closest('label').addClass('active'); }
if (media_type == 'episode') { $('#history-tv_shows').closest('label').addClass('active'); }
if (media_type == 'track') { $('#history-music').closest('label').addClass('active'); }
}
$( "#history-tab-btn" ).one( "click", function() {
var media_type = 'all';
loadHistoryTable(media_type)
}); });
$( "#ip-tab-btn" ).one( "click", function() { $( "#ip-tab-btn" ).one( "click", function() {

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 # PlexPy is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -141,10 +141,13 @@ class DataTables(object):
c_where += w[0] + ' = ? AND ' c_where += w[0] + ' = ? AND '
# The order of our args changes if we are grouping # The order of our args changes if we are grouping
if grouping: #if grouping:
args.insert(0, w[1]) # args.insert(0, w[1])
else: #else:
args.append(w[1]) # args.append(w[1])
# My testing shows that order of args doesn't change
args.append(w[1])
if c_where: if c_where:
c_where = 'WHERE ' + c_where.rstrip(' AND ') c_where = 'WHERE ' + c_where.rstrip(' AND ')

View file

@ -571,27 +571,28 @@ class WebInterface(object):
custom_where = [] custom_where = []
if user_id: if user_id:
custom_where = [['session_history.user_id', user_id]] custom_where.append(['session_history.user_id', user_id])
elif user: elif user:
custom_where = [['session_history.user', user]] custom_where.append(['session_history.user', user])
if 'rating_key' in kwargs: if 'rating_key' in kwargs:
rating_key = kwargs.get('rating_key', "") 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: if 'parent_rating_key' in kwargs:
rating_key = kwargs.get('parent_rating_key', "") 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: if 'grandparent_rating_key' in kwargs:
rating_key = kwargs.get('grandparent_rating_key', "") 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: if 'start_date' in kwargs:
start_date = kwargs.get('start_date', "") 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: if 'reference_id' in kwargs:
reference_id = kwargs.get('reference_id', "") 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: if 'media_type' in kwargs:
media_type = kwargs.get('media_type', "") 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() data_factory = datafactory.DataFactory()
history = data_factory.get_history(kwargs=kwargs, custom_where=custom_where, grouping=grouping, watched_percent=watched_percent) history = data_factory.get_history(kwargs=kwargs, custom_where=custom_where, grouping=grouping, watched_percent=watched_percent)