All files / Scripts/table Other.ts

96.42% Statements 27/28
83.33% Branches 10/12
100% Functions 7/7
96.15% Lines 25/26

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 523x   3x   3x 17x 17x 17x 17x     2x 1x   1x 1x     2x       2x 2x         6x 5x       5x     1x     16x   72x   2x 1x 1x 2x   1x      
import { ITable } from "./ITable";
import { Header } from "../row/Header";
import { OtherRow } from "../row/OtherRow";
 
export class Other extends ITable {
    private otherRows: OtherRow[] = [];
    protected sortColumnInternal = "number";
    protected sortOrderInternal = 1;
    public readonly tableName: string = "otherHeaders";
 
    public doSort(col: string): void {
        if (this.sortColumnInternal === col) {
            this.sortOrderInternal *= -1;
        } else {
            this.sortColumnInternal = col;
            this.sortOrderInternal = 1;
        }
 
        Iif (this.rows[0] && this.sortColumnInternal + "Sort" in this.rows[0]) {
            col = col + "Sort";
        }
 
        this.rows.sort((a: OtherRow, b: OtherRow) => {
            return this.sortOrderInternal * ((a[col] as string | number) < (b[col] as string | number) ? -1 : 1);
        });
    }
 
    public add(header: Header): boolean {
        if (header.header || header.value) {
            this.rows.push(new OtherRow(
                this.rows.length + 1,
                header.header,
                header.value));
            return true;
        }
 
        return false;
    }
 
    public exists() { return this.rows.length > 0; }
 
    public get rows(): OtherRow[] { return this.otherRows; }
    public toString() {
        if (!this.exists()) return "";
        const ret: string[] = ["Other"];
        this.rows.forEach(function (row) {
            if (row.value) { ret.push(row.value); }
        });
        return ret.join("\n");
    }
}