Skip to content

Commit 4d117b3

Browse files
authored
Fix sys contact null (librenms#18205)
* Fix override sysContact null issue * Restore the previously set override when enabled.
1 parent 6344f83 commit 4d117b3

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

app/Http/Controllers/Device/EditDeviceController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function index(Device $device): View
6868
'poller_groups' => PollerGroup::orderBy('group_name')->pluck('group_name', 'id'),
6969
'default_poller_group' => LibrenmsConfig::get('distributed_poller_group'),
7070
'override_sysContact_bool' => $device->getAttrib('override_sysContact_bool'),
71-
'override_sysContact_string' => $device->getAttrib('override_sysContact_bool') ? $device->getAttrib('override_sysContact_string') : $device->sysContact,
71+
'override_sysContact_string' => $device->getAttrib('override_sysContact_string'),
7272
'maintenance' => $isUnderMaintenance,
7373
'default_maintenance_behavior' => MaintenanceBehavior::from((int) LibrenmsConfig::get('alert.scheduled_maintenance_default_behavior'))->value,
7474
'exclusive_maintenance_id' => $exclusive_schedule_id,
@@ -95,7 +95,7 @@ public function update(UpdateDeviceRequest $request, Device $device): RedirectRe
9595
// check if sysContact is overridden
9696
if ($request->get('override_sysContact')) {
9797
$device->setAttrib('override_sysContact_bool', true);
98-
$device->setAttrib('override_sysContact_string', $request->get('override_sysContact_string', ''));
98+
$device->setAttrib('override_sysContact_string', (string) $request->get('override_sysContact_string'));
9999
} else {
100100
$device->forgetAttrib('override_sysContact_bool');
101101
}

resources/views/device/edit/device.blade.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ class="btn btn-primary" name="rediscover" title="{{ __('device.edit.rediscover_t
112112
<div class="col-sm-6">
113113
<input id="override_sysContact_string" class="form-control" name="override_sysContact_string" size="32"
114114
{{ old('override_sysContact', $override_sysContact_bool) ? '' : 'disabled' }}
115-
value="{{ old('override_sysContact_string', $override_sysContact_string) }}"
115+
data-override="{{ $override_sysContact_string }}"
116+
data-default="{{ $device->sysContact }}"
117+
value="{{ old('override_sysContact_string', $override_sysContact_bool ? $override_sysContact_string : $device->sysContact) }}"
116118
/>
117119
</div>
118120
</div>
@@ -219,6 +221,14 @@ class="btn btn-primary" name="rediscover" title="{{ __('device.edit.rediscover_t
219221
@push('scripts')
220222
<script>
221223
$('[type="checkbox"]').bootstrapSwitch('offColor', 'danger');
224+
$('#override_sysContact').on('switchChange.bootstrapSwitch', function(event, state) {
225+
var $input = $('#override_sysContact_string');
226+
var newValue = state ? $input.data('override') : $input.data('default');
227+
228+
if (!state || newValue) {
229+
$input.val(newValue);
230+
}
231+
});
222232
$("#rediscover").on("click", function() {
223233
fetch('{{ route('device.rediscover', [$device->device_id]) }}', {
224234
method: 'POST',

0 commit comments

Comments
 (0)