jsdoc fix and one test added in the viewer

This commit is contained in:
Eugenio Romano
2016-06-13 11:34:21 +01:00
parent 4f28f60d11
commit 8e5f120e94
5 changed files with 63 additions and 17 deletions

View File

@@ -6,7 +6,7 @@
- [Core library](ng2-alfresco-core/README.md)
- [DataTable](ng2-alfresco-datatable/README.md)
- [Document List](ng2-alfresco-documentlist/README.md)
- [Viewer](ng2-components/ng2-alfresco-viewer/README.md)
- [Viewer](ng2-alfresco-viewer/README.md)
- [Login](ng2-alfresco-login/README.md)
- [Upload](ng2-alfresco-upload/README.md)

View File

@@ -46,4 +46,24 @@ describe('Not Supported Format View', () => {
});
}));
});
describe('User Interaction', () => {
it('Click on Download button should call download method', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb
.createAsync(NotSupportedFormat)
.then((fixture) => {
let element = fixture.nativeElement;
let component = fixture.componentInstance;
fixture.detectChanges();
spyOn(component, 'download');
let downloadButton = element.querySelector('#viewer-download-button');
downloadButton.click();
expect(component.download).toHaveBeenCalled();
});
}));
});
});

View File

@@ -34,9 +34,9 @@ export class NotSupportedFormat {
urlFile: string;
/**
* Download file
* Download file opening it in a new window
*/
private download(){
private download() {
window.open(this.urlFile);
}
}

View File

@@ -53,7 +53,7 @@
<pdf-viewer [urlFile]="urlFile" ></pdf-viewer>
</div>
<div *ngIf="isImage()" ><img src="{{urlFile}}" id="viewer-image" class="center-element viewer-image"/></div>
<div *ngIf="notSupportedExtension()">
<div *ngIf="!supportedExtension()">
<not-supported-format [urlFile]="urlFile" [nameFile]="displayName" ></not-supported-format>
</div>
<!-- End View Switch -->

View File

@@ -52,10 +52,6 @@ export class ViewerComponent {
otherMenu: any;
displayName: string;
currentPdfDocument: any;
page: number;
displayPage: number;
totalPages: number;
extension: string;
@@ -64,7 +60,7 @@ export class ViewerComponent {
ngOnChanges(changes) {
if (this.showViewer) {
this.hideOtherMenu();
this.hideOtherHeaderBar();
if (!this.urlFile) {
throw new Error('Attribute urlFile is required');
}
@@ -92,6 +88,8 @@ export class ViewerComponent {
/**
* get File name from url
*
* @returns {string} name file
*/
getFilenameFromUrl(url: string) {
let anchor = url.indexOf('#');
@@ -112,12 +110,19 @@ export class ViewerComponent {
return fileName.split('.').pop().toLowerCase();
}
/**
* Check if the content is an image thorugh the extension or mime type
*
* @returns {boolean}
*/
private isImage() {
return this.isImageExtension() || this.isImageMimeType();
}
/**
* check if the current file is a supported image extension
*
* @returns {boolean}
*/
private isImageExtension() {
return this.extension === 'png' || this.extension === 'jpg' ||
@@ -126,23 +131,29 @@ export class ViewerComponent {
/**
* check if the current file has an image-based mimetype
*
* @returns {boolean}
*/
private isImageMimeType() {
return this.mimeType !== null && this.mimeType.indexOf('image/') === 0;
}
/**
* check if the current file is a suppoerted pdf extension
* check if the current file is a supported pdf extension
*
* @returns {boolean}
*/
private isPdf() {
return this.extension === 'pdf' || this.mimeType === 'application/pdf';
}
/**
* check if the current file is not a supported extension
* check if the current file is a supported extension
*
* @returns {boolean}
*/
private notSupportedExtension() {
return !this.isImage() && !this.isPdf();
private supportedExtension() {
return this.isImage() || this.isPdf();
}
/**
@@ -157,8 +168,23 @@ export class ViewerComponent {
}
}
private closestElement(el: HTMLElement, nodeName: string) {
let parent = el.parentElement;
/**
* Check if the viewer is used inside and header element
*
* @returns {boolean}
*/
private isParentElementHeaderBar() {
return !!this.closestElement(this.element.nativeElement, 'header');
}
/**
* Check if the viewer is used inside and header element
* @param {HTMLElement} elelemnt
* @param {string} nodeName
* @returns {HTMLElement}
*/
private closestElement(elelemnt: HTMLElement, nodeName: string) {
let parent = elelemnt.parentElement;
if (parent) {
if (parent.nodeName.toLowerCase() === nodeName) {
return parent;
@@ -173,8 +199,8 @@ export class ViewerComponent {
/**
* Hide the other possible menu in the application
*/
private hideOtherMenu() {
if (this.overlayMode && !this.closestElement(this.element.nativeElement, 'header')) {
private hideOtherHeaderBar() {
if (this.overlayMode && !this.isParentElementHeaderBar()) {
this.otherMenu = document.querySelector('header');
if (this.otherMenu) {
this.otherMenu.hidden = true;