fix: ng2-alfresco-search

This commit is contained in:
Denys Vuika
2016-12-08 18:35:29 +00:00
parent f954930678
commit d973c39462
12 changed files with 45 additions and 11 deletions

View File

@@ -134,11 +134,14 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
spyOn(thumbnailService, 'getMimeTypeIcon').and.returnValue('fake-type-icon.svg');
spyOn(thumbnailService, 'getMimeTypeKey').and.returnValue('FAKE_TYPE');
let path = 'http://localhost/fake-type-icon.svg';
spyOn(component, 'resolveIconPath').and.returnValue(path);
component.resultsLoad.subscribe(() => {
fixture.detectChanges();
let imgEl = <any> element.querySelector('#result_row_0 img');
expect(imgEl).not.toBeNull();
expect(imgEl.src).toBe('../img/fake-type-icon.svg');
expect(imgEl.src).toBe(path);
expect(imgEl.alt).toBe('SEARCH.ICONS.FAKE_TYPE');
done();
});

View File

@@ -124,10 +124,25 @@ export class AlfrescoSearchAutocompleteComponent implements OnInit, OnChanges {
getMimeTypeIcon(node: any): string {
if (node.entry.content && node.entry.content.mimeType) {
let icon = this.alfrescoThumbnailService.getMimeTypeIcon(node.entry.content.mimeType);
return require(`./../img/${icon}`);
return this.resolveIconPath(icon);
}
}
resolveIconPath(icon: string): string {
let result = null;
try {
// webpack
result = require(`./../img/${icon}`);
} catch (e) {
// system.js
if (module && module.id) {
let baseComponentPath = module.id.replace('/components/alfresco-search-autocomplete.component.js', '');
result = `${baseComponentPath}/img/${icon}`;
}
}
return result;
}
/**
* Gets thumbnail message key for the given document node, which can be used to look up alt text
* @param node Node to get URL for.

View File

@@ -91,10 +91,25 @@ export class AlfrescoSearchComponent implements OnChanges, OnInit {
getMimeTypeIcon(node: any): string {
if (node.entry.content && node.entry.content.mimeType) {
let icon = this._alfrescoThumbnailService.getMimeTypeIcon(node.entry.content.mimeType);
return require(`./../img/${icon}`);
return this.resolveIconPath(icon);
}
}
private resolveIconPath(icon: string): string {
let result = null;
try {
// webpack
result = require(`./../img/${icon}`);
} catch (e) {
// system.js
if (module && module.id) {
let baseComponentPath = module.id.replace('/components/alfresco-search.component.js', '');
result = `${baseComponentPath}/img/${icon}`;
}
}
return result;
}
/**
* Gets thumbnail message key for the given document node, which can be used to look up alt text
* @param node Node to get URL for.