Implement naive plugin framework.

Will be refactored to use MooseX::Object::Pluggable.
agranig/1_0_subfix
Andreas Granig 12 years ago
parent 87bd6918a0
commit ee4de08f89

@ -45,11 +45,11 @@ __PACKAGE__->config(
INCLUDE_PATH => [
__PACKAGE__->path_to('share', 'templates'),
__PACKAGE__->path_to('share', 'layout'),
]
],
ABSOLUTE => 1,
},
'Plugin::Static::Simple' => {
logging => 1,
include_path => [
__PACKAGE__->path_to('share', 'static'),
],

@ -0,0 +1,55 @@
package NGCP::Panel::Controller::Dashboard;
use Moose;
use namespace::autoclean;
BEGIN { extends 'Catalyst::Controller'; }
use NGCP::Panel::Widget;
=head1 NAME
NGCP::Panel::Controller::Dashboard - Catalyst Controller
=head1 DESCRIPTION
Catalyst Controller.
=head1 METHODS
=cut
=head2 index
Dashboard index
=cut
sub index :Path :Args(0) {
my ( $self, $c ) = @_;
my $widgets = NGCP::Panel::Widget->widgets($c, '*Overview.pm');
foreach(@{ $widgets }) {
$_->handle($c);
}
my @widget_templates = map { $_->template } @{ $widgets };
$c->stash(widgets => \@widget_templates);
$c->stash(template => 'dashboard.tt');
}
=head1 AUTHOR
Andreas Granig,,,
=head1 LICENSE
This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
__PACKAGE__->meta->make_immutable;
1;
# vim: set tabstop=4 expandtab:

@ -29,20 +29,7 @@ The root page (/)
sub index :Path :Args(0) {
my ( $self, $c ) = @_;
# Hello World
$c->response->body( $c->welcome_message );
}
=head2 test
Some test method
=cut
sub test :Path('/test') {
my ( $self, $c ) = @_;
$c->stash(template => 'test.tt');
$c->response->redirect($c->uri_for('/dashboard'));
}
=head2 default

@ -0,0 +1,33 @@
package NGCP::Panel::Widget;
use Moose;
use File::Find::Rule;
sub widgets {
my ($self, $c, $filter) = @_;
my $path =
$c->config->{home} .
'/lib/' .
$self->meta->name =~ s/::/\//rg ;
my @widget_files = File::Find::Rule
->file()
->name($filter)
->relative()
->in($path);
my $widgets = [];
foreach(@widget_files) {
my $mpath = $path . '/' . $_;
my $mname = $self->meta->name . '::' . s/\.pm$//r;
require $mpath;
push @{ $widgets }, $mname->new;
}
return $widgets;
}
no Moose;
__PACKAGE__->meta->make_immutable;
1;
# vim: set tabstop=4 expandtab:

@ -0,0 +1,20 @@
package NGCP::Panel::Widget::BillingOverview;
use Moose;
extends 'NGCP::Panel::Widget';
has 'template' => (
is => 'ro',
default => sub { return 'widgets/billing_overview.tt'; }
);
sub handle {
my ($c) = @_;
return;
}
no Moose;
__PACKAGE__->meta->make_immutable;
1;
# vim: set tabstop=4 expandtab:

@ -0,0 +1,19 @@
package NGCP::Panel::Widget::PeeringOverview;
use Moose;
extends 'NGCP::Panel::Widget';
has 'template' => (
is => 'ro',
default => sub { return 'widgets/peering_overview.tt'; }
);
sub handle {
return;
}
no Moose;
__PACKAGE__->meta->make_immutable;
1;
# vim: set tabstop=4 expandtab:

@ -0,0 +1,21 @@
package NGCP::Panel::Widget::ResellerOverview;
use Moose;
extends 'NGCP::Panel::Widget';
has 'template' => (
is => 'ro',
default => sub { return 'widgets/reseller_overview.tt'; }
);
sub handle {
my ($c) = @_;
$c->stash->{resellers} = $c->model->{Provisioning}->resellers->find();
return;
}
no Moose;
__PACKAGE__->meta->make_immutable;
1;
# vim: set tabstop=4 expandtab:

@ -0,0 +1,19 @@
package NGCP::Panel::Widget::SystemOverview;
use Moose;
extends 'NGCP::Panel::Widget';
has 'template' => (
is => 'ro',
default => sub { return 'widgets/system_overview.tt'; }
);
sub handle {
return;
}
no Moose;
__PACKAGE__->meta->make_immutable;
1;
# vim: set tabstop=4 expandtab:

@ -134,7 +134,11 @@
</div>
</div>
</div>
[% content %]
<div id="content">
<div class="container">
[% content %]
</div>
</div>
</div> <!-- /#wrapper -->
<div id="footer">

@ -0,0 +1,13 @@
[% META title = 'Dashboard' -%]
[% wcount = widgets.size() > 4 ? 4 : widgets.size() -%]
<div class="row">
<div class="span12">
<div class="pricing-plans plans-[% wcount %]">
[% FOR w IN widgets -%]
[% INCLUDE $w -%]
[% END -%]
</div>
</div>
</div>
[% # vim: set tabstop=4 syntax=html expandtab: -%]

@ -1,2 +0,0 @@
[% META title = 'Resellers' %]
[% # vim: set tabstop=4 syntax=html expandtab: -%]

@ -0,0 +1,21 @@
<div class="plan-container">
<div class="plan">
<div class="plan-header">
<div class="plan-title">Billing</div>
<div class="plan-price">
<span>28</span>
<span class="term">Billing Profiles</span>
</div>
</div>
<div class="plan-features" style="min-height:135px;"><!-- 3 rows -->
<ul>
<li><strong>€2000</strong> Peering Costs</li>
<li><strong>€5000</strong> Reseller Revenue</li>
</ul>
</div>
<div class="plan-actions">
<a href="javascript:;" class="btn">Configure</a>
</div>
</div>
</div>
[% # vim: set tabstop=4 syntax=html expandtab: -%]

@ -0,0 +1,21 @@
<div class="plan-container">
<div class="plan">
<div class="plan-header">
<div class="plan-title">Peerings</div>
<div class="plan-price">
<span>7</span>
<span class="term">Peering Groups</span>
</div>
</div>
<div class="plan-features" style="min-height:135px;"><!-- 3 rows -->
<ul>
<li><strong>12</strong> Peering Servers</li>
<li><strong>24</strong> Peering Rules</li>
</ul>
</div>
<div class="plan-actions">
<a href="javascript:;" class="btn">Configure</a>
</div>
</div>
</div>
[% # vim: set tabstop=4 syntax=html expandtab: -%]

@ -0,0 +1,22 @@
<div class="plan-container">
<div class="plan">
<div class="plan-header">
<div class="plan-title">Resellers</div>
<div class="plan-price">
<span>[% resellers.size %]</span>
<span class="term">Resellers</span>
</div>
</div>
<div class="plan-features" style="min-height:135px;"><!-- 3 rows -->
<ul>
<li><strong>13</strong> Domains</li>
<li><strong>22745</strong> Accounts</li>
<li><strong>49355</strong> Subscribers</li>
</ul>
</div>
<div class="plan-actions">
<a href="javascript:;" class="btn">Configure</a>
</div>
</div>
</div>
[% # vim: set tabstop=4 syntax=html expandtab: -%]

@ -0,0 +1,22 @@
<div class="plan-container">
<div class="plan">
<div class="plan-header">
<div class="plan-title">System Status</div>
<div class="plan-price">
<span style="color:#0f0;">&#9702;</span>
<span class="term">All services running</span>
</div>
</div>
<div class="plan-features" style="min-height:135px;"><!-- 3 rows -->
<ul>
<li>Applications <strong>Ok</strong></li>
<li>System <strong>Ok</strong></li>
<li>Hardware <strong>Ok</strong></li>
</ul>
</div>
<div class="plan-actions">
<a href="javascript:;" class="btn">View Statistics</a>
</div>
</div>
</div>
[% # vim: set tabstop=4 syntax=html expandtab: -%]

@ -0,0 +1,10 @@
use strict;
use warnings;
use Test::More;
use Catalyst::Test 'NGCP::Panel';
use NGCP::Panel::Controller::Dashboard;
ok( request('/dashboard')->is_success, 'Request should succeed' );
done_testing();
Loading…
Cancel
Save