TT#37205 bnumber cf in API: /api/callforwards

plus reorganize the Form to reduce code duplication

Change-Id: I361fccb7b717649ebd439992d79856c97413feeb
changes/20/22220/4
Gerhard Jungwirth 8 years ago
parent 5a504e97c1
commit a97cbbab0d

@ -411,7 +411,7 @@ sub get_field_poperties :Private{
$name = 'country';
} elsif($field->type =~ /LnpCarrier$/) {
$name = 'carrier_id';
} elsif($field->type !~ /Regex|EmailList|Identifier|PosInteger|Interval|Select|DateTime|URI|IPAddress|DatePicker|ProfileNetwork/) { # ...?
} elsif($field->type !~ /Regex|EmailList|Identifier|PosInteger|Interval|Select|DateTime|URI|IPAddress|DatePicker|ProfileNetwork|CFSimpleAPICompound/) { # ...?
$name .= '_id';
}
}

@ -0,0 +1,71 @@
package NGCP::Panel::Field::CFSimpleAPICompound;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler::Field::Compound';
has_field 'destinations' => (
type => 'Repeatable',
do_wrapper => 1,
do_label => 0,
);
has_field 'destinations.destination' => (
type => 'Text',
);
has_field 'destinations.timeout' => (
type => 'PosInteger',
);
has_field 'destinations.announcement_id' => (
type => 'PosInteger',
);
has_field 'times' => (
type => 'Repeatable',
do_wrapper => 1,
do_label => 0,
);
has_field 'sources' => (
type => 'Repeatable',
do_wrapper => 1,
do_label => 0,
);
has_field 'sources.source' => (
type => 'Text',
);
has_field 'sources_mode' => (
type => 'Select',
options => [
{ value => 'whitelist', label => 'Whitelist' },
{ value => 'blacklist', label => 'Blacklist' },
],
default => 'whitelist',
);
has_field 'bnumbers' => (
type => 'Repeatable',
do_wrapper => 1,
do_label => 0,
);
has_field 'bnumbers.bnumber' => (
type => 'Text',
);
has_field 'bnumbers_mode' => (
type => 'Select',
options => [
{ value => 'whitelist', label => 'Whitelist' },
{ value => 'blacklist', label => 'Blacklist' },
],
default => 'whitelist',
);
no Moose;
1;
# vim: set tabstop=4 expandtab:

@ -13,7 +13,7 @@ has_field 'id' => (
);
has_field 'cfu' => (
type => 'Compound',
type => '+NGCP::Panel::Field::CFSimpleAPICompound',
do_wrapper => 1,
do_label => 0,
required => 0,
@ -27,7 +27,7 @@ has_field 'cfu' => (
);
has_field 'cfb' => (
type => 'Compound',
type => '+NGCP::Panel::Field::CFSimpleAPICompound',
do_wrapper => 1,
do_label => 0,
required => 0,
@ -41,7 +41,7 @@ has_field 'cfb' => (
);
has_field 'cft' => (
type => 'Compound',
type => '+NGCP::Panel::Field::CFSimpleAPICompound',
do_wrapper => 1,
do_label => 0,
required => 0,
@ -56,7 +56,7 @@ has_field 'cft' => (
);
has_field 'cfna' => (
type => 'Compound',
type => '+NGCP::Panel::Field::CFSimpleAPICompound',
do_wrapper => 1,
do_label => 0,
required => 0,
@ -70,7 +70,7 @@ has_field 'cfna' => (
);
has_field 'cfs' => (
type => 'Compound',
type => '+NGCP::Panel::Field::CFSimpleAPICompound',
do_wrapper => 1,
do_label => 0,
required => 0,
@ -83,176 +83,6 @@ has_field 'cfs' => (
},
);
has_field 'cfu.destinations' => (
type => 'Repeatable',
do_wrapper => 1,
do_label => 0,
);
has_field 'cfu.destinations.destination' => (
type => 'Text',
);
has_field 'cfu.destinations.timeout' => (
type => 'PosInteger',
);
has_field 'cfu.destinations.announcement_id' => (
type => 'PosInteger',
);
has_field 'cfu.times' => (
type => 'Repeatable',
do_wrapper => 1,
do_label => 0,
);
has_field 'cfu.sources' => (
type => 'Repeatable',
do_wrapper => 1,
do_label => 0,
);
has_field 'cfu.sources.source' => (
type => 'Text',
);
has_field 'cfb.destinations' => (
type => 'Repeatable',
do_wrapper => 1,
do_label => 0,
);
has_field 'cfb.destinations.destination' => (
type => 'Text',
);
has_field 'cfb.destinations.timeout' => (
type => 'PosInteger',
);
has_field 'cfb.destinations.announcement_id' => (
type => 'PosInteger',
);
has_field 'cfb.times' => (
type => 'Repeatable',
do_wrapper => 1,
do_label => 0,
);
has_field 'cfb.sources' => (
type => 'Repeatable',
do_wrapper => 1,
do_label => 0,
);
has_field 'cfb.sources.source' => (
type => 'Text',
);
has_field 'cft.destinations' => (
type => 'Repeatable',
do_wrapper => 1,
do_label => 0,
);
has_field 'cft.destinations.destination' => (
type => 'Text',
);
has_field 'cft.destinations.timeout' => (
type => 'PosInteger',
);
has_field 'cft.times' => (
type => 'Repeatable',
do_wrapper => 1,
do_label => 0,
);
has_field 'cft.destinations.announcement_id' => (
type => 'PosInteger',
);
has_field 'cft.sources' => (
type => 'Repeatable',
do_wrapper => 1,
do_label => 0,
);
has_field 'cft.sources.source' => (
type => 'Text',
);
has_field 'cfna.destinations' => (
type => 'Repeatable',
do_wrapper => 1,
do_label => 0,
);
has_field 'cfna.destinations.destination' => (
type => 'Text',
);
has_field 'cfna.destinations.timeout' => (
type => 'PosInteger',
);
has_field 'cfna.destinations.announcement_id' => (
type => 'PosInteger',
);
has_field 'cfna.times' => (
type => 'Repeatable',
do_wrapper => 1,
do_label => 0,
);
has_field 'cfna.sources' => (
type => 'Repeatable',
do_wrapper => 1,
do_label => 0,
);
has_field 'cfna.sources.source' => (
type => 'Text',
);
has_field 'cfs.destinations' => (
type => 'Repeatable',
do_wrapper => 1,
do_label => 0,
);
has_field 'cfs.destinations.destination' => (
type => 'Text',
);
has_field 'cfs.destinations.timeout' => (
type => 'PosInteger',
);
has_field 'cfs.destinations.announcement_id' => (
type => 'PosInteger',
);
has_field 'cfs.times' => (
type => 'Repeatable',
do_wrapper => 1,
do_label => 0,
);
has_field 'cfs.sources' => (
type => 'Repeatable',
do_wrapper => 1,
do_label => 0,
);
has_field 'cfs.sources.source' => (
type => 'Text',
);
has_field 'cft.ringtimeout' => (
type => 'PosInteger',
do_wrapper => 1,

@ -181,7 +181,7 @@ sub update_item {
my $mapping_count = $mapping->count;
my $cf_preference = NGCP::Panel::Utils::Preferences::get_usr_preference_rs(
c => $c, prov_subscriber => $prov_subs, attribute => $type);
my ($dset, $tset, $sset);
my ($dset, $tset, $sset, $bset);
if ($mapping_count == 0) {
next unless (defined $resource->{$type});
$mapping = $c->model('DB')->resultset('voip_cf_mappings')->create({
@ -197,6 +197,7 @@ sub update_item {
$dset = $mapping->destination_set;
$tset = $mapping->time_set;
$sset = $mapping->source_set;
$bset = $mapping->bnumber_set;
}
try {
@ -258,6 +259,21 @@ sub update_item {
$mapping->update({source_set_id => $sset->id});
}
}
if ($bset) {
if ((defined $resource->{$type}{bnumbers}) && @{ $resource->{$type}{bnumbers}}) {
$bset->voip_cf_bnumbers->delete; #empty bset
} else {
$mapping_count && $mapping->update({bnumber_set_id => undef});
if ($bset->name =~ m/^quickset_/) {
$bset->delete; # delete bset
}
}
} else {
if ((defined $resource->{$type}{bnumbers}) && @{ $resource->{$type}{bnumbers}}) {
$bset = $mapping->create_related('bnumber_set', {'name' => "quickset_$type", subscriber_id => $prov_subscriber_id,} );
$mapping->update({bnumber_set_id => $bset->id});
}
}
for my $d (@{ $resource->{$type}{destinations} }) {
delete $d->{destination_set_id};
delete $d->{simple_destination};
@ -280,6 +296,18 @@ sub update_item {
delete $s->{source_set_id};
$sset->voip_cf_sources->update_or_create($s);
}
for my $b (@{ $resource->{$type}{bnumbers} }) {
delete $b->{bnumber_set_id};
$bset->voip_cf_bnumbers->update_or_create($b);
}
if (@{ $resource->{$type}{sources} } > 0 &&
$sset->mode ne $resource->{$type}{sources_mode}) {
$sset->update({mode => $resource->{$type}{sources_mode}});
}
if (@{ $resource->{$type}{bnumbers} } > 0 &&
$bset->mode ne $resource->{$type}{bnumbers_mode}) {
$bset->update({mode => $resource->{$type}{bnumbers_mode}});
}
$dset->discard_changes if $dset; # update destinations
my $new_autoattendant = NGCP::Panel::Utils::Subscriber::check_dset_autoattendant_status($dset);
@ -322,11 +350,13 @@ sub update_item {
sub _contents_from_cfm {
my ($self, $c, $cfm_item, $sub) = @_;
my (@times, @destinations, @sources);
my (@times, @destinations, @sources, @bnumbers);
my $timeset_item = $cfm_item->time_set;
my $dset_item = $cfm_item->destination_set;
my $sourceset_item = $cfm_item->source_set;
my $sourceset_mode = $sourceset_item ? $sourceset_item->mode : 'whitelist';
my $bnumberset_item = $cfm_item->bnumber_set;
my $bnumberset_mode = $bnumberset_item ? $bnumberset_item->mode : 'whitelist';
for my $time ($timeset_item ? $timeset_item->voip_cf_periods->all : () ) {
push @times, {$time->get_inflated_columns};
delete @{$times[-1]}{'time_set_id', 'id'};
@ -348,8 +378,13 @@ sub _contents_from_cfm {
push @sources, {$source->get_inflated_columns};
delete @{$sources[-1]}{'source_set_id', 'id'};
}
for my $bnumber ($bnumberset_item ? $bnumberset_item->voip_cf_bnumbers->all : () ) {
push @bnumbers, {$bnumber->get_inflated_columns};
delete @{$bnumbers[-1]}{'bnumber_set_id', 'id'};
}
return {times => \@times, destinations => \@destinations,
sources => \@sources, sources_mode => $sourceset_mode};
sources => \@sources, sources_mode => $sourceset_mode,
bnumbers => \@bnumbers, bnumbers_mode => $bnumberset_mode};
}
1;

Loading…
Cancel
Save