mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Refresh in widget settings (#12127)
* add timeout for widget in widget settings * forgot get saved timeout and added default value for all widgets * code correction * move refresh to json * forgot remove old code * added refresh validate rule * fix empty refresh for exist widgets * fix empty settings for new widgets * Set refresh in base Update refresh at runtime (doesn't interrupt previous timeout) * Update WidgetSettingsController.php Co-authored-by: Tony Murray <murraytony@gmail.com>
This commit is contained in:
@@ -32,10 +32,14 @@ class WidgetSettingsController extends Controller
|
||||
{
|
||||
public function update(Request $request, $widget_settings)
|
||||
{
|
||||
$this->validate($request, ['settings' => 'array']);
|
||||
$this->validate($request, [
|
||||
'settings' => 'array',
|
||||
'settings.refresh' => 'int|min:1',
|
||||
]);
|
||||
|
||||
$widget = UserWidget::with('dashboard')->findOrFail($widget_settings);
|
||||
$widget_settings = (array) $request->get('settings', []);
|
||||
unset($widget_settings['_token']);
|
||||
|
||||
if (! $widget->dashboard->canWrite($request->user())) {
|
||||
return response()->json([
|
||||
|
||||
@@ -77,7 +77,7 @@ class OverviewController extends Controller
|
||||
|
||||
$data = $dashboard
|
||||
->widgets()
|
||||
->select(['user_widget_id', 'users_widgets.widget_id', 'title', 'widget', 'col', 'row', 'size_x', 'size_y', 'refresh'])
|
||||
->select(['user_widget_id', 'users_widgets.widget_id', 'title', 'widget', 'col', 'row', 'size_x', 'size_y', 'refresh', 'settings'])
|
||||
->join('widgets', 'widgets.widget_id', '=', 'users_widgets.widget_id')
|
||||
->get();
|
||||
|
||||
@@ -96,7 +96,7 @@ class OverviewController extends Controller
|
||||
|
||||
$bare = $request->bare;
|
||||
$data = serialize(json_encode($data));
|
||||
$dash_config = unserialize(stripslashes($data));
|
||||
$dash_config = unserialize($data);
|
||||
$hide_dashboard_editor = UserPref::getPref($user, 'hide_dashboard_editor');
|
||||
$widgets = Widget::select('widget_id', 'widget_title')->orderBy('widget_title')->get();
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@ use App\Models\Device;
|
||||
use App\Models\MuninPlugin;
|
||||
use App\Models\Port;
|
||||
use App\Models\Service;
|
||||
use App\Models\UserWidget;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
@@ -43,6 +42,7 @@ class GraphController extends WidgetController
|
||||
protected $title = 'Graph';
|
||||
protected $defaults = [
|
||||
'title' => null,
|
||||
'refresh' => 60,
|
||||
'graph_type' => null,
|
||||
'graph_range' => 'oneday',
|
||||
'graph_legend' => 'yes',
|
||||
@@ -252,10 +252,7 @@ class GraphController extends WidgetController
|
||||
public function getSettings($settingsView = false)
|
||||
{
|
||||
if (is_null($this->settings)) {
|
||||
$id = \Request::get('id');
|
||||
$widget = UserWidget::findOrFail($id);
|
||||
$settings = array_replace($this->defaults, (array) $widget->settings);
|
||||
$settings['id'] = $id;
|
||||
$settings = parent::getSettings($settingsView);
|
||||
|
||||
// legacy data conversions
|
||||
if ($settings['graph_type'] == 'manual') {
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
namespace App\Http\Controllers\Widgets;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class NotesController extends WidgetController
|
||||
{
|
||||
|
||||
@@ -86,6 +86,7 @@ abstract class WidgetController extends Controller
|
||||
/**
|
||||
* Get the settings (with defaults applied)
|
||||
*
|
||||
* @param bool $settingsView
|
||||
* @return array
|
||||
*/
|
||||
public function getSettings($settingsView = false)
|
||||
@@ -93,6 +94,7 @@ abstract class WidgetController extends Controller
|
||||
if (is_null($this->settings)) {
|
||||
$id = \Request::get('id');
|
||||
$widget = UserWidget::find($id);
|
||||
$this->defaults['refresh'] = $this->defaults['refresh'] ?? 60;
|
||||
$this->settings = array_replace($this->defaults, $widget ? (array) $widget->settings : []);
|
||||
$this->settings['id'] = $id;
|
||||
|
||||
|
||||
@@ -110,6 +110,7 @@
|
||||
"down": "лежит",
|
||||
"Total services": "Всего сервисов",
|
||||
"Widget title": "Заголовок виджета",
|
||||
"Widget refresh": "Обновление виджета, сек",
|
||||
"Default Title": "Заголовок по умолчанию",
|
||||
"Columns": "Колонка",
|
||||
"Markers": "Маркеры",
|
||||
@@ -155,6 +156,7 @@
|
||||
"Show Port Errors": "Показать ошибки портов",
|
||||
"Notes": "Заметки",
|
||||
"Custom title for widget": "Изменяемый заголовок для виджета",
|
||||
"Custom refresh for widget": "Интервал обновления виджета",
|
||||
"Display type": "Отображаемый тип",
|
||||
"boxes": "боксы",
|
||||
"compact": "компактный",
|
||||
|
||||
@@ -488,7 +488,7 @@
|
||||
'</span>'+
|
||||
'</header>'+
|
||||
'<div class="widget_body" id="widget_body_'+data.user_widget_id+'">'+data.widget+'</div>'+
|
||||
'\<script\>var timeout'+data.user_widget_id+' = grab_data('+data.user_widget_id+','+data.refresh+',\''+data.widget+'\');\<\/script\>'+
|
||||
'\<script\>var timeout'+data.user_widget_id+' = grab_data('+data.user_widget_id+',\''+data.widget+'\');\<\/script\>'+
|
||||
'</li>';
|
||||
|
||||
if (data.hasOwnProperty('col') && data.hasOwnProperty('row')) {
|
||||
@@ -574,6 +574,7 @@
|
||||
if (data.status === 'ok') {
|
||||
$("#widget_title_"+id).html(data.title);
|
||||
$widget_body.html(data.html).parent().data('settings', data.show_settings);
|
||||
$widget_body.html(data.html).parent().data('refresh', data.settings.refresh);
|
||||
} else {
|
||||
$widget_body.html('<div class="alert alert-info">' + data.message + '</div>');
|
||||
}
|
||||
@@ -590,16 +591,18 @@
|
||||
});
|
||||
}
|
||||
|
||||
function grab_data(id,refresh, data_type) {
|
||||
if( $("#widget_body_"+id).parent().data('settings') == 0 ) {
|
||||
function grab_data(id, data_type) {
|
||||
var parent = $("#widget_body_"+id).parent();
|
||||
|
||||
if( parent.data('settings') == 0 ) {
|
||||
widget_reload(id, data_type);
|
||||
}
|
||||
new_refresh = refresh * 1000;
|
||||
|
||||
setTimeout(function() {
|
||||
grab_data(id,refresh,data_type);
|
||||
},
|
||||
new_refresh);
|
||||
grab_data(id, data_type);
|
||||
}, (parent.data('refresh') > 0 ? parent.data('refresh') : 60) * 1000);
|
||||
}
|
||||
|
||||
$('#new-widget').popover();
|
||||
|
||||
@if (empty($dashboard->dashboard_id) && $default_dash == 0)
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
@csrf
|
||||
@yield('form')
|
||||
|
||||
@hassection('form')
|
||||
<div style="margin-top: 8px;">
|
||||
<button type="submit" class="btn btn-primary pull-right">@lang('Save')</button>
|
||||
</div>
|
||||
@else
|
||||
No settings for this widget
|
||||
@endif
|
||||
<div class="form-group">
|
||||
<label for="refresh-{{ $id }}" class="control-label">@lang('Widget refresh interval (s)')</label>
|
||||
<input type="number" step="1" min="1" class="form-control" name="refresh" id="refresh-{{ $id }}" value="{{ $refresh }}">
|
||||
</div>
|
||||
<div style="margin-top: 8px;">
|
||||
<button type="submit" class="btn btn-primary pull-right">@lang('Save')</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@yield('javascript')
|
||||
|
||||
Reference in New Issue
Block a user