Skip to content

Commit

Permalink
feat: Add navigation between agent home and ToolBox plugin
Browse files Browse the repository at this point in the history
Closes #255
  • Loading branch information
g-bougard committed Nov 14, 2023
1 parent 754359f commit 1ec8997
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ toolbox:
* fix #254: Add credential to iprange not working after adding first one
* Use tabler-icons v 2.24.0
* Store discovered snmp credentials and ip_range in dedicated storage in place of netdisco XML
* fix #255: Add ToolBox url on agent index page and support enabling agent home
link in navigation bar

packaging:
* Update MacOSX packages to use OpenSSL 3.1.4 & zlib 1.3
Expand Down
23 changes: 22 additions & 1 deletion lib/GLPI/Agent/HTTP/Server/ToolBox.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use parent "GLPI::Agent::HTTP::Server::Plugin";
use English qw(-no_match_vars);
use UNIVERSAL::require;
use Text::Template;
use URI;
use URI::Escape;
use HTML::Entities;
use Encode qw(decode encode);
Expand Down Expand Up @@ -297,6 +298,16 @@ sub yaml_config_specs {
icon => "clipboard-text",
index => 100, # index in navbar
},
agent_home_navbar => {
category => "Navigation bar",
type => $self->isyes($yaml_config->{updating_support}) ? "bool" : "readonly",
value => $self->yesno($yaml_config->{agent_home_navbar}),
text => "Show agent home navigation",
navbar => "Agent home",
link => "agent-home", # agent home link is set dynamically when this is set to agent-home
icon => "home",
index => 110, # index in navbar
},
default_page => {
category => "Navigation",
type => $self->isyes($yaml_config->{updating_support}) ? "option" : "readonly",
Expand Down Expand Up @@ -754,6 +765,16 @@ sub _index {
or next;
my $icon = delete $config_specs->{$key}->{icon};
next unless $self->isyes($config_specs->{$key}->{value});
# Update agent home navigation link if required
if ($link eq "agent-home") {
my ($scheme) = ref($request->uri()) =~ /^URI::(.+)$/;
if ($scheme && $scheme =~ /^http/) {
my $uri = URI->new($scheme.'://'.$request->header('host').'/');
$uri->port($self->{server}->{port})
if $self->{server}->{port} && $self->{server}->{port} != $self->port();
$link = $uri->canonical();
}
}
my $index = delete $config_specs->{$key}->{index} || 0;
push @{$navbar{$index}}, [ $navbar, $link, $icon ];
}
Expand Down Expand Up @@ -1087,7 +1108,7 @@ sub _fix_default_page_options {
foreach my $list (@{$config_specs}) {
foreach my $config (%{$list}) {
my $page = $list->{$config};
next unless $page->{navbar} && $page->{link} && defined($page->{index});
next unless $page->{navbar} && $page->{link} && defined($page->{index}) && $page->{link} ne 'agent-home';
next unless $self->isyes($page->{value});
$enabled{$config} = $page;
}
Expand Down
2 changes: 1 addition & 1 deletion share/html/toolbox/navbar.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
my ( $text, $link, $icon ) = @{$navbar};
$OUT .= "
<li".($request eq $link ? $li_style : "").
'><a href="'.$url_path."/".$link.
'><a href="'.($link =~ /^http/ ? $link : $url_path."/".$link).
'"'.($request eq $link ? $a_style : "").
" id='navbar-$link'><div class='nav'>".($icon ? "<i class='ti ti-$icon'></i>" : "")._($text)."</div></a></li>";
}
Expand Down

0 comments on commit 1ec8997

Please sign in to comment.