#68 first simple integration filelist and viewer

This commit is contained in:
Eugenio Romano
2016-05-31 17:57:27 +01:00
parent f4e8f6ed65
commit 367f2cc4ca
5 changed files with 212 additions and 146 deletions

View File

@@ -25,7 +25,16 @@ describe('Ng2-alfresco-viewer', () => {
describe('View', () => {
it('Next an Previous Buttons have to be present', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
it('Canvas should be present', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb
.createAsync(ViewerComponent)
.then((fixture) => {
let element = fixture.nativeElement;
expect(element.querySelector('#vviewer-the-canvas')).toBeDefined();
});
}));
it('Next an Previous Buttons should be present', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb
.createAsync(ViewerComponent)
.then((fixture) => {
@@ -35,7 +44,7 @@ describe('Ng2-alfresco-viewer', () => {
});
}));
it('Input Page elements have to be present', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
it('Input Page elements should be present', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb
.createAsync(ViewerComponent)
.then((fixture) => {

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { Component, Input } from 'angular2/core';
import { Component, Input, SimpleChange } from 'angular2/core';
declare let PDFJS: any;
declare let __moduleName: string;
@@ -38,20 +38,28 @@ export class ViewerComponent {
displayPage: number;
totalPages: number;
ngOnInit() {
console.log('urlFile ' + this.urlFile);
ngOnChanges(changes: {[urlFile: string]: SimpleChange}) {
if (this.urlFile) {
this.nameFile = this.getPDFJS().getFilenameFromUrl(this.urlFile);
this.nameFile = this.getPDFJS().getFilenameFromUrl(this.urlFile);
this.urlFile = this.addAlfrescoTicket(this.urlFile);
return this.getPDFJS().getDocument(this.urlFile).then((pdf) => {
this.currentPdf = pdf;
this.totalPages = pdf.numPages;
this.currentPage = 1;
this.displayPage = 1;
this.loadPage(this.currentPdf, this.currentPage);
});
return this.getPDFJS().getDocument(this.urlFile).then((pdf) => {
this.currentPdf = pdf;
this.totalPages = pdf.numPages;
this.currentPage = 1;
this.displayPage = 1;
this.loadPage(this.currentPdf, this.currentPage);
});
} else {
console.log('Url File is a required value');
}
}
/**
* return the PDFJS global object (exist to facilitate the mock of PDFJS in the test)
* @returns {PDFJS}
*/
getPDFJS() {
return PDFJS;
}
@@ -81,6 +89,9 @@ export class ViewerComponent {
});
}
/**
* load the previous page
*/
previousPage() {
if (this.currentPage > 1) {
this.currentPage--;
@@ -89,6 +100,9 @@ export class ViewerComponent {
}
}
/**
* load the next page
*/
nextPage() {
if (this.currentPage < this.totalPages) {
this.currentPage++;
@@ -97,7 +111,12 @@ export class ViewerComponent {
}
}
inputPage(page: any) {
/**
* load the page in input
*
* @param {string} page - page to load
*/
inputPage(page: string) {
let pageInput = parseInt(page, 10);
if (!isNaN(pageInput) && pageInput > 0 && pageInput <= this.totalPages) {
@@ -107,4 +126,20 @@ export class ViewerComponent {
this.displayPage = this.currentPage;
}
}
/**
* Add Ticket to the file request
* @returns {string}
*/
private addAlfrescoTicket(url: string) {
return url + '?alf_ticket=' + this.getAlfrescoTicket();
}
/**
* Get the token from the local storage
* @returns {string}
*/
private getAlfrescoTicket(): string {
return localStorage.getItem('token');
}
}