custom fields on devices and ports in the web from config (#945)

* custom device field web display and edit

* make display work; relies on T::T calling dict slot or method with same syntax

* add storing port custom fields

* use resultset method instead, use cf_ prefix

* update Pg min ver for jsonb

* allow override of position and default for port custom fields

* support hidden for custom fields

* update description of Objects API class

* allow left and mid position for custom fields

* add custom fields in csv

* change port control sidebar label

* fix default missing bug on backend jobs
This commit is contained in:
Oliver Gorwits
2022-12-09 10:20:26 +00:00
committed by GitHub
parent d03eab02db
commit 1c7c749f0e
15 changed files with 225 additions and 44 deletions

View File

@@ -112,7 +112,7 @@ sidebar_defaults:
search_device:
matchall: { default: checked }
device_ports:
c_admin: { label: 'Port Controls', default: null, idx: 0 }
c_admin: { label: 'Port Control and Editing', default: null, idx: 0 }
c_port: { label: 'Port', default: checked, idx: 1 }
c_descr: { label: 'Description', default: null, idx: 2 }
c_comment: { label: 'Last Comment', default: null, idx: 3 }
@@ -275,6 +275,9 @@ community_rw: []
device_auth: []
use_legacy_rancidexport: false
use_legacy_sshcollector: false
custom_fields:
device: []
device_port: []
get_credentials: ""
bulkwalk_off: false
bulkwalk_no: []

View File

@@ -0,0 +1,11 @@
BEGIN;
ALTER TABLE device ADD COLUMN "custom_fields" jsonb DEFAULT '{}';
UPDATE device SET custom_fields = '{}';
ALTER TABLE device_port ADD COLUMN "custom_fields" jsonb DEFAULT '{}';
UPDATE device_port SET custom_fields = '{}';
COMMIT;

View File

@@ -79,14 +79,25 @@
<tr>
<td>
[% config.label | html_entity %]
</td>
<td>
[% TRY %]
[% INCLUDE "plugin/${config.name}/device_details.tt" %]
[% CATCH %]
<!-- dummy content required by Template Toolkit TRY -->
[% IF config.editable AND user_can_port_control %]
<i class="icon-edit nd_edit-icon nd_device-details-edit"></i>
[% END %]
</td>
[% TRY %]
<td>
[% INCLUDE "plugin/${config.name}/device_details.tt" %]
</td>
[% CATCH %]
[% CLEAR %]
[% IF config.editable AND user_can_port_control %]
<td class="nd_editable-cell" contenteditable="true"
data-field="[% config.field | html_entity %]" data-for-device="[% d.ip | html_entity %]">
[% ELSE %]
<td>
[% END %]
[% d.${config.field} | html_entity %]
</td>
[% END %]
</tr>
[% END %]
[% END %]

View File

@@ -60,13 +60,26 @@
[% FOREACH config IN settings._extra_device_port_cols %]
[% NEXT UNLESS config.position == 'left' AND params.${config.name} %]
<td>
[% TRY %]
[% TRY %]
<td>
[% INCLUDE "plugin/${config.name}/device_port_column.tt" %]
[% CATCH %]
<!-- dummy content required by Template Toolkit TRY -->
</td>
[% CATCH %]
[% CLEAR %]
[% IF config.editable AND user_can_port_control AND params.c_admin AND row.portctl %]
<td nowrap class="nd_editable-cell" contenteditable="true"
data-field="[% config.field | html_entity %]" data-for-device="[% device.ip | html_entity %]" data-for-port="[% row.port | html_entity %]">
<i class="icon-edit nd_edit-icon"></i>
[% ELSE %]
<td nowrap class="nd_editable-cell">
[% END %]
</td>
<div class="nd_editable-cell-content">
[% row.get_column(config.field) | html_entity %]
</div>
</td>
[% END %]
[% END %]
[% IF params.c_port %]
@@ -124,13 +137,26 @@
[% FOREACH config IN settings._extra_device_port_cols %]
[% NEXT UNLESS config.position == 'mid' AND params.${config.name} %]
<td>
[% TRY %]
[% TRY %]
<td>
[% INCLUDE "plugin/${config.name}/device_port_column.tt" %]
[% CATCH %]
<!-- dummy content required by Template Toolkit TRY -->
</td>
[% CATCH %]
[% CLEAR %]
[% IF config.editable AND user_can_port_control AND params.c_admin AND row.portctl %]
<td nowrap class="nd_editable-cell" contenteditable="true"
data-field="[% config.field | html_entity %]" data-for-device="[% device.ip | html_entity %]" data-for-port="[% row.port | html_entity %]">
<i class="icon-edit nd_edit-icon"></i>
[% ELSE %]
<td nowrap class="nd_editable-cell">
[% END %]
</td>
<div class="nd_editable-cell-content">
[% row.get_column(config.field) | html_entity %]
</div>
</td>
[% END %]
[% END %]
[% IF params.c_descr %]
@@ -408,13 +434,26 @@
[% FOREACH config IN settings._extra_device_port_cols %]
[% NEXT UNLESS config.position == 'right' AND params.${config.name} %]
<td>
[% TRY %]
[% TRY %]
<td>
[% INCLUDE "plugin/${config.name}/device_port_column.tt" %]
[% CATCH %]
<!-- dummy content required by Template Toolkit TRY -->
</td>
[% CATCH %]
[% CLEAR %]
[% IF config.editable AND user_can_port_control AND params.c_admin AND row.portctl %]
<td nowrap class="nd_editable-cell" contenteditable="true"
data-field="[% config.field | html_entity %]" data-for-device="[% device.ip | html_entity %]" data-for-port="[% row.port | html_entity %]">
<i class="icon-edit nd_edit-icon"></i>
[% ELSE %]
<td nowrap class="nd_editable-cell">
[% END %]
</td>
<div class="nd_editable-cell-content">
[% row.get_column(config.field) | html_entity %]
</div>
</td>
[% END %]
[% END %]
</tr>
[% END %]

View File

@@ -40,7 +40,7 @@
[% TRY %]
[% PROCESS "plugin/${config.name}/device_port_column_csv.tt" %]
[% CATCH %]
[% myport.push('') %]
[% myport.push( row.get_column(config.field) ) %]
[% END %]
[% END %]
@@ -53,7 +53,7 @@
[% TRY %]
[% PROCESS "plugin/${config.name}/device_port_column_csv.tt" %]
[% CATCH %]
[% myport.push('') %]
[% myport.push( row.get_column(config.field) ) %]
[% END %]
[% END %]
@@ -178,7 +178,7 @@
[% TRY %]
[% PROCESS "plugin/${config.name}/device_port_column_csv.tt" %]
[% CATCH %]
[% myport.push('') %]
[% myport.push( row.get_column(config.field) ) %]
[% END %]
[% END %]