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:
86
lib/App/Netdisco/Web/CustomFields.pm
Normal file
86
lib/App/Netdisco/Web/CustomFields.pm
Normal file
@@ -0,0 +1,86 @@
|
||||
package App::Netdisco::Web::CustomFields;
|
||||
|
||||
use Dancer ':syntax';
|
||||
use Dancer::Plugin::DBIC;
|
||||
|
||||
use App::Netdisco::DB::ResultSet::Device;
|
||||
use App::Netdisco::DB::ResultSet::DevicePort;
|
||||
|
||||
use App::Netdisco::Web::Plugin;
|
||||
|
||||
my @inline_device_actions = ();
|
||||
my @inline_device_port_actions = ();
|
||||
|
||||
foreach my $config (@{ setting('custom_fields')->{'device'} || [] }) {
|
||||
|
||||
if (! $config->{'name'}) {
|
||||
error 'custom_field missing name';
|
||||
next;
|
||||
}
|
||||
|
||||
register_device_details({
|
||||
%{ $config },
|
||||
field => ('cf_' . $config->{'name'}),
|
||||
label => ($config->{'label'} || ucfirst $config->{'name'}),
|
||||
}) unless $config->{'hidden'};
|
||||
|
||||
push @inline_device_actions, $config->{'name'};
|
||||
|
||||
}
|
||||
|
||||
foreach my $config (@{ setting('custom_fields')->{'device_port'} || [] }) {
|
||||
|
||||
if (! $config->{'name'}) {
|
||||
error 'custom_field missing name';
|
||||
next;
|
||||
}
|
||||
|
||||
register_device_port_column({
|
||||
position => 'right', # or "mid" or "right"
|
||||
default => undef, # or undef
|
||||
%{ $config },
|
||||
field => ('cf_' . $config->{'name'}),
|
||||
label => ($config->{'label'} || ucfirst $config->{'name'}),
|
||||
}) unless $config->{'hidden'};
|
||||
|
||||
push @inline_device_port_actions, $config->{'name'};
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
package App::Netdisco::DB::ResultSet::Device;
|
||||
|
||||
sub with_custom_fields {
|
||||
my ($rs, $cond, $attrs) = @_;
|
||||
|
||||
return $rs
|
||||
->search_rs($cond, $attrs)
|
||||
->search({},
|
||||
{ '+columns' => {
|
||||
map {( ('cf_'. $_) => \[ 'me.custom_fields ->> ?' => $_ ] )}
|
||||
@inline_device_actions
|
||||
}});
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
package App::Netdisco::DB::ResultSet::DevicePort;
|
||||
|
||||
sub with_custom_fields {
|
||||
my ($rs, $cond, $attrs) = @_;
|
||||
|
||||
return $rs
|
||||
->search_rs($cond, $attrs)
|
||||
->search({},
|
||||
{ '+columns' => {
|
||||
map {( ('cf_'. $_) => \[ 'me.custom_fields ->> ?' => $_ ] )}
|
||||
@inline_device_port_actions
|
||||
}});
|
||||
}
|
||||
}
|
||||
|
||||
set('_inline_actions' => [
|
||||
map {'cf_' . $_} (@inline_device_actions, @inline_device_port_actions)
|
||||
]);
|
||||
|
||||
true;
|
||||
Reference in New Issue
Block a user