1 | import {Constants} from "../constants";
|
2 | import {Utils as _} from '../utils';
|
3 | import {GridCell, GridCellDef} from "./gridCell";
|
4 | import {Column} from "./column";
|
5 |
|
6 | export 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 |
|
43 | public before(otherSelection: GridRow): boolean {
|
44 | let otherFloating = otherSelection.floating;
|
45 | switch (this.floating) {
|
46 | case Constants.PINNED_TOP:
|
47 |
|
48 | if (otherFloating!==Constants.PINNED_TOP) { return true; }
|
49 | break;
|
50 | case Constants.PINNED_BOTTOM:
|
51 |
|
52 | if (otherFloating!==Constants.PINNED_BOTTOM) { return false; }
|
53 | break;
|
54 | default:
|
55 |
|
56 | if (_.exists(otherFloating)) {
|
57 | if (otherFloating===Constants.PINNED_TOP) {
|
58 |
|
59 | return false;
|
60 | } else {
|
61 |
|
62 | return true;
|
63 | }
|
64 | }
|
65 | break;
|
66 | }
|
67 | return this.rowIndex < otherSelection.rowIndex;
|
68 | }
|
69 | }
|