src/main/webapp/js/singlepage-interface.js
/**
	 * Convert a blacklab-server reply containing information about documents into a table containing the results.
	 *
	 * @param {any} data the blacklab-server response.
	 * @returns An array of html strings containing the <thead> and <tbody>, but without the enclosing <table> element.
	 */
Convert a blacklab-server reply containing information about documents into a table containing the results.
@param {any} data the blacklab-server response.
@returns An array of html strings containing the  and , but without the enclosing  element.
Convert a blacklab - server reply containing information about documents into a table containing the results . @param { any } data the blacklab - server response . @returns An array of html strings containing the and but without the enclosing element .
function formatDocs(data, textDirection) {
		var html = [];
		html.push(
			'<thead><tr>',
				'<th style="width:70%"><a data-bls-sort="field:', data.summary.docFields.titleField, '">Document title</a></th>',
				'<th style="width:15%"><a data-bls-sort="field:', data.summary.docFields.dateField, '">Year</a></th>',
				'<th style="width:15%"><a data-bls-sort="numhits">Hits</a></th>',
			'</tr></thead>'
		);
		html.push('<tbody>');
		$.each(data.docs, function(index, doc) {
			var docPid = doc.docPid;
			var docTitle = doc.docInfo[data.summary.docFields.titleField] || 'UNKNOWN';
			var docAuthor = doc.docInfo[data.summary.docFields.authorField] ? ' by ' + doc.docInfo[data.summary.docFields.authorField] : '';
			var docDate = doc.docInfo[data.summary.docFields.dateField] || '';
			var docHits = doc.numberOfHits || '';
			var snippetStrings = [];
			$.each(doc.snippets, function(index, snippet) {
				var parts = snippetParts(snippet);
				snippetStrings.push(ELLIPSIS, ' ', parts[0], '<strong>', parts[1], '</strong>', parts[2], ELLIPSIS);
				return false; 
			});
			var docUrl;
			switch (new URI().filename()) {
				case '':
					docUrl = new URI('../../docs/'); 
					break;
				case 'docs':
				case 'hits':
					docUrl = new URI('../docs/');
					break;
				case 'search':
				default: 
					docUrl = new URI('./docs/');
					break;
			}
			docUrl = docUrl
			.absoluteTo(new URI().toString())
			.filename(docPid)
			.search({
				'query': data.summary.searchParam.patt
			})
			.toString();
			html.push(
				'<tr class="documentrow">',
					'<td>',
						'<a target="_blank" href="', docUrl, '">', docTitle, docAuthor, '</a><br>', '<span dir="', textDirection, '">',
						snippetStrings.join(''), snippetStrings.length > 0 ? '<br>' : '', '</span>',
						'<a class="green btn btn-xs btn-default" target="_blank" href="', docUrl,'">View document info</a>',
					'</td>',
					'<td>', docDate, '</td>',
					'<td>', docHits, '</td>',
				'</tr>');
		});
		html.push('</tbody>');
		return html;
	}
function formatDocs ( data , textDirection ) { var html = [ ] ; html . push ( '<thead><tr>' , '<th style="width:70%"><a data-bls-sort="field:' , data . summary . docFields . titleField , '">Document title</a></th>' , '<th style="width:15%"><a data-bls-sort="field:' , data . summary . docFields . dateField , '">Year</a></th>' , '<th style="width:15%"><a data-bls-sort="numhits">Hits</a></th>' , '</tr></thead>' ) ; html . push ( '<tbody>' ) ; $ . each ( data . docs , function ( index , doc ) { var docPid = doc . docPid ; var docTitle = doc . docInfo [ data . summary . docFields . titleField ] || 'UNKNOWN' ; var docAuthor = doc . docInfo [ data . summary . docFields . authorField ] ? ' by ' + doc . docInfo [ data . summary . docFields . authorField ] : '' ; var docDate = doc . docInfo [ data . summary . docFields . dateField ] || '' ; var docHits = doc . numberOfHits || '' ; var snippetStrings = [ ] ; $ . each ( doc . snippets , function ( index , snippet ) { var parts = snippetParts ( snippet ) ; snippetStrings . push ( ELLIPSIS , ' ' , parts [ 0 ] , '<strong>' , parts [ 1 ] , '</strong>' , parts [ 2 ] , ELLIPSIS ) ; return false ; } ) ; var docUrl ; switch ( new URI ( ) . filename ( ) ) { case '' : docUrl = new URI ( '../../docs/' ) ; break ; case 'docs' : case 'hits' : docUrl = new URI ( '../docs/' ) ; break ; case 'search' : default : docUrl = new URI ( './docs/' ) ; break ; } docUrl = docUrl . absoluteTo ( new URI ( ) . toString ( ) ) . filename ( docPid ) . search ( { 'query' : data . summary . searchParam . patt } ) . toString ( ) ; html . push ( '<tr class="documentrow">' , '<td>' , '<a target="_blank" href="' , docUrl , '">' , docTitle , docAuthor , '</a><br>' , '<span dir="' , textDirection , '">' , snippetStrings . join ( '' ) , snippetStrings . length > 0 ? '<br>' : '' , '</span>' , '<a class="green btn btn-xs btn-default" target="_blank" href="' , docUrl , '">View document info</a>' , '</td>' , '<td>' , docDate , '</td>' , '<td>' , docHits , '</td>' , '</tr>' ) ; } ) ; html . push ( '</tbody>' ) ; return html ; }
Convert a blacklab-server reply containing information about documents into a table containing the results.
Convert a blacklab - server reply containing information about documents into a table containing the results .
// only need the first snippet for now // TODO the clientside url generation story... https://github.com/INL/corpus-frontend/issues/95 // Ideally use absolute urls everywhere, if the application needs to be proxied, let the proxy server handle it. // Have a configurable url in the backend that's made available on the client that we can use here. // some weird proxy?