Skip to main content

Preview Service

Overview

The PreviewService is responsible for handling the preview of documents, including fetching and displaying highlighted extracts and entities.

preview

Previews the data for a given ID and query.

preview(
id: string,
q: Partial<Query>,
customHighlights?: CustomHighlights[],
audit?: AuditEvents
): Observable<PreviewData>
ParameterTypeDescription
idstringThe ID to preview.
queryPartial<Query>The query parameters for the preview.
customHighlightsCustomHighlights[](Optional) Custom highlights for the preview.
auditAuditEvents(Optional) The audit events to log.

Returns:

Observable<PreviewData> - An observable that emits the preview data.

Usage

this.previewService.preview('documentId', { text: 'query' }).subscribe(data => {
console.log('Preview data:', data);
});
this.previewService.preview('documentId', { text: 'query' }, customHighlights).subscribe(data => {
console.log('Preview data:', data);
});

close

Closes the preview with the specified ID and updates the audit log.

close(id: string, query: Partial<Query>): void
ParameterTypeDescription
idstringThe ID of the preview to close.
queryPartial<Query>The partial query object used to retrieve the preview detail.

Usage

this.previewService.close('documentId', { text: 'query' });

openExternal

Previews an article in a new browser's tab.

openExternal(article: Article): void
ParameterTypeDescription
articleArticleThe article to preview.

Usage

this.previewService.openExternal(article);

setIframe

Sets the iframe window object.

setIframe(iframe: Window | null): void
ParameterTypeDescription
iframeWindow | nullThe window object of the iframe or null to unset.

Usage

this.previewService.setIframe(window);

setPreviewData

Sets the preview data and updates the highlight category based on the provided data.

setPreviewData(data: PreviewData): void
ParameterTypeDescription
dataPreviewDataThe preview data to be set.

Usage

this.previewService.setPreviewData(previewData);

sendMessage

Sends a message to the iframe if it exists.

sendMessage(message: unknown): void
ParameterTypeDescription
messageunknownThe message to be sent. It can be of any type.

Usage

this.previewService.sendMessage({ type: 'message' });
this.previewService.sendMessage({ action: 'init' });

retrieveHtmlContent

Send a message to the preview iFrame with the required data to retrieve HTML content for a specific highlight category.

retrieveHtmlContent(id: string, highlightCategory: string, previewData: PreviewData): void
ParameterTypeDescription
idstringThe unique identifier for the request.
highlightCategorystringThe category of highlights to retrieve.
previewDataPreviewDataThe data containing highlights and their locations.

Usage

this.previewService.retrieveHtmlContent('documentId', 'highlightCategory', previewData);

zoomIn

Sends a message to zoom in.

this.previewService.zoomIn();

zoomOut

Sends a message to zoom out the preview.

this.previewService.zoomOut();

toggle

Toggles the highlights based on the provided flags for extracts and entities.

toggle(extracts: boolean, entities: boolean): void
ParameterTypeDescription
extractsbooleanA boolean flag indicating whether to include extracts highlights.
entitiesbooleanA boolean flag indicating whether to include entities highlights.

Usage

this.previewService.toggle(true, false);