Dynamically load top menu widgets.

agranig/1_0_subfix
Andreas Granig 12 years ago
parent 3c5acf467f
commit 6ede6b4e09

@ -1,5 +1,2 @@
- DataTable field doesn't preserve checked value correctly if other
fields don't validate (id gets set to 1 for all rows, and all boxes
are checked).
- Modal needs more flexible width. It breaks when making screen narrower - Modal needs more flexible width. It breaks when making screen narrower
than 816px, and if no DataTable field is there, it can be narrower also. than 816px, and if no DataTable field is there, it can be narrower also.

@ -24,9 +24,9 @@ sub list :Chained('/') :PathPart('contact') :CaptureArgs(0) {
my $contacts = [ my $contacts = [
{id => 1, firstname => 'Foo1', lastname => '1Bar', email => 'foo1@example.org' }, {id => 1, firstname => 'Foo1', lastname => '1Bar', email => 'foo1@example.org' },
{id => 1, firstname => 'Foo2', lastname => '2Bar', email => 'foo2@example.org' }, {id => 2, firstname => 'Foo2', lastname => '2Bar', email => 'foo2@example.org' },
{id => 1, firstname => 'Foo3', lastname => '3Bar', email => 'foo3@example.org' }, {id => 3, firstname => 'Foo3', lastname => '3Bar', email => 'foo3@example.org' },
{id => 1, firstname => 'Foo4', lastname => '4Bar', email => 'foo4@example.org' }, {id => 4, firstname => 'Foo4', lastname => '4Bar', email => 'foo4@example.org' },
]; ];
$c->stash(contacts => $contacts); $c->stash(contacts => $contacts);
$c->stash(template => 'contact/list.tt'); $c->stash(template => 'contact/list.tt');

@ -28,14 +28,15 @@ Dashboard index
sub index :Path :Args(0) { sub index :Path :Args(0) {
my ($self, $c) = @_; my ($self, $c) = @_;
my $plugin_finder = NGCP::Panel::Widget->new;
my $widget_templates = []; my $widget_templates = [];
my $finder = NGCP::Panel::Widget->new; foreach($plugin_finder->instantiate_plugins($c, 'dashboard_widgets')) {
foreach($finder->instantiate_plugins($c)) {
$_->handle($c); $_->handle($c);
push @{ $widget_templates }, $_->template; push @{ $widget_templates }, $_->template;
} }
$c->stash(widgets => $widget_templates); $c->stash(widgets => $widget_templates);
$c->stash(template => 'dashboard.tt'); $c->stash(template => 'dashboard.tt');
delete $c->session->{redirect_targets}; delete $c->session->{redirect_targets};
} }

@ -4,6 +4,8 @@ use namespace::autoclean;
BEGIN { extends 'Catalyst::Controller' } BEGIN { extends 'Catalyst::Controller' }
use NGCP::Panel::Widget;
# #
# Sets the actions in this controller to be registered with no prefix # Sets the actions in this controller to be registered with no prefix
# so they function identically to actions created in MyApp.pm # so they function identically to actions created in MyApp.pm
@ -64,6 +66,16 @@ sub auto :Private {
} }
$c->log->debug("*** Root::auto grant access for authenticated user"); $c->log->debug("*** Root::auto grant access for authenticated user");
# load top menu widgets
my $plugin_finder = NGCP::Panel::Widget->new;
my $topmenu_templates = [];
foreach($plugin_finder->instantiate_plugins($c, 'topmenu_widgets')) {
$_->handle($c);
push @{ $topmenu_templates }, $_->template;
}
$c->stash(topmenu => $topmenu_templates);
return 1; return 1;
} }

@ -15,14 +15,14 @@ sub filter {
} }
sub instantiate_plugins { sub instantiate_plugins {
my ($self, $c) = @_; my ($self, $c, $type_filter) = @_;
my @plugins = map { s/^.*:://; $_; } $self->_plugin_locator->plugins; my @plugins = map { s/^.*:://; $_; } $self->_plugin_locator->plugins;
my @instances = (); my @instances = ();
foreach(@plugins) { foreach(@plugins) {
my $inst = NGCP::Panel::Widget->new; my $inst = NGCP::Panel::Widget->new;
$inst->load_plugin($_); $inst->load_plugin($_);
if($inst->filter($c)) { if($inst->filter($c, $type_filter)) {
push @instances, $inst; push @instances, $inst;
} }
} }

@ -7,6 +7,12 @@ has 'template' => (
default => 'widgets/admin_billing_overview.tt' default => 'widgets/admin_billing_overview.tt'
); );
has 'type' => (
is => 'ro',
isa => 'Str',
default => 'dashboard_widgets',
);
around handle => sub { around handle => sub {
my ($foo, $self, $c) = @_; my ($foo, $self, $c) = @_;
@ -14,15 +20,16 @@ around handle => sub {
return; return;
}; };
around filter => sub { sub filter {
my ($foo, $self, $c) = @_; my ($self, $c, $type) = @_;
return $self if( return $self if(
$type eq $self->type &&
$c->check_user_roles(qw/administrator/) && $c->check_user_roles(qw/administrator/) &&
ref $c->controller eq 'NGCP::Panel::Controller::Dashboard' ref $c->controller eq 'NGCP::Panel::Controller::Dashboard'
); );
return; return;
}; }
1; 1;
# vim: set tabstop=4 expandtab: # vim: set tabstop=4 expandtab:

@ -7,6 +7,12 @@ has 'template' => (
default => 'widgets/admin_peering_overview.tt' default => 'widgets/admin_peering_overview.tt'
); );
has 'type' => (
is => 'ro',
isa => 'Str',
default => 'dashboard_widgets',
);
around handle => sub { around handle => sub {
my ($foo, $self, $c) = @_; my ($foo, $self, $c) = @_;
@ -14,15 +20,16 @@ around handle => sub {
return; return;
}; };
around filter => sub { sub filter {
my ($foo, $self, $c) = @_; my ($self, $c, $type) = @_;
return $self if( return $self if(
$type eq $self->type &&
$c->check_user_roles(qw/administrator/) && $c->check_user_roles(qw/administrator/) &&
ref $c->controller eq 'NGCP::Panel::Controller::Dashboard' ref $c->controller eq 'NGCP::Panel::Controller::Dashboard'
); );
return; return;
}; }
1; 1;
# vim: set tabstop=4 expandtab: # vim: set tabstop=4 expandtab:

@ -7,6 +7,12 @@ has 'template' => (
default => 'widgets/admin_reseller_overview.tt' default => 'widgets/admin_reseller_overview.tt'
); );
has 'type' => (
is => 'ro',
isa => 'Str',
default => 'dashboard_widgets',
);
around handle => sub { around handle => sub {
my ($foo, $self, $c) = @_; my ($foo, $self, $c) = @_;
@ -14,15 +20,16 @@ around handle => sub {
return; return;
}; };
around filter => sub { sub filter {
my ($foo, $self, $c) = @_; my ($self, $c, $type) = @_;
return $self if( return $self if(
$type eq $self->type &&
$c->check_user_roles(qw/administrator/) && $c->check_user_roles(qw/administrator/) &&
ref $c->controller eq 'NGCP::Panel::Controller::Dashboard' ref $c->controller eq 'NGCP::Panel::Controller::Dashboard'
); );
return; return;
}; }
1; 1;
# vim: set tabstop=4 expandtab: # vim: set tabstop=4 expandtab:

@ -7,6 +7,12 @@ has 'template' => (
default => 'widgets/admin_system_overview.tt' default => 'widgets/admin_system_overview.tt'
); );
has 'type' => (
is => 'ro',
isa => 'Str',
default => 'dashboard_widgets',
);
around handle => sub { around handle => sub {
my ($foo, $self, $c) = @_; my ($foo, $self, $c) = @_;
@ -14,15 +20,16 @@ around handle => sub {
return; return;
}; };
around filter => sub { sub filter {
my ($foo, $self, $c) = @_; my ($self, $c, $type) = @_;
return $self if( return $self if(
$type eq $self->type &&
$c->check_user_roles(qw/administrator/) && $c->check_user_roles(qw/administrator/) &&
ref $c->controller eq 'NGCP::Panel::Controller::Dashboard' ref $c->controller eq 'NGCP::Panel::Controller::Dashboard'
); );
return; return;
}; }
1; 1;
# vim: set tabstop=4 expandtab: # vim: set tabstop=4 expandtab:

@ -0,0 +1,32 @@
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->check_user_roles(qw/administrator/)
);
return;
}
1;
# vim: set syntax=perl tabstop=4 expandtab:

@ -7,6 +7,12 @@ has 'template' => (
default => 'widgets/reseller_domain_overview.tt' default => 'widgets/reseller_domain_overview.tt'
); );
has 'type' => (
is => 'ro',
isa => 'Str',
default => 'dashboard_widgets',
);
around handle => sub { around handle => sub {
my ($foo, $self, $c) = @_; my ($foo, $self, $c) = @_;
@ -14,15 +20,16 @@ around handle => sub {
return; return;
}; };
around filter => sub { sub filter {
my ($foo, $self, $c) = @_; my ($self, $c, $type) = @_;
return $self if( return $self if(
$type eq $self->type &&
$c->check_user_roles(qw/reseller/) && $c->check_user_roles(qw/reseller/) &&
ref $c->controller eq 'NGCP::Panel::Controller::Dashboard' ref $c->controller eq 'NGCP::Panel::Controller::Dashboard'
); );
return; return;
}; }
1; 1;
# vim: set tabstop=4 expandtab: # vim: set tabstop=4 expandtab:

@ -65,62 +65,14 @@
<ul id="main-nav" class="nav pull-right"> <ul id="main-nav" class="nav pull-right">
<li class="nav-icon"> <li class="nav-icon">
<a href="./index.html"> <a href="[% c.uri_for('/') %]">
<i class="icon-home"></i> <i class="icon-home"></i>
<span>Home</span> <span>Home</span>
</a> </a>
</li> </li>
[% FOREACH t IN topmenu -%]
<li class="dropdown"> [% INCLUDE $t -%]
<a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown"> [% END -%]
<i class="icon-th"></i>
<span>Components</span>
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><a href="./elements.html">Elements</a></li>
<li><a href="./validation.html">Validation</a></li>
<li><a href="./jqueryui.html">jQuery UI</a></li>
<li><a href="./charts.html">Charts</a></li>
<li><a href="./bonus.html">Bonus Elements</a></li>
<li class="dropdown-submenu">
<a tabindex="-1" href="#">Dropdown menu</a>
<ul class="dropdown-menu">
<li><a tabindex="-1" href="#">Second level link</a></li>
<li><a tabindex="-1" href="#">Second level link</a></li>
<li><a tabindex="-1" href="#">Second level link</a></li>
</ul>
</li>
</ul>
</li>
<li class="dropdown active">
<a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown">
<i class="icon-copy"></i>
<span>Sample Pages</span>
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><a href="./faq.html">FAQ</a></li>
<li><a href="./gallery.html">Image Gallery</a></li>
<li><a href="./pricing.html">Pricing Plans</a></li>
<li><a href="./reports.html">Reports</a></li>
<li><a href="./settings.html">Settings</a></li>
</ul>
</li>
<li class="dropdown">
<a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown">
<i class="icon-external-link"></i>
<span>Extras</span>
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><a href="./login.html">Login</a></li>
<li><a href="./signup.html">Signup</a></li>
<li><a href="./error.html">Error</a></li>
<li><a href="./skins.html">Skins</a></li>
<li><a href="./sticky.html">Sticky Footer</a></li>
</ul>
</li>
</ul> <!-- /.dropdown-menu --> </ul> <!-- /.dropdown-menu -->
</div> <!-- /.nav-collapse --> </div> <!-- /.nav-collapse -->
</div> <!-- /.container --> </div> <!-- /.container -->

@ -105,7 +105,7 @@ $.extend( $.fn.dataTableExt.oStdClasses, {
} ); } );
$(document).ready(function() { $(document).ready(function() {
$('#maintable') $('#[% helper.name.remove('[\s+\.]') %]_table')
.dataTable( { .dataTable( {
"sDom": "<'row'<'span6'r><'span6'f>>t<'row'<'span6'i><'span6'p>>", "sDom": "<'row'<'span6'r><'span6'f>>t<'row'<'span6'i><'span6'p>>",
"bProcessing": true, "bProcessing": true,
@ -166,7 +166,7 @@ $(document).ready(function() {
<div style="margin-top:10px;"></div> <div style="margin-top:10px;"></div>
<table class="table table-bordered table-striped table-highlight table-hover" id="maintable"> <table class="table table-bordered table-striped table-highlight table-hover" id="[% helper.name.remove('[\s+\.]') %]_table">
<thead> <thead>
<tr> <tr>
[% FOREACH t IN helper.column_titles -%] [% FOREACH t IN helper.column_titles -%]

@ -0,0 +1,23 @@
<li class="dropdown">
<a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown">
<i class="icon-th"></i>
<span>Settings</span>
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><a href="./elements.html">Foo</a></li>
<li><a href="./validation.html">Validation</a></li>
<li><a href="./jqueryui.html">jQuery UI</a></li>
<li><a href="./charts.html">Charts</a></li>
<li><a href="./bonus.html">Bonus Elements</a></li>
<li class="dropdown-submenu">
<a tabindex="-1" href="#">Dropdown menu</a>
<ul class="dropdown-menu">
<li><a tabindex="-1" href="#">Second level link</a></li>
<li><a tabindex="-1" href="#">Second level link</a></li>
<li><a tabindex="-1" href="#">Second level link</a></li>
</ul>
</li>
</ul>
</li>
[% # vim: set tabstop=4 syntax=html expandtab: -%]
Loading…
Cancel
Save