import html from './doc_table.html' ; import { dispatchRenderComplete } from '../../../../../opensearch_dashboards_utils/public' ; import { SAMPLE_SIZE_SETTING } from '../../../../common' ; import { getLimitedSearchResultsMessage } from './doc_table_strings' ; import { getServices } from '../../../opensearch_dashboards_services' ; import './index.scss' ; export interface LazyScope extends ng . IScope { [ key ] : any ; } export function createDocTableDirective ( pagerFactory , $filter ) { return { restrict : 'E' , template : html , scope : { sorting : '=' , columns : '=' , hits : '=' , totalHitCount : '=' , indexPattern : '=' , isLoading : '=?' , infiniteScroll : '=?' , filter : '=?' , minimumVisibleRows : '=?' , onAddColumn : '=?' , onChangeSortOrder : '=?' , onMoveColumn : '=?' , onRemoveColumn : '=?' , inspectorAdapters : '=?' , } , link : ( $scope , $el ) => { $scope . persist = { sorting : $scope . sorting , columns : $scope . columns , } ; const limitTo = $filter ( 'limitTo' ) ; const calculateItemsOnPage = ( ) => { $scope . pager . setTotalItems ( $scope . hits . length ) ; $scope . pageOfItems = limitTo ( $scope . hits , $scope . pager . pageSize , $scope . pager . startIndex ) ; } ; $scope . limitedResultsWarning = getLimitedSearchResultsMessage ( getServices ( ) . uiSettings . get ( SAMPLE_SIZE_SETTING , 500 ) ) ; $scope . addRows = function ( ) { $scope . limit += 50 ; } ; $scope . $watch ( 'hits' , ( hits ) => { if ( ! hits ) return ; $scope . limit = $scope . minimumVisibleRows || 50 ; if ( hits . length === 0 ) { dispatchRenderComplete ( $el [ 0 ] ) ; } if ( $scope . infiniteScroll ) return ; $scope . pager = pagerFactory . create ( hits . length , 50 , 1 ) ; calculateItemsOnPage ( ) ; } ) ; $scope . pageOfItems = [ ] ; $scope . onPageNext = ( ) => { $scope . pager . nextPage ( ) ; calculateItemsOnPage ( ) ; } ; $scope . onPagePrevious = ( ) => { $scope . pager . previousPage ( ) ; calculateItemsOnPage ( ) ; } ; $scope . shouldShowLimitedResultsWarning = ( ) => ! $scope . pager . hasNextPage && $scope . pager . totalItems < $scope . totalHitCount ; } , } ; }