Improved type safety

This commit is contained in:
Denys Vuika 2016-08-24 18:12:41 +01:00
parent f08796a3d2
commit dee7166a26
3 changed files with 14 additions and 9 deletions

View File

@ -15,10 +15,10 @@
* limitations under the License.
*/
import {it, describe, beforeEach, afterEach} from '@angular/core/testing';
import {ReflectiveInjector, provide} from '@angular/core';
import {AlfrescoSettingsService} from './AlfrescoSettings.service';
import {AlfrescoAuthenticationService} from './AlfrescoAuthentication.service';
import { it, describe, beforeEach, afterEach } from '@angular/core/testing';
import { ReflectiveInjector } from '@angular/core';
import { AlfrescoSettingsService } from './AlfrescoSettings.service';
import { AlfrescoAuthenticationService } from './AlfrescoAuthentication.service';
import { AlfrescoApiService } from './AlfrescoApi.service';
declare var AlfrescoApi: any;

View File

@ -19,7 +19,7 @@ import {describe, expect, it, inject, beforeEachProviders, beforeEach} from '@an
import {TestComponentBuilder} from '@angular/compiler/testing';
import {ViewerComponent} from './viewer.component';
import {EventMock} from './assets/event.mock';
import {AlfrescoAuthenticationService, AlfrescoSettingsService} from 'ng2-alfresco-core';
import { AlfrescoApiService, AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core';
describe('ViewerComponent', () => {
@ -27,6 +27,7 @@ describe('ViewerComponent', () => {
beforeEachProviders(() => {
return [
AlfrescoApiService,
AlfrescoSettingsService,
AlfrescoAuthenticationService
];

View File

@ -20,7 +20,8 @@ import { PdfViewerComponent } from './pdfViewer.component';
import { ImgViewerComponent } from './imgViewer.component';
import { NotSupportedFormat } from './notSupportedFormat.component';
import { DOCUMENT } from '@angular/platform-browser';
import { AlfrescoAuthenticationService} from 'ng2-alfresco-core';
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
import { AlfrescoApiService } from 'ng2-alfresco-core';
declare let __moduleName: string;
@ -61,7 +62,9 @@ export class ViewerComponent {
loaded: boolean = false;
constructor(private authService: AlfrescoAuthenticationService, private element: ElementRef, @Inject(DOCUMENT) private document) {
constructor(private apiService: AlfrescoApiService,
private element: ElementRef,
@Inject(DOCUMENT) private document) {
}
ngOnChanges(changes) {
@ -72,15 +75,16 @@ export class ViewerComponent {
throw new Error('Attribute urlFile or fileNodeId is required');
}
return new Promise((resolve) => {
let alfrescoApi = this.apiService.getInstance();
if (this.urlFile) {
let filenameFromUrl = this.getFilenameFromUrl(this.urlFile);
this.displayName = filenameFromUrl ? filenameFromUrl : '';
this.extension = this.getFileExtension(filenameFromUrl);
} else if (this.fileNodeId) {
this.authService.getAlfrescoApi().nodes.getNodeInfo(this.fileNodeId).then((data) => {
alfrescoApi.nodes.getNodeInfo(this.fileNodeId).then((data: MinimalNodeEntryEntity) => {
this.mimeType = data.content.mimeType;
this.displayName = data.name;
this.urlFile = this.authService.getAlfrescoApi().content.getContentUrl(data.id);
this.urlFile = alfrescoApi.content.getContentUrl(data.id);
this.loaded = true;
}, function (error) {
console.log('This node does not exist');