OPNsense Forum

English Forums => Development and Code Review => Topic started by: Droid999 on August 03, 2024, 01:56:53 AM

Title: Help with developing Widget
Post by: Droid999 on August 03, 2024, 01:56:53 AM
Hi

Is there a tutorial / hello world  / sample  on how to develop a widget for 24.7?

Thanks

Edit 1:

Where can I find debug / error messages that I might be generating while trying to get this new widget working?

Nothing is showing up in System > Log files ( Debug ) > Backend / General.

(https://i.ibb.co/qNyg0N1/broken.jpg) (https://ibb.co/VgjCHgB)
Title: Re: Help with developing Widget
Post by: Monviech (Cedrik) on August 03, 2024, 05:42:05 AM
Here is a widget I made recently:

https://github.com/opnsense/plugins/commit/dd68ab68d88c5afd355a1662cfc4bcb44117a4ed

Esentially you check out what kind of information an API has, and then show it in a widget.

Here are some of the methods explained:

https://github.com/opnsense/docs/blob/7d69a107ab87146bd91373485ecfa5c49c8be26d/source/development/frontend/dashboard.rst


An even easier example widget where the api doesnt serve an array with uuids, but only one option:

https://github.com/opnsense/plugins/blob/master/security/etpro-telemetry/src/opnsense/www/js/widgets/ETProTelemetry.js


When widgets fail to load the console log in the browser is your friend.
Title: Re: Help with developing Widget
Post by: vlannister on August 03, 2024, 01:15:46 PM
I got a custom widget working by placing my .js file in
/usr/local/opnsense/www/js/widgets/
And adding an entry to /usr/local/opnsense/www/js/widgets/Metadata/Core.xml

However a minor OPNsense update reverted my Core.xml changes. Is there a method that persists through updates?
Title: Re: Help with developing Widget
Post by: Monviech (Cedrik) on August 03, 2024, 02:18:11 PM
Yes certainly, check out the first link above.
Title: Re: Help with developing Widget
Post by: vlannister on August 03, 2024, 08:24:12 PM
Ah, so creating my own xml in /usr/local/opnsense/www/js/widgets/Metadata/ is the way.

Thanks!
Title: Re: Help with developing Widget
Post by: Droid999 on August 04, 2024, 06:26:32 AM
Quote from: Monviech on August 03, 2024, 05:42:05 AM
When widgets fail to load the console log in the browser is your friend.

Yes indeed - my new BEST friend.

Thanks for the pointers - got the plugin written and working.

Cheers
Title: Re: Help with developing Widget
Post by: Monviech (Cedrik) on August 04, 2024, 06:29:32 AM
Good job, but now there is already another one for UPS in a pull request too.

Which one will make it in? Yours or the other? Tune in next time for battle of the widgets.  ;D

https://github.com/opnsense/plugins/pull/4150