implement host_group_displaynames and fix vlan save bug

This commit is contained in:
Oliver Gorwits
2017-12-23 22:06:24 +00:00
parent 35ed34ed2f
commit 9a13bb7f9b
5 changed files with 33 additions and 18 deletions

View File

@@ -16,6 +16,7 @@ set('connected_properties' => [
]); ]);
hook 'before_template' => sub { hook 'before_template' => sub {
my $tokens = shift;
my $defaults = var('sidebar_defaults')->{'device_ports'} my $defaults = var('sidebar_defaults')->{'device_ports'}
or return; or return;
@@ -34,6 +35,13 @@ hook 'before_template' => sub {
} }
} }
# used in the device search sidebar template to set selected items
foreach my $opt (qw/devgrp/) {
my $p = (ref [] eq ref param($opt) ? param($opt)
: (param($opt) ? [param($opt)] : []));
$tokens->{"${opt}_lkp"} = { map { $_ => 1 } @$p };
}
return if param('reset') return if param('reset')
or not var('sidebar_key') or (var('sidebar_key') ne 'device_ports'); or not var('sidebar_key') or (var('sidebar_key') ne 'device_ports');
@@ -69,6 +77,7 @@ get '/device' => require_login sub {
params->{'tab'} ||= 'details'; params->{'tab'} ||= 'details';
template 'device', { template 'device', {
display_name => ($others ? $first->ip : ($first->dns || $first->ip)), display_name => ($others ? $first->ip : ($first->dns || $first->ip)),
devgrp_list => setting('host_group_displaynames'),
device => params->{'tab'}, device => params->{'tab'},
}; };
}; };

View File

@@ -133,6 +133,7 @@ sidebar_defaults:
mac_format: { default: IEEE } mac_format: { default: IEEE }
neigh_id: { default: null } neigh_id: { default: null }
device_netmap: device_netmap:
mapshow: { default: neighbors }
colorgroups: { default: checked } colorgroups: { default: checked }
report_moduleinventory: report_moduleinventory:
fruonly: { default: checked } fruonly: { default: checked }
@@ -180,6 +181,7 @@ host_groups:
- '::1' - '::1'
- 'fe80::/10' - 'fe80::/10'
- '127.0.0.0/8' - '127.0.0.0/8'
host_group_displaynames: {}
device_identity: [] device_identity: []
community: [] community: []
community_rw: [] community_rw: []

View File

@@ -634,7 +634,7 @@ form .clearfix.success input {
} }
.nd_netmap-sidebar { .nd_netmap-sidebar {
margin-top: 7px; /* margin-top: 7px; */
margin-left: -9px; margin-left: -9px;
} }

View File

@@ -120,9 +120,10 @@
}); });
$('#nd_netmap-save').on('click', function(event) { $('#nd_netmap-save').on('click', function(event) {
event.preventDefault(); event.preventDefault();
// if user enters vlan but does not submit this will save wrong data
$.post( $.post(
'[% uri_for('/ajax/data/device/netmappositions') %]' '[% uri_for('/ajax/data/device/netmappositions') %]'
,'vlan=[% params.vlan %]&positions=' + JSON.stringify(graph.positions()) ,'vlan=' + $('#nd_vlan-entry').val() + '&positions=' + JSON.stringify(graph.positions())
); );
}); });
$('#nd_netmap-zoomtodevice').on('click', function(event) { $('#nd_netmap-zoomtodevice').on('click', function(event) {

View File

@@ -51,16 +51,18 @@
<div class="radio radio-success"> <div class="radio radio-success">
<input type="radio" name="mapshow" id="nd_mapshow-all" <input type="radio" name="mapshow" id="nd_mapshow-all"
[% 'checked' IF params.mapshow == 'all' %] value="all"> [% 'checked' IF vars.sidebar_defaults.device_netmap.mapshow == 'all' %] value="all">
<label for="nd_mapshow-all">All Devices</label> <label for="nd_mapshow-all">All Devices</label>
</div> </div>
<div class="radio radio-success"> <div class="radio radio-success">
<input type="radio" name="mapshow" id="nd_mapshow-neighbors" value="neighbors" checked> <input type="radio" name="mapshow" id="nd_mapshow-neighbors"
[% 'checked' IF vars.sidebar_defaults.device_netmap.mapshow == 'neighbors' %] value="neighbors">
<label for="nd_mapshow-neighbors">Neighbors Only</label> <label for="nd_mapshow-neighbors">Neighbors Only</label>
</div> </div>
<div class="radio radio-success"> <div class="radio radio-success">
<input type="radio" name="mapshow" id="nd_mapshow-only" <input type="radio" name="mapshow" id="nd_mapshow-only"
[% 'checked' IF vars.sidebar_defaults.device_netmap.mapshow == 'only' %]
[% 'disabled' IF NOT devgrp_list.size %] value="only"> [% 'disabled' IF NOT devgrp_list.size %] value="only">
<label for="nd_mapshow-only">Host Groups</label> <label for="nd_mapshow-only">Host Groups</label>
</div> </div>
@@ -70,8 +72,9 @@
<select class="nd_side-select" size="[% devgrp_list.size > 5 ? 5 : devgrp_list.size %]" <select class="nd_side-select" size="[% devgrp_list.size > 5 ? 5 : devgrp_list.size %]"
multiple="on" name="devgrp" multiple="on" name="devgrp"
rel="tooltip" data-placement="left" data-offset="5" data-title="Host Groups"/> rel="tooltip" data-placement="left" data-offset="5" data-title="Host Groups"/>
[% FOREACH opt IN devgrp_list %] [% FOREACH opt IN devgrp_list.pairs %]
<option[% ' selected="selected"' IF os_lkp.exists(opt) %]>[% opt | html_entity %]</option> <option[% ' selected="selected"' IF devgrp_lkp.exists(opt.key) %]
value="[% opt.key %]">[% opt.value | html_entity %]</option>
[% END %] [% END %]
</select> </select>
</div> </div>
@@ -82,8 +85,8 @@
[% IF devgrp_list.size %] [% IF devgrp_list.size %]
<div class="clearfix input-prepend"> <div class="clearfix input-prepend">
<label class="add-on"> <label class="add-on">
<input type="checkbox" id="colorgroups" <input type="checkbox" id="colorgroups" name="colorgroups"
name="colorgroups"[% ' checked="checked"' IF vars.sidebar_defaults.device_netmap.colorgroups %]/> [% 'checked="checked"' IF vars.sidebar_defaults.device_netmap.colorgroups %]/>
</label> </label>
<label class="nd_checkboxlabel" for="colorgroups"> <label class="nd_checkboxlabel" for="colorgroups">
<span class="nd_searchcheckbox uneditable-input">Color Groups</span> <span class="nd_searchcheckbox uneditable-input">Color Groups</span>
@@ -91,6 +94,16 @@
</div> </div>
[% END %] [% END %]
<div class="clearfix input-prepend">
<label class="add-on">
<input type="checkbox" id="dynamicsize" name="dynamicsize" disabled
[% 'checked="checked"' IF params.dynamicsize %]/>
</label>
<label class="nd_checkboxlabel" for="dynamicsize">
<span class="nd_searchcheckbox uneditable-input">Dynamic Size</span>
</label>
</div>
<div id="nd_vlan-label" class="control-group"> <div id="nd_vlan-label" class="control-group">
<div class="controls"> <div class="controls">
<label><span id="nd_vlan-label-text">Carrying VLAN: </span> <label><span id="nd_vlan-label-text">Carrying VLAN: </span>
@@ -100,16 +113,6 @@
</div> </div>
</div> </div>
<div class="clearfix input-prepend">
<label class="add-on">
<input type="checkbox" id="dynamicsize" disabled
name="dynamicsize"[% ' checked="checked"' IF vars.sidebar_defaults.device_netmap.dynamicsize %]/>
</label>
<label class="nd_checkboxlabel" for="dynamicsize">
<span class="nd_searchcheckbox uneditable-input">Dynamic Size</span>
</label>
</div>
</div> </div>
<button id="[% tab.tag %]_submit" type="submit" class="btn btn-info"> <button id="[% tab.tag %]_submit" type="submit" class="btn btn-info">