Skip to main content

Preview

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

Functions

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

export class MyComponent {
previewService: PreviewService = ...; // Assume this is injected or instantiated

previewDocument() {
// Assuming 'documentId' is the ID of the document to preview
this.previewService.preview('documentId', { text: 'query' }).subscribe(data => {
console.log('Preview data:', data);
});
}
}
export class MyComponent {
previewService: PreviewService = ...; // Assume this is injected or instantiated

previewDocument() {
const customHighlights: CustomHighlights[] = [
{ id: 'highlight1', text: 'Custom highlight text', category: 'category1' },
// Add more custom highlights as needed
];
// Assuming 'documentId' is the ID of the document to preview
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

export class MyComponent {
previewService: PreviewService = ...; // Assume this is injected or instantiated

closePreview() {
// Assuming 'documentId' is the ID of the document to close
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

export class MyComponent {
previewService: PreviewService = ...; // Assume this is injected or instantiated

openArticlePreview(article: Article) {
// Assuming 'article' is an instance of Article
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

export class MyComponent {
previewService: PreviewService = ...; // Assume this is injected or instantiated

setIframeWindow() {
// Assuming you have a reference to the iframe window
const iframeWindow: Window = document.getElementById('myIframe')?.contentWindow;
this.previewService.setIframe(iframeWindow);
}
}

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

export class MyComponent {
previewService: PreviewService = ...; // Assume this is injected or instantiated

setPreview() {
const previewData: PreviewData = { /* ... */ }; // Your preview data here
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

export class MyComponent {
previewService: PreviewService = ...; // Assume this is injected or instantiated

sendMessageToPreview() {
this.previewService.sendMessage({ type: 'message', data: { /* your data */ } });
}

initPreview() {
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

export class MyComponent {
previewService: PreviewService = ...; // Assume this is injected or instantiated

getHtmlContent() {
const previewData: PreviewData = { /* ... */ }; // Your preview data here
this.previewService.retrieveHtmlContent('documentId', 'highlightCategory', previewData);
}
}

zoomIn()

Sends a message to zoom in.

export class MyComponent {
previewService: PreviewService = ...; // Assume this is injected or instantiated

zoomInPreview() {
this.previewService.zoomIn();
}
}

zoomOut()

Sends a message to zoom out the preview.

export class MyComponent {
previewService: PreviewService = ...; // Assume this is injected or instantiated

zoomOutPreview() {
this.previewService.zoomOut();
}
}

toggleAIDescription()

Toggles the AI description in the preview.

toggleAIDescription(enabled: boolean): void;
ParameterTypeDescription
enabledbooleanA boolean flag indicating whether to enable or disable the AI description.

Usage

export class MyComponent {
previewService: PreviewService = ...; // Assume this is injected or instantiated

toggleDescription() {
this.previewService.toggleAiDescription(false); // Disable AI description
}
}

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

export class MyComponent {
previewService: PreviewService = ...; // Assume this is injected or instantiated

toggleHighlights() {
const entities = true; // or false
const extracts = false; // or true
this.previewService.toggle(extracts, entities);
}
}