mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
jsdoc fix and one test added in the viewer
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
- [Core library](ng2-alfresco-core/README.md)
|
- [Core library](ng2-alfresco-core/README.md)
|
||||||
- [DataTable](ng2-alfresco-datatable/README.md)
|
- [DataTable](ng2-alfresco-datatable/README.md)
|
||||||
- [Document List](ng2-alfresco-documentlist/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)
|
- [Login](ng2-alfresco-login/README.md)
|
||||||
- [Upload](ng2-alfresco-upload/README.md)
|
- [Upload](ng2-alfresco-upload/README.md)
|
||||||
|
|
||||||
|
@@ -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();
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -34,9 +34,9 @@ export class NotSupportedFormat {
|
|||||||
urlFile: string;
|
urlFile: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Download file
|
* Download file opening it in a new window
|
||||||
*/
|
*/
|
||||||
private download(){
|
private download() {
|
||||||
window.open(this.urlFile);
|
window.open(this.urlFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -53,7 +53,7 @@
|
|||||||
<pdf-viewer [urlFile]="urlFile" ></pdf-viewer>
|
<pdf-viewer [urlFile]="urlFile" ></pdf-viewer>
|
||||||
</div>
|
</div>
|
||||||
<div *ngIf="isImage()" ><img src="{{urlFile}}" id="viewer-image" class="center-element viewer-image"/></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>
|
<not-supported-format [urlFile]="urlFile" [nameFile]="displayName" ></not-supported-format>
|
||||||
</div>
|
</div>
|
||||||
<!-- End View Switch -->
|
<!-- End View Switch -->
|
||||||
|
@@ -52,10 +52,6 @@ export class ViewerComponent {
|
|||||||
otherMenu: any;
|
otherMenu: any;
|
||||||
|
|
||||||
displayName: string;
|
displayName: string;
|
||||||
currentPdfDocument: any;
|
|
||||||
page: number;
|
|
||||||
displayPage: number;
|
|
||||||
totalPages: number;
|
|
||||||
|
|
||||||
extension: string;
|
extension: string;
|
||||||
|
|
||||||
@@ -64,7 +60,7 @@ export class ViewerComponent {
|
|||||||
|
|
||||||
ngOnChanges(changes) {
|
ngOnChanges(changes) {
|
||||||
if (this.showViewer) {
|
if (this.showViewer) {
|
||||||
this.hideOtherMenu();
|
this.hideOtherHeaderBar();
|
||||||
if (!this.urlFile) {
|
if (!this.urlFile) {
|
||||||
throw new Error('Attribute urlFile is required');
|
throw new Error('Attribute urlFile is required');
|
||||||
}
|
}
|
||||||
@@ -92,6 +88,8 @@ export class ViewerComponent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* get File name from url
|
* get File name from url
|
||||||
|
*
|
||||||
|
* @returns {string} name file
|
||||||
*/
|
*/
|
||||||
getFilenameFromUrl(url: string) {
|
getFilenameFromUrl(url: string) {
|
||||||
let anchor = url.indexOf('#');
|
let anchor = url.indexOf('#');
|
||||||
@@ -112,12 +110,19 @@ export class ViewerComponent {
|
|||||||
return fileName.split('.').pop().toLowerCase();
|
return fileName.split('.').pop().toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the content is an image thorugh the extension or mime type
|
||||||
|
*
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
private isImage() {
|
private isImage() {
|
||||||
return this.isImageExtension() || this.isImageMimeType();
|
return this.isImageExtension() || this.isImageMimeType();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if the current file is a supported image extension
|
* check if the current file is a supported image extension
|
||||||
|
*
|
||||||
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
private isImageExtension() {
|
private isImageExtension() {
|
||||||
return this.extension === 'png' || this.extension === 'jpg' ||
|
return this.extension === 'png' || this.extension === 'jpg' ||
|
||||||
@@ -126,23 +131,29 @@ export class ViewerComponent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* check if the current file has an image-based mimetype
|
* check if the current file has an image-based mimetype
|
||||||
|
*
|
||||||
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
private isImageMimeType() {
|
private isImageMimeType() {
|
||||||
return this.mimeType !== null && this.mimeType.indexOf('image/') === 0;
|
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() {
|
private isPdf() {
|
||||||
return this.extension === 'pdf' || this.mimeType === 'application/pdf';
|
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() {
|
private supportedExtension() {
|
||||||
return !this.isImage() && !this.isPdf();
|
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) {
|
||||||
if (parent.nodeName.toLowerCase() === nodeName) {
|
if (parent.nodeName.toLowerCase() === nodeName) {
|
||||||
return parent;
|
return parent;
|
||||||
@@ -173,8 +199,8 @@ export class ViewerComponent {
|
|||||||
/**
|
/**
|
||||||
* Hide the other possible menu in the application
|
* Hide the other possible menu in the application
|
||||||
*/
|
*/
|
||||||
private hideOtherMenu() {
|
private hideOtherHeaderBar() {
|
||||||
if (this.overlayMode && !this.closestElement(this.element.nativeElement, 'header')) {
|
if (this.overlayMode && !this.isParentElementHeaderBar()) {
|
||||||
this.otherMenu = document.querySelector('header');
|
this.otherMenu = document.querySelector('header');
|
||||||
if (this.otherMenu) {
|
if (this.otherMenu) {
|
||||||
this.otherMenu.hidden = true;
|
this.otherMenu.hidden = true;
|
||||||
|
Reference in New Issue
Block a user