diff --git a/lute/book/datatables.py b/lute/book/datatables.py index 2d22a047..a4b799f1 100644 --- a/lute/book/datatables.py +++ b/lute/book/datatables.py @@ -70,7 +70,6 @@ def get_data_tables_list(parameters, is_archived): if language_id != 0: base_sql += f" and LgID = {language_id}" - # print(base_sql) session = db.session connection = session.connection() diff --git a/lute/book/routes.py b/lute/book/routes.py index fbcec850..c1506ca7 100644 --- a/lute/book/routes.py +++ b/lute/book/routes.py @@ -39,6 +39,10 @@ def _load_term_custom_filters(request_form, parameters): def datatables_source(is_archived): "Get datatables json for books." + # In the future, we might want to create an API such as + # get_books(sort_order, search_string, length, index, language_id). + # See DataTablesFlaskParamParser.parse_params_2(request.form) + # (currently unused) parameters = DataTablesFlaskParamParser.parse_params(request.form) _load_term_custom_filters(request.form, parameters) data = get_data_tables_list(parameters, is_archived) diff --git a/lute/bookmarks/datatables.py b/lute/bookmarks/datatables.py index e1a24766..f70c8fcc 100644 --- a/lute/bookmarks/datatables.py +++ b/lute/bookmarks/datatables.py @@ -10,7 +10,7 @@ def get_data_tables_list(parameters, book_id): "Bookmark json data for datatables." base_sql = f""" - SELECT tb.TbID, tb.TbTxID, tb.TbTitle, tx.TxText, tx.TxOrder + SELECT tb.TbID, tb.TbTxID, tb.TbTitle, tx.TxOrder FROM textbookmarks as tb INNER JOIN texts as tx ON tb.TbTxID = tx.TxID WHERE tx.TxBkID = { book_id } diff --git a/lute/templates/book/tablelisting.html b/lute/templates/book/tablelisting.html index 47573e3c..3262798f 100644 --- a/lute/templates/book/tablelisting.html +++ b/lute/templates/book/tablelisting.html @@ -68,8 +68,7 @@ }, buttons: [ { - extend: 'colvis', - columns: '.colVisToggled' + extend: 'colvis' } ], {% if status != 'Archived' %} @@ -89,24 +88,15 @@ stateSave: true, stateDuration: 0, /* never expire saved state. */ search: { search: initial_search }, - columnDefs: [ - { "name": "BkTitle", "targets": 0, "width": "40%", "render": render_book_title, className: "colVisToggled" }, - { "name": "LgName", "targets": 1, "width": "10%", className: "colVisToggled" }, - { "name": "TagList", "targets": 2, "width": "10%", className: "colVisToggled" }, - { "name": "WordCount", "targets": 3, "width": "10%", className: "colVisToggled" }, - { "name": "UnknownPercent", "targets": 4, "data": null, "searchable": true, "orderable": true, "render": render_book_stats_graph, className: "colVisToggled" }, - { "targets": 5, "data": null, "width": "8%", "searchable": false, "orderable": false, "render": render_book_actions, className: "colVisToggled" }, - - /* Extra data that is returned in the row for rendering, but not shown, not changed by colvis. */ - { "name": "BkID", "targets": 6, "data": null, "visible": false }, - { "name": "BkArchived", "targets": 7, "data": null, "visible": false }, - { "name": "PageCount", "targets": 8, "data": null, "visible": false }, - { "name": "PageNum", "targets": 9, "data": null, "visible": false }, - { "name": "IsCompleted", "targets": 10, "data": null, "visible": false }, - { "name": "StatusDistribution", "targets": 11, "data": null, "visible": false }, + columns: [ + { name: "BkTitle", width: "40%", render: render_book_title }, + { name: "LgName", width: "10%", data: "LgName" }, + { name: "TagList", width: "10%", data: "TagList" }, + { name: "WordCount", width: "10%", data: "WordCount" }, + { name: "UnknownPercent", render: render_book_stats_graph }, + { width: "8%", "searchable": false, "orderable": false, render: render_book_actions }, ], - // Ajax call ajax: { url: "/book/datatables/{{ status or 'active' }}", // Additional filters. func calls are required to get the @@ -121,9 +111,6 @@ }, }); - - // var dropdown = $('#defaultLanguageSelect'); - // $('div.toolbar').append(dropdown); } // end setup_book_datatable @@ -209,13 +196,16 @@ do_action_post('delete', bookid); } + // Rendering helpers. ================================================= + // each row in the table is a json dict, the keys are the SQL column names. + let render_book_title = function ( data, type, row, meta ) { - const bkid = parseInt(row[5]); - const pgnum = parseInt(row[8]); - const pgcount = parseInt(row[7]); + const bkid = parseInt(row['BkID']); + const pgnum = parseInt(row['PageNum']); + const pgcount = parseInt(row['PageCount']); let pgfraction = ''; - const completed = (parseInt(row[9]) == 1); + const completed = (parseInt(row['IsCompleted']) == 1); let book_title_classes = ['book-title']; if (completed) { book_title_classes.push('completed_book'); @@ -224,13 +214,13 @@ pgfraction = ` (${pgnum}/${pgcount})`; } - return `${row[0]}${pgfraction}`; + return `${row['BkTitle']}${pgfraction}`; }; let render_book_stats_graph = function(data, type, row, meta) { const empty_stats = `