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

@ -16,7 +16,7 @@
*/ */
import { it, describe, beforeEach, afterEach } from '@angular/core/testing'; import { it, describe, beforeEach, afterEach } from '@angular/core/testing';
import {ReflectiveInjector, provide} from '@angular/core'; import { ReflectiveInjector } from '@angular/core';
import { AlfrescoSettingsService } from './AlfrescoSettings.service'; import { AlfrescoSettingsService } from './AlfrescoSettings.service';
import { AlfrescoAuthenticationService } from './AlfrescoAuthentication.service'; import { AlfrescoAuthenticationService } from './AlfrescoAuthentication.service';
import { AlfrescoApiService } from './AlfrescoApi.service'; import { AlfrescoApiService } from './AlfrescoApi.service';

View File

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

View File

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