Skip to content

Commit 08dea98

Browse files
committed
feat(js): dt cont;
- Removed responsive modal option and functionality. - Commented our copy table state button w/ comments. - Finalized visual table info output.
1 parent fb30a42 commit 08dea98

File tree

5 files changed

+63
-45
lines changed

5 files changed

+63
-45
lines changed

ckanext/datatablesview/assets/datatablesview.js

Lines changed: 61 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ this.ckan.module('datatables_view', function($){
2020
ckanFilters: null,
2121
responsiveFlag: false,
2222
pageLengthChoices: [20, 50, 100, 500, 1000],
23-
responsiveModal: false,
2423
resourceUrl: null,
2524
dataDictionary: null,
2625
editable: false,
@@ -98,7 +97,6 @@ function load_datatable(CKAN_MODULE){
9897
const ckanFilters = CKAN_MODULE.options.ckanFilters;
9998
const defaultCompactView = CKAN_MODULE.options.responsiveFlag;
10099
const pageLengthChoices = CKAN_MODULE.options.pageLengthChoices;
101-
const useCompactViewModal = CKAN_MODULE.options.responsiveModal;
102100
const resourceURI = CKAN_MODULE.options.resourceUrl;
103101
const dataDictionary = CKAN_MODULE.options.dataDictionary;
104102
const isEditable = CKAN_MODULE.options.editable;
@@ -124,7 +122,9 @@ function load_datatable(CKAN_MODULE){
124122
const colSortAscLabel = _('Ascending');
125123
const colSortDescLabel = _('Descending');
126124
const colSortAnyLabel = _('Any');
127-
const estimatedLabel = _('(estimated)');
125+
const estimatedLabel = _('Total was estimated');
126+
const exactLabel = _('Total is exact');
127+
const elapsedTimeLabel = _('seconds');
128128
const numberTypes = [
129129
'year',
130130
'month',
@@ -146,7 +146,6 @@ function load_datatable(CKAN_MODULE){
146146
]
147147
const colOffset = 1; // _id col
148148
const defaultSortOrder = [[0, "asc"]]; // _id col
149-
const defaultDidEstimatedTotal = false;
150149
let ajaxStartTime = 0;
151150
let ajaxElapsedTime;
152151

@@ -160,7 +159,7 @@ function load_datatable(CKAN_MODULE){
160159
let isCompactView = typeof tableState != 'undefined' && typeof tableState.compact_view != 'undefined' ? tableState.compact_view : defaultCompactView;
161160
let pageLength = typeof tableState != 'undefined' && typeof tableState.page_length != 'undefined' ? tableState.page_length : pageLengthChoices[0];
162161
let sortOrder = typeof tableState != 'undefined' && typeof tableState.sort_order != 'undefined' ? tableState.sort_order : defaultSortOrder;
163-
let didEstimatedTotal = typeof tableState != 'undefined' && typeof tableState.did_estimated_total != 'undefined' ? tableState.did_estimated_total : defaultDidEstimatedTotal;
162+
let didEstimatedTotal;
164163

165164
let availableColumns = [{
166165
"name": '_id',
@@ -468,18 +467,23 @@ function load_datatable(CKAN_MODULE){
468467
stripHtml: false
469468
}
470469
},
471-
{
472-
name: 'shareButton',
473-
text: '<i class="fa fa-share"></i>',
474-
titleAttr: shareButtonLabel,
475-
className: 'btn-secondary',
476-
action: function (e, dt, node, config) {
477-
dt.state.save();
478-
let sharelink = window.location.href + '?state=' + window.btoa(JSON.stringify(dt.state()));
479-
// TODO: do copy state link stuffs... ONLY NEEDED vars
480-
// copyLink(dt, sharelink, that._('Share current view'), that._('Copied deeplink to clipboard'));
481-
}
482-
}
470+
// FIXME: Base64ing the entire table state is way too large.
471+
// We could add normal URI params for the only required things
472+
// like "sort, col_filters, query, compact, page, length";
473+
// However, we cannot reliably add column reordering,
474+
// column visibility, and view filters to the URI as they can
475+
// be almost infinite for a URI. Network middlewares and proxies
476+
// may also set max lengths and parameters, so those would break.
477+
// {
478+
// name: 'shareButton',
479+
// text: '<i class="fa fa-share"></i>',
480+
// titleAttr: shareButtonLabel,
481+
// className: 'btn-secondary',
482+
// action: function (e, dt, node, config) {
483+
// dt.state.save();
484+
// let sharelink = window.location.href + '?state=' + window.btoa(JSON.stringify(dt.state()));
485+
// }
486+
// }
483487
];
484488
}
485489

@@ -501,6 +505,41 @@ function load_datatable(CKAN_MODULE){
501505
_render_failure(_message, ajaxErrorMessage, 'warning');
502506
}
503507

508+
function render_timing_info(){
509+
/**
510+
* Render timing and estimated total info.
511+
*
512+
* Also save non HTML versions for use throughout functional code.
513+
*
514+
* NOTE: this is done separate from render_table_info
515+
* due to how ajax complete callbacks and draw callbacks
516+
* work in DataTables.
517+
*/
518+
let countInfo = $('#dtprv_info');
519+
let info = '';
520+
if( typeof didEstimatedTotal != 'undefined' && didEstimatedTotal != null ){
521+
if( didEstimatedTotal ){
522+
info += estimatedLabel;
523+
}else{
524+
info += exactLabel;
525+
}
526+
}
527+
if( typeof ajaxElapsedTime != 'undefined' && ajaxElapsedTime != null ){
528+
if( info.length > 0 ){
529+
info += '\n';
530+
}
531+
info += (ajaxElapsedTime / 1000).toFixed(2) + ' ' + elapsedTimeLabel;
532+
}
533+
if( info.length == 0 ){
534+
$(countInfo).find('#timing-info').remove();
535+
return;
536+
}
537+
if( $(countInfo).find('#timing-info').length == 0 ){
538+
$(countInfo).append('&nbsp;<i class="fa fa-info-circle" id="timing-info"></i>');
539+
}
540+
$(countInfo).find('#timing-info').attr('title', info);
541+
}
542+
504543
function render_table_info(){
505544
/**
506545
* Render table and resource info for the current table state.
@@ -509,15 +548,6 @@ function load_datatable(CKAN_MODULE){
509548
*/
510549
// TODO: save table info into object...
511550

512-
// TODO: add or remove estimatedLabel
513-
console.log(didEstimatedTotal);
514-
if( didEstimatedTotal ){
515-
// $('#dtprv_info')
516-
}
517-
518-
// TODO: output ajaxElapsedTime somewhere...
519-
console.log(ajaxElapsedTime);
520-
521551
let resourceInfo = $('#dtv-resource-info');
522552
let content = $(resourceInfo).find('.dtv-resource-info-content');
523553
$(resourceInfo).find('i').attr('title', content.text());
@@ -712,19 +742,22 @@ function load_datatable(CKAN_MODULE){
712742
*/
713743
$('#dtprv_wrapper').find('#dtprv_failure_message').remove();
714744
set_table_visibility();
715-
// render_expand_buttons();
716745
render_table_info();
746+
render_timing_info();
717747
set_button_states();
718748
}
719749

720-
function init_callback(){
750+
function init_callback(_setting, _data){
721751
/**
722752
* Executes once the DataTable initializes.
723753
*/
724754
set_table_visibility();
725755
if( ! isCompactView ){
726756
table.columns.adjust();
727757
}
758+
ajaxElapsedTime = window.performance.now() - ajaxStartTime; // track ajax performance time
759+
didEstimatedTotal = _data.total_was_estimated;
760+
render_timing_info();
728761
set_row_selects();
729762
bind_custom_events();
730763
set_button_states();
@@ -790,8 +823,6 @@ function load_datatable(CKAN_MODULE){
790823
tableState.sort_order = localInstanceState.sort_order;
791824
tableState.compact_view = localInstanceState.compact_view;
792825

793-
// TODO: check URL params for base64 decode...
794-
795826
return _data;
796827
}
797828

ckanext/datatablesview/blueprint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ def ajax(resource_view_id: str):
156156
'recordsTotal': unfiltered_response.get('total', 0),
157157
'recordsFiltered': response.get('total', 0),
158158
'data': data,
159-
'total_was_estimated': False #unfiltered_response.get(
160-
# 'total_was_estimated', False),
159+
'total_was_estimated': unfiltered_response.get(
160+
'total_was_estimated', False),
161161
}
162162
status = 200
163163

ckanext/datatablesview/config_declaration.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,6 @@ groups:
103103
The option defines the label used to display NoneType values for the front-end.
104104
This should be a string and can be translated via po files.
105105
106-
- key: ckan.datatables.responsive_modal
107-
default: false
108-
type: bool
109-
example: 'true'
110-
description: |
111-
When a table is in list (responsive) view mode with some columns hidden
112-
and the user clicks on the first cell, use a modal dialog to display the
113-
complete row contents instead of expanding the missing columns
114-
in the table itself. Prior to CKAN 2.12 the default setting was "true".
115-
116106
- key: ckan.datatables.show_histograms
117107
default: true
118108
type: bool

ckanext/datatablesview/plugin.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ def update_config(self, config: CKANConfig):
6262
"ckan.datatables.ellipsis_length")
6363
self.date_format = config.get("ckan.datatables.date_format")
6464
self.default_view = config.get("ckan.datatables.default_view")
65-
self.responsive_modal = config.get("ckan.datatables.responsive_modal")
6665

6766
toolkit.add_template_directory(config, 'templates')
6867
toolkit.add_resource('assets', 'ckanext-datatablesview')
@@ -97,7 +96,6 @@ def setup_template_variables(self, context: Context,
9796
'ellipsis_length': self.ellipsis_length,
9897
'date_format': self.date_format,
9998
'default_view': self.default_view,
100-
'responsive_modal': self.responsive_modal,
10199
'request_timeout': self.request_timeout,
102100
'language_object': language_object,
103101
'fullscreen': fullscreen,

ckanext/datatablesview/templates/datatables/datatables_view.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
data-module-ckan-filters='{{ request.args.get("filters", "")|e or "null" }}'
4343
data-module-responsive-flag='{{ resource_view.get('responsive')|tojson }}'
4444
data-module-page-length-choices="{{ page_length_choices }}"
45-
data-module-responsive-modal='{{ responsive_modal|tojson }}'
4645
data-module-resource-url="{{ h.url_for(package.type ~ '_resource.read', id=package.name, resource_id=resource.id ) }}"
4746
data-module-data-dictionary='{{- data_dictionary|tojson -}}'
4847
data-module-editable='{{ can_edit|tojson }}'

0 commit comments

Comments
 (0)