From 2c627f11665ebeddf1b9218f89cb067d040c55b5 Mon Sep 17 00:00:00 2001
From: MichalKinas <113341662+MichalKinas@users.noreply.github.com>
Date: Thu, 25 Jan 2024 19:36:59 +0100
Subject: [PATCH] [ACS-6620] Proper viewer extension template projection to
viewer renderer (#9273)
* [ACS-6620] Proper viewer extension template projection to viewer renderer
* [ACS-6620] Use extensions instead of content for viewer config
* [ACS-6620] Lint fix
---
demo-shell/src/assets/app.extensions.json | 2 +-
.../components/alfresco-viewer.component.md | 55 ++++++-------
.../components/viewer-render.component.md | 48 ++++++------
docs/core/components/viewer.component.md | 57 +++++++-------
.../components/alfresco-viewer.component.html | 1 +
.../components/alfresco-viewer.component.ts | 3 +
.../components/viewer-render.component.html | 17 ++--
.../viewer-render.component.spec.ts | 56 ++++++++++++-
.../components/viewer-render.component.ts | 12 ++-
.../viewer/components/viewer.component.html | 3 +-
.../lib/viewer/components/viewer.component.ts | 7 ++
.../viewer-extension.directive.spec.ts | 12 ++-
.../directives/viewer-extension.directive.ts | 8 +-
.../viewer/services/view-util.service.spec.ts | 78 +++++++++++++++++++
.../lib/viewer/services/view-util.service.ts | 13 ++--
.../src/lib/services/app-extension.service.ts | 2 +-
.../lib/services/extension-loader.service.ts | 2 +-
17 files changed, 265 insertions(+), 111 deletions(-)
create mode 100644 lib/core/src/lib/viewer/services/view-util.service.spec.ts
diff --git a/demo-shell/src/assets/app.extensions.json b/demo-shell/src/assets/app.extensions.json
index 04dd7ce556..e32a4e5cab 100644
--- a/demo-shell/src/assets/app.extensions.json
+++ b/demo-shell/src/assets/app.extensions.json
@@ -5,7 +5,7 @@
"features": {
"viewer": {
- "content": []
+ "extensions": []
},
"documentList": {
diff --git a/docs/content-services/components/alfresco-viewer.component.md b/docs/content-services/components/alfresco-viewer.component.md
index 5e5331d3d8..633c2f205c 100644
--- a/docs/content-services/components/alfresco-viewer.component.md
+++ b/docs/content-services/components/alfresco-viewer.component.md
@@ -237,47 +237,48 @@ The Viewer supports dynamically-loaded viewer preview extensions, to know more a
#### Code extension mechanism]
-You can define your own custom handler to handle other file formats that are not yet supported by
+You can define your own custom handler to override supported file formats or handle other file formats that are not yet supported by
the [Alfresco Viewer component](viewer.component.md). Below is an example that shows how to use the `adf-viewer-extension`
to handle 3D data files:
```html
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
```
Note: you need to add the `ng2-3d-editor` dependency to your `package.json` file to make the example above work.
-You can define multiple `adf-viewer-extension` templates if required:
+You need to keep all instances of `adf-viewer-extension` inside `viewerExtensions` template, also you can define multiple `adf-viewer-extension` templates if required:
```html
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
```
diff --git a/docs/core/components/viewer-render.component.md b/docs/core/components/viewer-render.component.md
index 25e6caf308..1e9fb40ccd 100644
--- a/docs/core/components/viewer-render.component.md
+++ b/docs/core/components/viewer-render.component.md
@@ -62,6 +62,7 @@ Using with file [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob):
| thumbnailsTemplate | [`TemplateRef`](https://angular.io/api/core/TemplateRef)`` | null | The template for the pdf thumbnails. |
| tracks | [`Track`](../../../lib/core/src/lib/viewer/models/viewer.model.ts)`[]` | \[] | media subtitles for the media player |
| urlFile | `string` | "" | If you want to load an external file that does not come from ACS you can use this URL to specify where to load the file from. |
+| viewerTemplateExtensions | [`TemplateRef`](https://angular.io/api/core/TemplateRef)`` | null | Template containing ViewerExtensionDirective instances providing different viewer extensions based on supported file extension. |
### Events
@@ -200,34 +201,13 @@ The [Viewer render component](viewer.component.md) should now be able to display
The Viewer supports dynamically-loaded viewer preview extensions, to know more about it [Preview Extension component](../../extensions/components/preview-extension.component.md). This
-#### Code extension mechanism]
+#### Code extension mechanism
-You can define your own custom handler to handle other file formats that are not yet supported by
-the [Viewer render component](viewer.component.md). Below is an example that shows how to use the `adf-viewer-render-extension`
-to handle 3D data files:
-
-```html
-
-
-
-
-
-
-
-
-
-
-```
-
-Note: you need to add the `ng2-3d-editor` dependency to your `package.json` file to make the example above work.
-
-You can define multiple `adf-viewer-render-extension` templates if required:
-
-```html
-
+You can define your own custom handler to override supported file formats or handle other file formats that are not yet supported by
+the [Viewer render component](viewer.component.md). In order to do that first you need to define a template containing at least one `adf-viewer-extension`:
+```html
+
+
+```
+
+Next in your component you need to get a reference of created template
+
+```ts
+@ViewChild('viewerExtensions')
+viewerTemplateExtensions: TemplateRef;
+```
+
+and pass it via `viewerTemplateExtensions` input:
+
+```html
+
+ ...
+ [viewerTemplateExtensions]="viewerTemplateExtensions"
```
diff --git a/docs/core/components/viewer.component.md b/docs/core/components/viewer.component.md
index 54c5bec5c2..83bd0b9ccf 100644
--- a/docs/core/components/viewer.component.md
+++ b/docs/core/components/viewer.component.md
@@ -85,6 +85,7 @@ See the [Custom layout](#custom-layout) section for full details of all availabl
| sidebarRightTemplateContext | | null | Context object available for binding by the local sidebarRightTemplate with let declarations. |
| tracks | [`Track`](../../../lib/core/src/lib/viewer/models/viewer.model.ts)`[]` | \[] | media subtitles for the media player |
| urlFile | `string` | "" | If you want to load an external file that does not come from ACS you can use this URL to specify where to load the file from. |
+| viewerExtensions | [`TemplateRef`](https://angular.io/api/core/TemplateRef)`` | null | Template containing ViewerExtensionDirective instances providing different viewer extensions based on supported file extension. |
### Events
@@ -209,47 +210,47 @@ The Viewer supports dynamically-loaded viewer preview extensions, to know more a
#### Code extension mechanism]
-You can define your own custom handler to handle other file formats that are not yet supported by
+You can define your own custom handler to override supported file formats or handle other file formats that are not yet supported by
the [Viewer component](viewer.component.md). Below is an example that shows how to use the `adf-viewer-extension`
to handle 3D data files:
```html
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
```
Note: you need to add the `ng2-3d-editor` dependency to your `package.json` file to make the example above work.
-You can define multiple `adf-viewer-extension` templates if required:
-
+You need to keep all instances of `adf-viewer-extension` inside `viewerExtensions` template, also you can define multiple `adf-viewer-extension` templates if required:
```html
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
```
diff --git a/lib/content-services/src/lib/viewer/components/alfresco-viewer.component.html b/lib/content-services/src/lib/viewer/components/alfresco-viewer.component.html
index 314fc14620..62b61b0233 100644
--- a/lib/content-services/src/lib/viewer/components/alfresco-viewer.component.html
+++ b/lib/content-services/src/lib/viewer/components/alfresco-viewer.component.html
@@ -24,6 +24,7 @@
[urlFile]="urlFileContent"
[tracks]="tracks"
[readOnly]="readOnly"
+ [viewerExtensions]="viewerExtensions"
(downloadFile)="onDownloadFile()"
(navigateBefore)="onNavigateBeforeClick($event)"
(navigateNext)="onNavigateNextClick($event)"
diff --git a/lib/content-services/src/lib/viewer/components/alfresco-viewer.component.ts b/lib/content-services/src/lib/viewer/components/alfresco-viewer.component.ts
index c6be71e932..80d72aa48b 100644
--- a/lib/content-services/src/lib/viewer/components/alfresco-viewer.component.ts
+++ b/lib/content-services/src/lib/viewer/components/alfresco-viewer.component.ts
@@ -80,6 +80,9 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit, OnDestroy {
@ContentChild(ViewerOpenWithComponent)
openWith: ViewerOpenWithComponent;
+ @ContentChild('viewerExtensions', { static: false })
+ viewerExtensions: TemplateRef;
+
/** Node Id of the file to load. */
@Input()
nodeId: string = null;
diff --git a/lib/core/src/lib/viewer/components/viewer-render.component.html b/lib/core/src/lib/viewer/components/viewer-render.component.html
index 1d10891f41..013857c540 100644
--- a/lib/core/src/lib/viewer/components/viewer-render.component.html
+++ b/lib/core/src/lib/viewer/components/viewer-render.component.html
@@ -79,13 +79,13 @@
-
-
-
-
+
+
+
+
+
+
@@ -94,3 +94,6 @@
+
+
+
diff --git a/lib/core/src/lib/viewer/components/viewer-render.component.spec.ts b/lib/core/src/lib/viewer/components/viewer-render.component.spec.ts
index 183cb48af3..fff55d9d55 100644
--- a/lib/core/src/lib/viewer/components/viewer-render.component.spec.ts
+++ b/lib/core/src/lib/viewer/components/viewer-render.component.spec.ts
@@ -17,7 +17,7 @@
import { Location } from '@angular/common';
import { SpyLocation } from '@angular/common/testing';
-import { Component, ViewChild } from '@angular/core';
+import { Component, TemplateRef, ViewChild } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RenderingQueueServices } from '../services/rendering-queue.services';
import { ViewerRenderComponent } from './viewer-render.component';
@@ -33,8 +33,20 @@ import { By } from '@angular/platform-browser';
@Component({
selector: 'adf-double-viewer',
template: `
-
+
+
+
+
+ JSON Viewer
+
+
+
+
+ Test Viewer
+
+
+
`
})
class DoubleViewerComponent {
@@ -44,6 +56,9 @@ class DoubleViewerComponent {
@ViewChild('viewer2')
viewer2: ViewerRenderComponent;
+ @ViewChild('viewerExtension', { static: true })
+ viewerTemplateExtensions: TemplateRef;
+
urlFileViewer1: string;
urlFileViewer2: string;
@@ -261,6 +276,42 @@ describe('ViewerComponent', () => {
});
});
+ describe('Custom viewer extension template', () => {
+ const getCustomViewerContent = (customFixture: ComponentFixture): HTMLHeadingElement =>
+ customFixture.debugElement.query(By.css('.adf-viewer-render-custom-content h1')).nativeElement;
+
+ it('should render provided custom template when file type matches supported extensions', async () => {
+ const fixtureCustom = TestBed.createComponent(DoubleViewerComponent);
+ fixtureCustom.detectChanges();
+ await fixtureCustom.whenStable();
+
+ const customComponent = fixtureCustom.componentInstance.viewer1;
+ fixtureCustom.componentInstance.urlFileViewer1 = 'fake-url-file.json';
+ customComponent.ngOnChanges();
+
+ fixtureCustom.detectChanges();
+ await fixtureCustom.whenStable();
+
+ let customContent = getCustomViewerContent(fixtureCustom);
+ expect(customComponent.extensionsSupportedByTemplates).toEqual(['json', 'test']);
+ expect(customComponent.extensionTemplates.length).toBe(2);
+ expect(customComponent.extensionTemplates[0].isVisible).toBeTrue();
+ expect(customComponent.extensionTemplates[1].isVisible).toBeFalse();
+ expect(customContent.innerText).toBe('JSON Viewer');
+
+ fixtureCustom.componentInstance.urlFileViewer1 = 'fake-url-file.test';
+ customComponent.ngOnChanges();
+
+ fixtureCustom.detectChanges();
+ await fixtureCustom.whenStable();
+
+ customContent = getCustomViewerContent(fixtureCustom);
+ expect(customComponent.extensionTemplates[0].isVisible).toBeFalse();
+ expect(customComponent.extensionTemplates[1].isVisible).toBeTrue();
+ expect(customContent.innerText).toBe('Test Viewer');
+ });
+ });
+
describe('MimeType handling', () => {
it('should display an image file identified by mimetype when the filename has no extension', (done) => {
component.urlFile = 'fake-content-img';
@@ -338,7 +389,6 @@ describe('ViewerComponent', () => {
expect(element.querySelector('adf-pdf-viewer')).not.toBeNull();
done();
});
-
}, 25000);
it('should display a PDF file identified by mimetype when the file extension is wrong', (done) => {
diff --git a/lib/core/src/lib/viewer/components/viewer-render.component.ts b/lib/core/src/lib/viewer/components/viewer-render.component.ts
index 20c4846db6..b4d7352f4d 100644
--- a/lib/core/src/lib/viewer/components/viewer-render.component.ts
+++ b/lib/core/src/lib/viewer/components/viewer-render.component.ts
@@ -18,7 +18,7 @@
import {
Component, EventEmitter,
Input, OnChanges, Output, TemplateRef,
- ViewEncapsulation, OnInit, OnDestroy
+ ViewEncapsulation, OnInit, OnDestroy, Injector
} from '@angular/core';
import { Subject } from 'rxjs';
import { ViewUtilService } from '../services/view-util.service';
@@ -79,6 +79,10 @@ export class ViewerRenderComponent implements OnChanges, OnInit, OnDestroy {
@Input()
tracks: Track[] = [];
+ /** Template containing ViewerExtensionDirective instances providing different viewer extensions based on supported file extension. */
+ @Input()
+ viewerTemplateExtensions: TemplateRef;
+
/** Emitted when the filename extension changes. */
@Output()
extensionChange = new EventEmitter();
@@ -96,6 +100,7 @@ export class ViewerRenderComponent implements OnChanges, OnInit, OnDestroy {
isSaving = new EventEmitter();
extensionTemplates: { template: TemplateRef; isVisible: boolean }[] = [];
+ extensionsSupportedByTemplates: string[] = [];
extension: string;
internalFileName: string;
viewerType: string = 'unknown';
@@ -133,7 +138,8 @@ export class ViewerRenderComponent implements OnChanges, OnInit, OnDestroy {
constructor(private viewUtilService: ViewUtilService,
private extensionService: AppExtensionService,
- public dialog: MatDialog) {
+ public dialog: MatDialog,
+ public readonly injector: Injector) {
}
ngOnInit() {
@@ -166,7 +172,7 @@ export class ViewerRenderComponent implements OnChanges, OnInit, OnDestroy {
private setUpUrlFile() {
this.internalFileName = this.fileName ? this.fileName : this.viewUtilService.getFilenameFromUrl(this.urlFile);
this.extension = this.viewUtilService.getFileExtension(this.internalFileName);
- this.viewerType = this.viewUtilService.getViewerType(this.extension, this.mimeType);
+ this.viewerType = this.viewUtilService.getViewerType(this.extension, this.mimeType, this.extensionsSupportedByTemplates);
this.extensionChange.emit(this.extension);
this.scrollTop();
diff --git a/lib/core/src/lib/viewer/components/viewer.component.html b/lib/core/src/lib/viewer/components/viewer.component.html
index 2eb3b76460..c6b22b44f1 100644
--- a/lib/core/src/lib/viewer/components/viewer.component.html
+++ b/lib/core/src/lib/viewer/components/viewer.component.html
@@ -171,7 +171,8 @@
(submitFile)="onSubmitFile($event)"
[urlFile]="urlFile"
(isSaving)="allowNavigate = !$event"
- [tracks]="tracks">
+ [tracks]="tracks"
+ [viewerTemplateExtensions]="viewerExtensions ?? viewerTemplateExtensions">
diff --git a/lib/core/src/lib/viewer/components/viewer.component.ts b/lib/core/src/lib/viewer/components/viewer.component.ts
index 3789c3c7f3..edd7b054c4 100644
--- a/lib/core/src/lib/viewer/components/viewer.component.ts
+++ b/lib/core/src/lib/viewer/components/viewer.component.ts
@@ -71,6 +71,9 @@ export class ViewerComponent implements OnDestroy, OnInit, OnChanges {
@ContentChild(ViewerMoreActionsComponent)
mnuMoreActions: ViewerMoreActionsComponent;
+ @ContentChild('viewerExtensions', { static: false })
+ viewerTemplateExtensions: TemplateRef;
+
get CloseButtonPosition() {
return CloseButtonPosition;
}
@@ -190,6 +193,10 @@ export class ViewerComponent implements OnDestroy, OnInit, OnChanges {
@Input()
hideInfoButton = false;
+ /** Template containing ViewerExtensionDirective instances providing different viewer extensions based on supported file extension. */
+ @Input()
+ viewerExtensions: TemplateRef;
+
/**
* Enable dialog box to allow user to download the previewed file, in case the preview is not responding for a set period of time.
*/
diff --git a/lib/core/src/lib/viewer/directives/viewer-extension.directive.spec.ts b/lib/core/src/lib/viewer/directives/viewer-extension.directive.spec.ts
index 10fc39a265..2c03444794 100644
--- a/lib/core/src/lib/viewer/directives/viewer-extension.directive.spec.ts
+++ b/lib/core/src/lib/viewer/directives/viewer-extension.directive.spec.ts
@@ -26,6 +26,7 @@ import { TranslateModule } from '@ngx-translate/core';
describe('ExtensionViewerDirective', () => {
let extensionViewerDirective: ViewerExtensionDirective;
+ let viewerRenderer: ViewerRenderComponent;
class MockElementRef extends ElementRef {
constructor() {
@@ -42,12 +43,13 @@ describe('ExtensionViewerDirective', () => {
providers: [
{ provide: Location, useClass: SpyLocation },
ViewerExtensionDirective,
- {provide: ElementRef, useClass: MockElementRef},
+ { provide: ElementRef, useClass: MockElementRef },
ViewerRenderComponent,
{ provide: ChangeDetectorRef, useValue: { detectChanges: () => {} } }
]
});
extensionViewerDirective = TestBed.inject(ViewerExtensionDirective);
+ viewerRenderer = TestBed.inject(ViewerRenderComponent);
extensionViewerDirective.templateModel = {template: '', isVisible: false};
});
@@ -64,4 +66,12 @@ describe('ExtensionViewerDirective', () => {
extensionViewerDirective.supportedExtensions = ['xls', 'sts'];
expect(extensionViewerDirective.isVisible('png')).not.toBeTruthy();
});
+
+ it('should set correct template and supported extensions in viewer renderer component', () => {
+ extensionViewerDirective.supportedExtensions = ['png', 'txt'];
+ extensionViewerDirective.ngAfterContentInit();
+ expect(viewerRenderer.extensionTemplates.length).toBe(1);
+ expect(viewerRenderer.extensionTemplates[0]).toEqual(extensionViewerDirective.templateModel);
+ expect(viewerRenderer.extensionsSupportedByTemplates).toEqual(extensionViewerDirective.supportedExtensions);
+ });
});
diff --git a/lib/core/src/lib/viewer/directives/viewer-extension.directive.ts b/lib/core/src/lib/viewer/directives/viewer-extension.directive.ts
index e992d4aae9..50954d0a28 100644
--- a/lib/core/src/lib/viewer/directives/viewer-extension.directive.ts
+++ b/lib/core/src/lib/viewer/directives/viewer-extension.directive.ts
@@ -46,7 +46,7 @@ export class ViewerExtensionDirective implements AfterContentInit, OnDestroy {
ngAfterContentInit() {
this.templateModel = { template: this.template, isVisible: false };
-
+ this.viewerComponent.extensionsSupportedByTemplates.push(...this.supportedExtensions);
this.viewerComponent.extensionTemplates.push(this.templateModel);
this.viewerComponent.extensionChange
@@ -54,12 +54,6 @@ export class ViewerExtensionDirective implements AfterContentInit, OnDestroy {
.subscribe(fileExtension => {
this.templateModel.isVisible = this.isVisible(fileExtension);
});
-
- if (this.supportedExtensions instanceof Array) {
- this.supportedExtensions.forEach((extension) => {
- this.viewerComponent.externalExtensions.push(extension);
- });
- }
}
ngOnDestroy() {
diff --git a/lib/core/src/lib/viewer/services/view-util.service.spec.ts b/lib/core/src/lib/viewer/services/view-util.service.spec.ts
new file mode 100644
index 0000000000..8bc0ec8302
--- /dev/null
+++ b/lib/core/src/lib/viewer/services/view-util.service.spec.ts
@@ -0,0 +1,78 @@
+/*!
+ * @license
+ * Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { AppExtensionService } from '@alfresco/adf-extensions';
+import { HttpClientTestingModule } from '@angular/common/http/testing';
+import { TestBed } from '@angular/core/testing';
+import { ViewUtilService } from './view-util.service';
+
+describe('ViewUtilService', () => {
+ let viewUtilService: ViewUtilService;
+ let appExtensionService: AppExtensionService;
+ const extensionsSupportedByTemplates = ['dmn', 'txt'];
+
+ beforeEach(() => {
+ TestBed.configureTestingModule({
+ imports: [HttpClientTestingModule],
+ providers: [AppExtensionService]
+ });
+
+ viewUtilService = TestBed.inject(ViewUtilService);
+ appExtensionService = TestBed.inject(AppExtensionService);
+ });
+
+ it('should extract file name from url', () => {
+ expect(viewUtilService.getFilenameFromUrl('http://localhost/test.jpg?cache=1000')).toBe('test.jpg');
+ expect(viewUtilService.getFilenameFromUrl('http://localhost:4200/test-path/test2.json#cache=1000')).toBe('test2.json');
+ });
+
+ it('should extract file extension from url', () => {
+ expect(viewUtilService.getFileExtension('http://localhost/test.jpg?cache=1000')).toBe('jpg');
+ expect(viewUtilService.getFileExtension('http://localhost:4200/test-path/test2.json#cache=1000')).toBe('json');
+ });
+
+ it('should return correct viewer type based on file mime type', () => {
+ expect(viewUtilService.getViewerTypeByMimeType('text/plain')).toBe('text');
+ expect(viewUtilService.getViewerTypeByMimeType('application/pdf')).toBe('pdf');
+ expect(viewUtilService.getViewerTypeByMimeType('image/gif')).toBe('image');
+ expect(viewUtilService.getViewerTypeByMimeType('video/webm')).toBe('media');
+ expect(viewUtilService.getViewerTypeByMimeType('image/test')).toBe('unknown');
+ });
+
+ it('should check if extension is custom one added either by extension service or by a template in viewer renderer', () => {
+ spyOn(appExtensionService, 'getViewerExtensions').and.returnValue([{ fileExtension: 'json', component: 'test', id: 'test' }]);
+ expect(viewUtilService.isCustomViewerExtension('pdf')).toBeFalse();
+ expect(viewUtilService.isCustomViewerExtension('txt')).toBeFalse();
+ expect(viewUtilService.isCustomViewerExtension('json')).toBeTrue();
+ expect(viewUtilService.isCustomViewerExtension('docx', extensionsSupportedByTemplates)).toBeFalse();
+ expect(viewUtilService.isCustomViewerExtension('dmn', extensionsSupportedByTemplates)).toBeTrue();
+ expect(viewUtilService.isCustomViewerExtension('txt', extensionsSupportedByTemplates)).toBeTrue();
+ });
+
+ it('should return correct viewer type based on extension and mime type', () => {
+ spyOn(appExtensionService, 'getViewerExtensions').and.returnValue([{ fileExtension: '*', component: 'test', id: 'test' }]);
+ expect(viewUtilService.getViewerType('pdf', 'application/pdf')).toBe('external');
+
+ appExtensionService.getViewerExtensions = jasmine.createSpy().and.returnValue([{ fileExtension: 'json', component: 'test', id: 'test' }]);
+ expect(viewUtilService.getViewerType('json', '')).toBe('custom');
+ expect(viewUtilService.getViewerType('dmn', '')).toBe('unknown');
+ expect(viewUtilService.getViewerType('dmn', '', extensionsSupportedByTemplates)).toBe('custom');
+
+ expect(viewUtilService.getViewerType('pdf', '')).toBe('pdf');
+ expect(viewUtilService.getViewerType('', 'application/pdf')).toBe('pdf');
+ });
+});
diff --git a/lib/core/src/lib/viewer/services/view-util.service.ts b/lib/core/src/lib/viewer/services/view-util.service.ts
index 6e2e497f58..418d35300a 100644
--- a/lib/core/src/lib/viewer/services/view-util.service.ts
+++ b/lib/core/src/lib/viewer/services/view-util.service.ts
@@ -88,8 +88,8 @@ export class ViewUtilService {
return null;
}
- getViewerType(extension: string, mimeType: string): string {
- let viewerType = this.getViewerTypeByExtension(extension);
+ getViewerType(extension: string, mimeType: string, extensionsSupportedByTemplates?: string[]): string {
+ let viewerType = this.getViewerTypeByExtension(extension, extensionsSupportedByTemplates);
if (viewerType === 'unknown') {
viewerType = this.getViewerTypeByMimeType(mimeType);
@@ -112,7 +112,7 @@ export class ViewUtilService {
return 'unknown';
}
- private getViewerTypeByExtension(extension: string): string {
+ private getViewerTypeByExtension(extension: string, extensionsSupportedByTemplates?: string[]): string {
if (extension) {
extension = extension.toLowerCase();
}
@@ -121,7 +121,7 @@ export class ViewUtilService {
return 'external';
}
- if (this.isCustomViewerExtension(extension)) {
+ if (this.isCustomViewerExtension(extension, extensionsSupportedByTemplates)) {
return 'custom';
}
@@ -148,8 +148,11 @@ export class ViewUtilService {
return !!this.viewerExtensions.find((ext) => ext.fileExtension === '*');
}
- isCustomViewerExtension(extension: string): boolean {
+ isCustomViewerExtension(extension: string, extensionsSupportedByTemplates?: string[]): boolean {
const extensions = this.externalExtensions || [];
+ if (extensionsSupportedByTemplates) {
+ extensions.push(...extensionsSupportedByTemplates);
+ }
if (extension && extensions.length > 0) {
extension = extension.toLowerCase();
diff --git a/lib/extensions/src/lib/services/app-extension.service.ts b/lib/extensions/src/lib/services/app-extension.service.ts
index b95a25f647..086a3419b4 100644
--- a/lib/extensions/src/lib/services/app-extension.service.ts
+++ b/lib/extensions/src/lib/services/app-extension.service.ts
@@ -72,7 +72,7 @@ export class AppExtensionService {
*/
getViewerExtensions(): ViewerExtensionRef[] {
return this.extensionService
- .getElements('features.viewer.content')
+ .getElements('features.viewer.extensions')
.filter((extension) => !this.isViewerExtensionDisabled(extension));
}
diff --git a/lib/extensions/src/lib/services/extension-loader.service.ts b/lib/extensions/src/lib/services/extension-loader.service.ts
index 1e036bce8c..3ee3096ccc 100644
--- a/lib/extensions/src/lib/services/extension-loader.service.ts
+++ b/lib/extensions/src/lib/services/extension-loader.service.ts
@@ -96,7 +96,7 @@ export class ExtensionLoaderService {
* Retrieves configuration elements.
* Filters element by **enabled** and **order** attributes.
* Example:
- * `getElements(config, 'features.viewer.content')`
+ * `getElements(config, 'features.viewer.extensions')`
*
* @param config configuration settings
* @param key element key