From c3ed47b5c78117e8d73bb21077a7601ceea2c72c Mon Sep 17 00:00:00 2001 From: Kirill Solomko Date: Tue, 5 Mar 2019 17:58:11 +0100 Subject: [PATCH] TT#51911 rework Header Manipulations to support datatables * header manipulations related endpoints are now rendered with the datatables and support pagination, and search Change-Id: I264d2c55ec97199714159bbc2d1d3181e23880fb --- lib/NGCP/Panel/Controller/Header.pm | 123 ++++++++++++++++------ share/templates/header/actions_edit.tt | 88 ---------------- share/templates/header/actions_list.tt | 120 +++++---------------- share/templates/header/conditions_list.tt | 100 ++++-------------- share/templates/header/rules_list.tt | 115 +++++--------------- 5 files changed, 164 insertions(+), 382 deletions(-) delete mode 100644 share/templates/header/actions_edit.tt diff --git a/lib/NGCP/Panel/Controller/Header.pm b/lib/NGCP/Panel/Controller/Header.pm index 615f757ba3..1432edd9d9 100644 --- a/lib/NGCP/Panel/Controller/Header.pm +++ b/lib/NGCP/Panel/Controller/Header.pm @@ -270,6 +270,16 @@ sub rules_list :Chained('set_base') :PathPart('rules') :CaptureArgs(0) { order_by => { -asc => 'priority' }, }); $c->stash(rules_rs => $rules_rs); + + $c->stash->{rule_dt_columns} = NGCP::Panel::Utils::Datatables::set_columns($c, [ + { name => 'priority', search => 0, title => $c->loc('Priority') }, + { name => 'id', search => 1, title => $c->loc('#') }, + { name => 'name', search => 1, title => $c->loc('Name') }, + { name => 'description', search => 1, title => $c->loc('Description') }, + { name => 'stopper', search => 1, title => $c->loc('Stopper') }, + { name => 'enabled', search => 1, title => $c->loc('Enabled') }, + ]); + $c->stash(rules_uri => $c->uri_for_action("/header/rules_root", [$c->req->captures->[0]])); $c->stash(template => 'header/rules_list.tt'); @@ -323,6 +333,13 @@ sub rules_root :Chained('rules_list') :PathPart('') :Args(0) { return; } +sub rules_ajax :Chained('rules_list') :PathPart('ajax') :Args(0) { + my ($self, $c) = @_; + my $rs = $c->stash->{rules_rs}; + NGCP::Panel::Utils::Datatables::process($c, $rs, $c->stash->{rule_dt_columns}); + $c->detach( $c->view("JSON") ); +} + sub rules_base :Chained('rules_list') :PathPart('') :CaptureArgs(1) { my ($self, $c, $rule_id) = @_; @@ -456,8 +473,21 @@ sub conditions_list :Chained('rules_base') :PathPart('conditions') :CaptureArgs( my ( $self, $c ) = @_; my $conditions_rs = $c->stash->{rule_result}->conditions; + $c->stash(conditions_rs => $conditions_rs); + $c->stash->{condition_dt_columns} = NGCP::Panel::Utils::Datatables::set_columns($c, [ + { name => 'id', search => 1, title => $c->loc('#') }, + { name => 'match_type', search => 1, title => $c->loc('Match') }, + { name => 'match_part', search => 1, title => $c->loc('Part') }, + { name => 'match_name', search => 1, title => $c->loc('Name') }, + { name => 'expression', search => 1, title => $c->loc('Expression') }, + { name => 'value_type', search => 1, title => $c->loc('Type') }, + { name => 'c_values', search => 0, title => $c->loc('Values') }, + { name => 'c_rwr_set', search => 0, title => $c->loc('Rewrite Rule Set') }, + { name => 'enabled', search => 1, title => $c->loc('Enabled') }, + ]); + $c->stash(conditions_uri => $c->uri_for_action("/header/conditions_root", $c->req->captures)); $c->stash(template => 'header/conditions_list.tt'); @@ -469,26 +499,36 @@ sub conditions_root :Chained('conditions_list') :PathPart('') :Args(0) { my $conditions_rs = $c->stash->{conditions_rs}; - my @conditions = (); + $c->stash(conditions => [ $conditions_rs->all ] ); - foreach my $condition ($conditions_rs->all) { - my $row = { $condition->get_inflated_columns }; - @{$row->{values}} = map { $_->value } $condition->values->all; - push @conditions, $row; - if ($row->{rwr_set_id}) { - my $rwr_set = { $condition->rwr_set->get_inflated_columns }; - $row->{rwr_set} = $rwr_set->{name}; - my $dp_id = $row->{rwr_dp_id} // 0; - ($row->{rwr_dp}) = - grep { $_ =~ /_dpid/ && $rwr_set->{$_} eq $dp_id } - keys %{$rwr_set}; - } - } - - $c->stash(conditions => \@conditions); return; } +sub conditions_ajax :Chained('conditions_list') :PathPart('rules_ajax') :Args(0) { + my ($self, $c) = @_; + my $rs = $c->stash->{conditions_rs}; + NGCP::Panel::Utils::Datatables::process($c, $rs, $c->stash->{condition_dt_columns}, sub { + my $item = shift; + my %cols = $item->get_inflated_columns; + my ($c_rwr_set, $c_rwr_dp) = ('',''); + if ($cols{rwr_set_id}) { + my %rwr_set = $item->rwr_set->get_inflated_columns; + $c_rwr_set = $rwr_set{name}; + my $dp_id = $cols{rwr_dp_id} // 0; + ($c_rwr_dp) = + grep { $_ =~ /_dpid/ && $rwr_set{$_} eq $dp_id } + keys %rwr_set; + $c_rwr_dp =~ s/_dpid$//; + } + return ( + expression => ($cols{expression_negation} ? ' ! ' : ' ') . $cols{expression}, + c_values => join("
", map { $_->value } $item->values->all) // '', + c_rwr_set => $c_rwr_set ? "$c_rwr_set ($c_rwr_dp)" : '', + ); + }); + $c->detach( $c->view("JSON") ); +} + sub conditions_base :Chained('conditions_list') :PathPart('') :CaptureArgs(1) { my ($self, $c, $condition_id) = @_; @@ -695,6 +735,18 @@ sub actions_list :Chained('rules_base') :PathPart('actions') :CaptureArgs(0) { }); $c->stash(actions_rs => $actions_rs); + $c->stash->{action_dt_columns} = NGCP::Panel::Utils::Datatables::set_columns($c, [ + { name => 'priority', search => 0, title => $c->loc('Priority') }, + { name => 'id', search => 1, title => $c->loc('#') }, + { name => 'header', search => 1, title => $c->loc('Header') }, + { name => 'header_part', search => 1, title => $c->loc('Part') }, + { name => 'action_type', search => 1, title => $c->loc('Type') }, + { name => 'value_part', search => 1, title => $c->loc('Value Part') }, + { name => 'value', search => 1, title => $c->loc('Value') }, + { name => 'c_rwr_set', search => 0, title => $c->loc('Rewrite Rule Set') }, + { name => 'enabled', search => 1, title => $c->loc('Enabled') }, + ]); + $c->stash(actions_uri => $c->uri_for_action("/header/actions_root", $c->req->captures)); $c->stash(template => 'header/actions_list.tt'); @@ -744,25 +796,34 @@ sub actions_root :Chained('actions_list') :PathPart('') :Args(0) { } } - my @actions = (); + $c->stash(actions => [ $actions_rs->all ]); - foreach my $action ($actions_rs->all) { - my $row = { $action->get_inflated_columns }; - push @actions, $row; - if ($row->{rwr_set_id}) { - my $rwr_set = { $action->rwr_set->get_inflated_columns }; - $row->{rwr_set} = $rwr_set->{name}; - my $dp_id = $row->{rwr_dp_id} // 0; - ($row->{rwr_dp}) = - grep { $_ =~ /_dpid/ && $rwr_set->{$_} eq $dp_id } - keys %{$rwr_set}; - } - } - - $c->stash(actions => \@actions); return; } +sub actions_ajax :Chained('actions_list') :PathPart('rules_ajax') :Args(0) { + my ($self, $c) = @_; + my $rs = $c->stash->{actions_rs}; + NGCP::Panel::Utils::Datatables::process($c, $rs, $c->stash->{action_dt_columns}, sub { + my $item = shift; + my %cols = $item->get_inflated_columns; + my ($c_rwr_set, $c_rwr_dp) = ('',''); + if ($cols{rwr_set_id}) { + my %rwr_set = $item->rwr_set->get_inflated_columns; + $c_rwr_set = $rwr_set{name}; + my $dp_id = $cols{rwr_dp_id} // 0; + ($c_rwr_dp) = + grep { $_ =~ /_dpid/ && $rwr_set{$_} eq $dp_id } + keys %rwr_set; + $c_rwr_dp =~ s/_dpid$//; + } + return ( + c_rwr_set => $c_rwr_set ? "$c_rwr_set ($c_rwr_dp)" : '', + ); + }); + $c->detach( $c->view("JSON") ); +} + sub actions_base :Chained('actions_list') :PathPart('') :CaptureArgs(1) { my ($self, $c, $action_id) = @_; diff --git a/share/templates/header/actions_edit.tt b/share/templates/header/actions_edit.tt deleted file mode 100644 index 4b8c7a0dd9..0000000000 --- a/share/templates/header/actions_edit.tt +++ /dev/null @@ -1,88 +0,0 @@ -[% site_config.title = c.loc('Header Rules for [_1]', set_result.name) -%] - -
- - [% c.loc('Back') %] - - [% back_created = 1 -%] - [% UNLESS c.user.read_only -%] - - [% c.loc('Create Header Rule') %] - - [% END -%] -
- -[% IF messages -%] -
- [% FOREACH m IN messages -%] -
[% m.text %]
- [% END -%] -
-[% END -%] - -
- - - - - - - - - - - [% FOR r IN rules %] - - - - - - - [% END %] - -
[% c.loc('Name') %][% c.loc('Description') %]
- - - - - - - [% r.name %][% r.description %] - [% UNLESS c.user.read_only -%] -
- [%- FILTER null; - backuritmp=c.req.uri; - backuritmp.query_param_delete('back'); - backuritmp.query_param_delete('move'); - backuritmp.query_param_delete('where'); - END; - %] - - [% c.loc('Edit') %] - - - [% c.loc('Conditions') %] - - - [% c.loc('Actions') %] - - - [% c.loc('Delete') %] - -
- [% END -%] -
- -[% IF edit_flag || create_flag -%] -[% - PROCESS "helpers/modal.tt"; - modal_header(m.name = c.loc('Header Rule'), - m.create_flag = create_flag); - form.render; - modal_footer(); - modal_script(m.close_target = rules_uri); --%] -[% END -%] - - -[% # vim: set tabstop=4 syntax=html expandtab: -%] diff --git a/share/templates/header/actions_list.tt b/share/templates/header/actions_list.tt index 1c16d42a8d..7b25fcdd34 100644 --- a/share/templates/header/actions_list.tt +++ b/share/templates/header/actions_list.tt @@ -1,104 +1,32 @@ [% site_config.title = c.loc('Header Rule Actions for [_1]', rule_result.name) -%] -
- - [% c.loc('Back') %] - - [% back_created = 1 -%] - [% UNLESS c.user.read_only -%] - - [% c.loc('Create Header Rule Action') %] - - [% END -%] - - [% c.loc('Conditions') %] - -
- -[% IF messages -%] -
- [% FOREACH m IN messages -%] -
[% m.text %]
- [% END -%] -
-[% END -%] +[% + helper.name = c.loc('Header Rule Actions'); + helper.identifier = 'header_rule_actions'; + helper.messages = messages; + helper.dt_columns = action_dt_columns; + helper.length_change = 1; -
- - - - - - - - - - - - - - - - - [% FOR action IN actions %] - - - - - - - - - - - - - [% END %] - -
[% c.loc('Header') %][% c.loc('Part') %][% c.loc('Type') %][% c.loc('Value Part') %][% c.loc('Value') %][% c.loc('Rewrite Rule Set') %][% c.loc('Rewrite Rules') %][% c.loc('Enabled') %]
- [% IF action != actions.first %] - - - - [% END %] - [% IF action != actions.last %] - - - - [% END %] - [% action.header %][% action.header_part %][% action.action_type %][% action.value_part %][% action.value %][% action.rwr_set %][% action.rwr_dp %][% action.enabled %] - [% UNLESS c.user.read_only -%] -
- [%- FILTER null; - backuritmp=c.req.uri; - backuritmp.query_param_delete('back'); - backuritmp.query_param_delete('move'); - backuritmp.query_param_delete('where'); - END; - %] - - [% c.loc('Edit') %] - - - [% c.loc('Delete') %] - -
- [% END -%] -
+ helper.close_target = close_target; + helper.create_flag = create_flag; + helper.edit_flag = edit_flag; + helper.form_object = form; + helper.ajax_uri = c.uri_for_action( "/header/actions_ajax", [c.req.captures.0, c.req.captures.1] ); -[% IF edit_flag || create_flag -%] -[% - IF form.has_for_js; - form.render_repeatable_js; + UNLESS c.user.read_only; + helper.dt_buttons = [ + { uri = "/header/" _ set_result.id _ "/rules/" _ rule_result.id _ "/actions/?move='+full.id+'&where=up", class = 'btn-small btn-primary', icon = 'icon-arrow-up' }, + { uri = "/header/" _ set_result.id _ "/rules/" _ rule_result.id _ "/actions/?move='+full.id+'&where=down", class = 'btn-small btn-primary', icon = 'icon-arrow-down' }, + { name = c.loc('Edit'), uri = "/header/" _ set_result.id _ "/rules/" _ rule_result.id _ "/actions/'+full.id+'/edit", class = 'btn-small btn-primary', icon = 'icon-edit' }, + { name = c.loc('Delete'), uri = "/header/" _ set_result.id _ "/rules/" _ rule_result.id _ "/actions/'+full.id+'/delete", class = 'btn-small btn-secondary', icon = 'icon-trash' }, + ]; + helper.top_buttons = [ + { name = c.loc('Create Header Rule Action'), uri = c.uri_for_action('/header/actions_create', [c.req.captures.0, c.req.captures.1]), icon = 'icon-star' }, + { name = c.loc('Conditions'), uri = "/header/" _ set_result.id _ "/rules/" _ rule_result.id _ "/conditions", class = 'btn btn-teritary btn-large', icon = 'icon-play' }, + ]; END; - PROCESS "helpers/modal.tt"; - modal_header(m.name = c.loc('Header Rule Actions'), - m.create_flag = create_flag); - form.render; - modal_footer(); - modal_script(m.close_target = actions_uri); --%] -[% END -%] + PROCESS 'helpers/datatables.tt'; +-%] [% # vim: set tabstop=4 syntax=html expandtab: -%] diff --git a/share/templates/header/conditions_list.tt b/share/templates/header/conditions_list.tt index 3f369b79cb..6c654dcd71 100644 --- a/share/templates/header/conditions_list.tt +++ b/share/templates/header/conditions_list.tt @@ -1,86 +1,30 @@ [% site_config.title = c.loc('Header Rule Conditions for [_1]', rule_result.name) -%] -
- - [% c.loc('Back') %] - - [% back_created = 1 -%] - [% UNLESS c.user.read_only -%] - - [% c.loc('Create Header Rule Condition') %] - - [% END -%] - - [% c.loc('Actions') %] - -
- -[% IF messages -%] -
- [% FOREACH m IN messages -%] -
[% m.text %]
- [% END -%] -
-[% END -%] +[% + helper.name = c.loc('Header Rule Conditions'); + helper.identifier = 'header_rule_conditions'; + helper.messages = messages; + helper.dt_columns = condition_dt_columns; + helper.length_change = 1; -
- - - - - - - - - - - - - - - - - [% FOR condition IN conditions %] - - - - - - - - - - - - - [% END %] - -
[% c.loc('Match') %][% c.loc('Part') %][% c.loc('Name') %][% c.loc('Expression') %][% c.loc('Type') %][% c.loc('Values') %][% c.loc('Rewrite Rule Set') %][% c.loc('Rewrite Rules') %][% c.loc('Enabled') %]
[% condition.match_type %][% condition.match_part %][% condition.match_name %][% IF condition.expression_negation %] ! [% END %][% condition.expression %][% condition.value_type %][% condition.values.join('
') %]
[% condition.rwr_set %][% condition.rwr_dp %][% condition.enabled %] - [% UNLESS c.user.read_only -%] - - [% END -%] -
+ helper.close_target = close_target; + helper.create_flag = create_flag; + helper.edit_flag = edit_flag; + helper.form_object = form; + helper.ajax_uri = c.uri_for_action( "/header/conditions_ajax", [c.req.captures.0, c.req.captures.1] ); -[% IF edit_flag || create_flag -%] -[% - IF form.has_for_js; - form.render_repeatable_js; + UNLESS c.user.read_only; + helper.dt_buttons = [ + { name = c.loc('Edit'), uri = "/header/" _ set_result.id _ "/rules/" _ rule_result.id _ "/conditions/'+full.id+'/edit", class = 'btn-small btn-primary', icon = 'icon-edit' }, + { name = c.loc('Delete'), uri = "/header/" _ set_result.id _ "/rules/" _ rule_result.id _ "/conditions/'+full.id+'/delete", class = 'btn-small btn-secondary', icon = 'icon-trash' }, + ]; + helper.top_buttons = [ + { name = c.loc('Create Header Rule Condition'), uri = c.uri_for_action('/header/conditions_create', [c.req.captures.0, c.req.captures.1]), icon = 'icon-star' }, + { name = c.loc('Actions'), uri = "/header/" _ set_result.id _ "/rules/" _ rule_result.id _ "/actions", class = 'btn btn-teritary btn-large', icon = 'icon-play' }, + ]; END; - PROCESS "helpers/modal.tt"; - modal_header(m.name = c.loc('Header Rule Conditions'), - m.create_flag = create_flag); - form.render; - modal_footer(); - modal_script(m.close_target = conditions_uri); --%] -[% END -%] + PROCESS 'helpers/datatables.tt'; +-%] [% # vim: set tabstop=4 syntax=html expandtab: -%] diff --git a/share/templates/header/rules_list.tt b/share/templates/header/rules_list.tt index 983c168860..4dec9d0ad1 100644 --- a/share/templates/header/rules_list.tt +++ b/share/templates/header/rules_list.tt @@ -1,98 +1,35 @@ [% site_config.title = c.loc('Header Rules for [_1]', set_result.name) -%] -
- - [% c.loc('Back') %] - - [% back_created = 1 -%] - [% UNLESS c.user.read_only -%] - - [% c.loc('Create Header Rule') %] - - [% END -%] -
+[% + helper.name = c.loc('Header Rules'); + helper.identifier = 'header_rules'; + helper.messages = messages; + helper.dt_columns = rule_dt_columns; + helper.length_change = 1; -[% IF messages -%] -
- [% FOREACH m IN messages -%] -
[% m.text %]
- [% END -%] -
-[% END -%] + helper.close_target = close_target; + helper.create_flag = create_flag; + helper.edit_flag = edit_flag; + helper.form_object = form; + helper.ajax_uri = c.uri_for_action( "/header/rules_ajax", [c.req.captures.0] ); -
- - - - - - - - - - - - - - [% FOR r IN rules %] - - - - - - - - - - [% END %] - -
[% c.loc('Name') %][% c.loc('Direction') %][% c.loc('Description') %][% c.loc('Stopper') %][% c.loc('Enabled') %]
- [% IF r != rules.first %] - - - - [% END %] - [% IF r != rules.last %] - - - - [% END %] - [% r.name %][% r.direction %][% r.description %][% r.stopper %][% r.enabled %] - [% UNLESS c.user.read_only -%] -
- [%- FILTER null; - backuritmp=c.req.uri; - backuritmp.query_param_delete('back'); - backuritmp.query_param_delete('move'); - backuritmp.query_param_delete('where'); - END; - %] - - [% c.loc('Edit') %] - - - [% c.loc('Conditions') %] - - - [% c.loc('Actions') %] - - - [% c.loc('Delete') %] - -
- [% END -%] -
+ UNLESS c.user.read_only; + helper.dt_buttons = [ + { uri = "/header/" _ set_result.id _ "/rules/?move='+full.id+'&where=up", class = 'btn-small btn-primary', icon = 'icon-arrow-up' }, + { uri = "/header/" _ set_result.id _ "/rules/?move='+full.id+'&where=down", class = 'btn-small btn-primary', icon = 'icon-arrow-down' }, + { name = c.loc('Edit'), uri = "/header/" _ set_result.id _ "/rules/'+full.id+'/edit", class = 'btn-small btn-primary', icon = 'icon-edit' }, + { name = c.loc('Conditions'), uri = "/header/"_ set_result.id _ "/rules/'+full.id+'/conditions", class = 'btn-small btn-tertiary', icon = 'icon-glass' }, + { name = c.loc('Actions'), uri = "/header/"_ set_result.id _ "/rules/'+full.id+'/actions", class = 'btn-small btn-tertiary', icon = 'icon-play' }, + { name = c.loc('Delete'), uri = "/header/" _ set_result.id _ "/rules/'+full.id+'/delete", class = 'btn-small btn-secondary', icon = 'icon-trash' }, + ]; + helper.top_buttons = [ + { name = c.loc('Create Header Rule'), uri = c.uri_for_action('/header/rules_create', [c.req.captures.0]), icon = 'icon-star' }, + ]; + END; -[% IF edit_flag || create_flag -%] -[% - PROCESS "helpers/modal.tt"; - modal_header(m.name = c.loc('Header Rule'), - m.create_flag = create_flag); - form.render; - modal_footer(); - modal_script(m.close_target = rules_uri); + PROCESS 'helpers/datatables.tt'; -%] -[% END -%] + [% # vim: set tabstop=4 syntax=html expandtab: -%]