[913a75]: Netdisco / lib / App / Netdisco / Web / Plugin.pm  Maximize  Restore  History

Download this file

287 lines (208 with data), 7.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
package App::Netdisco::Web::Plugin;
use Dancer ':syntax';
use Dancer::Plugin;
use Path::Class 'dir';
set(
'_additional_css' => [],
'_additional_javascript' => [],
'_extra_device_port_cols' => [],
'_extra_device_details' => [],
'_navbar_items' => [],
'_search_tabs' => [],
'_device_tabs' => [],
'_admin_tasks' => {},
'_reports_menu' => {},
'_reports' => {},
'_report_order' => [qw/Device Port Node VLAN Network Wireless/],
);
# this is what Dancer::Template::TemplateToolkit does by default
config->{engines}->{template_toolkit}->{INCLUDE_PATH} ||= [ setting('views') ];
register 'register_template_path' => sub {
my ($self, $path) = plugin_args(@_);
if (!$path) {
return error "bad template path to register_template_paths";
}
unshift
@{ config->{engines}->{template_toolkit}->{INCLUDE_PATH} },
$path, dir($path, 'views')->stringify;
};
sub _register_include {
my ($type, $plugin) = @_;
if (!$type) {
return error "bad type to _register_include";
}
if (!$plugin) {
return error "bad plugin name to register_$type";
}
push @{ setting("_additional_$type") }, $plugin;
}
register 'register_css' => sub {
my ($self, $plugin) = plugin_args(@_);
_register_include('css', $plugin);
};
register 'register_javascript' => sub {
my ($self, $plugin) = plugin_args(@_);
_register_include('javascript', $plugin);
};
register 'register_device_port_column' => sub {
my ($self, $config) = plugin_args(@_);
$config->{default} ||= '';
$config->{position} ||= 'right';
if (!$config->{name} or !$config->{label}) {
return error "bad config to register_device_port_column";
}
foreach my $item (@{ setting('_extra_device_port_cols') }) {
if ($item->{name} eq $config->{name}) {
$item = $config;
return;
}
}
push @{ setting('_extra_device_port_cols') }, $config;
};
register 'register_device_details' => sub {
my ($self, $config) = plugin_args(@_);
if (!$config->{name} or !$config->{label}) {
return error "bad config to register_device_details";
}
foreach my $item (@{ setting('_extra_device_details') }) {
if ($item->{name} eq $config->{name}) {
$item = $config;
return;
}
}
push @{ setting('_extra_device_details') }, $config;
};
register 'register_navbar_item' => sub {
my ($self, $config) = plugin_args(@_);
if (!$config->{tag}
or !$config->{path}
or !$config->{label}) {
return error "bad config to register_navbar_item";
}
foreach my $item (@{ setting('_navbar_items') }) {
if ($item->{tag} eq $config->{tag}) {
$item = $config;
return;
}
}
push @{ setting('_navbar_items') }, $config;
};
register 'register_admin_task' => sub {
my ($self, $config) = plugin_args(@_);
if (!$config->{tag}
or !$config->{label}) {
return error "bad config to register_admin_task";
}
setting('_admin_tasks')->{ $config->{tag} } = $config;
};
sub _register_tab {
my ($nav, $config) = @_;
my $stash = setting("_${nav}_tabs");
if (!$config->{tag}
or !$config->{label}) {
return error "bad config to register_${nav}_item";
}
foreach my $item (@{ $stash }) {
if ($item->{tag} eq $config->{tag}) {
$item = $config;
return;
}
}
push @{ $stash }, $config;
}
register 'register_search_tab' => sub {
my ($self, $config) = plugin_args(@_);
_register_tab('search', $config);
};
register 'register_device_tab' => sub {
my ($self, $config) = plugin_args(@_);
_register_tab('device', $config);
};
register 'register_report' => sub {
my ($self, $config) = plugin_args(@_);
my @categories = @{ setting('_report_order') };
if (!$config->{category}
or !$config->{tag}
or !$config->{label}
or 0 == scalar grep {$config->{category} eq $_} @categories) {
return error "bad config to register_report";
}
foreach my $item (@{setting('_reports_menu')->{ $config->{category} }}) {
if ($item eq $config->{tag}) {
setting('_reports')->{$config->{tag}} = $config;
return;
}
}
push @{setting('_reports_menu')->{ $config->{category} }}, $config->{tag};
setting('_reports')->{$config->{tag}} = $config;
};
register_plugin;
true;
=head1 NAME
App::Netdisco::Web::Plugin - Netdisco Web UI components
=head1 Introduction
L<App::Netdisco>'s plugin system allows you more control of what Netdisco
components are displayed in the web interface. Plugins can be distributed
independently from Netdisco and are a better alternative to source code
patches.
The following web interface components are implemented as plugins:
=over 4
=item *
Navigation Bar items (e.g. Inventory link)
=item *
Tabs for Search and Device pages
=item *
Reports (pre-canned searches)
=item *
Additional Device Port Columns
=item *
Additional Device Details
=item *
Admin Menu function (job control, manual topology, pseudo devices)
=back
This document explains how to configure which plugins are loaded. See
L<App::Netdisco::Manual::WritingPlugins> if you want to develop new plugins.
=head1 Application Configuration
Netdisco configuration supports a C<web_plugins> directive along with the
similar C<extra_web_plugins>. These list, in YAML format, the set of Perl
module names which are the plugins to be loaded. Each item injects one part of
the Netdisco web user interface.
You can override these settings to add, change, or remove entries from the
default lists. Here is an example of the C<web_plugins> list:
web_plugins:
- Inventory
- Report::DuplexMismatch
- Search::Device
- Search::Node
- Search::Port
- Device::Details
- Device::Ports
Any change should go into your local C<deployment.yml> configuration file. If
you want to view the default settings, see the C<share/config.yml> file in the
C<App::Netdisco> distribution.
=head1 How to Configure
The C<extra_web_plugins> setting is empty, and used only if you want to add
new plugins but not change the set enabled by default. If you do want to add
to or remove from the default set, then create a version of C<web_plugins>
instead.
Netdisco prepends "C<App::Netdisco::Web::Plugin::>" to any entry in the list.
For example, "C<Inventory>" will load the
C<App::Netdisco::Web::Plugin::Inventory> module.
Such plugin modules can either ship with the App::Netdisco distribution
itself, or be installed separately. Perl uses the standard C<@INC> path
searching mechanism to load the plugin modules.
If an entry in the list starts with a "C<+>" (plus) sign then Netdisco attemps
to load the module as-is, without prepending anything to the name. This allows
you to have App::Netdiso web UI plugins in other namespaces:
web_plugins:
- Inventory
- Search::Device
- Device::Details
- +My::Other::Netdisco::Web::Component
The order of the entries is significant. Unsurprisingly, the modules are
loaded in order. Therefore Navigation Bar items appear in the order listed,
and Tabs appear on the Search and Device pages in the order listed, and so on.
Finally, you can also prepend module names with "C<X::>", to support the
"Netdisco extension" namespace. For example, "C<X::Observium>" will load the
L<App::NetdiscoX::Web::Plugin::Observium> module.
=cut

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks