Skip to content

Commit

Permalink
Merge pull request #330 from ghetolay/master
Browse files Browse the repository at this point in the history
Resolve all implicit any
  • Loading branch information
amcdnl authored Nov 30, 2016
2 parents 4218ce3 + fb9653b commit 2002da7
Show file tree
Hide file tree
Showing 24 changed files with 163 additions and 151 deletions.
23 changes: 11 additions & 12 deletions src/components/body/body-cell.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,18 @@ export class DataTableBodyCellComponent {
renderer.setElementClass(this.element, 'datatable-body-cell', true);
}

@HostListener('focus', ['$event'])
onFocus(event): void {
@HostListener('focus')
onFocus(): void {
this.isFocused = true;
}

@HostListener('blur', ['$event'])
onBlur(event): void {
@HostListener('blur')
onBlur(): void {
this.isFocused = false;
}

@HostListener('click', ['$event'])
onClick(event): void {
onClick(event: MouseEvent): void {
this.activate.emit({
type: 'click',
event,
Expand All @@ -110,7 +110,7 @@ export class DataTableBodyCellComponent {
}

@HostListener('dblclick', ['$event'])
onDblClick(event): void {
onDblClick(event: MouseEvent): void {
this.activate.emit({
type: 'dblclick',
event,
Expand All @@ -122,11 +122,11 @@ export class DataTableBodyCellComponent {
}

@HostListener('keydown', ['$event'])
onKeyDown(event): void {
onKeyDown(event: KeyboardEvent): void {
const keyCode = event.keyCode;
const isTargetCell = event.target === this.element;
const isAction =

const isAction =
keyCode === Keys.return ||
keyCode === Keys.down ||
keyCode === Keys.up ||
Expand All @@ -148,14 +148,13 @@ export class DataTableBodyCellComponent {
}
}

calcSortDir(sorts): any {
calcSortDir(sorts: any[]): any {
if(!sorts) return;

const sort = sorts.find(s => {
const sort = sorts.find((s: any) => {
return s.prop === this.column.prop;
});

if(sort) return sort.dir;
}

}
18 changes: 9 additions & 9 deletions src/components/body/body-row.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
import {
Component, Input, HostBinding, ElementRef, ChangeDetectionStrategy,
Renderer, Output, EventEmitter , HostListener
} from '@angular/core';

import {
columnsByPin, columnGroupWidths, columnsByPinArr,
import {
columnsByPin, columnGroupWidths, columnsByPinArr,
translateXY, Keys, scrollbarWidth
} from '../../utils';

Expand Down Expand Up @@ -34,8 +34,8 @@ export class DataTableBodyRowComponent {
this.recalculateColumns(val);
}

get columns(): any[] {
return this._columns;
get columns(): any[] {
return this._columns;
}

@Input() set innerWidth(val: number) {
Expand Down Expand Up @@ -79,7 +79,7 @@ export class DataTableBodyRowComponent {
renderer.setElementClass(this.element, 'datatable-body-row', true);
}

stylesByGroup(group) {
stylesByGroup(group: string) {
const widths = this.columnGroupWidths;
const offsetX = this.offsetX;

Expand All @@ -100,18 +100,18 @@ export class DataTableBodyRowComponent {
return styles;
}

onActivate(event, index) {
onActivate(event: any, index: number) {
event.cellIndex = index;
event.rowElement = this.element;
this.activate.emit(event);
}

@HostListener('keydown', ['$event'])
onKeyDown(event): void {
onKeyDown(event: KeyboardEvent): void {
const keyCode = event.keyCode;
const isTargetRow = event.target === this.element;

const isAction =
const isAction =
keyCode === Keys.return ||
keyCode === Keys.down ||
keyCode === Keys.up ||
Expand Down
54 changes: 29 additions & 25 deletions src/components/body/body.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ScrollerComponent } from './scroller.component';
@Component({
selector: 'datatable-body',
template: `
<datatable-selection
<datatable-selection
#selector
[selected]="selected"
[rows]="rows"
Expand All @@ -29,7 +29,7 @@ import { ScrollerComponent } from './scroller.component';
[scrollHeight]="scrollHeight"
[scrollWidth]="columnGroupWidths.total"
(scroll)="onBodyScroll($event)">
<datatable-row-wrapper
<datatable-row-wrapper
*ngFor="let row of temp; let i = index; trackBy: rowTrackingFn"
[ngStyle]="getRowsStyles(row)"
[rowDetailTemplate]="rowDetailTemplate"
Expand Down Expand Up @@ -94,24 +94,24 @@ export class DataTableBodyComponent {

@Input() set columns(val: any[]) {
this._columns = val;

const colsByPin = columnsByPin(val);
this.columnGroupWidths = columnGroupWidths(colsByPin, val);
}

get columns(): any[] {
return this._columns;
get columns(): any[] {
return this._columns;
}

@Input() set offset(val: number) {
this._offset = val;
this.recalcLayout();
}

get offset(): number {
return this._offset;
}

@Input() set rowCount(val: number) {
this._rowCount = val;
this.recalcLayout();
Expand All @@ -131,7 +131,7 @@ export class DataTableBodyComponent {
return '100%';
}
}

@Input()
@HostBinding('style.height')
set bodyHeight(val) {
Expand All @@ -144,8 +144,8 @@ export class DataTableBodyComponent {
this.recalcLayout();
}

get bodyHeight() {
return this._bodyHeight;
get bodyHeight() {
return this._bodyHeight;
}

@Output() scroll: EventEmitter<any> = new EventEmitter();
Expand Down Expand Up @@ -185,7 +185,7 @@ export class DataTableBodyComponent {
return this.rowHeightsCache.query(this.rowCount - 1);
}
}

constructor(element: ElementRef, renderer: Renderer) {
renderer.setElementClass(element.nativeElement, 'datatable-body', true);

Expand All @@ -209,25 +209,29 @@ export class DataTableBodyComponent {
this.scroller.setOffset(offset || 0);
}

onBodyScroll({ scrollYPos, scrollXPos, direction }): void {
// was unable to find the fitting type of event
onBodyScroll(event: any): void {
const scrollYPos: number = event.scrollYPos;
const scrollXPos: number = event.scrollXPos;

// if scroll change, trigger update
// this is mainly used for header cell positions
if(this.offsetY !== scrollYPos || this.offsetX !== scrollXPos) {
this.scroll.emit({
this.scroll.emit({
offsetY: scrollYPos,
offsetX: scrollXPos
});
}

this.offsetY = scrollYPos;
this.offsetX = scrollXPos;

this.updateIndexes();
this.updatePage(direction);
this.updatePage(event.direction);
this.updateRows();
}

updatePage(direction): void {
updatePage(direction: string): void {
let offset = this.indexes.first / this.pageSize;

if(direction === 'up') {
Expand All @@ -245,7 +249,7 @@ export class DataTableBodyComponent {
const { first, last } = this.indexes;
let rowIndex = first;
let idx = 0;
let temp = [];
let temp: any[] = [];

while (rowIndex < last && rowIndex < this.rowCount) {
let row = this.rows[rowIndex];
Expand Down Expand Up @@ -292,7 +296,7 @@ export class DataTableBodyComponent {
* @param row The row that needs to be placed in the 2D space.
* @returns {{styles: string}} Returns the CSS3 style to be applied
*/
getRowsStyles(row): any {
getRowsStyles(row: any): any {
const rowHeight = this.getRowHeight(row);

let styles = {
Expand All @@ -301,7 +305,7 @@ export class DataTableBodyComponent {

if(this.scrollbarV) {
const idx = row ? row.$$index : 0;

// const pos = idx * rowHeight;
// The position of this row would be the sum of all row heights
// until the previous row position.
Expand Down Expand Up @@ -386,13 +390,13 @@ export class DataTableBodyComponent {
const detailRowHeight = this.detailRowHeight * (row.$$expanded ? -1 : 1);
this.rowHeightsCache.update(row.$$index, detailRowHeight);
}

// Update the toggled row and update the heights in the cache.
row.$$expanded ^= 1;

this.detailToggle.emit({
rows: [row],
currentIndex: viewPortFirstRowIndex
rows: [row],
currentIndex: viewPortFirstRowIndex
});
}

Expand All @@ -402,7 +406,7 @@ export class DataTableBodyComponent {
*/
toggleAllRows(expanded: boolean): void {
let rowExpanded = expanded ? 1 : 0;

// Capture the row index of the first row that is visible on the viewport.
let viewPortFirstRowIndex = this.getAdjustedViewPortIndex();

Expand All @@ -417,8 +421,8 @@ export class DataTableBodyComponent {

// Emit all rows that have been expanded.
this.detailToggle.emit({
rows: this.rows,
currentIndex: viewPortFirstRowIndex
rows: this.rows,
currentIndex: viewPortFirstRowIndex
});
}

Expand Down
8 changes: 4 additions & 4 deletions src/components/body/scroller.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class ScrollerComponent implements OnInit, OnDestroy {
private element: any;
private parentElement: any;
private onScrollListener: Function;

constructor(element: ElementRef, private renderer: Renderer) {
this.element = element.nativeElement;
this.element.classList.add('datatable-scroll');
Expand All @@ -57,16 +57,16 @@ export class ScrollerComponent implements OnInit, OnDestroy {
}
}

onScrolled(event) {
const dom = event.currentTarget;
onScrolled(event: MouseEvent) {
const dom: Element = <Element>event.currentTarget;
this.scrollYPos = dom.scrollTop;
this.scrollXPos = dom.scrollLeft;

requestAnimationFrame(this.updateOffset.bind(this));
}

updateOffset() {
let direction;
let direction: string;
if(this.scrollYPos < this.prevScrollYPos) {
direction = 'down';
} else if(this.scrollYPos > this.prevScrollYPos) {
Expand Down
Loading

0 comments on commit 2002da7

Please sign in to comment.