Hellowlol / HTPC-Manager

A fully responsive interface to manage all your favorite software on your Htpc.
MIT License
344 stars 48 forks source link

Request: Auto-refresh of dash widgets #581

Closed jeremysherriff closed 6 years ago

jeremysherriff commented 6 years ago

A number of the dash widgets already have a refresh button. I would love to have a setting that allows these to be refreshed automatically instead of via a manual click.

I can imagine that people will add refresh capabilities to existing widgets if this suggestion is adopted.

I envision the value being an integer rather than an on/off toggle, which represents the refresh interval with zero disabling the feature. Maybe the settings GUI for this option should be a drop-down box populated with relevant timings? This would remove the need to sanitize the input (as a bogus interval value would break the jscript, and therefore break the dashboard page). [0 - disabled] [30 seconds] [60 seconds] [2 minutes] [5 minutes]

I am happy to code this and submit a pull request if someone can help me with the challenges outlined below:

  1. I do not know how to add a field & value into the database to store the new refresh setting needed to implement this option, nor how to reference the value from the database in the .js and .html files. See code snippet below for my best guess for referencing the setting in code.

  2. I have done some experimentation and found that a simple setInterval() java function call will refresh the existing (refresh-enabled) widgets on a timer, if placed in dash.js. The following code should be very close:

    setInterval(function () {
    loaduTorrent();
    loadqbit();
    loadsysinfo();
    loaddiskinfo();
    loadsmartinfo();
    }, 1000*$('#dash_refresh_interval') ); //timer uses milliseconds
    } 

    What I can't figure out is how to dynamically build the list of widgets that are being displayed and have the refresh capability enabled - but do I need to? There seems to be no downside to setInterval() calling loaddiskinfo() whether the disk widget is enabled or not??

As a workaround, people would also need to add their widget function into this function call, once they enabled refresh capabilities on other widgets. This is not really a problem but it would be nice if we could dynamically build the list of functions that supported refresh (there is already some logic in each relevant widget that adds the refresh button).

Cheers for listening, J

Hellowlol commented 6 years ago
  1. https://github.com/Hellowlol/HTPC-Manager/blob/master2/interfaces/default/html/settings.html#L31
  2. https://github.com/Hellowlol/HTPC-Manager/blob/master2/interfaces/default/js/dash.js#L889
jeremysherriff commented 6 years ago

Thanks for that, I'll see what I can do :)

jeremysherriff commented 6 years ago

I'm struggling to make this work. I have been able to get and store the setting in settings.html, which was relatively easy. Now I'm trying to fetch and use the setting is dash.js, but I cannot seem to get the format right to fetch a value from the settings.

For test purposes I have added a notify() pop with the value, so that I can visually confirm I'm getting the value. notify('Testing','Refresh interval = ' + $('#dash_refresh_interval'), 'info') But I get: image

Can anyone help me with fetching either a text value or a bool from the database settings values?

(I can correctly fetch the value if I do it in dash.html so I know my value is in the database, but it's of no use in the .html file unless there's a way to pass a value from the html to the js invocation)

jeremysherriff commented 6 years ago

Disregard that last - I got it working.

jeremysherriff commented 6 years ago

Implemented in merge #584