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