MT#19439 topmenu widget refactoring

drop "inversion of control" loading them
this way we can remove MooseX::Object::Pluggable completely, which did
a filesystem search on _every_ panel page called.

Change-Id: If22dbb1a5a2ab24dee7af68a0085072ab1b2b855
changes/25/5925/2
Gerhard Jungwirth 9 years ago
parent cbad4ce55d
commit d659ae10ed

1
debian/control vendored

@ -66,7 +66,6 @@ Depends: gettext,
libmodule-runtime-perl,
libmoose-perl (>= 2.0~),
libmoosex-method-signatures-perl,
libmoosex-object-pluggable-perl,
libmoosex-singleton-perl,
libnamespace-sweep-perl,
libnet-http-perl,

@ -10,7 +10,6 @@ use NGCP::Panel::Utils::Statistics qw();
use DateTime qw();
use Time::HiRes qw();
use DateTime::Format::RFC3339 qw();
use NGCP::Panel::Widget;
#
# Sets the actions in this controller to be registered with no prefix
@ -183,11 +182,15 @@ sub auto :Private {
}
# load top menu widgets
my $plugin_finder = NGCP::Panel::Widget->new;
my $topmenu_templates = [];
foreach($plugin_finder->instantiate_plugins($c, 'topmenu_widgets')) {
$_->{instance}->handle($c);
push @{ $topmenu_templates }, $_->{instance}->template;
if ($c->user->roles eq 'admin') {
$topmenu_templates = ['widgets/admin_topmenu_settings.tt'];
} elsif ($c->user->roles eq 'reseller') {
$topmenu_templates = ['widgets/reseller_topmenu_settings.tt'];
} elsif ($c->user->roles eq 'subscriberadmin') {
$topmenu_templates = ['widgets/subscriberadmin_topmenu_settings.tt'];
} elsif ($c->user->roles eq 'subscriber') {
$topmenu_templates = ['widgets/subscriber_topmenu_settings.tt'];
}
$c->stash(topmenu => $topmenu_templates);

@ -1,35 +0,0 @@
package NGCP::Panel::Widget;
use Moose;
with 'MooseX::Object::Pluggable';
sub handle {
my ($self, $c) = @_;
return;
}
sub filter {
my ($self, $c) = @_;
return;
}
sub instantiate_plugins {
my ($self, $c, $type_filter) = @_;
my @plugins = map { s/^.*:://r; } $self->_plugin_locator->plugins;
my @instances = ();
foreach(@plugins) {
my $inst = NGCP::Panel::Widget->new;
$inst->load_plugin($_);
if($inst->filter($c, $type_filter)) {
push @instances, { instance => $inst, name => $_ };
}
}
my @sorted_instances = sort {$a->{instance}->priority <=> $b->{instance}->priority} @instances;
return @sorted_instances;
}
no Moose;
__PACKAGE__->meta->make_immutable;
1;
# vim: set tabstop=4 expandtab:

@ -1,32 +0,0 @@
package NGCP::Panel::Widget::Plugin::AdminTopMenuSettings;
use Moose::Role;
has 'template' => (
is => 'ro',
isa => 'Str',
default => 'widgets/admin_topmenu_settings.tt'
);
has 'type' => (
is => 'ro',
isa => 'Str',
default => 'topmenu_widgets',
);
around handle => sub {
my ($foo, $self, $c) = @_;
return;
};
sub filter {
my ($self, $c, $type) = @_;
return $self if(
$type eq $self->type &&
$c->user->roles eq 'admin'
);
return;
}
1;
# vim: set syntax=perl tabstop=4 expandtab:

@ -1,32 +0,0 @@
package NGCP::Panel::Widget::Plugin::ResellerTopMenuSettings;
use Moose::Role;
has 'template' => (
is => 'ro',
isa => 'Str',
default => 'widgets/reseller_topmenu_settings.tt'
);
has 'type' => (
is => 'ro',
isa => 'Str',
default => 'topmenu_widgets',
);
around handle => sub {
my ($foo, $self, $c) = @_;
return;
};
sub filter {
my ($self, $c, $type) = @_;
return $self if(
$type eq $self->type &&
$c->user->roles eq 'reseller'
);
return;
}
1;
# vim: set syntax=perl tabstop=4 expandtab:

@ -1,32 +0,0 @@
package NGCP::Panel::Widget::Plugin::SubscriberAdminTopMenuSettings;
use Moose::Role;
has 'template' => (
is => 'ro',
isa => 'Str',
default => 'widgets/subscriberadmin_topmenu_settings.tt'
);
has 'type' => (
is => 'ro',
isa => 'Str',
default => 'topmenu_widgets',
);
around handle => sub {
my ($foo, $self, $c) = @_;
return;
};
sub filter {
my ($self, $c, $type) = @_;
return $self if(
$type eq $self->type &&
$c->user->roles eq 'subscriberadmin'
);
return;
}
1;
# vim: set syntax=perl tabstop=4 expandtab:

@ -1,32 +0,0 @@
package NGCP::Panel::Widget::Plugin::SubscriberTopMenuSettings;
use Moose::Role;
has 'template' => (
is => 'ro',
isa => 'Str',
default => 'widgets/subscriber_topmenu_settings.tt'
);
has 'type' => (
is => 'ro',
isa => 'Str',
default => 'topmenu_widgets',
);
around handle => sub {
my ($foo, $self, $c) = @_;
return;
};
sub filter {
my ($self, $c, $type) = @_;
return $self if(
$type eq $self->type &&
$c->user->roles eq 'subscriber'
);
return;
}
1;
# vim: set syntax=perl tabstop=4 expandtab:
Loading…
Cancel
Save