@@ -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 ( ' <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
0 commit comments