MT#19439 dashboard always import modules

this is neccessary to support multiple threads
plus remove the "handle" indirection
plus remove Moo - OO has no advantage here

Change-Id: I1c0657fd454c5dc2001404920abfadd01aa0a953
changes/31/6131/3
Gerhard Jungwirth 9 years ago
parent 0e91b8fc60
commit 5ec78b34bb

@ -15,23 +15,19 @@ sub dashb_index :Path :Args(0) {
for my $widget_name (@{ $db_config->{$role} // [] }) {
# will be resorted to something proper later instead of eval
my $instance;
my $module = "NGCP::Panel::Widget::Dashboard::$widget_name";
eval {
my $module = "NGCP::Panel::Widget::Dashboard::$widget_name";
my $file = $module =~ s|::|/|gr;
require $file . '.pm';
$module->import();
$instance = $module->new;
if ($module->filter($c)) {
push @{ $widget_templates }, $module->template;
}
};
if ($@) {
$c->log->debug("error loading widget '$widget_name': " . $@);
}
if ($instance) {
next unless ($instance->filter($c));
$instance->handle($c);
push @{ $widget_templates }, $instance->template;
}
}
$c->stash(widgets => $widget_templates);
@ -42,13 +38,20 @@ sub dashb_index :Path :Args(0) {
sub ajax :Path('ajax') :Args(1) {
my ($self, $c, $exec) = @_;
my $widget = $c->request->param("widget");
my $widget_name = $c->request->param("widget");
my $value = undef;
$c->log->debug("calling $exec in $widget");
$c->log->debug("calling $exec in $widget_name");
my $module = "NGCP::Panel::Widget::Dashboard::$widget_name";
eval {
$value = "NGCP::Panel::Widget::Dashboard::$widget"->$exec($c);
my $file = $module =~ s|::|/|gr;
require $file . '.pm';
$module->import();
if ($module->filter($c)) {
$value = $module->$exec($c);
}
};
if ($@) {
$c->log->debug("error processing widget ajax request '$exec': " . $@);

@ -1,19 +1,13 @@
package NGCP::Panel::Widget::Dashboard::AdminBillingOverview;
use Moo;
use NGCP::Panel::Utils::DateTime;
has 'template' => (
is => 'ro',
default => 'widgets/admin_billing_overview.tt'
);
sub handle {
my ($self, $c) = @_;
use warnings;
use strict;
# add queries used in tt here ...
use NGCP::Panel::Utils::DateTime;
return;
};
sub template {
return 'widgets/admin_billing_overview.tt';
}
sub filter {
my ($self, $c) = @_;

@ -1,17 +1,10 @@
package NGCP::Panel::Widget::Dashboard::AdminPeeringOverview;
use Moo;
has 'template' => (
is => 'ro',
default => 'widgets/admin_peering_overview.tt'
);
use warnings;
use strict;
sub handle {
my ($self, $c) = @_;
# add queries used in tt here ...
return;
sub template {
return 'widgets/admin_peering_overview.tt';
}
sub filter {

@ -1,18 +1,11 @@
package NGCP::Panel::Widget::Dashboard::AdminResellerOverview;
use Moo;
has 'template' => (
is => 'ro',
default => 'widgets/admin_reseller_overview.tt'
);
use warnings;
use strict;
sub handle {
my ($self, $c) = @_;
# add queries used in tt here ...
return;
};
sub template {
return 'widgets/admin_reseller_overview.tt';
}
sub filter {
my ($self, $c) = @_;

@ -1,16 +1,10 @@
package NGCP::Panel::Widget::Dashboard::AdminSystemOverview;
use Moo;
has 'template' => (
is => 'ro',
default => 'widgets/admin_system_overview.tt'
);
use warnings;
use strict;
sub handle {
my ($self, $c) = @_;
$c->log->debug("AdminSystemOverview::handle");
return;
sub template {
return 'widgets/admin_system_overview.tt';
}
sub filter {

@ -1,18 +1,12 @@
package NGCP::Panel::Widget::Dashboard::ResellerBillingOverview;
use Moo;
use NGCP::Panel::Utils::DateTime;
has 'template' => (
is => 'ro',
default => 'widgets/reseller_billing_overview.tt',
);
sub handle {
my ($self, $c) = @_;
use warnings;
use strict;
# add queries used in tt here ...
use NGCP::Panel::Utils::DateTime;
return;
sub template {
return 'widgets/reseller_billing_overview.tt';
}
sub _get_interval {

@ -1,17 +1,10 @@
package NGCP::Panel::Widget::Dashboard::ResellerCustomerOverview;
use Moo;
has 'template' => (
is => 'ro',
default => 'widgets/reseller_customer_overview.tt'
);
use warnings;
use strict;
sub handle {
my ($self, $c) = @_;
# add queries used in tt here ...
return;
sub template {
return 'widgets/reseller_customer_overview.tt';
}
sub filter {

@ -1,17 +1,10 @@
package NGCP::Panel::Widget::Dashboard::ResellerDomainOverview;
use Moo;
has 'template' => (
is => 'ro',
default => 'widgets/reseller_domain_overview.tt'
);
use warnings;
use strict;
sub handle {
my ($self, $c) = @_;
# add queries used in tt here ...
return;
sub template {
return 'widgets/reseller_domain_overview.tt';
}
sub filter {

@ -1,24 +1,11 @@
package NGCP::Panel::Widget::Dashboard::SubscriberCFOverview;
use Moo;
has 'template' => (
is => 'ro',
default => 'widgets/subscriber_cf_overview.tt'
);
use warnings;
use strict;
sub handle {
my ($self, $c) = @_;
unless ($c->stash->{subscriber}) {
$c->stash(
subscriber => $c->model('DB')->resultset('voip_subscribers')->find({
uuid => $c->user->uuid,
}),
);
}
return;
};
sub template {
return 'widgets/subscriber_cf_overview.tt';
}
sub filter {
my ($self, $c) = @_;

@ -1,28 +1,15 @@
package NGCP::Panel::Widget::Dashboard::SubscriberCallsOverview;
use Moo;
use warnings;
use strict;
use NGCP::Panel::Utils::DateTime;
use DateTime::Format::Strptime;
use URI::Escape;
has 'template' => (
is => 'ro',
default => 'widgets/subscriber_calls_overview.tt'
);
sub handle {
my ($self, $c) = @_;
unless ($c->stash->{subscriber}) {
$c->stash(
subscriber => $c->model('DB')->resultset('voip_subscribers')->find({
uuid => $c->user->uuid,
}),
);
}
return;
};
sub template {
return 'widgets/subscriber_calls_overview.tt';
}
sub filter {
my ($self, $c) = @_;

@ -1,23 +1,10 @@
package NGCP::Panel::Widget::Dashboard::SubscriberRegisterOverview;
use Moo;
has 'template' => (
is => 'ro',
default => 'widgets/subscriber_reg_overview.tt'
);
use warnings;
use strict;
sub handle {
my ($self, $c) = @_;
unless ($c->stash->{subscriber}) {
$c->stash(
subscriber => $c->model('DB')->resultset('voip_subscribers')->find({
uuid => $c->user->uuid,
}),
);
}
return;
sub template {
return 'widgets/subscriber_reg_overview.tt';
}
sub filter {

@ -1,25 +1,12 @@
package NGCP::Panel::Widget::Dashboard::SubscriberVmOverview;
use Moo;
use DateTime::Format::Strptime;
has 'template' => (
is => 'ro',
default => 'widgets/subscriber_vm_overview.tt'
);
sub handle {
my ($self, $c) = @_;
use warnings;
use strict;
unless ($c->stash->{subscriber}) {
$c->stash(
subscriber => $c->model('DB')->resultset('voip_subscribers')->find({
uuid => $c->user->uuid,
}),
);
}
use DateTime::Format::Strptime;
return;
sub template {
return 'widgets/subscriber_vm_overview.tt';
}
sub filter {

@ -63,7 +63,7 @@ enqueLists.push([{
</ul>
</div>
<div class="plan-actions">
<a href="[% c.uri_for_action('/subscriber/calllist', [subscriber.id]) %]" class="btn">[% c.loc('View Call List') %]</a>
<a href="[% c.uri_for_action('/subscriber/calllist', [c.user.voip_subscriber.id]) %]" class="btn">[% c.loc('View Call List') %]</a>
</div>
</div>
</div>

@ -38,7 +38,7 @@ enqueLists.push([{
</ul>
</div>
<div class="plan-actions">
<a href="[% c.uri_for_action('/subscriber/preferences', [subscriber.id]) %]" class="btn">[% c.loc('Configure Preferences') %]</a>
<a href="[% c.uri_for_action('/subscriber/preferences', [c.user.voip_subscriber.id]) %]" class="btn">[% c.loc('Configure Preferences') %]</a>
</div>
</div>
</div>

@ -47,7 +47,7 @@ enqueLists.push([{
</ul>
</div>
<div class="plan-actions">
<a href="[% c.uri_for_action('/subscriber/reglist', [subscriber.id]) %]" class="btn">[% c.loc('View All Registered Devices') %]</a>
<a href="[% c.uri_for_action('/subscriber/reglist', [c.user.voip_subscriber.id]) %]" class="btn">[% c.loc('View All Registered Devices') %]</a>
</div>
</div>
</div>

@ -52,7 +52,7 @@ enqueLists.push([{
</ul>
</div>
<div class="plan-actions">
<a href="[% c.uri_for_action('/subscriber/voicemails', [subscriber.id]) %]" class="btn">[% c.loc('View Voicebox Messages') %]</a>
<a href="[% c.uri_for_action('/subscriber/voicemails', [c.user.voip_subscriber.id]) %]" class="btn">[% c.loc('View Voicebox Messages') %]</a>
</div>
</div>
</div>

Loading…
Cancel
Save