annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
466
5055031f4a06 - Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents: 319
diff changeset
1 import wasmApplicationRunner = require('../../../../Platforms/Wasm/wasm-application-runner');
319
daa04d15192c new SimpleViewer sample that has been split in multiple files to be able to scale it
am@osimis.io
parents:
diff changeset
2
466
5055031f4a06 - Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents: 319
diff changeset
3 wasmApplicationRunner.InitializeWasmApplication("OrthancStoneSimpleViewer", "/orthanc");
319
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 };
535
79bb0a02d1cc - Added ORTHANC_OVERRIDE to several methods (translates to "override" in C++ 11 compilers)
Benjamin Golinvaux <bgo@osimis.io>
parents: 510
diff changeset
12 wasmApplicationRunner.SendSerializedMessageToStoneApplication(JSON.stringify(command));
319
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 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
16 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
17 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
18 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
19 args: {
daa04d15192c new SimpleViewer sample that has been split in multiple files to be able to scale it
am@osimis.io
parents:
diff changeset
20 }
daa04d15192c new SimpleViewer sample that has been split in multiple files to be able to scale it
am@osimis.io
parents:
diff changeset
21 };
535
79bb0a02d1cc - Added ORTHANC_OVERRIDE to several methods (translates to "override" in C++ 11 compilers)
Benjamin Golinvaux <bgo@osimis.io>
parents: 510
diff changeset
22 wasmApplicationRunner.SendSerializedMessageToStoneApplication(JSON.stringify(command));
319
daa04d15192c new SimpleViewer sample that has been split in multiple files to be able to scale it
am@osimis.io
parents:
diff changeset
23 }
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 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
26
daa04d15192c new SimpleViewer sample that has been split in multiple files to be able to scale it
am@osimis.io
parents:
diff changeset
27 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
28 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
29
daa04d15192c new SimpleViewer sample that has been split in multiple files to be able to scale it
am@osimis.io
parents:
diff changeset
30 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
31 // 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
32 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
33 (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
34 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
35 });
daa04d15192c new SimpleViewer sample that has been split in multiple files to be able to scale it
am@osimis.io
parents:
diff changeset
36 });
daa04d15192c new SimpleViewer sample that has been split in multiple files to be able to scale it
am@osimis.io
parents:
diff changeset
37
daa04d15192c new SimpleViewer sample that has been split in multiple files to be able to scale it
am@osimis.io
parents:
diff changeset
38 // 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
39 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
40 (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
41 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
42 });
daa04d15192c new SimpleViewer sample that has been split in multiple files to be able to scale it
am@osimis.io
parents:
diff changeset
43 });
daa04d15192c new SimpleViewer sample that has been split in multiple files to be able to scale it
am@osimis.io
parents:
diff changeset
44
daa04d15192c new SimpleViewer sample that has been split in multiple files to be able to scale it
am@osimis.io
parents:
diff changeset
45 // 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
46 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
47 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
48 }
daa04d15192c new SimpleViewer sample that has been split in multiple files to be able to scale it
am@osimis.io
parents:
diff changeset
49
daa04d15192c new SimpleViewer sample that has been split in multiple files to be able to scale it
am@osimis.io
parents:
diff changeset
50 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
51 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
52 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
53 // 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
54 }
daa04d15192c new SimpleViewer sample that has been split in multiple files to be able to scale it
am@osimis.io
parents:
diff changeset
55
daa04d15192c new SimpleViewer sample that has been split in multiple files to be able to scale it
am@osimis.io
parents:
diff changeset
56 }
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 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
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 // 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
61 // it can be used to update the UI of the application
508
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 466
diff changeset
62 function UpdateWebApplicationWithString(statusUpdateMessageString: string) {
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 466
diff changeset
63 console.log("updating web application with string: ", statusUpdateMessageString);
319
daa04d15192c new SimpleViewer sample that has been split in multiple files to be able to scale it
am@osimis.io
parents:
diff changeset
64 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
65
daa04d15192c new SimpleViewer sample that has been split in multiple files to be able to scale it
am@osimis.io
parents:
diff changeset
66 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
67 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
68 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
69 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
70 }
daa04d15192c new SimpleViewer sample that has been split in multiple files to be able to scale it
am@osimis.io
parents:
diff changeset
71 }
daa04d15192c new SimpleViewer sample that has been split in multiple files to be able to scale it
am@osimis.io
parents:
diff changeset
72 }
508
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 466
diff changeset
73
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 466
diff changeset
74 function UpdateWebApplicationWithSerializedMessage(statusUpdateMessageString: string) {
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 466
diff changeset
75 console.log("updating web application with serialized message: ", statusUpdateMessageString);
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 466
diff changeset
76 console.log("<not supported in the simple viewer!>");
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 466
diff changeset
77 }
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 466
diff changeset
78
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 466
diff changeset
79 // make it available to other js scripts in the application
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 466
diff changeset
80 (<any> window).UpdateWebApplicationWithString = UpdateWebApplicationWithString;
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 466
diff changeset
81 (<any> window).UpdateWebApplicationWithSerializedMessage = UpdateWebApplicationWithSerializedMessage;