Mercurial > hg > orthanc-stone
comparison Applications/Samples/Deprecated/SimpleViewer/Wasm/simple-viewer.ts @ 1347:bfd77672d825 broker
Moved Application/Samples/* to Application/Samples/Deprecated/*
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Tue, 07 Apr 2020 14:29:01 +0200 |
parents | Applications/Samples/SimpleViewer/Wasm/simple-viewer.ts@79bb0a02d1cc |
children |
comparison
equal
deleted
inserted
replaced
1346:df8bf351c23f | 1347:bfd77672d825 |
---|---|
1 import wasmApplicationRunner = require('../../../../Platforms/Wasm/wasm-application-runner'); | |
2 | |
3 wasmApplicationRunner.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 wasmApplicationRunner.SendSerializedMessageToStoneApplication(JSON.stringify(command)); | |
13 } | |
14 | |
15 function PerformAction(actionName: string) { | |
16 var command = { | |
17 command: "action:" + actionName, | |
18 commandType: "generic-no-arg-command", | |
19 args: { | |
20 } | |
21 }; | |
22 wasmApplicationRunner.SendSerializedMessageToStoneApplication(JSON.stringify(command)); | |
23 } | |
24 | |
25 class SimpleViewerUI { | |
26 | |
27 private _labelPatientId: HTMLSpanElement; | |
28 private _labelStudyDescription: HTMLSpanElement; | |
29 | |
30 public constructor() { | |
31 // install "SelectTool" handlers | |
32 document.querySelectorAll("[tool-selector]").forEach((e) => { | |
33 (e as HTMLButtonElement).addEventListener("click", () => { | |
34 SelectTool(e.attributes["tool-selector"].value); | |
35 }); | |
36 }); | |
37 | |
38 // install "PerformAction" handlers | |
39 document.querySelectorAll("[action-trigger]").forEach((e) => { | |
40 (e as HTMLButtonElement).addEventListener("click", () => { | |
41 PerformAction(e.attributes["action-trigger"].value); | |
42 }); | |
43 }); | |
44 | |
45 // connect all ui elements to members | |
46 this._labelPatientId = document.getElementById("label-patient-id") as HTMLSpanElement; | |
47 this._labelStudyDescription = document.getElementById("label-study-description") as HTMLSpanElement; | |
48 } | |
49 | |
50 public onAppStatusUpdated(status: any) { | |
51 this._labelPatientId.innerText = status["patientId"]; | |
52 this._labelStudyDescription.innerText = status["studyDescription"]; | |
53 // this.highlighThumbnail(status["currentInstanceIdInMainViewport"]); | |
54 } | |
55 | |
56 } | |
57 | |
58 var ui = new SimpleViewerUI(); | |
59 | |
60 // this method is called "from the C++ code" when the StoneApplication is updated. | |
61 // it can be used to update the UI of the application | |
62 function UpdateWebApplicationWithString(statusUpdateMessageString: string) { | |
63 console.log("updating web application with string: ", statusUpdateMessageString); | |
64 let statusUpdateMessage = JSON.parse(statusUpdateMessageString); | |
65 | |
66 if ("event" in statusUpdateMessage) { | |
67 let eventName = statusUpdateMessage["event"]; | |
68 if (eventName == "appStatusUpdated") { | |
69 ui.onAppStatusUpdated(statusUpdateMessage["data"]); | |
70 } | |
71 } | |
72 } | |
73 | |
74 function UpdateWebApplicationWithSerializedMessage(statusUpdateMessageString: string) { | |
75 console.log("updating web application with serialized message: ", statusUpdateMessageString); | |
76 console.log("<not supported in the simple viewer!>"); | |
77 } | |
78 | |
79 // make it available to other js scripts in the application | |
80 (<any> window).UpdateWebApplicationWithString = UpdateWebApplicationWithString; | |
81 (<any> window).UpdateWebApplicationWithSerializedMessage = UpdateWebApplicationWithSerializedMessage; |