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>
Parameter | Type | Description |
---|---|---|
id | string | The ID to preview. |
query | Partial<Query> | The query parameters for the preview. |
customHighlights | CustomHighlights[] | (Optional) Custom highlights for the preview. |
audit | AuditEvents | (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
Parameter | Type | Description |
---|---|---|
id | string | The ID of the preview to close. |
query | Partial<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
Parameter | Type | Description |
---|---|---|
article | Article | The article to preview. |
Usage
this.previewService.openExternal(article);
setIframe
Sets the iframe window object.
setIframe(iframe: Window | null): void
Parameter | Type | Description |
---|---|---|
iframe | Window | null | The 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
Parameter | Type | Description |
---|---|---|
data | PreviewData | The preview data to be set. |
Usage
this.previewService.setPreviewData(previewData);
sendMessage
Sends a message to the iframe if it exists.
sendMessage(message: unknown): void
Parameter | Type | Description |
---|---|---|
message | unknown | The 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
Parameter | Type | Description |
---|---|---|
id | string | The unique identifier for the request. |
highlightCategory | string | The category of highlights to retrieve. |
previewData | PreviewData | The 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
Parameter | Type | Description |
---|---|---|
extracts | boolean | A boolean flag indicating whether to include extracts highlights. |
entities | boolean | A boolean flag indicating whether to include entities highlights. |
Usage
this.previewService.toggle(true, false);