mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-12 17:04:57 +00:00
[ACS-8863] Add nodeMimeType to keep proper file icon when renditions are generated (#10508)
* [ACS-8863] Add nodeMimeType to keep proper file icon when renditions are generated * [ACS-8863] Small fix
This commit is contained in:
parent
dc7e5c2215
commit
d45155bcb2
@ -89,6 +89,7 @@ See the [Custom layout](#custom-layout) section for full details of all availabl
|
|||||||
| 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. |
|
| 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)`<any>` | null | Template containing ViewerExtensionDirective instances providing different viewer extensions based on supported file extension. |
|
| viewerExtensions | [`TemplateRef`](https://angular.io/api/core/TemplateRef)`<any>` | null | Template containing ViewerExtensionDirective instances providing different viewer extensions based on supported file extension. |
|
||||||
| nodeId | `string` | null | Identifier of a node opened by a viewer. |
|
| nodeId | `string` | null | Identifier of a node opened by a viewer. |
|
||||||
|
| nodeMimeType | `string` | undefined | Original node mime type, should be provided when renditiona mime type is different. |
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
[hideInfoButton]="hideInfoButton"
|
[hideInfoButton]="hideInfoButton"
|
||||||
[fileName]="fileName"
|
[fileName]="fileName"
|
||||||
[mimeType]="mimeType"
|
[mimeType]="mimeType"
|
||||||
|
[nodeMimeType]="nodeMimeType"
|
||||||
[urlFile]="urlFileContent"
|
[urlFile]="urlFileContent"
|
||||||
[tracks]="tracks"
|
[tracks]="tracks"
|
||||||
[readOnly]="readOnly"
|
[readOnly]="readOnly"
|
||||||
|
@ -466,7 +466,7 @@ describe('AlfrescoViewerComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('mimeType', () => {
|
describe('mimeType', () => {
|
||||||
it('should set mime type based on renditionMimeType rather then nodeData', async () => {
|
it('should set mime type based on renditionMimeType rather then nodeData and keep proper nodeMimeType', async () => {
|
||||||
const defaultNode: Node = {
|
const defaultNode: Node = {
|
||||||
id: 'mock-id',
|
id: 'mock-id',
|
||||||
name: 'Mock Node',
|
name: 'Mock Node',
|
||||||
@ -499,6 +499,7 @@ describe('AlfrescoViewerComponent', () => {
|
|||||||
|
|
||||||
await fixture.whenStable();
|
await fixture.whenStable();
|
||||||
expect(component.mimeType).toEqual('application/pdf');
|
expect(component.mimeType).toEqual('application/pdf');
|
||||||
|
expect(component.nodeMimeType).toEqual('application/msWord');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -211,6 +211,7 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit {
|
|||||||
urlFileContent: string;
|
urlFileContent: string;
|
||||||
fileName: string;
|
fileName: string;
|
||||||
mimeType: string;
|
mimeType: string;
|
||||||
|
nodeMimeType: string;
|
||||||
nodeEntry: NodeEntry;
|
nodeEntry: NodeEntry;
|
||||||
tracks: Track[] = [];
|
tracks: Track[] = [];
|
||||||
readOnly: boolean = true;
|
readOnly: boolean = true;
|
||||||
@ -317,6 +318,7 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit {
|
|||||||
private async setUpNodeFile(nodeData: Node, versionData?: Version): Promise<void> {
|
private async setUpNodeFile(nodeData: Node, versionData?: Version): Promise<void> {
|
||||||
this.readOnly = !this.contentService.hasAllowableOperations(nodeData, 'update');
|
this.readOnly = !this.contentService.hasAllowableOperations(nodeData, 'update');
|
||||||
let mimeType: string;
|
let mimeType: string;
|
||||||
|
let nodeMimeType: string;
|
||||||
let urlFileContent: string;
|
let urlFileContent: string;
|
||||||
|
|
||||||
if (versionData?.content) {
|
if (versionData?.content) {
|
||||||
@ -324,6 +326,7 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit {
|
|||||||
} else if (nodeData.content) {
|
} else if (nodeData.content) {
|
||||||
mimeType = nodeData.content.mimeType;
|
mimeType = nodeData.content.mimeType;
|
||||||
}
|
}
|
||||||
|
nodeMimeType = mimeType;
|
||||||
|
|
||||||
const currentFileVersion = this.nodeEntry?.entry?.properties?.['cm:versionLabel']
|
const currentFileVersion = this.nodeEntry?.entry?.properties?.['cm:versionLabel']
|
||||||
? encodeURI(this.nodeEntry?.entry?.properties['cm:versionLabel'])
|
? encodeURI(this.nodeEntry?.entry?.properties['cm:versionLabel'])
|
||||||
@ -333,7 +336,6 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit {
|
|||||||
urlFileContent = urlFileContent + '&' + currentFileVersion;
|
urlFileContent = urlFileContent + '&' + currentFileVersion;
|
||||||
|
|
||||||
const fileExtension = this.viewUtilService.getFileExtension(versionData ? versionData.name : nodeData.name);
|
const fileExtension = this.viewUtilService.getFileExtension(versionData ? versionData.name : nodeData.name);
|
||||||
this.fileName = versionData ? versionData.name : nodeData.name;
|
|
||||||
const viewerType = this.viewUtilService.getViewerType(fileExtension, mimeType);
|
const viewerType = this.viewUtilService.getViewerType(fileExtension, mimeType);
|
||||||
|
|
||||||
if (viewerType === 'unknown') {
|
if (viewerType === 'unknown') {
|
||||||
@ -346,7 +348,7 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit {
|
|||||||
if (nodeRendition) {
|
if (nodeRendition) {
|
||||||
urlFileContent = nodeRendition.url;
|
urlFileContent = nodeRendition.url;
|
||||||
|
|
||||||
const nodeMimeType = nodeData?.content?.mimeType;
|
nodeMimeType = nodeData?.content?.mimeType;
|
||||||
const renditionMimeType = nodeRendition.mimeType;
|
const renditionMimeType = nodeRendition.mimeType;
|
||||||
mimeType = renditionMimeType || nodeMimeType;
|
mimeType = renditionMimeType || nodeMimeType;
|
||||||
}
|
}
|
||||||
@ -355,6 +357,8 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.mimeType = mimeType;
|
this.mimeType = mimeType;
|
||||||
|
this.nodeMimeType = nodeMimeType;
|
||||||
|
this.fileName = versionData ? versionData.name : nodeData.name;
|
||||||
this.urlFileContent = urlFileContent + (this.cacheBusterNumber ? '&' + this.cacheBusterNumber : '');
|
this.urlFileContent = urlFileContent + (this.cacheBusterNumber ? '&' + this.cacheBusterNumber : '');
|
||||||
this.sidebarRightTemplateContext.node = nodeData;
|
this.sidebarRightTemplateContext.node = nodeData;
|
||||||
this.sidebarLeftTemplateContext.node = nodeData;
|
this.sidebarLeftTemplateContext.node = nodeData;
|
||||||
|
@ -35,6 +35,7 @@ import { ViewerWithCustomSidebarComponent } from './mock/adf-viewer-container-si
|
|||||||
import { ViewerWithCustomToolbarActionsComponent } from './mock/adf-viewer-container-toolbar-actions.component.mock';
|
import { ViewerWithCustomToolbarActionsComponent } from './mock/adf-viewer-container-toolbar-actions.component.mock';
|
||||||
import { ViewerWithCustomToolbarComponent } from './mock/adf-viewer-container-toolbar.component.mock';
|
import { ViewerWithCustomToolbarComponent } from './mock/adf-viewer-container-toolbar.component.mock';
|
||||||
import { ViewerComponent } from './viewer.component';
|
import { ViewerComponent } from './viewer.component';
|
||||||
|
import { ThumbnailService } from '@alfresco/adf-core';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'adf-dialog-dummy',
|
selector: 'adf-dialog-dummy',
|
||||||
@ -49,6 +50,7 @@ describe('ViewerComponent', () => {
|
|||||||
let dialog: MatDialog;
|
let dialog: MatDialog;
|
||||||
let viewUtilService: ViewUtilService;
|
let viewUtilService: ViewUtilService;
|
||||||
let appConfigService: AppConfigService;
|
let appConfigService: AppConfigService;
|
||||||
|
let thumbnailService: ThumbnailService;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
@ -72,6 +74,7 @@ describe('ViewerComponent', () => {
|
|||||||
dialog = TestBed.inject(MatDialog);
|
dialog = TestBed.inject(MatDialog);
|
||||||
viewUtilService = TestBed.inject(ViewUtilService);
|
viewUtilService = TestBed.inject(ViewUtilService);
|
||||||
appConfigService = TestBed.inject(AppConfigService);
|
appConfigService = TestBed.inject(AppConfigService);
|
||||||
|
thumbnailService = TestBed.inject(ThumbnailService);
|
||||||
component.fileName = 'test-file.pdf';
|
component.fileName = 'test-file.pdf';
|
||||||
|
|
||||||
appConfigService.config = {
|
appConfigService.config = {
|
||||||
@ -97,6 +100,27 @@ describe('ViewerComponent', () => {
|
|||||||
|
|
||||||
expect(component.mimeType).toBe('image/png');
|
expect(component.mimeType).toBe('image/png');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should set mimeTypeIconUrl when mimeType changes and no nodeMimeType is provided', () => {
|
||||||
|
spyOn(thumbnailService, 'getMimeTypeIcon').and.returnValue('image/png');
|
||||||
|
const mockSimpleChanges: any = { mimeType: { currentValue: 'image/png' }, nodeMimeType: undefined };
|
||||||
|
|
||||||
|
component.ngOnChanges(mockSimpleChanges);
|
||||||
|
|
||||||
|
expect(thumbnailService.getMimeTypeIcon).toHaveBeenCalledWith('image/png');
|
||||||
|
expect(component.mimeTypeIconUrl).toBe('image/png');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set mimeTypeIconUrl when nodeMimeType changes', () => {
|
||||||
|
spyOn(thumbnailService, 'getMimeTypeIcon').and.returnValue('application/pdf');
|
||||||
|
const mockSimpleChanges: any = { mimeType: { currentValue: 'image/png' }, nodeMimeType: { currentValue: 'application/pdf' } };
|
||||||
|
|
||||||
|
component.ngOnChanges(mockSimpleChanges);
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(thumbnailService.getMimeTypeIcon).toHaveBeenCalledWith('application/pdf');
|
||||||
|
expect(component.mimeTypeIconUrl).toBe('application/pdf');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('File Name Test', () => {
|
describe('File Name Test', () => {
|
||||||
|
@ -244,6 +244,10 @@ export class ViewerComponent<T> implements OnDestroy, OnInit, OnChanges {
|
|||||||
@Input()
|
@Input()
|
||||||
nodeId: string = null;
|
nodeId: string = null;
|
||||||
|
|
||||||
|
/** Original node mime type, should be provided when renditiona mime type is different. */
|
||||||
|
@Input()
|
||||||
|
nodeMimeType: string = undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable dialog box to allow user to download the previewed file, in case the preview is not responding for a set period of time.
|
* Enable dialog box to allow user to download the previewed file, in case the preview is not responding for a set period of time.
|
||||||
*/
|
*/
|
||||||
@ -303,7 +307,7 @@ export class ViewerComponent<T> implements OnDestroy, OnInit, OnChanges {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnChanges(changes: SimpleChanges) {
|
ngOnChanges(changes: SimpleChanges) {
|
||||||
const { blobFile, urlFile, mimeType } = changes;
|
const { blobFile, urlFile, mimeType, nodeMimeType } = changes;
|
||||||
|
|
||||||
if (blobFile?.currentValue) {
|
if (blobFile?.currentValue) {
|
||||||
this.mimeType = blobFile.currentValue.type;
|
this.mimeType = blobFile.currentValue.type;
|
||||||
@ -314,9 +318,13 @@ export class ViewerComponent<T> implements OnDestroy, OnInit, OnChanges {
|
|||||||
this.fileName ||= this.viewUtilsService.getFilenameFromUrl(urlFile.currentValue);
|
this.fileName ||= this.viewUtilsService.getFilenameFromUrl(urlFile.currentValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mimeType?.currentValue) {
|
if (mimeType?.currentValue && !nodeMimeType?.currentValue) {
|
||||||
this.mimeTypeIconUrl = this.thumbnailService.getMimeTypeIcon(mimeType.currentValue);
|
this.mimeTypeIconUrl = this.thumbnailService.getMimeTypeIcon(mimeType.currentValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nodeMimeType?.currentValue) {
|
||||||
|
this.mimeTypeIconUrl = this.thumbnailService.getMimeTypeIcon(nodeMimeType.currentValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user