From d659ae10edbd0b74063206c96a08ba46efaa7f71 Mon Sep 17 00:00:00 2001 From: Gerhard Jungwirth Date: Fri, 29 Apr 2016 15:30:32 +0200 Subject: [PATCH] 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 --- debian/control | 1 - lib/NGCP/Panel/Controller/Root.pm | 13 ++++--- lib/NGCP/Panel/Widget.pm | 35 ------------------- .../Widget/Plugin/AdminTopMenuSettings.pm | 32 ----------------- .../Widget/Plugin/ResellerTopMenuSettings.pm | 32 ----------------- .../Plugin/SubscriberAdminTopMenuSettings.pm | 32 ----------------- .../Plugin/SubscriberTopMenuSettings.pm | 32 ----------------- 7 files changed, 8 insertions(+), 169 deletions(-) delete mode 100644 lib/NGCP/Panel/Widget.pm delete mode 100644 lib/NGCP/Panel/Widget/Plugin/AdminTopMenuSettings.pm delete mode 100644 lib/NGCP/Panel/Widget/Plugin/ResellerTopMenuSettings.pm delete mode 100644 lib/NGCP/Panel/Widget/Plugin/SubscriberAdminTopMenuSettings.pm delete mode 100644 lib/NGCP/Panel/Widget/Plugin/SubscriberTopMenuSettings.pm diff --git a/debian/control b/debian/control index ac856ffaa6..8c699ac8c7 100644 --- a/debian/control +++ b/debian/control @@ -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, diff --git a/lib/NGCP/Panel/Controller/Root.pm b/lib/NGCP/Panel/Controller/Root.pm index e786e46206..c900d9fd5e 100644 --- a/lib/NGCP/Panel/Controller/Root.pm +++ b/lib/NGCP/Panel/Controller/Root.pm @@ -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); diff --git a/lib/NGCP/Panel/Widget.pm b/lib/NGCP/Panel/Widget.pm deleted file mode 100644 index 038e2cb122..0000000000 --- a/lib/NGCP/Panel/Widget.pm +++ /dev/null @@ -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: diff --git a/lib/NGCP/Panel/Widget/Plugin/AdminTopMenuSettings.pm b/lib/NGCP/Panel/Widget/Plugin/AdminTopMenuSettings.pm deleted file mode 100644 index 975b0aacff..0000000000 --- a/lib/NGCP/Panel/Widget/Plugin/AdminTopMenuSettings.pm +++ /dev/null @@ -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: diff --git a/lib/NGCP/Panel/Widget/Plugin/ResellerTopMenuSettings.pm b/lib/NGCP/Panel/Widget/Plugin/ResellerTopMenuSettings.pm deleted file mode 100644 index b637f28365..0000000000 --- a/lib/NGCP/Panel/Widget/Plugin/ResellerTopMenuSettings.pm +++ /dev/null @@ -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: diff --git a/lib/NGCP/Panel/Widget/Plugin/SubscriberAdminTopMenuSettings.pm b/lib/NGCP/Panel/Widget/Plugin/SubscriberAdminTopMenuSettings.pm deleted file mode 100644 index f69f9a36d1..0000000000 --- a/lib/NGCP/Panel/Widget/Plugin/SubscriberAdminTopMenuSettings.pm +++ /dev/null @@ -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: diff --git a/lib/NGCP/Panel/Widget/Plugin/SubscriberTopMenuSettings.pm b/lib/NGCP/Panel/Widget/Plugin/SubscriberTopMenuSettings.pm deleted file mode 100644 index b74c5923d5..0000000000 --- a/lib/NGCP/Panel/Widget/Plugin/SubscriberTopMenuSettings.pm +++ /dev/null @@ -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: