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 = `
 
`; - let statuscounts = row[10]; + let statuscounts = row['StatusDistribution']; if ((statuscounts ?? '')== '') { return empty_stats; } @@ -285,9 +275,9 @@ let render_book_actions = function ( data, type, row, meta ) { // TODO zzfuture fix: security - add CSRF token - const bkid = row[5]; - const bktitle = encodeURIComponent(row[0]); - const is_active = (row[6] == 0); + const bkid = row['BkID']; + const bktitle = encodeURIComponent(row['BkTitle']); + const is_active = (row['BkArchived'] == 0); const links = []; const make_link = function(label, func) { diff --git a/lute/templates/bookmarks/list.html b/lute/templates/bookmarks/list.html index d8de1b69..846dcc9c 100644 --- a/lute/templates/bookmarks/list.html +++ b/lute/templates/bookmarks/list.html @@ -55,18 +55,14 @@

{{ book.title }}

], bottomEnd: 'paging' }, - columnDefs: [ - { "name": "TxOrder", "targets": 0, "width": "5%", className: "colVisToggled" }, - { "name": "TbTitle", "targets": 1, "width": "70%", className: "colVisToggled", "render": render_page_link }, - { "targets": 2, "data": null, "width": "15%", "searchable": false, "orderable": false, "render": render_bookmark_actions, className: "colVisToggled" }, - - // Hidden data for processing bookmark actions - { "name": "TbID", "targets": 3, "data": null, "visible": false }, + columns: [ + { name: "TxOrder", data: "TxOrder", width: "5%" }, + { name: "TbTitle", width: "70%", render: render_page_link }, + { data: null, width: "15%", searchable: false, orderable: false, render: render_bookmark_actions }, ], buttons: [ { - extend: 'colvis', - columns: '.colVisToggled' + extend: 'colvis' } ], responsive: true, @@ -162,11 +158,9 @@

{{ book.title }}

} let render_bookmark_actions = function(data, type, row, meta) { - // TODO zzfuture fix: security - add CSRF token - const links = []; const make_link = function(label, func) { - const s = `${label}`; + const s = `${label}`; links.push(s); }; @@ -179,8 +173,8 @@

{{ book.title }}

}; const render_page_link = function(data, type, row, meta) { - page_num = row[0]; - return `${row[1]}` + page_num = row['TxOrder']; + return `${row['TbTitle']}` } /** diff --git a/lute/templates/term/index.html b/lute/templates/term/index.html index e8241a41..3efac8f1 100644 --- a/lute/templates/term/index.html +++ b/lute/templates/term/index.html @@ -107,15 +107,6 @@