openhab / openhab-webui

Web UIs of openHAB
Eclipse Public License 2.0
221 stars 239 forks source link

Save comments in custom YAML widgets #1598

Open TilmanGuenther opened 1 year ago

TilmanGuenther commented 1 year ago

The problem

I have found myself creating many YAML widgets, and it is difficult to maintain a clear overview of the code without being able to place persistent comments. Only temporary ones with # work, but these are deleted when the widget is loaded from save.

Your suggestion

Change it so that comments stay in widgets when they are saved.

rkoshak commented 1 year ago

This has been requested before but there are technical issues that make this extremely difficult to support.

The problem is JSON doesn't support comments. the YAML you see in the browser is converted from the JSON, which is the raw representation of the widget, on the fly. Because the JSON doesn't support comments at all, and the JSON needs to be structured, there's no clear way to insert comments.

I'm not saying this can't ever be done. Just explaining why it's not already supported and while it might be quite some time before a suitable technical solution is found.

soenkekueper commented 1 year ago

During implementation of sungrow widget (https://community.openhab.org/t/sungrow-binding/147442/13) i'v put lots of comments into the yaml, because otherwise it's very hard to get the structure of the code - and so i was very disappointed once they were gone after saving. So i would really enjoy this pr. Maybe it would be helpfull to have any kind of outline available, so you hava a little more orientation within the widget editor. But afaik the codemirror doesn't have such a function (yet).

rkoshak commented 1 year ago

One work around that has been mentioned on the forum is to just add a YAML element along side the others. You can call it what ever you want so long as you don't use the name of an element that has meaning. "comment" is a good choice. MainUI will ignore elements it's not looking for and because it's an element it gets rendered in to the JSON and therefore gets saved.