mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
Improved type safety
This commit is contained in:
parent
f08796a3d2
commit
dee7166a26
@ -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';
|
||||||
|
@ -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
|
||||||
];
|
];
|
||||||
|
@ -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');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user