ome / omero-iviewer

An OMERO.web app allowing to view images
https://www.openmicroscopy.org/omero/iviewer/
Other
18 stars 29 forks source link

Adding config, best practice? #409

Closed barrettMCW closed 2 years ago

barrettMCW commented 2 years ago

I modified spectrum color picker to give us its palette. I'd like to integrate this as a config option to contribute to source. As I understand it omero iviewer/web configs are done through django? My first idea for an implementation was just writing colorpicker options to a file and using that to get the info into js, but I'd like to avoid adding a file that does almost nothing. The only other option I found is using JSON script from django templates (https://docs.djangoproject.com/en/4.0/ref/templates/builtins/#json-script) but this gives me issues when trying to use the iviewer in a dev server as it isn't run by django. I've gotten around this by just mimicking the output but that feels like bad practice. TLDR: How to access OMERO configs in javascript? (And if I'm completely off base how do omero configs work?)

will-moore commented 2 years ago

Add a setting to https://github.com/ome/omero-iviewer/blob/master/plugin/omero_iviewer/iviewer_settings.py

That allows you to config like:

$ omero config set omero.web.iviewer.max_projection_bytes 12345

Then you can see how that gets into the parameters used to render the Django template at https://github.com/ome/omero-iviewer/blob/f98323a4bf24e3474537bd79195283e909dac78c/plugin/omero_iviewer/views.py#L106

Finally, it gets used to initialise parameters at https://github.com/ome/omero-iviewer/blob/f98323a4bf24e3474537bd79195283e909dac78c/src/app/context.js#L454 and can then be read like this.context.max_projection_bytes (e.g. in dimension-slider.js).

Those existing config examples use int() to convert between the settings input (string) and the config.value.

You can find a lot more examples of settings in https://github.com/ome/omero-web/blob/master/omeroweb/settings.py (including json.loads if you want your config to be a whole JSON object).

barrettMCW commented 2 years ago

This is exactly what I was looking for tysm <3