{
@@ -134,15 +104,15 @@ export class DocumentListService {
* @returns {string} URL address.
*/
getDocumentThumbnailUrl(node: MinimalNodeEntity) {
- if (node && this.contentService) {
- return this.contentService.getDocumentThumbnailUrl(node);
- }
- return null;
+ return this.thumbnailService.getDocumentThumbnailUrl(node);
}
getMimeTypeIcon(mimeType: string): string {
- let icon = this.mimeTypeIcons[mimeType];
- return icon || DocumentListService.DEFAULT_MIME_TYPE_ICON;
+ return this.thumbnailService.getMimeTypeIcon(mimeType);
+ }
+
+ getDefaultMimeTypeIcon(): string {
+ return this.thumbnailService.getDefaultMimeTypeIcon();
}
private handleError(error: Response) {
diff --git a/ng2-components/ng2-alfresco-search/index.ts b/ng2-components/ng2-alfresco-search/index.ts
index 6ac815eb1d..62629bdaa1 100644
--- a/ng2-components/ng2-alfresco-search/index.ts
+++ b/ng2-components/ng2-alfresco-search/index.ts
@@ -19,7 +19,6 @@ import { NgModule, ModuleWithProviders } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { CoreModule } from 'ng2-alfresco-core';
import { AlfrescoSearchService } from './src/services/alfresco-search.service';
-import { AlfrescoThumbnailService } from './src/services/alfresco-thumbnail.service';
import { AlfrescoSearchComponent } from './src/components/alfresco-search.component';
import { AlfrescoSearchControlComponent } from './src/components/alfresco-search-control.component';
import { AlfrescoSearchAutocompleteComponent } from './src/components/alfresco-search-autocomplete.component';
@@ -27,7 +26,6 @@ import { DocumentListModule } from 'ng2-alfresco-documentlist';
// services
export * from './src/services/alfresco-search.service';
-export * from './src/services/alfresco-thumbnail.service';
export * from './src/components/alfresco-search.component';
export * from './src/components/alfresco-search-control.component';
export * from './src/components/alfresco-search-autocomplete.component';
@@ -39,8 +37,7 @@ export const ALFRESCO_SEARCH_DIRECTIVES: [any] = [
];
export const ALFRESCO_SEARCH_PROVIDERS: [any] = [
- AlfrescoSearchService,
- AlfrescoThumbnailService
+ AlfrescoSearchService
];
@NgModule({
diff --git a/ng2-components/ng2-alfresco-search/src/components/alfresco-search-autocomplete.component.html b/ng2-components/ng2-alfresco-search/src/components/alfresco-search-autocomplete.component.html
index af3d623fc0..04e51ce444 100644
--- a/ng2-components/ng2-alfresco-search/src/components/alfresco-search-autocomplete.component.html
+++ b/ng2-components/ng2-alfresco-search/src/components/alfresco-search-autocomplete.component.html
@@ -9,7 +9,7 @@
(keyup.arrowup)="onRowArrowUp($event)"
(keyup.escape)="onRowEscape($event)"
attr.data-automation-id="autocomplete_result_for_{{result.entry.name}}">
- }}) |
+ }}) |
{{result.entry.name}}
{{result.entry.createdByUser.displayName}}
diff --git a/ng2-components/ng2-alfresco-search/src/components/alfresco-search-autocomplete.component.spec.ts b/ng2-components/ng2-alfresco-search/src/components/alfresco-search-autocomplete.component.spec.ts
index 3e2a83c70d..41f20b1e96 100644
--- a/ng2-components/ng2-alfresco-search/src/components/alfresco-search-autocomplete.component.spec.ts
+++ b/ng2-components/ng2-alfresco-search/src/components/alfresco-search-autocomplete.component.spec.ts
@@ -17,7 +17,7 @@
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { AlfrescoSearchAutocompleteComponent } from './alfresco-search-autocomplete.component';
-import { AlfrescoThumbnailService } from './../services/alfresco-thumbnail.service';
+import { ThumbnailService } from 'ng2-alfresco-core';
import { TranslationMock } from './../assets/translation.service.mock';
import { result, results, folderResult, noResult, errorJson } from './../assets/alfresco-search.component.mock';
import { AlfrescoSearchService } from '../services/alfresco-search.service';
@@ -49,7 +49,7 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
declarations: [ AlfrescoSearchAutocompleteComponent ], // declare the test component
providers: [
{provide: AlfrescoTranslationService, useClass: TranslationMock},
- AlfrescoThumbnailService,
+ ThumbnailService,
AlfrescoSettingsService,
AlfrescoApiService,
AlfrescoAuthenticationService,
@@ -130,19 +130,14 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
spyOn(searchService, 'getQueryNodesPromise')
.and.returnValue(Promise.resolve(result));
- let thumbnailService = fixture.debugElement.injector.get(AlfrescoThumbnailService);
+ let thumbnailService = fixture.debugElement.injector.get(ThumbnailService);
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 = element.querySelector('#result_row_0 img');
expect(imgEl).not.toBeNull();
- expect(imgEl.src).toBe(path);
- expect(imgEl.alt).toBe('SEARCH.ICONS.FAKE_TYPE');
+ expect(imgEl.src).toContain('fake-type-icon.svg');
done();
});
@@ -233,8 +228,7 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
it('should emit fileSelect event if when folder item clicked', (done) => {
- spyOn(searchService, 'getQueryNodesPromise')
- .and.returnValue(Promise.resolve(folderResult));
+ spyOn(searchService, 'getQueryNodesPromise').and.returnValue(Promise.resolve(folderResult));
spyOn(component.fileSelect, 'emit');
component.resultsLoad.subscribe(() => {
diff --git a/ng2-components/ng2-alfresco-search/src/components/alfresco-search-autocomplete.component.ts b/ng2-components/ng2-alfresco-search/src/components/alfresco-search-autocomplete.component.ts
index 0e39a43c81..a4cdabb6aa 100644
--- a/ng2-components/ng2-alfresco-search/src/components/alfresco-search-autocomplete.component.ts
+++ b/ng2-components/ng2-alfresco-search/src/components/alfresco-search-autocomplete.component.ts
@@ -19,7 +19,7 @@ import { Component, ElementRef, EventEmitter, Input, OnInit, OnChanges, Output,
import { AlfrescoTranslationService } from 'ng2-alfresco-core';
import { MinimalNodeEntity } from 'alfresco-js-api';
import { AlfrescoSearchService, SearchOptions } from './../services/alfresco-search.service';
-import { AlfrescoThumbnailService } from './../services/alfresco-thumbnail.service';
+import { ThumbnailService } from 'ng2-alfresco-core';
declare var require: any;
@@ -71,7 +71,7 @@ export class AlfrescoSearchAutocompleteComponent implements OnInit, OnChanges {
constructor(private searchService: AlfrescoSearchService,
private translateService: AlfrescoTranslationService,
- private thumbnailService: AlfrescoThumbnailService) {
+ private thumbnailService: ThumbnailService) {
}
ngOnInit(): void {
@@ -124,30 +124,16 @@ export class AlfrescoSearchAutocompleteComponent implements OnInit, OnChanges {
* @returns {string} URL address.
*/
getMimeTypeIcon(node: MinimalNodeEntity): string {
+ let mimeType;
+
if (node.entry.content && node.entry.content.mimeType) {
- let icon = this.thumbnailService.getMimeTypeIcon(node.entry.content.mimeType);
- return this.resolveIconPath(icon);
+ mimeType = node.entry.content.mimeType;
}
if (node.entry.isFolder) {
- return require('../assets/images/ft_ic_folder.svg');
+ mimeType = 'folder';
}
- }
- resolveIconPath(icon: string): string {
- return require('../assets/images/' + icon);
- }
-
- /**
- * 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.
- * @returns {string} URL address.
- */
- getMimeTypeKey(node: MinimalNodeEntity): string {
- if (node.entry.content && node.entry.content.mimeType) {
- return 'SEARCH.ICONS.' + this.thumbnailService.getMimeTypeKey(node.entry.content.mimeType);
- } else {
- return '';
- }
+ return this.thumbnailService.getMimeTypeIcon(mimeType);
}
focusResult(): void {
diff --git a/ng2-components/ng2-alfresco-search/src/components/alfresco-search-control.component.spec.ts b/ng2-components/ng2-alfresco-search/src/components/alfresco-search-control.component.spec.ts
index 79ef73cb6a..0280d13b1b 100644
--- a/ng2-components/ng2-alfresco-search/src/components/alfresco-search-control.component.spec.ts
+++ b/ng2-components/ng2-alfresco-search/src/components/alfresco-search-control.component.spec.ts
@@ -18,7 +18,7 @@
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { AlfrescoSearchControlComponent } from './alfresco-search-control.component';
import { AlfrescoSearchAutocompleteComponent } from './alfresco-search-autocomplete.component';
-import { AlfrescoThumbnailService } from './../services/alfresco-thumbnail.service';
+import { ThumbnailService } from 'ng2-alfresco-core';
import { TranslationMock } from './../assets/translation.service.mock';
import { result } from './../assets/alfresco-search.component.mock';
import { CoreModule, AlfrescoTranslationService } from 'ng2-alfresco-core';
@@ -43,7 +43,7 @@ describe('AlfrescoSearchControlComponent', () => {
],
providers: [
{provide: AlfrescoTranslationService, useClass: TranslationMock},
- AlfrescoThumbnailService,
+ ThumbnailService,
AlfrescoSearchService
]
}).compileComponents().then(() => {
diff --git a/ng2-components/ng2-alfresco-search/src/services/alfresco-thumbnail.service.spec.ts b/ng2-components/ng2-alfresco-search/src/services/alfresco-thumbnail.service.spec.ts
deleted file mode 100644
index 8ad849eb14..0000000000
--- a/ng2-components/ng2-alfresco-search/src/services/alfresco-thumbnail.service.spec.ts
+++ /dev/null
@@ -1,62 +0,0 @@
-/*!
- * @license
- * Copyright 2016 Alfresco Software, Ltd.
- *
- * 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 { TestBed, async } from '@angular/core/testing';
-import { AlfrescoThumbnailService } from './alfresco-thumbnail.service';
-import { CoreModule } from 'ng2-alfresco-core';
-
-describe('AlfrescoThumbnailService', () => {
-
- let service: AlfrescoThumbnailService;
-
- beforeEach(async(() => {
- TestBed.configureTestingModule({
- imports: [
- CoreModule.forRoot()
- ],
- providers: [
- AlfrescoThumbnailService
- ]
- }).compileComponents();
- }));
-
- beforeEach(() => {
- service = TestBed.get(AlfrescoThumbnailService);
- });
-
- it('should return the correct icon for a plain text file', () => {
- expect(service.getMimeTypeIcon('text/plain')).toBe('ft_ic_document.svg');
- });
-
- it('should return the correct icon for a PNG file', () => {
- expect(service.getMimeTypeIcon('image/png')).toBe('ft_ic_raster_image.svg');
- });
-
- it('should return the correct icon for a MP4 video file', () => {
- expect(service.getMimeTypeIcon('video/mp4')).toBe('ft_ic_video.svg');
- });
-
- it('should return a generic icon for an unknown file', () => {
- expect(service.getMimeTypeIcon('x-unknown/yyy')).toBe('ft_ic_miscellaneous.svg');
- });
-
- it('should return the thumbnail URL for a content item', () => {
- spyOn(service.contentService, 'getDocumentThumbnailUrl').and.returnValue('/fake-thumbnail.png');
- expect(service.getDocumentThumbnailUrl({})).toBe('/fake-thumbnail.png');
- });
-
-});
diff --git a/ng2-components/ng2-alfresco-search/src/services/alfresco-thumbnail.service.ts b/ng2-components/ng2-alfresco-search/src/services/alfresco-thumbnail.service.ts
deleted file mode 100644
index 6cec75e9e4..0000000000
--- a/ng2-components/ng2-alfresco-search/src/services/alfresco-thumbnail.service.ts
+++ /dev/null
@@ -1,73 +0,0 @@
-/*!
- * @license
- * Copyright 2016 Alfresco Software, Ltd.
- *
- * 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 { Injectable } from '@angular/core';
-import { AlfrescoContentService } from 'ng2-alfresco-core';
-
-@Injectable()
-export class AlfrescoThumbnailService {
-
- mimeTypeIcons: any = {
- 'image/png': 'ft_ic_raster_image',
- 'image/jpeg': 'ft_ic_raster_image',
- 'image/gif': 'ft_ic_raster_image',
- 'application/pdf': 'ft_ic_pdf',
- 'application/vnd.ms-excel': 'ft_ic_ms_excel',
- 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'ft_ic_ms_excel',
- 'application/vnd.openxmlformats-officedocument.spreadsheetml.template': 'ft_ic_ms_excel',
- 'application/msword': 'ft_ic_ms_word',
- 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'ft_ic_ms_word',
- 'application/vnd.openxmlformats-officedocument.wordprocessingml.template': 'ft_ic_ms_word',
- 'application/vnd.ms-powerpoint': 'ft_ic_ms_powerpoint',
- 'application/vnd.openxmlformats-officedocument.presentationml.presentation': 'ft_ic_ms_powerpoint',
- 'application/vnd.openxmlformats-officedocument.presentationml.template': 'ft_ic_ms_powerpoint',
- 'application/vnd.openxmlformats-officedocument.presentationml.slideshow': 'ft_ic_ms_powerpoint',
- 'video/mp4': 'ft_ic_video',
- 'text/plain': 'ft_ic_document',
- 'application/x-javascript': 'ft_ic_document',
- 'application/json': 'ft_ic_document',
- 'image/svg+xml': 'ft_ic_vector_image',
- 'text/html': 'ft_ic_website',
- 'application/x-compressed': 'ft_ic_archive',
- 'application/x-zip-compressed': 'ft_ic_archive',
- 'application/zip': 'ft_ic_archive',
- 'application/vnd.apple.keynote': 'ft_ic_presentation',
- 'application/vnd.apple.pages': 'ft_ic_document',
- 'application/vnd.apple.numbers': 'ft_ic_spreadsheet'
- };
-
- constructor(public contentService: AlfrescoContentService) {
- }
-
- /**
- * Get thumbnail URL for the given document node.
- * @param document Node to get URL for.
- * @returns {string} URL address.
- */
- public getDocumentThumbnailUrl(document: any): string {
- return this.contentService.getDocumentThumbnailUrl(document);
- }
-
- public getMimeTypeKey(mimeType: string): string {
- let icon = this.mimeTypeIcons[mimeType];
- return icon || 'ft_ic_miscellaneous';
- }
-
- public getMimeTypeIcon(mimeType: string): string {
- return this.getMimeTypeKey(mimeType) + '.svg';
- }
-}
|