diff --git a/lib/NGCP/Panel/Controller/Billing.pm b/lib/NGCP/Panel/Controller/Billing.pm index ec4e2aa3b4..e8dc64d8ec 100644 --- a/lib/NGCP/Panel/Controller/Billing.pm +++ b/lib/NGCP/Panel/Controller/Billing.pm @@ -7,8 +7,11 @@ BEGIN { extends 'Catalyst::Controller'; } use NGCP::Panel::Form::BillingProfile; use NGCP::Panel::Form::BillingFee; use NGCP::Panel::Form::BillingZone; +use NGCP::Panel::Form::BillingPeaktimeWeekdays; use NGCP::Panel::Utils; +my @WEEKDAYS = qw(Monday Tuesday Wednesday Thursday Friday Saturday Sunday); + sub profile_list :Chained('/') :PathPart('billing') :CaptureArgs(0) :Args(0) { my ( $self, $c ) = @_; @@ -326,6 +329,60 @@ sub zones_delete :Chained('zones_base') :PathPart('delete') :Args(0) { $c->response->redirect($c->stash->{zones_root_uri}); } +sub peaktimes_list :Chained('base') :PathPart('peaktimes') :CaptureArgs(0) { + my ($self, $c) = @_; + + my @weekdays; + for(0 .. 6) { + $weekdays[$_] = { + name => $WEEKDAYS[$_], + ranges => [], + edit_link => $c->uri_for_action("/billing/peaktime_weekdays_edit", + [$c->req->captures->[0], $_]), + }; + } + + my $rs = $c->stash->{profile_result}->billing_peaktime_weekdays; + + foreach my $range ($rs->all) { + push @{ $weekdays[$range->weekday]->{ranges} }, { + start => $range->start, + end => $range->end, + id => $range->id, + } + } + + $c->stash(weekdays => \@weekdays); + $c->stash(template => 'billing/peaktimes.tt'); +} + +sub peaktimes :Chained('peaktimes_list') :PathPart('') :Args(0) { + my ($self, $c) = @_; +} + +sub peaktime_weekdays_base :Chained('peaktimes_list') :PathPart('weekday') :CaptureArgs(1) { + my ($self, $c, $weekday_id) = @_; + unless (defined $weekday_id && $weekday_id >= 0 && $weekday_id <= 6) { + $c->flash(messages => [{ + type => 'error', + text => 'This weekday does not exist.' + }]); + $c->response->redirect($c->uri_for_action( + "/billing/peaktimes", [$c->req->captures->[0]], + )); + } + $c->stash(weekday => $c->stash->{weekdays}->[$weekday_id]); +} + +sub peaktime_weekdays_edit :Chained('peaktime_weekdays_base') :PathPart('edit') :Args(0) { + my ($self, $c) = @_; + + my $form = NGCP::Panel::Form::BillingPeaktimeWeekdays->new; + + $c->stash(form => $form); + $c->stash(edit_flag => 1); +} + __PACKAGE__->meta->make_immutable; 1; diff --git a/lib/NGCP/Panel/Form/BillingPeaktimeWeekdays.pm b/lib/NGCP/Panel/Form/BillingPeaktimeWeekdays.pm new file mode 100644 index 0000000000..88f6df154b --- /dev/null +++ b/lib/NGCP/Panel/Form/BillingPeaktimeWeekdays.pm @@ -0,0 +1,57 @@ +package NGCP::Panel::Form::BillingPeaktimeWeekdays; + +use HTML::FormHandler::Moose; +use Moose; +extends 'HTML::FormHandler'; +use Moose::Util::TypeConstraints; + +has_field 'weekday' => ( + type => 'Hidden', +); + +has_field 'start' => ( + type => 'Text', + do_label => 0, + do_wrapper => 0, +); + +has_field 'end' => ( + type => 'Text', + do_label => 0, + do_wrapper => 0, +); + +has_field 'add' => ( + type => 'Submit', + value => 'Add', + element_class => [qw/btn btn-primary/], + do_label => 0, + do_wrapper => 0, +); + +1; + +__END__ + +=head1 NAME + +NGCP::Panel::Form::BillingPeaktimeWeekdays + +=head1 DESCRIPTION + +Preferences Form. + +=head1 METHODS + +=head1 AUTHOR + +Gerhard Jungwirth + +=head1 LICENSE + +This library is free software. You can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +# vim: set tabstop=4 expandtab: diff --git a/share/static/css/main.css b/share/static/css/main.css index b58cd85f25..0877c8240e 100644 --- a/share/static/css/main.css +++ b/share/static/css/main.css @@ -80,6 +80,7 @@ table.ngcp-datatable .headerSortUp:after { } .ngcp-actions-column { /* TODO: use responsive design */ + width: 10px; white-space: nowrap; } diff --git a/share/templates/billing/peaktimes.tt b/share/templates/billing/peaktimes.tt new file mode 100644 index 0000000000..0f51d92c51 --- /dev/null +++ b/share/templates/billing/peaktimes.tt @@ -0,0 +1,76 @@ +[% site_config.title = 'Off-peak-times for ' _ profile.name -%] + +< Back + +[% IF messages -%] +
| Weekday | +Start - End | +[% #Actions %] + |
|---|---|---|
| [% w.name %] | +
+ [% FOR r IN w.ranges %]
+ [% r.start %] – [% r.end %] + [% END %] + |
+
+ [% IF w.edit_link %]
+
+
+ Edit
+
+
+ [% END %]
+ |
+