comparison Applications/Samples/SimpleViewer/Wasm/simple-viewer.ts @ 319:daa04d15192c am-2

new SimpleViewer sample that has been split in multiple files to be able to scale it
author am@osimis.io
date Thu, 11 Oct 2018 13:16:54 +0200
parents
children 5055031f4a06
comparison
equal deleted inserted replaced
318:3a4ca166fafa 319:daa04d15192c
1 ///<reference path='../../../../Platforms/Wasm/wasm-application-runner.ts'/>
2
3 InitializeWasmApplication("OrthancStoneSimpleViewer", "/orthanc");
4
5 function SelectTool(toolName: string) {
6 var command = {
7 command: "selectTool:" + toolName,
8 commandType: "generic-no-arg-command",
9 args: {
10 }
11 };
12 SendMessageToStoneApplication(JSON.stringify(command));
13
14 }
15
16 function PerformAction(actionName: string) {
17 var command = {
18 command: "action:" + actionName,
19 commandType: "generic-no-arg-command",
20 args: {
21 }
22 };
23 SendMessageToStoneApplication(JSON.stringify(command));
24 }
25
26 class SimpleViewerUI {
27
28 private _labelPatientId: HTMLSpanElement;
29 private _labelStudyDescription: HTMLSpanElement;
30
31 public constructor() {
32 // install "SelectTool" handlers
33 document.querySelectorAll("[tool-selector]").forEach((e) => {
34 console.log(e);
35 (e as HTMLButtonElement).addEventListener("click", () => {
36 console.log(e);
37 SelectTool(e.attributes["tool-selector"].value);
38 });
39 });
40
41 // install "PerformAction" handlers
42 document.querySelectorAll("[action-trigger]").forEach((e) => {
43 (e as HTMLButtonElement).addEventListener("click", () => {
44 PerformAction(e.attributes["action-trigger"].value);
45 });
46 });
47
48 // connect all ui elements to members
49 this._labelPatientId = document.getElementById("label-patient-id") as HTMLSpanElement;
50 this._labelStudyDescription = document.getElementById("label-study-description") as HTMLSpanElement;
51 }
52
53 public onAppStatusUpdated(status: any) {
54 this._labelPatientId.innerText = status["patientId"];
55 this._labelStudyDescription.innerText = status["studyDescription"];
56 // this.highlighThumbnail(status["currentInstanceIdInMainViewport"]);
57 }
58
59 }
60
61 var ui = new SimpleViewerUI();
62
63 // this method is called "from the C++ code" when the StoneApplication is updated.
64 // it can be used to update the UI of the application
65 function UpdateWebApplication(statusUpdateMessageString: string) {
66 console.log("updating web application: ", statusUpdateMessageString);
67 let statusUpdateMessage = JSON.parse(statusUpdateMessageString);
68
69 if ("event" in statusUpdateMessage) {
70 let eventName = statusUpdateMessage["event"];
71 if (eventName == "appStatusUpdated") {
72 ui.onAppStatusUpdated(statusUpdateMessage["data"]);
73 }
74 }
75 }