All files / Scripts/ui classicDesktopFrame.ts

0% Statements 0/47
0% Branches 0/8
0% Functions 0/8
0% Lines 0/46

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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91                                                                                                                                                                                     
import "../../Content/Office.css";
import "../../Content/classicDesktopFrame.css";
import $ from "jquery";
 
import { HeaderModel } from "../HeaderModel";
import { mhaStrings } from "../mhaStrings";
import { Poster } from "../Poster";
import { Table } from "./Table";
 
// This is the "classic" UI rendered in classicDesktopFrame.html
 
let viewModel: HeaderModel;
let table: Table;
 
function postError(error: unknown, message: string): void {
    Poster.postMessageToParent("LogError", { error: JSON.stringify(error), message: message });
}
 
function enableSpinner(): void {
    $("#response").css("background-image", "url(../Resources/loader.gif)");
    $("#response").css("background-repeat", "no-repeat");
    $("#response").css("background-position", "center");
}
 
function disableSpinner(): void {
    $("#response").css("background", "none");
}
 
function updateStatus(statusText: string): void {
    enableSpinner();
    $("#status").text(statusText);
    Iif (viewModel !== null) {
        viewModel.status = statusText;
    }
 
    table.recalculateVisibility();
}
 
function renderItem(headers: string) {
    updateStatus(mhaStrings.mhaFoundHeaders);
    $("#originalHeaders").text(headers);
    viewModel = new HeaderModel(headers);
    table.rebuildTables(viewModel);
    updateStatus("");
    disableSpinner();
}
 
// Handles rendering of an error.
// Does not log the error - caller is responsible for calling PostError
function showError(error: unknown, message: string) {
    console.error("Error:", error);
    updateStatus(message);
    disableSpinner();
    table.rebuildSections(viewModel);
}
 
function eventListener(event: MessageEvent): void {
    Iif (!event || event.origin !== Poster.site()) return;
 
    Iif (event.data) {
        switch (event.data.eventName) {
            case "showError":
                showError(JSON.parse(event.data.data.error), event.data.data.message);
                break;
            case "updateStatus":
                updateStatus(event.data.data);
                break;
            case "renderItem":
                renderItem(event.data.data);
                break;
        }
    }
}
 
// This function is run when the app is ready to start interacting with the host application.
// It ensures the DOM is ready before updating the span elements with values from the current message.
$(function() {
    try {
        viewModel = new HeaderModel();
        table = new Table();
        table.initializeTableUI(viewModel);
        updateStatus(mhaStrings.mhaLoading);
        window.addEventListener("message", eventListener, false);
        Poster.postMessageToParent("frameActive");
    }
    catch (e) {
        postError(e, "Failed initializing frame");
        showError(e, "Failed initializing frame");
    }
});