[Rt-commit] rt branch, 5.0/priority-as-string, repushed
? sunnavy
sunnavy at bestpractical.com
Wed Mar 18 15:17:38 EDT 2020
The branch 5.0/priority-as-string was deleted and repushed:
was 0c2c37e9bfc29f619f53f7d73ff7c91d5b54fc07
now 8f4722c85ce6f347c1e81dcec03b17d365ab7840
1: 96bf477512 ! 1: 020ad76279 Core RT-Extension-PriorityAsString
@@ -246,7 +246,7 @@
+%# END BPS TAGGED BLOCK }}}
+<select class="select-priority selectpicker form-control" name="<% $Name %>">
+% unless ( defined $Default ) {
-+<option value="">-</option>
++ <option value="">-</option>
+% }
+<%PERL>
+foreach my $label ( @order ) {
@@ -257,7 +257,7 @@
+ ($value, $selected) = ($map{ $label }, '');
+ }
+</%PERL>
-+<option class="<% lc $label %>" value="<% $value %>" <% $selected |n %>><% loc($label) %></option>
++ <option class="<% lc $label %>" value="<% $value %>" <% $selected |n %>><% loc($label) %></option>
+% }
+</select>
+<%ARGS>
2: cfa722a81a ! 2: 00e43354ee Add "priority-" prefix to css classes of priority strings
@@ -11,8 +11,8 @@
($value, $selected) = ($map{ $label }, '');
}
</%PERL>
--<option class="<% lc $label %>" value="<% $value %>" <% $selected |n %>><% loc($label) %></option>
-+<option class="priority-<% lc $label %>" value="<% $value %>" <% $selected |n %>><% loc($label) %></option>
+- <option class="<% lc $label %>" value="<% $value %>" <% $selected |n %>><% loc($label) %></option>
++ <option class="priority-<% lc $label %>" value="<% $value %>" <% $selected |n %>><% loc($label) %></option>
% }
</select>
<%ARGS>
3: 692297d580 = 3: d4833d2397 Drop @PriorityAsStringOrder and %PriorityAsStringQueues configs
4: 1db69b7f11 ! 4: 0cd0ff4787 Add $EnablePriorityAsString config to globally disable PriorityAsString
@@ -12,11 +12,15 @@
Set($HideOneTimeSuggestions, 0);
-+=item C<%EnablePriorityAsString>
++=item C<$EnablePriorityAsString>
+
-+Priorities are stored as numbers internally. This determines if we should
-+convert and render them as strings instead. Set this to C<0> to render them
-+as internal numbers.
++Priority is stored as a number internally. This determines whether
++Priority is displayed to users as a number or using configured
++labels like Low, Medium, High. See L<%PriorityAsString> for details
++on this configuration.
++
++The default is enabled, so strings are shown. Set to C<0> to display
++numbers, which was the previous default for RT.
+
+=cut
+
5: 9126a53bfa ! 5: 85a9cc398f Refactor %PriorityAsString format to be more flexible and powerful
@@ -9,27 +9,33 @@
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@
+
=item C<%PriorityAsString>
- Specify a mapping between priority strings and the internal numeric
+-Specify a mapping between priority strings and the internal numeric
-representation
-+representation. E.g.
++This setting allows you to define labels for priority values
++available on tickets. RT stores these values internally as a number,
++but this number will be hidden if C<$EnablePriorityAsString> is true.
++For the configuration, link the labels to numbers as shown below. If
++you have more or less priority settings, you can adjust the numbers,
++giving a unique number to each.
+
+ Set(%PriorityAsString,
+ Default => { Low => 0, Medium => 50, High => 100 },
-+ General => [ Medium => 50, Low => 0, High => 100 ],
++ General => [ Medium => 50, Low => 0, High => 80, 'On Fire' => 100],
+ Support => 0,
+ );
+
-+Key is queue name or "Default", which is the fallback for unspecified
-+queues. Values could be ArrayRef or HashRef or C<0>.
++The key is queue name or "Default", which is the fallback for unspecified
++queues. Values can be an ArrayRef, HashRef, or C<0>.
+
+=over
+
+=item ArrayRef
+
+This is the ordered String => Number map list. Pririty options will be
-+rendered in the same order.
++rendered in the order they are listed in the list.
+
+=item HashRef
+
@@ -38,7 +44,7 @@
+
+=item C<0>
+
-+This is to render priorities as numbers.
++Priority is rendered as a number.
+
+=back
@@ -66,7 +72,7 @@
+ return unless $self->Get('EnablePriorityAsString');
+ my $config = $self->Get('PriorityAsString');
+
-+ my %label_value_map;
++ my %map;
+
+ for my $name ( keys %$config ) {
+ if ( my $value = $config->{$name} ) {
@@ -84,22 +90,17 @@
+
+ while ( my $label = shift @list ) {
+ my $value = shift @list;
-+
-+ if ( defined $label_value_map{$label} ) {
-+ if ( $label_value_map{$label} != $value ) {
-+ RT->Logger->debug(
-+ "Priority $label is inconsistent: $label_value_map{$label} VS $value");
-+ }
-+ }
-+ else {
-+ $label_value_map{$label} = $value;
++ $map{$label} //= $value;
++
++ if ( $map{$label} != $value ) {
++ RT->Logger->debug("Priority $label is inconsistent: $map{$label} VS $value");
+ }
+ }
+
+ }
+ }
+
-+ unless ( keys %label_value_map ) {
++ unless ( keys %map ) {
+ RT->Logger->debug("No valid PriorityAsString options");
+ $self->Set( 'EnablePriorityAsString', 0 );
+ }
@@ -256,7 +257,6 @@
+ }
+ }
+
-+ $use_numeric = 1 unless @options;
+ return $m->comp( "/Elements/SelectPriorityAsString", %ARGS, Options => \@options ) unless $use_numeric;
}
@@ -266,7 +266,7 @@
--- a/share/html/Elements/SelectPriorityAsString
+++ b/share/html/Elements/SelectPriorityAsString
@@
- <option value="">-</option>
+ <option value="">-</option>
% }
<%PERL>
-foreach my $label ( @order ) {
@@ -281,7 +281,7 @@
- ($value, $selected) = ($map{ $label }, '');
}
</%PERL>
- <option class="priority-<% lc $label %>" value="<% $value %>" <% $selected |n %>><% loc($label) %></option>
+ <option class="priority-<% lc $label %>" value="<% $value %>" <% $selected |n %>><% loc($label) %></option>
@@
<%ARGS>
$Name => 'Priority'
--: ------- > 6: aea948b080 Display priority options per queue like status options in search builder
6: a8c2452c52 ! 7: 90add74160 Show string version of priorities to end users when possible
@@ -28,42 +28,9 @@
General => { Low => 0, Medium => 50, High => 100 },
Support => { Low => 20, Medium => 70, High => 200 },
- or
-
- General => { Low => 0, Medium => 50, High => 100 },
- Support => { VeryLow => 0, Medium => 50, VeryHigh => 100 },
-
- Since there is no one-to-one map of Number <=> String, to avoid
+ Since there is no one-to-one map of String => Number, to avoid
confusion, we have to show priorities as numbers(e.g. in search builder
when invovled queues conflict). I believe it's a rare case.
-
-diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
---- a/lib/RT/Config.pm
-+++ b/lib/RT/Config.pm
-@@
- my $config = $self->Get('PriorityAsString');
-
- my %label_value_map;
-+ my %value_label_map;
-
- for my $name ( keys %$config ) {
- if ( my $value = $config->{$name} ) {
-@@
- RT->Logger->debug(
- "Priority $label is inconsistent: $label_value_map{$label} VS $value");
- }
-+
-+ if ( $value_label_map{$value} ne $label ) {
-+ RT->Logger->debug(
-+ "Priority $value is inconsistent: $value_label_map{$value} VS $label");
-+ }
- }
- else {
- $label_value_map{$label} = $value;
-+ $value_label_map{$value} = $label;
- }
- }
-
diff --git a/lib/RT/Queue.pm b/lib/RT/Queue.pm
--- a/lib/RT/Queue.pm
@@ -246,53 +213,33 @@
<%INIT>
use List::MoreUtils 'uniq';
@@
+ }
}
- my @options;
-- my %map;
-+ my %label_value_map;
-+ my %value_label_map;
-
- # Items in @values are hashrefs/arrayrefs, we still can de-duplicate
- # using uniq because duplicated ones are totally identical.
-@@
- }
-
++ my %map;
+ my %options;
+
+ for my $name ( @names ) {
+@@
while ( my $label = shift @list ) {
-- my $option = { Label => $label, Value => shift @list };
-- if ( defined $map{$label} ) {
-- if ( $map{$label} != $option->{Value} ) {
-+ my $value = shift @list;
-+ my $option = { Label => $label, Value => $value };
-+
-+ if ( defined $label_value_map{$label} ) {
-+ if ( $label_value_map{$label} != $value ) {
- $use_numeric = 1;
- last;
- }
-+
-+ if ( $ValueAsString && $value_label_map{$value} ne $label ) {
-+ $ValueAsString = 0;
-+ }
- }
- else {
-- $map{$label} = $option->{Value};
-+ $label_value_map{$label} = $value;
-+ $value_label_map{$value} = $label;
- push @options, $option;
- }
+ my $option = { Label => $label, Value => shift @list };
+ push @{ $options{$name} }, $option;
++
++ $map{$label} //= $option->{Value};
++ if ( $ValueAsString && $map{$label} != $option->{Value} ) {
++ $ValueAsString = 0;
++ }
++ }
++ }
++
++ if ($ValueAsString) {
++ for my $name ( keys %options ) {
++ for my $option ( @{ $options{$name} } ) {
++ $option->{Value} = $option->{Label};
++ }
}
}
-+ if ($ValueAsString) {
-+ for my $option (@options) {
-+ $option->{Value} = $option->{Label};
-+ }
-+ }
-+
- $use_numeric = 1 unless @options;
- return $m->comp( "/Elements/SelectPriorityAsString", %ARGS, Options => \@options ) unless $use_numeric;
- }
diff --git a/share/html/Search/Bulk.html b/share/html/Search/Bulk.html
--- a/share/html/Search/Bulk.html
7: b9833fe125 = 8: c70858329c Update tests as PriorityAsString is enabled by default
8: a765790317 ! 9: 0bd0ec5336 Test the PriorityAsString feature
@@ -259,16 +259,21 @@
+$m->follow_link_ok( { text => 'Tickets' }, 'Ticket search builder' );
+$form = $m->form_name('BuildQuery');
+my $priority_input = $form->find_input('ValueOfPriority');
-+is( $priority_input->type, 'text', "ValueOfPriority input is a text" );
++is( $priority_input->type, 'option', 'ValueOfPriority input is a select' );
++is_deeply(
++ [ $priority_input->possible_values ],
++ [ '', 0, 50, 100, 50, 0, 20, 100, 200 ],
++ 'ValueOfPriority option values are numbers'
++);
+
+$m->submit_form_ok( { fields => { ValueOfQueue => 'General' }, button => 'AddClause' }, 'Limit queue' );
+$form = $m->form_name('BuildQuery');
+$priority_input = $form->find_input('ValueOfPriority');
-+is( $priority_input->type, 'option', "ValueOfPriority input is a select" );
++is( $priority_input->type, 'option', 'ValueOfPriority input is a select' );
+is_deeply(
+ [ $priority_input->possible_values ],
+ [ '', 'Medium', 'VeryLow', 'Low', 'High', 'VeryHigh' ],
-+ "ValueOfPriority options"
++ 'ValueOfTicketPriority option values are strings'
+);
+
+$m->submit_form_ok( { fields => { PriorityOp => '=', ValueOfPriority => 'High' }, button => 'DoSearch' },
@@ -286,16 +291,20 @@
+$m->follow_link_ok( { text => 'Transactions' }, 'Transaction search builder' );
+$form = $m->form_name('BuildQuery');
+$priority_input = $form->find_input('ValueOfTicketPriority');
-+is( $priority_input->type, 'text', "ValueOfTicketPriority input is a text" );
++is_deeply(
++ [ $priority_input->possible_values ],
++ [ '', 0, 50, 100, 50, 0, 20, 100, 200 ],
++ 'ValueOfPriority option values are numbers'
++);
+
+$m->submit_form_ok( { fields => { ValueOfTicketQueue => 'General' }, button => 'AddClause' }, 'Limit queue' );
+$form = $m->form_name('BuildQuery');
+$priority_input = $form->find_input('ValueOfTicketPriority');
-+is( $priority_input->type, 'option', "ValueOfTicketPriority input is a select" );
++is( $priority_input->type, 'option', 'ValueOfTicketPriority input is a select' );
+is_deeply(
+ [ $priority_input->possible_values ],
+ [ '', 'Medium', 'VeryLow', 'Low', 'High', 'VeryHigh' ],
-+ "ValueOfTicketPriority options"
++ 'ValueOfTicketPriority option values are strings'
+);
+
+$m->submit_form_ok( { fields => { TicketPriorityOp => '=', ValueOfTicketPriority => 'High' }, button => 'DoSearch' },
9: 0c2c37e9bf < --: ------- Revise documentation
--: ------- > 10: 8f4722c85c Hide the confusing FinalPriority from end users
More information about the rt-commit
mailing list