All files / Scripts Summary.ts

65% Statements 26/40
50% Branches 9/18
70% Functions 7/10
70.58% Lines 24/34

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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 752x 2x 2x     2x 2x   2x 19x 19x 19x 19x     18x 18x           19x   19x   19x                         160x 20x       18x         144x 18x         18x     76x     18x 18x                        
import { mhaStrings } from "./mhaStrings";
import { ArchivedRow } from "./row/ArchivedRow";
import { CreationRow } from "./row/CreationRow";
import { Header } from "./row/Header";
import { Row } from "./row/Row";
import { SummaryRow } from "./row/SummaryRow";
import { SummaryTable } from "./table/SummaryTable";
 
export class Summary extends SummaryTable {
    public readonly tableName: string = "summary";
    public readonly displayName: string = mhaStrings.mhaSummary;
    public readonly tag: string = "SUM";
    private totalTimeInternal = "";
 
    private creationPostFix(totalTime: string): string {
        Eif (!totalTime) {
            return "";
        }
 
        return ` ${mhaStrings.mhaDeliveredStart} ${totalTime}${mhaStrings.mhaDeliveredEnd}`;
    }
 
    private dateRow = new CreationRow("Date", mhaStrings.mhaCreationTime);
 
    private archivedRow = new ArchivedRow("Archived-At", mhaStrings.mhaArchivedAt,);
 
    private summaryRows: SummaryRow[] = [
        new SummaryRow("Subject", mhaStrings.mhaSubject),
        new SummaryRow("Message-ID", mhaStrings.mhaMessageId),
        this.archivedRow,
        this.dateRow,
        new SummaryRow("From", mhaStrings.mhaFrom),
        new SummaryRow("Reply-To", mhaStrings.mhaReplyTo),
        new SummaryRow("To", mhaStrings.mhaTo),
        new SummaryRow("CC", mhaStrings.mhaCc)
    ];
 
    public override exists(): boolean {
        let row: Row | undefined;
        this.rows.forEach((r: Row) => { Iif (!row && r.value) row = r; });
        return row !== undefined;
    }
 
    public add(header: Header) {
        Iif (!header) {
            return false;
        }
 
        let row: SummaryRow | undefined;
        this.rows.forEach((r: Row) => { Iif (!row && r.header.toUpperCase() === header.header.toUpperCase()) row = r; });
        Iif (row) {
            row.value = header.value;
            return true;
        }
 
        return false;
    }
 
    public get rows(): SummaryRow[] { return this.summaryRows; }
    public get totalTime(): string { return this.totalTimeInternal; }
    public set totalTime(value: string) {
        this.totalTimeInternal = value;
        this.dateRow.postFix = this.creationPostFix(value);
    }
 
    public override toString(): string {
        if (!this.exists()) return "";
        const ret = ["Summary"];
        this.rows.forEach(function (row) {
            if (row.value) { ret.push(row.toString()); }
        });
        return ret.join("\n");
    }
}