view Applications/Samples/SimpleViewer/Wasm/simple-viewer.ts @ 535:79bb0a02d1cc bgo-commands-codegen

- Added ORTHANC_OVERRIDE to several methods (translates to "override" in C++ 11 compilers) - Last fixes to new style command handling (removed useless commands and switch command handling in simple samples to use XxxxSerializedMessageXxxx instead of XxxxCommandXxxx - Fixed hardcoded input instance in SingleFrameEditorApplication
author Benjamin Golinvaux <bgo@osimis.io>
date Tue, 19 Mar 2019 09:13:57 +0100
parents 97a16b694321
children
line wrap: on
line source

import wasmApplicationRunner = require('../../../../Platforms/Wasm/wasm-application-runner');

wasmApplicationRunner.InitializeWasmApplication("OrthancStoneSimpleViewer", "/orthanc");

function SelectTool(toolName: string) {
  var command = {
    command: "selectTool:" + toolName,
    commandType: "generic-no-arg-command",
    args: {
    }                                                                                                                       
  };
  wasmApplicationRunner.SendSerializedMessageToStoneApplication(JSON.stringify(command));
}

function PerformAction(actionName: string) {
  var command = {
    command: "action:" + actionName,
    commandType: "generic-no-arg-command",
    args: {
    }
  };
  wasmApplicationRunner.SendSerializedMessageToStoneApplication(JSON.stringify(command));
}

class SimpleViewerUI {

  private _labelPatientId: HTMLSpanElement;
  private _labelStudyDescription: HTMLSpanElement;

  public constructor() {
    // install "SelectTool" handlers
    document.querySelectorAll("[tool-selector]").forEach((e) => {
      (e as HTMLButtonElement).addEventListener("click", () => {
        SelectTool(e.attributes["tool-selector"].value);
      });
    });

    // install "PerformAction" handlers
    document.querySelectorAll("[action-trigger]").forEach((e) => {
      (e as HTMLButtonElement).addEventListener("click", () => {
        PerformAction(e.attributes["action-trigger"].value);
      });
    });

    // connect all ui elements to members
    this._labelPatientId = document.getElementById("label-patient-id") as HTMLSpanElement;
    this._labelStudyDescription = document.getElementById("label-study-description") as HTMLSpanElement;
  }

  public onAppStatusUpdated(status: any) {
    this._labelPatientId.innerText = status["patientId"];
    this._labelStudyDescription.innerText = status["studyDescription"];
    // this.highlighThumbnail(status["currentInstanceIdInMainViewport"]);
  }

}

var ui = new SimpleViewerUI();

// this method is called "from the C++ code" when the StoneApplication is updated.
// it can be used to update the UI of the application
function UpdateWebApplicationWithString(statusUpdateMessageString: string) {
  console.log("updating web application with string: ", statusUpdateMessageString);
  let statusUpdateMessage = JSON.parse(statusUpdateMessageString);

  if ("event" in statusUpdateMessage) {
    let eventName = statusUpdateMessage["event"];
    if (eventName == "appStatusUpdated") {
      ui.onAppStatusUpdated(statusUpdateMessage["data"]);
    }
  }
}

function UpdateWebApplicationWithSerializedMessage(statusUpdateMessageString: string) {
  console.log("updating web application with serialized message: ", statusUpdateMessageString);
  console.log("<not supported in the simple viewer!>");
}

// make it available to other js scripts in the application
(<any> window).UpdateWebApplicationWithString = UpdateWebApplicationWithString;
(<any> window).UpdateWebApplicationWithSerializedMessage = UpdateWebApplicationWithSerializedMessage;