mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Even more widget fixes/improvements (#9561)
* Device Summary: don't count deleted ports * General: prevent widget refresh while in settings (synchronize "show_settings" between frontend and backend) * General: reduce reload flicker by delaying clearing of old content until the backend is complete. * Port Select: exclude deleted and orphaned ports
This commit is contained in:
committed by
Neil Lathwood
parent
5d20686d34
commit
ce9790539f
@ -62,6 +62,8 @@ class PortController extends SelectController
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $query */
|
||||
$query = Port::hasAccess($request->user())
|
||||
->isNotDeleted()
|
||||
->has('device')
|
||||
->with(['device' => function ($query) {
|
||||
$query->select('device_id', 'hostname', 'sysName');
|
||||
}])
|
||||
|
@ -65,12 +65,12 @@ abstract class DeviceSummaryController extends WidgetController
|
||||
];
|
||||
|
||||
$data['ports'] = [
|
||||
'count' => Port::hasAccess($user)->count(),
|
||||
'up' => Port::hasAccess($user)->isUp()->count(),
|
||||
'down' => Port::hasAccess($user)->isDown()->count(),
|
||||
'ignored' => Port::hasAccess($user)->isIgnored()->count(),
|
||||
'shutdown' => Port::hasAccess($user)->isShutdown()->count(),
|
||||
'errored' => $data['summary_errors'] ? Port::hasAccess($user)->hasErrors()->count() : -1,
|
||||
'count' => Port::hasAccess($user)->isNotDeleted()->count(),
|
||||
'up' => Port::hasAccess($user)->isNotDeleted()->isUp()->count(),
|
||||
'down' => Port::hasAccess($user)->isNotDeleted()->isDown()->count(),
|
||||
'ignored' => Port::hasAccess($user)->isNotDeleted()->isIgnored()->count(),
|
||||
'shutdown' => Port::hasAccess($user)->isNotDeleted()->isShutdown()->count(),
|
||||
'errored' => $data['summary_errors'] ? Port::hasAccess($user)->isNotDeleted()->hasErrors()->count() : -1,
|
||||
];
|
||||
|
||||
if ($data['show_services']) {
|
||||
|
@ -93,12 +93,28 @@ abstract class WidgetController extends Controller
|
||||
return $this->settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param View|string $view
|
||||
* @param string $title
|
||||
* @param array $settings
|
||||
* @param string $status
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
private function formatResponse($view, $title, $settings, $status = 'ok')
|
||||
{
|
||||
if ($view instanceof View) {
|
||||
$html = $view->__toString();
|
||||
$show_settings = (int)starts_with($view->getName(), 'widgets.settings.');
|
||||
} else {
|
||||
$html = (string)$view;
|
||||
$show_settings = (int)$this->show_settings;
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status' => $status,
|
||||
'title' => __($title),
|
||||
'html' => is_string($view) ? $view : $view->__toString(),
|
||||
'html' => $html,
|
||||
'show_settings' => $show_settings,
|
||||
'settings' => $settings,
|
||||
]);
|
||||
}
|
||||
|
@ -634,8 +634,8 @@ if (empty($vars['bare']) || $vars['bare'] == "no") {
|
||||
function widget_reload(id,data_type) {
|
||||
$("#widget_body_"+id+" .bootgrid-table").bootgrid("destroy");
|
||||
$("#widget_body_"+id+" *").off();
|
||||
$("#widget_body_"+id).empty();
|
||||
if( $("#widget_body_"+id).parent().data('settings') == 1 ) {
|
||||
var $widget_body = $("#widget_body_"+id);
|
||||
if ($widget_body.parent().data('settings') == 1 ) {
|
||||
settings = 1;
|
||||
} else {
|
||||
settings = 0;
|
||||
@ -645,24 +645,27 @@ if (empty($vars['bare']) || $vars['bare'] == "no") {
|
||||
url: 'ajax/dash/' + data_type,
|
||||
data: {
|
||||
id: id,
|
||||
dimensions: {x:$("#widget_body_"+id).width(), y:$("#widget_body_"+id).height()},
|
||||
dimensions: {x:$widget_body.width(), y:$widget_body.height()},
|
||||
settings:settings
|
||||
},
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (data.status == 'ok') {
|
||||
var $widget_body = $("#widget_body_"+id);
|
||||
$widget_body.empty();
|
||||
if (data.status === 'ok') {
|
||||
$("#widget_title_"+id).html(data.title);
|
||||
$("#widget_body_"+id).html(data.html);
|
||||
}
|
||||
else {
|
||||
$("#widget_body_"+id).html('<div class="alert alert-info">' + data.message + '</div>');
|
||||
$widget_body.html(data.html).parent().data('settings', data.show_settings);
|
||||
} else {
|
||||
$widget_body.html('<div class="alert alert-info">' + data.message + '</div>');
|
||||
}
|
||||
},
|
||||
error: function (data) {
|
||||
var $widget_body = $("#widget_body_"+id);
|
||||
$widget_body.empty();
|
||||
if (data.responseJSON.error) {
|
||||
$("#widget_body_"+id).html('<div class="alert alert-info">' + data.responseJSON.error + '</div>');
|
||||
$widget_body.html('<div class="alert alert-info">' + data.responseJSON.error + '</div>');
|
||||
} else {
|
||||
$("#widget_body_"+id).html('<div class="alert alert-info"><?php echo __('Problem with backend'); ?></div>');
|
||||
$widget_body.html('<div class="alert alert-info"><?php echo __('Problem with backend'); ?></div>');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user