UNPKG

2.48 kBPlain TextView Raw
1import {Constants} from "../constants";
2import {Utils as _} from '../utils';
3import {GridCell, GridCellDef} from "./gridCell";
4import {Column} from "./column";
5
6export class GridRow {
7
8 floating: string;
9 rowIndex: number;
10
11 constructor(rowIndex: number, floating: string) {
12 this.rowIndex = rowIndex;
13 this.floating = _.makeNull(floating);
14 }
15
16 public isFloatingTop(): boolean {
17 return this.floating === Constants.PINNED_TOP;
18 }
19
20 public isFloatingBottom(): boolean {
21 return this.floating === Constants.PINNED_BOTTOM;
22 }
23
24 public isNotFloating(): boolean {
25 return !this.isFloatingBottom() && !this.isFloatingTop();
26 }
27
28 public equals(otherSelection: GridRow): boolean {
29 return this.rowIndex === otherSelection.rowIndex
30 && this.floating === otherSelection.floating;
31 }
32
33 public toString(): string {
34 return `rowIndex = ${this.rowIndex}, floating = ${this.floating}`;
35 }
36
37 public getGridCell(column: Column): GridCell {
38 let gridCellDef = <GridCellDef> {rowIndex: this.rowIndex, floating: this.floating, column: column};
39 return new GridCell(gridCellDef);
40 }
41
42 // tests if this row selection is before the other row selection
43 public before(otherSelection: GridRow): boolean {
44 let otherFloating = otherSelection.floating;
45 switch (this.floating) {
46 case Constants.PINNED_TOP:
47 // we we are floating top, and other isn't, then we are always before
48 if (otherFloating!==Constants.PINNED_TOP) { return true; }
49 break;
50 case Constants.PINNED_BOTTOM:
51 // if we are floating bottom, and the other isn't, then we are never before
52 if (otherFloating!==Constants.PINNED_BOTTOM) { return false; }
53 break;
54 default:
55 // if we are not floating, but the other one is floating...
56 if (_.exists(otherFloating)) {
57 if (otherFloating===Constants.PINNED_TOP) {
58 // we are not floating, other is floating top, we are first
59 return false;
60 } else {
61 // we are not floating, other is floating bottom, we are always first
62 return true;
63 }
64 }
65 break;
66 }
67 return this.rowIndex < otherSelection.rowIndex;
68 }
69}