mirror of
https://github.com/librenms/librenms.git
synced 2024-09-21 10:28:13 +00:00
Add additional sorting options for Availability Map (#14073)
* Fix IPv6 in service check host (#13939) * Add hostName cleaning to Clean * Apply RFC 5952 formatting to Clean::hostName output * Use more liberal cleaning for hostnames * Remove unwanted whitespace * Apply Clean::hostName() to all relevant fields * Fix docstring * Use IP::isValid inline * Update Clean.php * Update services.inc.php Co-authored-by: Tony Murray <murraytony@gmail.com> * Add sorting support for additional columns + dual column Additional columns are Display Name (display) and System Name (sysName) Dual column means that first is sorted after status, then within each status group another sort is done (every columns from single column sorting is possible). * Change code for styleCI * Expand availability map sorting menu Also change sysName to System Name – there is no real reason for that short form. * Add german translation for avail. map sorting/display options * Adjust sorting behaviour in Availability Map The dropdown now presents two options: - Display Text: Sort by the selected value of the dropdown 'Display Text' - Status: Sort by status, then by selected value of dropdown 'Display Text' As the field 'display' (The display name) may contain template functions etc., sorting is not done by SQL means; instead custom sorting is done within the controller. * Apply fix for styleCI * Apply fix for styleCI, part 2 * Update availability-map.blade.php * Update availability-map.blade.php * Update availability-map.blade.php * Update de.json * Update AvailabilityMapController.php * Update AvailabilityMapController.php * Update availability-map.blade.php * Update de.json Co-authored-by: Sander Steffann <sander@steffann.nl> Co-authored-by: Tony Murray <murraytony@gmail.com>
This commit is contained in:
parent
53bfb24ef9
commit
22f84ef3d8
@ -99,14 +99,16 @@ class AvailabilityMapController extends WidgetController
|
||||
if (! $settings['show_disabled_and_ignored']) {
|
||||
$device_query->isNotDisabled();
|
||||
}
|
||||
$device_query->orderBy($settings['order_by']);
|
||||
$devices = $device_query->select(['devices.device_id', 'hostname', 'sysName', 'display', 'status', 'uptime', 'last_polled', 'disabled', 'disable_notify', 'location_id'])->get();
|
||||
|
||||
// process status
|
||||
$uptime_warn = Config::get('uptime_warning', 84600);
|
||||
$uptime_warn = Config::get('uptime_warning', 86400);
|
||||
$totals = ['warn' => 0, 'up' => 0, 'down' => 0, 'maintenance' => 0, 'ignored' => 0, 'disabled' => 0];
|
||||
$data = [];
|
||||
|
||||
// add another field for the selected device label
|
||||
$label_type = $settings['color_only_select'];
|
||||
|
||||
foreach ($devices as $device) {
|
||||
$row = ['device' => $device];
|
||||
if ($device->disabled) {
|
||||
@ -137,9 +139,40 @@ class AvailabilityMapController extends WidgetController
|
||||
$row['labelClass'] = 'label-default';
|
||||
$totals['maintenance']++;
|
||||
}
|
||||
|
||||
if ($label_type == 1) {
|
||||
$row['label'] = null;
|
||||
} elseif ($label_type == 4) {
|
||||
$row['label'] = strtolower($device->shortDisplayName());
|
||||
} elseif ($label_type == 2) {
|
||||
$row['label'] = strtolower($device->hostname);
|
||||
} elseif ($label_type == 3) {
|
||||
$row['label'] = strtolower($device->sysName);
|
||||
} else {
|
||||
$row['label'] = $device->status;
|
||||
}
|
||||
|
||||
$data[] = $row;
|
||||
}
|
||||
|
||||
// now apply sorting, depending on the selected device label
|
||||
$order_by = $settings['order_by'];
|
||||
|
||||
if ($order_by == 'status') {
|
||||
usort($data, function ($l, $r) {
|
||||
$retval = $l['device']->status <=> $r['device']->status;
|
||||
if ($retval == 0) {
|
||||
$retval = $l['label'] <=> $r['label'];
|
||||
}
|
||||
|
||||
return $retval;
|
||||
});
|
||||
} elseif ($order_by == 'label') {
|
||||
usort($data, function ($l, $r) {
|
||||
return $l['label'] <=> $r['label'];
|
||||
});
|
||||
}
|
||||
|
||||
return [$data, $totals];
|
||||
}
|
||||
|
||||
|
@ -15,12 +15,12 @@
|
||||
</div>
|
||||
|
||||
<div class="form-group" id="color_only_select-group-{{ $id }}" style="display: {{ $type == 0 ? 'block' : 'none' }};">
|
||||
<label for="color_only_select-{{ $id }}" class="control-label">{{ __('Display Text') }}</label>
|
||||
<label for="color_only_select-{{ $id }}" class="control-label">{{ __('Label') }}</label>
|
||||
<select class="form-control" name="color_only_select" id="color_only_select-{{ $id }}">
|
||||
<option value="1" @if($color_only_select == 1) selected @endif>{{ __('empty') }}</option>
|
||||
<option value="4" @if($color_only_select == 4) selected @endunless>{{ __('Display Name') }}</option>
|
||||
<option value="2" @if($color_only_select == 2) selected @endunless>{{ __('Hostname') }}</option>
|
||||
<option value="3" @if($color_only_select == 3) selected @endunless>{{ __('Sysname') }}</option>
|
||||
<option value="3" @if($color_only_select == 3) selected @endunless>{{ __('SNMP sysName') }}</option>
|
||||
<option value="0" @unless($color_only_select) selected @endunless>{{ __('Device Status') }}</option>
|
||||
</select>
|
||||
</div>
|
||||
@ -52,7 +52,7 @@
|
||||
<div class="form-group">
|
||||
<label for="order_by-{{ $id }}" class="control-label">{{ __('Order By') }}</label>
|
||||
<select class="form-control" name="order_by" id="order_by-{{ $id }}">
|
||||
<option value="hostname" @if($order_by == 'hostname') selected @endif>{{ __('Hostname') }}</option>
|
||||
<option value="label" @if($order_by == 'label') selected @endif>{{ __('Label') }}</option>
|
||||
<option value="status" @if($order_by == 'status') selected @endif>{{ __('Status') }}</option>
|
||||
</select>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user