src/main/webapp/js/singlepage-interface.js
/**
	 * Loads and displays a small amount of details about individual hits/documents within a specific group.
	 * Some data is attached to the button to track how many concordances are already loaded/are available.
	 *
	 * This function does not refresh the entire tab's contents, just inserts some extra data within a group's <tr>
	 * For the version that loads the full result set and displays the extensive information, see {@link viewConcordances}
	 *
	 * This function assumes it's being called within the context of a button element containing a data-group-id attribute.
	 * Some assumptions are also made about the exact structure of the document regarding placement of the results.
	 */
Loads and displays a small amount of details about individual hits/documents within a specific group.
Some data is attached to the button to track how many concordances are already loaded/are available.

This function does not refresh the entire tab's contents, just inserts some extra data within a group's 
For the version that loads the full result set and displays the extensive information, see  viewConcordances

This function assumes it's being called within the context of a button element containing a data-group-id attribute.
Some assumptions are also made about the exact structure of the document regarding placement of the results.
Loads and displays a small amount of details about individual hits / documents within a specific group . Some data is attached to the button to track how many concordances are already loaded / are available . This function does not refresh the entire tab ' s contents just inserts some extra data within a group ' s For the version that loads the full result set and displays the extensive information see viewConcordances This function assumes it ' s being called within the context of a button element containing a data - group - id attribute . Some assumptions are also made about the exact structure of the document regarding placement of the results .
function loadConcordances() {
		var $button = $(this);
		var $tab = $button.parents('.tab-pane').first();
		var textDirection = SINGLEPAGE.INDEX.textDirection || 'ltr';
		var groupId = $button.data('groupId');
		var currentConcordanceCount = $button.data('currentConcordanceCount') || 0;
		var availableConcordanceCount = $button.data('availableConcordanceCount') || Number.MAX_VALUE;
		if (currentConcordanceCount >= availableConcordanceCount)
			return;
		var searchParams = $.extend(
			{},
			$tab.data('defaultParameters'),
			$tab.data('parameters'),
			{
				pageSize: 20,
				page: currentConcordanceCount / 20,
				viewGroup: groupId,
				sampleSize: null,
				sampleMode: null,
				sampleSeed: null,
			},
			$tab.data('constParameters')
		);
		SINGLEPAGE.BLS.search(searchParams, function(data) {
			var totalConcordances = data.hits ? data.summary.numberOfHitsRetrieved : data.summary.numberOfDocsRetrieved;
			var loadedConcordances = data.summary.actualWindowSize;
			$button.data('currentConcordanceCount', currentConcordanceCount + loadedConcordances)
				.data('availableConcordanceCount', totalConcordances)
				.toggle(currentConcordanceCount + loadedConcordances < totalConcordances);
			var html = [];
			$.each(data.hits, function(index, hit) {
				var parts = snippetParts(hit);
				var left = textDirection=='ltr'? parts[0] : parts[2];
				var right = textDirection=='ltr'? parts[2] : parts[0];
				html.push(
					'<div class="clearfix">',
						'<div class="col-xs-5 text-right">', ELLIPSIS, ' ', left, '</div>',
						'<div class="col-xs-2 text-center"><b>', parts[1], '&nbsp;', '</b></div>',
						'<div class="col-xs-5">', right, ' ', ELLIPSIS, '</div>',
					'</div>');
			});
			$.each(data.docs, function(index, doc) {
				var title = doc.docInfo[data.summary.docFields.titleField];
				var hits = doc.numberOfHits;
				html.push(
					'<div class="clearfix">',
						'<div class="col-xs-10"><b>', title, '&nbsp;', '</b></div>',
						'<div class="col-xs-2">', hits, '&nbsp;', '</div>',
					'</div>');
			});
			$button.parent().parent().append(html.join(''));
		},
		function(jqXHR, textStatus, errorThrown) {
			var errordata = (jqXHR && jqXHR.responseJSON && jqXHR.responseJSON.error) || {
				'code': 'WEBSERVICE_ERROR',
				'message': 'Error contacting webservice: ' + textStatus + '; ' + errorThrown
			};
			var html = [];
			html.push('<div>',
				'<b>Could not retrieve concordances.</b><br>');
			if (jqXHR && jqXHR.status !== 0) 
				html.push('This is usually due to a misconfigured server, see ',
					'<a href="https://github.com/INL/BlackLab/blob/be5b5be75c064e87cbfc2271fd19d073f80839af/core/src/site/markdown/blacklab-server-overview.md#installation" target="_blank">here</a> for more information.');
			html.push('<hr><b>', errordata.code, '</b><br>', errordata.message, '</div>');
			$button.parent().parent().html(html.join(''));
		});
	}
function loadConcordances ( ) { var $button = $ ( this ) ; var $tab = $button . parents ( '.tab-pane' ) . first ( ) ; var textDirection = SINGLEPAGE . INDEX . textDirection || 'ltr' ; var groupId = $button . data ( 'groupId' ) ; var currentConcordanceCount = $button . data ( 'currentConcordanceCount' ) || 0 ; var availableConcordanceCount = $button . data ( 'availableConcordanceCount' ) || Number . MAX_VALUE ; if ( currentConcordanceCount >= availableConcordanceCount ) return ; var searchParams = $ . extend ( { } , $tab . data ( 'defaultParameters' ) , $tab . data ( 'parameters' ) , { pageSize : 20 , page : currentConcordanceCount / 20 , viewGroup : groupId , sampleSize : null , sampleMode : null , sampleSeed : null , } , $tab . data ( 'constParameters' ) ) ; SINGLEPAGE . BLS . search ( searchParams , function ( data ) { var totalConcordances = data . hits ? data . summary . numberOfHitsRetrieved : data . summary . numberOfDocsRetrieved ; var loadedConcordances = data . summary . actualWindowSize ; $button . data ( 'currentConcordanceCount' , currentConcordanceCount + loadedConcordances ) . data ( 'availableConcordanceCount' , totalConcordances ) . toggle ( currentConcordanceCount + loadedConcordances < totalConcordances ) ; var html = [ ] ; $ . each ( data . hits , function ( index , hit ) { var parts = snippetParts ( hit ) ; var left = textDirection == 'ltr' ? parts [ 0 ] : parts [ 2 ] ; var right = textDirection == 'ltr' ? parts [ 2 ] : parts [ 0 ] ; html . push ( '<div class="clearfix">' , '<div class="col-xs-5 text-right">' , ELLIPSIS , ' ' , left , '</div>' , '<div class="col-xs-2 text-center"><b>' , parts [ 1 ] , '&nbsp;' , '</b></div>' , '<div class="col-xs-5">' , right , ' ' , ELLIPSIS , '</div>' , '</div>' ) ; } ) ; $ . each ( data . docs , function ( index , doc ) { var title = doc . docInfo [ data . summary . docFields . titleField ] ; var hits = doc . numberOfHits ; html . push ( '<div class="clearfix">' , '<div class="col-xs-10"><b>' , title , '&nbsp;' , '</b></div>' , '<div class="col-xs-2">' , hits , '&nbsp;' , '</div>' , '</div>' ) ; } ) ; $button . parent ( ) . parent ( ) . append ( html . join ( '' ) ) ; } , function ( jqXHR , textStatus , errorThrown ) { var errordata = ( jqXHR && jqXHR . responseJSON && jqXHR . responseJSON . error ) || { 'code' : 'WEBSERVICE_ERROR' , 'message' : 'Error contacting webservice: ' + textStatus + '; ' + errorThrown } ; var html = [ ] ; html . push ( '<div>' , '<b>Could not retrieve concordances.</b><br>' ) ; if ( jqXHR && jqXHR . status !== 0 ) html . push ( 'This is usually due to a misconfigured server, see ' , '<a href="https://github.com/INL/BlackLab/blob/be5b5be75c064e87cbfc2271fd19d073f80839af/core/src/site/markdown/blacklab-server-overview.md#installation" target="_blank">here</a> for more information.' ) ; html . push ( '<hr><b>' , errordata . code , '</b><br>' , errordata . message , '</div>' ) ; $button . parent ( ) . parent ( ) . html ( html . join ( '' ) ) ; } ) ; }
Loads and displays a small amount of details about individual hits/documents within a specific group.
Loads and displays a small amount of details about individual hits / documents within a specific group .
// store new number of loaded elements // And generate html to display // Only one of these will run depending on what is present in the data // And what is present in the data depends on the current view, so all works out // TODO tidy up // server is up // TODO tidy up