enable prefer-const rule for tslint, fix issues (#4409)

* enable prefer-const rule for tslint, fix issues

* Update content-node-selector.component.spec.ts

* Update content-node-selector.component.spec.ts

* fix const

* fix lint issues

* update tests

* update tests

* update tests

* fix code

* fix page class
This commit is contained in:
Denys Vuika
2019-03-25 12:19:33 +00:00
committed by Eugenio Romano
parent 26c5982a1a
commit a7a48e8b2b
581 changed files with 5435 additions and 5402 deletions

View File

@@ -31,7 +31,7 @@ describe('Test Img viewer component ', () => {
let element: HTMLElement;
function createFakeBlob() {
let data = atob('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==');
const data = atob('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==');
return new Blob([data], {type: 'image/png'});
}
@@ -221,7 +221,7 @@ describe('Test Img viewer component ', () => {
});
it('If no url or blob are passed should thrown an error', () => {
let change = new SimpleChange(null, null, true);
const change = new SimpleChange(null, null, true);
expect(() => {
component.ngOnChanges({ 'blobFile': change });
}).toThrow(new Error('Attribute urlFile or blobFile is required'));
@@ -241,10 +241,10 @@ describe('Test Img viewer component ', () => {
});
it('If blob is passed should not thrown an error', () => {
let blob = createFakeBlob();
const blob = createFakeBlob();
spyOn(service, 'createTrustedUrl').and.returnValue('fake-blob-url');
let change = new SimpleChange(null, blob, true);
const change = new SimpleChange(null, blob, true);
expect(() => {
component.ngOnChanges({ 'blobFile': change });
}).not.toThrow(new Error('Attribute urlFile or blobFile is required'));

View File

@@ -132,7 +132,7 @@ export class ImgViewerComponent implements OnInit, OnChanges, OnDestroy {
}
ngOnChanges(changes: SimpleChanges) {
let blobFile = changes['blobFile'];
const blobFile = changes['blobFile'];
if (blobFile && blobFile.currentValue) {
this.urlFile = this.contentService.createTrustedUrl(this.blobFile);
return;

View File

@@ -29,7 +29,7 @@ xdescribe('Test Media player component ', () => {
let fixture: ComponentFixture<MediaPlayerComponent>;
function createFakeBlob() {
let data = atob('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==');
const data = atob('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==');
return new Blob([data], {type: 'image/png'});
}
@@ -73,10 +73,10 @@ xdescribe('Test Media player component ', () => {
});
it('should not thrown an error If blob is passed', () => {
let blob = createFakeBlob();
const blob = createFakeBlob();
spyOn(service, 'createTrustedUrl').and.returnValue('fake-blob-url');
let change = new SimpleChange(null, blob, true);
const change = new SimpleChange(null, blob, true);
expect(() => {
component.ngOnChanges({ 'blobFile': change });
}).not.toThrow(new Error('Attribute urlFile or blobFile is required'));

View File

@@ -42,7 +42,7 @@ export class MediaPlayerComponent implements OnChanges {
constructor(private contentService: ContentService ) {}
ngOnChanges(changes: SimpleChanges) {
let blobFile = changes['blobFile'];
const blobFile = changes['blobFile'];
if (blobFile && blobFile.currentValue) {
this.urlFile = this.contentService.createTrustedUrl(this.blobFile);
return;

View File

@@ -98,7 +98,7 @@ class BlobTestComponent {
}
createFakeBlob(): Blob {
let pdfData = atob(
const pdfData = atob(
'JVBERi0xLjcKCjEgMCBvYmogICUgZW50cnkgcG9pbnQKPDwKICAvVHlwZSAvQ2F0YWxvZwog' +
'IC9QYWdlcyAyIDAgUgo+PgplbmRvYmoKCjIgMCBvYmoKPDwKICAvVHlwZSAvUGFnZXMKICAv' +
'TWVkaWFCb3ggWyAwIDAgMjAwIDIwMCBdCiAgL0NvdW50IDEKICAvS2lkcyBbIDMgMCBSIF0K' +
@@ -350,7 +350,7 @@ describe('Test PdfViewer component', () => {
}, 5000);
it('should nextPage move to the next page', (done) => {
let nextPageButton: any = elementUrlTestComponent.querySelector('#viewer-next-page-button');
const nextPageButton: any = elementUrlTestComponent.querySelector('#viewer-next-page-button');
nextPageButton.click();
fixtureUrlTestComponent.detectChanges();
@@ -391,8 +391,8 @@ describe('Test PdfViewer component', () => {
}, 5000);
it('should previous page move to the previous page', (done) => {
let previousPageButton: any = elementUrlTestComponent.querySelector('#viewer-previous-page-button');
let nextPageButton: any = elementUrlTestComponent.querySelector('#viewer-next-page-button');
const previousPageButton: any = elementUrlTestComponent.querySelector('#viewer-previous-page-button');
const nextPageButton: any = elementUrlTestComponent.querySelector('#viewer-next-page-button');
nextPageButton.click();
nextPageButton.click();
@@ -428,27 +428,27 @@ describe('Test PdfViewer component', () => {
describe('Zoom', () => {
it('should zoom in increment the scale value', () => {
let zoomInButton: any = elementUrlTestComponent.querySelector('#viewer-zoom-in-button');
const zoomInButton: any = elementUrlTestComponent.querySelector('#viewer-zoom-in-button');
let zoomBefore = componentUrlTestComponent.pdfViewerComponent.currentScale;
const zoomBefore = componentUrlTestComponent.pdfViewerComponent.currentScale;
zoomInButton.click();
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('auto');
let currentZoom = componentUrlTestComponent.pdfViewerComponent.currentScale;
const currentZoom = componentUrlTestComponent.pdfViewerComponent.currentScale;
expect(zoomBefore < currentZoom).toBe(true);
}, 5000);
it('should zoom out decrement the scale value', () => {
let zoomOutButton: any = elementUrlTestComponent.querySelector('#viewer-zoom-out-button');
const zoomOutButton: any = elementUrlTestComponent.querySelector('#viewer-zoom-out-button');
let zoomBefore = componentUrlTestComponent.pdfViewerComponent.currentScale;
const zoomBefore = componentUrlTestComponent.pdfViewerComponent.currentScale;
zoomOutButton.click();
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('auto');
let currentZoom = componentUrlTestComponent.pdfViewerComponent.currentScale;
const currentZoom = componentUrlTestComponent.pdfViewerComponent.currentScale;
expect(zoomBefore > currentZoom).toBe(true);
}, 5000);
it('should it-in button toggle page-fit and auto scale mode', () => {
let itPage: any = elementUrlTestComponent.querySelector('#viewer-scale-page-button');
const itPage: any = elementUrlTestComponent.querySelector('#viewer-scale-page-button');
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('auto');
itPage.click();

View File

@@ -155,7 +155,7 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
};
this.loadingTask.onProgress = (progressData) => {
let level = progressData.loaded / progressData.total;
const level = progressData.loaded / progressData.total;
this.loadingPercent = Math.round(level * 100);
};
@@ -237,8 +237,8 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
if (this.pdfViewer) {
let viewerContainer = document.getElementById(`${this.randomPdfId}-viewer-main-container`);
let documentContainer = document.getElementById(`${this.randomPdfId}-viewer-pdf-viewer`);
const viewerContainer = document.getElementById(`${this.randomPdfId}-viewer-main-container`);
const documentContainer = document.getElementById(`${this.randomPdfId}-viewer-pdf-viewer`);
let widthContainer;
let heightContainer;
@@ -251,11 +251,11 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
heightContainer = documentContainer.clientHeight;
}
let currentPage = this.pdfViewer._pages[this.pdfViewer._currentPageNumber - 1];
const currentPage = this.pdfViewer._pages[this.pdfViewer._currentPageNumber - 1];
let padding = 20;
let pageWidthScale = (widthContainer - padding) / currentPage.width * currentPage.scale;
let pageHeightScale = (heightContainer - padding) / currentPage.width * currentPage.scale;
const padding = 20;
const pageWidthScale = (widthContainer - padding) / currentPage.width * currentPage.scale;
const pageHeightScale = (heightContainer - padding) / currentPage.width * currentPage.scale;
let scale;
@@ -409,7 +409,7 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
* @param page to load
*/
inputPage(page: string) {
let pageInput = parseInt(page, 10);
const pageInput = parseInt(page, 10);
if (!isNaN(pageInput) && pageInput > 0 && pageInput <= this.totalPages) {
this.page = pageInput;
@@ -466,7 +466,7 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
*/
@HostListener('document:keydown', ['$event'])
handleKeyboardEvent(event: KeyboardEvent) {
let key = event.keyCode;
const key = event.keyCode;
if (key === 39) { // right arrow
this.nextPage();
} else if (key === 37) {// left arrow
@@ -476,7 +476,7 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
private generateUuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
let r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
const r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}

View File

@@ -44,8 +44,8 @@ describe('Text View component', () => {
it('Should text container be present with urlFile', (done) => {
fixture.detectChanges();
let urlFile = './fake-test-file.txt';
let change = new SimpleChange(null, urlFile, true);
const urlFile = './fake-test-file.txt';
const change = new SimpleChange(null, urlFile, true);
component.ngOnChanges({ 'urlFile': change }).then(() => {
fixture.detectChanges();
@@ -57,9 +57,9 @@ describe('Text View component', () => {
});
it('Should text container be present with Blob file', (done) => {
let blobFile = new Blob(['text example'], {type: 'text/txt'});
const blobFile = new Blob(['text example'], {type: 'text/txt'});
let change = new SimpleChange(null, blobFile, true);
const change = new SimpleChange(null, blobFile, true);
component.ngOnChanges({ 'blobFile': change }).then(() => {
fixture.detectChanges();

View File

@@ -42,12 +42,12 @@ export class TxtViewerComponent implements OnChanges {
ngOnChanges(changes: SimpleChanges): Promise<any> {
let blobFile = changes['blobFile'];
const blobFile = changes['blobFile'];
if (blobFile && blobFile.currentValue) {
return this.readBlob(blobFile.currentValue);
}
let urlFile = changes['urlFile'];
const urlFile = changes['urlFile'];
if (urlFile && urlFile.currentValue) {
return this.getUrlContent(urlFile.currentValue);
}
@@ -58,7 +58,7 @@ export class TxtViewerComponent implements OnChanges {
}
private getUrlContent(url: string): Promise<any> {
let withCredentialsMode = this.appConfigService.get<boolean>('auth.withCredentials', false);
const withCredentialsMode = this.appConfigService.get<boolean>('auth.withCredentials', false);
return new Promise((resolve, reject) => {
this.http.get(url, { responseType: 'text', withCredentials: withCredentialsMode }).subscribe((res) => {
@@ -72,7 +72,7 @@ export class TxtViewerComponent implements OnChanges {
private readBlob(blob: Blob): Promise<any> {
return new Promise((resolve, reject) => {
let reader = new FileReader();
const reader = new FileReader();
reader.onload = () => {
this.content = reader.result;

View File

@@ -395,8 +395,8 @@ describe('ViewerComponent', () => {
describe('Viewer Example Component Rendering', () => {
it('should use custom toolbar', (done) => {
let customFixture = TestBed.createComponent(ViewerWithCustomToolbarComponent);
let customElement: HTMLElement = customFixture.nativeElement;
const customFixture = TestBed.createComponent(ViewerWithCustomToolbarComponent);
const customElement: HTMLElement = customFixture.nativeElement;
customFixture.detectChanges();
fixture.whenStable().then(() => {
@@ -406,8 +406,8 @@ describe('ViewerComponent', () => {
});
it('should use custom toolbar actions', (done) => {
let customFixture = TestBed.createComponent(ViewerWithCustomToolbarActionsComponent);
let customElement: HTMLElement = customFixture.nativeElement;
const customFixture = TestBed.createComponent(ViewerWithCustomToolbarActionsComponent);
const customElement: HTMLElement = customFixture.nativeElement;
customFixture.detectChanges();
fixture.whenStable().then(() => {
@@ -417,8 +417,8 @@ describe('ViewerComponent', () => {
});
it('should use custom info drawer', (done) => {
let customFixture = TestBed.createComponent(ViewerWithCustomSidebarComponent);
let customElement: HTMLElement = customFixture.nativeElement;
const customFixture = TestBed.createComponent(ViewerWithCustomSidebarComponent);
const customElement: HTMLElement = customFixture.nativeElement;
customFixture.detectChanges();
@@ -429,8 +429,8 @@ describe('ViewerComponent', () => {
});
it('should use custom open with menu', (done) => {
let customFixture = TestBed.createComponent(ViewerWithCustomOpenWithComponent);
let customElement: HTMLElement = customFixture.nativeElement;
const customFixture = TestBed.createComponent(ViewerWithCustomOpenWithComponent);
const customElement: HTMLElement = customFixture.nativeElement;
customFixture.detectChanges();
@@ -441,8 +441,8 @@ describe('ViewerComponent', () => {
});
it('should use custom more actions menu', (done) => {
let customFixture = TestBed.createComponent(ViewerWithCustomMoreActionsComponent);
let customElement: HTMLElement = customFixture.nativeElement;
const customFixture = TestBed.createComponent(ViewerWithCustomMoreActionsComponent);
const customElement: HTMLElement = customFixture.nativeElement;
customFixture.detectChanges();
@@ -472,7 +472,7 @@ describe('ViewerComponent', () => {
fixture.detectChanges();
fixture.whenStable().then(() => {
let sidebar = element.querySelector('#adf-right-sidebar');
const sidebar = element.querySelector('#adf-right-sidebar');
expect(sidebar).toBeNull();
done();
});
@@ -484,7 +484,7 @@ describe('ViewerComponent', () => {
fixture.detectChanges();
fixture.whenStable().then(() => {
let sidebar = element.querySelector('#adf-right-sidebar');
const sidebar = element.querySelector('#adf-right-sidebar');
expect(getComputedStyle(sidebar).order).toEqual('4');
done();
});
@@ -496,7 +496,7 @@ describe('ViewerComponent', () => {
fixture.detectChanges();
fixture.whenStable().then(() => {
let sidebar = element.querySelector('#adf-left-sidebar');
const sidebar = element.querySelector('#adf-left-sidebar');
expect(sidebar).toBeNull();
done();
});
@@ -509,7 +509,7 @@ describe('ViewerComponent', () => {
fixture.detectChanges();
fixture.whenStable().then(() => {
let sidebar = element.querySelector('#adf-left-sidebar');
const sidebar = element.querySelector('#adf-left-sidebar');
expect(getComputedStyle(sidebar).order).toEqual('1');
done();
});
@@ -658,7 +658,7 @@ describe('ViewerComponent', () => {
});
it('should Click on close button hide the viewer', (done) => {
let closebutton: any = element.querySelector('.adf-viewer-close-button');
const closebutton: any = element.querySelector('.adf-viewer-close-button');
closebutton.click();
fixture.detectChanges();

View File

@@ -332,7 +332,7 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
}
private setUpUrlFile() {
let filenameFromUrl = this.getFilenameFromUrl(this.urlFile);
const filenameFromUrl = this.getFilenameFromUrl(this.urlFile);
this.fileTitle = this.getDisplayName(filenameFromUrl);
this.extension = this.getFileExtension(filenameFromUrl);
this.urlFileContent = this.urlFile;
@@ -434,7 +434,7 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
mimeType = mimeType.toLowerCase();
const editorTypes = Object.keys(this.mimeTypes);
for (let type of editorTypes) {
for (const type of editorTypes) {
if (this.mimeTypes[type].indexOf(mimeType) >= 0) {
return type;
}
@@ -509,9 +509,9 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
* @param url - url file
*/
getFilenameFromUrl(url: string): string {
let anchor = url.indexOf('#');
let query = url.indexOf('?');
let end = Math.min(
const anchor = url.indexOf('#');
const query = url.indexOf('?');
const end = Math.min(
anchor > 0 ? anchor : url.length,
query > 0 ? query : url.length);
return url.substring(url.lastIndexOf('/', end) + 1, end);
@@ -679,7 +679,7 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
private async waitRendition(nodeId: string, renditionId: string): Promise<RenditionEntry> {
let currentRetry: number = 0;
return new Promise<RenditionEntry>((resolve, reject) => {
let intervalId = setInterval(() => {
const intervalId = setInterval(() => {
currentRetry++;
if (this.maxRetries >= currentRetry) {
this.apiService.renditionsApi.getRendition(nodeId, renditionId).then((rendition: RenditionEntry) => {

View File

@@ -98,14 +98,14 @@ export class RenderingQueueServices {
// 1 visible pages
// 2 if last scrolled down page after the visible pages
// 2 if last scrolled up page before the visible pages
let visibleViews = visible.views;
const visibleViews = visible.views;
let numVisible = visibleViews.length;
const numVisible = visibleViews.length;
if (numVisible === 0) {
return false;
}
for (let i = 0; i < numVisible; ++i) {
let view = visibleViews[i].view;
const view = visibleViews[i].view;
if (!this.isViewFinished(view)) {
return view;
}
@@ -113,13 +113,13 @@ export class RenderingQueueServices {
// All the visible views have rendered, try to render next/previous pages.
if (scrolledDown) {
let nextPageIndex = visible.last.id;
const nextPageIndex = visible.last.id;
// ID's start at 1 so no need to add 1.
if (views[nextPageIndex] && !this.isViewFinished(views[nextPageIndex])) {
return views[nextPageIndex];
}
} else {
let previousPageIndex = visible.first.id - 2;
const previousPageIndex = visible.first.id - 2;
if (views[previousPageIndex] && !this.isViewFinished(views[previousPageIndex])) {
return views[previousPageIndex];
}
@@ -142,7 +142,7 @@ export class RenderingQueueServices {
* @param view
*/
renderView(view: any) {
let state = view.renderingState;
const state = view.renderingState;
switch (state) {
case this.renderingStates.FINISHED:
return false;
@@ -155,7 +155,7 @@ export class RenderingQueueServices {
break;
case this.renderingStates.INITIAL:
this.highestPriorityPage = view.renderingId;
let continueRendering = function () {
const continueRendering = function () {
this.renderHighestPriority();
}.bind(this);
view.draw().then(continueRendering, continueRendering);