openhab / openhab-webui

Web UIs of openHAB
Eclipse Public License 2.0
214 stars 235 forks source link

[Habpanel] Store the panel registry in plain JSON files #227

Open asoltesz opened 4 years ago

asoltesz commented 4 years ago

Currently, the Habpanel panel definitions are stored in an escaped / compressed format in the userdata folder of Openhab.

This makes design / development / release workflow around panels very difficult and error-prone.

I develop panels in my OpenHAB development environment (on my laptop) and then I would like to transfer the new panels to my production environment (running on an Odroid sbc). Currently, I can only do this if all of my panels become production ready at the same time and even in that case, it is fairly cumbersome.

I store all of my OpenHAB configuration in Git and version control all changes (as it should be for every non-trivial systems). I only move config changes to my production system through Git.

If I have half-done, in-progress panels in my DEV environment, I cannot release at all because I would first need to extract the ready panels from the huge single, escaped panel-registry file, then merge it into my production file. This is so error-prone that I wouldn't even recommend it to anyone.

Exporting and importing the panel registry can only by done either manually, or via running scripts separately, that download / upload via REST.

I argue that the HabPanel panel definitions should be treated exactly the same way as sitemaps. They should be in well-formatted (pretty-printed), attribute-ordered JSON files in a logical folder structure that can be modified both manually and via the panel designer program.

I recommend the following structure:

All JSON files should have a predictable attribute ordering (say alphabetical), so that Git can show differences nicely.

When the panel developer saves panels, the differences should be reflected in the files immediately (like it is now in userdata).

When the panel definitions are updated externally (say via git fetch/rebase), OpenHAB should notify running HabPanel instances and allow them to reload the new panel / panel-configuration definitions from the server.

This would allow the same, proper, design / development / release workflow around panels which already exists for item and sitemap files.

ghys commented 4 years ago

FYI the plan is to eventually move the HABPanel panel registry from the service configuration to a dedicated namespace in the new UI components concept added recently (https://github.com/openhab/openhab-core/issues/1355) so they will be stored in userdata/jsondb (pretty-printed) and retrieved with a nicer API. Sourcing them from files like you suggest is probably not going to happen unless someone jumps to it.