# HG changeset patch # User Sebastien Jodogne # Date 1606470921 -3600 # Node ID f1bd464dc3e14ae7089464219906ec79582d0a9d # Parent 0598c87e1e88c7f665fb39af30b325d08901552c the plugin uses the Orthanc configuration instead of the default configuration diff -r 0598c87e1e88 -r f1bd464dc3e1 Applications/StoneWebViewer/Plugin/Plugin.cpp --- a/Applications/StoneWebViewer/Plugin/Plugin.cpp Fri Nov 27 10:21:48 2020 +0100 +++ b/Applications/StoneWebViewer/Plugin/Plugin.cpp Fri Nov 27 10:55:21 2020 +0100 @@ -160,6 +160,46 @@ } +void ServeConfiguration(OrthancPluginRestOutput* output, + const char* url, + const OrthancPluginHttpRequest* request) +{ + OrthancPluginContext* context = OrthancPlugins::GetGlobalContext(); + + if (request->method != OrthancPluginHttpMethod_Get) + { + OrthancPluginSendMethodNotAllowed(context, output, "GET"); + } + else + { + static const char* CONFIG_SECTION = "StoneWebViewer"; + + std::string config; + + OrthancPlugins::OrthancConfiguration orthanc; + if (orthanc.IsSection(CONFIG_SECTION)) + { + OrthancPlugins::OrthancConfiguration section(false); + orthanc.GetSection(section, CONFIG_SECTION); + + Json::Value wrapper = Json::objectValue; + wrapper[CONFIG_SECTION] = section.GetJson(); + config = wrapper.toStyledString(); + } + else + { + LOG(WARNING) << "The Orthanc configuration file doesn't contain a section \"" + << CONFIG_SECTION << "\" to configure the Stone Web viewer: " + << "Will use default settings"; + Orthanc::EmbeddedResources::GetDirectoryResource( + config, Orthanc::EmbeddedResources::WEB_APPLICATION, "/configuration.json"); + } + + OrthancPluginAnswerBuffer(context, output, config.c_str(), config.size(), "application/json"); + } +} + + extern "C" { ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) @@ -192,6 +232,9 @@ explorer, Orthanc::EmbeddedResources::ORTHANC_EXPLORER); OrthancPluginExtendOrthancExplorer(OrthancPlugins::GetGlobalContext(), explorer.c_str()); + OrthancPlugins::RegisterRestCallback + ("/stone-webviewer/configuration.json", true); + OrthancPlugins::RegisterRestCallback > ("/stone-webviewer/StoneWebViewer.wasm", true); diff -r 0598c87e1e88 -r f1bd464dc3e1 Applications/StoneWebViewer/WebApplication/app.js --- a/Applications/StoneWebViewer/WebApplication/app.js Fri Nov 27 10:21:48 2020 +0100 +++ b/Applications/StoneWebViewer/WebApplication/app.js Fri Nov 27 10:55:21 2020 +0100 @@ -861,7 +861,12 @@ axios.get(CONFIGURATION_SOURCE) .then(function(response) { - app.globalConfiguration = ParseJsonWithComments(response.data); + app.globalConfiguration = ParseJsonWithComments(response.data) ['StoneWebViewer']; + + if (app.globalConfiguration === undefined) { + console.warn('Empty configuration file'); + app.globalConfiguration = {}; + } // Option 1: Loading script using plain HTML diff -r 0598c87e1e88 -r f1bd464dc3e1 Applications/StoneWebViewer/WebApplication/configuration.json --- a/Applications/StoneWebViewer/WebApplication/configuration.json Fri Nov 27 10:21:48 2020 +0100 +++ b/Applications/StoneWebViewer/WebApplication/configuration.json Fri Nov 27 10:55:21 2020 +0100 @@ -1,37 +1,40 @@ { - /** - * Enables/disables the print button. - **/ - "PrintEnabled" : true, + "StoneWebViewer" : + { + /** + * Enables/disables the print button. + **/ + "PrintEnabled" : true, - /** - * Defines how dates are displayed in the UI. If this option is not - * set, the DICOM tags will be displayed as such. "DD" will be - * replaced by the day, "MM" by the month, and "YYYY" by the year. - **/ - // "DateFormat" : "DD/MM/YYYY", + /** + * Defines how dates are displayed in the UI. If this option is not + * set, the DICOM tags will be displayed as such. "DD" will be + * replaced by the day, "MM" by the month, and "YYYY" by the year. + **/ + // "DateFormat" : "DD/MM/YYYY", - /** - * This option allows you to define windowing presets. - * For each preset, you must provide a name, the window width - * and window center. - **/ - "WindowingPresets" : [ - {"Name": "CT Lung", "WindowCenter": -400, "WindowWidth": 1600}, - {"Name": "CT Abdomen", "WindowCenter": 60, "WindowWidth": 400}, - {"Name": "CT Bone", "WindowCenter": 300, "WindowWidth": 1500}, - {"Name": "CT Brain", "WindowCenter": 40, "WindowWidth": 80}, - {"Name": "CT Chest", "WindowCenter": 40, "WindowWidth": 400}, - {"Name": "CT Angio", "WindowCenter": 300, "WindowWidth": 600} - ], - - /** - * The allowed origin for messages corresponding to dynamic actions - * triggered by another Web page using "window.postMessage()". The - * special value "*" will allow any origin, which is an insecure - * value to be used only during development. If this option is not - * set, all the requests for dynamic actions will be rejected. - * https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage - **/ - "ExpectedMessageOrigin" : "http://localhost:8042" + /** + * This option allows you to define windowing presets. + * For each preset, you must provide a name, the window width + * and window center. + **/ + "WindowingPresets" : [ + {"Name": "CT Lung", "WindowCenter": -400, "WindowWidth": 1600}, + {"Name": "CT Abdomen", "WindowCenter": 60, "WindowWidth": 400}, + {"Name": "CT Bone", "WindowCenter": 300, "WindowWidth": 1500}, + {"Name": "CT Brain", "WindowCenter": 40, "WindowWidth": 80}, + {"Name": "CT Chest", "WindowCenter": 40, "WindowWidth": 400}, + {"Name": "CT Angio", "WindowCenter": 300, "WindowWidth": 600} + ], + + /** + * The allowed origin for messages corresponding to dynamic actions + * triggered by another Web page using "window.postMessage()". The + * special value "*" will allow any origin, which is an insecure + * value to be used only during development. If this option is not + * set, all the requests for dynamic actions will be rejected. + * https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage + **/ + "ExpectedMessageOrigin" : "http://localhost:8042" + } }