[Rt-commit] rt branch, 4.6/priority-as-string, repushed
Michel Rodriguez
michel at bestpractical.com
Wed Oct 23 16:11:34 EDT 2019
The branch 4.6/priority-as-string was deleted and repushed:
was 53affddf2d0deb03628c60a7b85ce923ece4c499
now ee5ff87baf3d1646e09ffae63e77752dbdee2cf1
1: e4dcd082e < -: ------- reapply dropped changes of "Remove dashboard from menu if it can't be loaded"
2: 52a22b454 < -: ------- Core RT::Extension::PriorityAsString existing behavior of extension.
3: 4504c9ba4 < -: ------- Test that PriorityAsString hash is reset when set from siteconfig
4: 53affddf2 ! 1: 30ae67df3 Cores PriorityAsString
@@ -1,18 +1,6 @@
Author: michel <michel at bestpractical.com>
- cored priority as string
-
- adds final proposal for the feature:
-
- Unify and streamline PriorityAsString configuration
-
- As an extension, PriorityAsString grew additional configuration
- options as features were added. As a core feature, we want to
- add as few new configuration options as possible while still
- providing the needed features.
-
- The updated configuration provides options to handle global
- configuration, per queue settings, and sensible defaults.
+ Cores PriorityAsString
diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
--- a/etc/RT_Config.pm.in
@@ -107,7 +95,7 @@
+
=back
- =head2 Self Service Interface
+ =head2 Group Summary Configuration
diff --git a/etc/RT_SiteConfig.pm b/etc/RT_SiteConfig.pm
deleted file mode 100644
@@ -154,6 +142,21 @@
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@
+ }
+ },
+
++ EnablePriorityAsString => {
++ Widget => '/Widgets/Form/Boolean',
++ },
++ PriorityAsString => {
++ DependsOn => 'EnablePriorityAsString',
++ },
++
++
+ # User overridable locale options
+ DateTimeFormat => {
+ Section => 'Locale', #loc
+@@
return;
}
@@ -174,7 +177,7 @@
+Logs an error if a PriorityAsString is found but it is neither a hash nor an
+array, nor 0.
+
-+=cut
++=cut
+
+sub PriorityMap
+ { my $self = shift;
@@ -201,11 +204,11 @@
+ : 'cannot happen';
+
+ # what's in the map definition
-+ my $option_desc = ref $option ? "map is a " . ref( $option)
-+ : length $option < 20 ? $option
++ my $option_desc = ref $option ? "map is a " . ref( $option)
++ : length $option < 20 ? $option
+ : substr( $option, 0, 17) . '...';
+
-+ $RT::Logger->error("Wrong priority map for $real_queue: $option_desc");
++ $RT::Logger->error("Wrong priority map for $real_queue: $option_desc");
+ return undef;
+ }
+ return $map;
@@ -272,14 +275,6 @@
--- a/lib/RT/Queue.pm
+++ b/lib/RT/Queue.pm
@@
- $args{'TransactionType'} = ($args{'Value'} == 1) ? "Disabled" : "Enabled";
- delete $args{'Field'};
- }
-+
- my ( undef, undef, $TransObj ) = $self->_NewTransaction(
- Type => $args{'TransactionType'},
- Field => $args{'Field'},
-@@
},
);
@@ -315,8 +310,8 @@
+
+ my $New= $args{'Value'};
+ # *Priority fields may need to be translated
-+ if( $args{'Field'} =~ m{^(Initial|Final)?Priority$}) {
-+ $Old= $self->_PriorityAsString( $Old );
++ if( $args{'Field'} =~ m{^(Initial|Final)?Priority$}) {
++ $Old= $self->_PriorityAsString( $Old );
+ $New= $self->_PriorityAsString( $New );
+ }
+
@@ -329,42 +324,68 @@
TimeTaken => $args{'TimeTaken'},
);
@@
- # Returns String: Various Ticket Priorities as either a string or integer
- sub PriorityAsString {
- my $self = shift;
-- return $self->_PriorityAsString($self->Priority);
+ Returns the current value of InitialPriority.
+ (In the database, InitialPriority is stored as int(11).)
+
++=head2 InitialPriorityAsString
+
++Returns the current mapped string value of InitialPriority.
+
+ =head2 SetInitialPriority VALUE
+
+@@
+ Returns the current value of FinalPriority.
+ (In the database, FinalPriority is stored as int(11).)
+
++=head2 FinalPriorityAsString
+
++Returns the current mapped string value of FinalPriority.
+
+ =head2 SetFinalPriority VALUE
+
+@@
+ Returns the current value of Priority.
+ (In the database, Priority is stored as int(11).)
+
++=head2 PriorityAsString
+
++Returns the current mapped string value of Priority.
+
+ =head2 SetPriority VALUE
+
+@@
+ return %store;
+ }
+
++# Returns String: Various Ticket Priorities as either a string or integer
++sub PriorityAsString {
++ my $self = shift;
+ return $self->_PriorityAsString( $self->Priority );
- }
-
- sub InitialPriorityAsString {
-@@
- my $priority = shift;
- return undef unless defined $priority && length $priority;
-
-- my %map;
-- my $queues = RT->Config->Get('PriorityAsStringQueues');
-- if (@_) {
-- %map = %{ shift(@_) };
-- } elsif ($queues and $queues->{$self->QueueObj->Name}) {
-- %map = %{ $queues->{$self->QueueObj->Name} };
-- } else {
-- %map = RT->Config->Get('PriorityAsString');
++}
++
++sub InitialPriorityAsString {
++ my $self = shift;
++ return $self->_PriorityAsString( $self->InitialPriority );
++}
++
++sub FinalPriorityAsString {
++ my $self=shift;
++ return $self->_PriorityAsString( $self->FinalPriority );
++}
++
++sub _PriorityAsString {
++ my $self = shift;
++ my $priority = shift;
++ return undef unless defined $priority && length $priority;
++
+ my $map;
+ if( @_ ) {
+ $map = shift;
-+ } else {
++ } else {
+ my $queue_name = $self->QueueObj->Name;
+ $map = RT->Config->PriorityMap( $queue_name);
- }
-
-- # Count from high down to low until we find one that our number is
-- # greater than or equal to.
-- if ( values %map ) {
-- foreach my $label ( sort { $map{$b} <=> $map{$a} } keys %map ) {
-- return $label if $priority >= $map{ $label };
-- };
-- }
-- return "unknown";
++ }
++
+ return $priority if ! $map;
+
+ my @orderedLabels = sort { $map->{$b} <=> $map->{$a} } keys %$map;
@@ -377,8 +398,7 @@
+ # return the label associated with the lowest priority
+ return $orderedLabels[-1];
+
- }
-
++}
+
RT::Base->_ImportOverlays();
@@ -388,73 +408,138 @@
--- a/share/html/Admin/Queues/DefaultValues.html
+++ b/share/html/Admin/Queues/DefaultValues.html
@@
- <td><& /Elements/SelectPriority,
- Name => "InitialPriority",
- Default => $queue->DefaultValue('InitialPriority'),
-+ QueueObj => $queue,
- &></td></tr>
- <tr><td class="label"><&|/l&>Final Priority</&>:</td>
- <td><& /Elements/SelectPriority,
- Name => "FinalPriority",
- Default => $queue->DefaultValue('FinalPriority'),
-+ QueueObj => $queue,
- &><br /><span><em><&|/l&>requires running rt-crontool</&></em></span></td></tr>
- <& /Elements/EditCustomFields,
- Object => RT::Ticket->new($session{CurrentUser}),
+ <&|/l&>Priority</&>:
+ </div>
+ <div class="col-md-9 value">
+- <& /Elements/SelectPriority, Name => "InitialPriority", Default => $queue->DefaultValue('InitialPriority') &>
++ <& /Elements/SelectPriority,
++ Name => "InitialPriority",
++ Default => $queue->DefaultValue('InitialPriority'),
++ QueueObj => $queue
++ &>
+ </div>
+ </div>
+
+@@
+ <&|/l&>Final Priority</&>:
+ </div>
+ <div class="col-md-9 value">
+- <& /Elements/SelectPriority, Name => "FinalPriority", Default => $queue->DefaultValue('FinalPriority') &>
++ <& /Elements/SelectPriority,
++ Name => "FinalPriority",
++ Default => $queue->DefaultValue('FinalPriority'),
++ QueueObj => $queue
++ &>
+ <span><em><&|/l&>requires running rt-crontool</&></em></span>
+ </div>
+ </div>
+
+diff --git a/share/html/Elements/RT__Queue/ColumnMap b/share/html/Elements/RT__Queue/ColumnMap
+--- a/share/html/Elements/RT__Queue/ColumnMap
++++ b/share/html/Elements/RT__Queue/ColumnMap
+@@
+ },
+ Priority => {
+ title => 'Priority', # loc
+- value => sub { return join '-', $_[0]->DefaultValue('InitialPriority') || '', $_[0]->DefaultValue('FinalPriority') || '' },
++ value => sub { return join '/',
++ map { $_[0]->_PriorityAsString( $_[0]->DefaultValue($_) || 0) }
++ qw( InitialPriority FinalPriority);
++ },
+ },
+ DefaultDueIn => {
+ title => 'DefaultDueIn', # loc
diff --git a/share/html/Elements/RT__Ticket/ColumnMap b/share/html/Elements/RT__Ticket/ColumnMap
--- a/share/html/Elements/RT__Ticket/ColumnMap
+++ b/share/html/Elements/RT__Ticket/ColumnMap
@@
- return \( qq{<span class="ticket-info-$class-}. lc($escaped) .qq{">$loc_escaped</span>} );
- };
-
+ }
+ }
+
++my $printer = sub {
++ my ($class, $string) = @_;
++ return '' unless defined $string && length $string;
++
++ my $request_path = $HTML::Mason::Commands::r->path_info;
++ if ($request_path and $request_path =~ /Results\.tsv/) {
++ return loc($string);
++ }
++
++ my $escaped = $m->interp->apply_escapes($string, 'h');
++ my $loc_escaped = $m->interp->apply_escapes(loc($string), 'h');
++ return \( qq{<span class="ticket-info-$class-}. lc($escaped) .qq{">$loc_escaped</span>} );
++};
++
+my $queues = RT->Config->Get('PriorityAsString') || {};
+
- foreach my $field (qw(Priority InitialPriority FinalPriority)) {
- $COLUMN_MAP->{ $field .'Number' } ||= $COLUMN_MAP->{ $field };
-
-@@
-
- my $method = $field .'AsString';
-
-- my %queues = RT->Config->Get('PriorityAsStringQueues') || ();
-- if (not keys %queues) {
++foreach my $field (qw(Priority InitialPriority FinalPriority)) {
++ $COLUMN_MAP->{ $field .'Number' } ||= $COLUMN_MAP->{ $field };
++
++ my $class = lc($field);
++ $class =~ s/(?=<.)(?=priority)/-/;
++
++ my $method = $field .'AsString';
++
+ if (not keys %$queues) {
- $COLUMN_MAP->{ $field }{'value'} = sub {
- return $printer->( $class, $_[0]->$method() );
- };
- } else {
- $COLUMN_MAP->{ $field }{'value'} = sub {
-- return $queues{$_[0]->QueueObj->Name}
++ $COLUMN_MAP->{ $field }{'value'} = sub {
++ return $printer->( $class, $_[0]->$method() );
++ };
++ } else {
++ $COLUMN_MAP->{ $field }{'value'} = sub {
+ return $queues->{$_[0]->QueueObj->Name}
- ? $printer->( $class, $_[0]->$method() )
- : $_[0]->$field;
- };
++ ? $printer->( $class, $_[0]->$method() )
++ : $_[0]->$field;
++ };
++ }
++}
++
+ $m->callback( GenericMap => $GenericMap, COLUMN_MAP => $COLUMN_MAP, CallbackName => 'Once', CallbackOnce => 1 );
+ return GetColumnMapEntry( Map => $COLUMN_MAP, Name => $Name, Attribute => $Attr );
+ </%init>
diff --git a/share/html/Elements/SelectPriority b/share/html/Elements/SelectPriority
--- a/share/html/Elements/SelectPriority
+++ b/share/html/Elements/SelectPriority
@@
- my $default_label = '';
- my %map = ();
-
--if ($PriorityStringMap) {
-- %map = %{$PriorityStringMap};
--} elsif ($QueueObj and ! RT->Config->Get('NumericalPriority')) {
-- my %config = RT->Config->Get('PriorityAsStringQueues') ? RT->Config->Get('PriorityAsStringQueues') : ();
-- %map = %config && $config{$QueueObj->Name} ? %{$config{$QueueObj->Name}} : RT->Config->Get('PriorityAsString');
--}
--
--if (%map) {
-- if (RT->Config->Get('PriorityAsStringOrder')) {
-- @order = grep {exists $map{$_}} RT->Config->Get('PriorityAsStringOrder');
-- } else {
-- @order = sort { $map{$a} <=> $map{$b} } keys %map;
-- }
--
-- if ( defined $Default && length $Default ) {
-- $default_label = RT::Ticket->_PriorityAsString( $Default, \%map ) || '';
+ %# those contributions and any derivatives thereof.
+ %#
+ %# END BPS TAGGED BLOCK }}}
+-<input name="<% $Name %>" type="text" value="<% $Default %>" size="5" class="form-control" />
++% if (%map) {
++<select class="select-priority form-control" name="<% $Name %>">
++% unless ( defined $Default ) {
++<option value="">-</option>
++% }
++<%PERL>
++foreach my $label ( @order ) {
++ my ($value, $selected);
++ if ( $label eq $default_label ) {
++ ($value, $selected) = ($Default, 'selected="selected"');
++ } else {
++ ($value, $selected) = ($map{ $label }, '');
++ }
++</%PERL>
++<option class="<% lc $label %>" value="<% $value %>" <% $selected |n %>><% loc($label) %></option>
++% }
++</select>
++% } else {
++<input name="<% $Name %>" value="<% $Default %>" size="5" class="form-control" />
++% }
+ <%ARGS>
+ $Name => 'Priority'
+ $Default => ''
++$QueueObj => undef
++$PriorityStringMap => undef
+ </%ARGS>
+ <%INIT>
++
++my $priority_is_string = undef;
++my @order;
++my $default_label = '';
++my %map = ();
++
++
+if( $QueueObj ) {
+ if( my $map = RT->Config->PriorityMap( $QueueObj->Name ) ) {
+ %map = %$map;
@@ -462,9 +547,8 @@
+ if ( defined $Default && length $Default ) {
+ $default_label = RT::Ticket->_PriorityAsString( $Default, \%map ) || '';
+ }
- }
- }
-
++ }
++}
+
$Default = '' unless defined $Default;
</%INIT>
@@ -476,18 +560,81 @@
},
);
--my %priority_strings = RT->Config->Get('PriorityAsStringQueues') || ();
--if ( !RT->Config->Get('NumericalPriority') ) {
+
+if ( RT->Config->Get('EnablePriorityAsString') ) {
- my ($priority_dropdown) = grep {$_->{Name} eq "Priority"} @lines;
- my %priority_map = ( '-' => '' );
- for my $queue (keys %queues) {
-- for my $priority (keys %{$priority_strings{$queue}}) {
-- $priority_map{ keys %queues > 1 ? "$queue: $priority" : "$priority" } = $priority_strings{$queue}{$priority};
-+ my $queue_priority_map= RT::Config->PriorityMap( $queue);
++ my ($priority_dropdown) = grep {$_->{Name} eq "Priority"} @lines;
++ my %priority_map = ( '-' => '' );
++ for my $queue (keys %queues) {
++ my $queue_priority_map= RT::Config->PriorityMap( $queue );
+ for my $priority ( keys %$queue_priority_map ) {
+ $priority_map{ keys %queues > 1 ? "$queue: $priority" : "$priority" } = $queue_priority_map->{$priority};
- }
- }
- $priority_dropdown->{Value}{Arguments}{PriorityStringMap} = \%priority_map;
++ }
++ }
++ $priority_dropdown->{Value}{Arguments}{PriorityStringMap} = \%priority_map;
++}
++
+ $m->callback( Conditions => \@lines );
+
+ </%INIT>
+
+diff --git a/share/html/Ticket/Create.html b/share/html/Ticket/Create.html
+--- a/share/html/Ticket/Create.html
++++ b/share/html/Ticket/Create.html
+@@
+ <div class="form-row">
+ <div class="label col-md-3"><&|/l&>Priority</&>:</div>
+ <div class="value col-md-9"><& /Elements/SelectPriority,
+- Name => "InitialPriority",
++ Name => "InitialPriority",
++ QueueObj => $QueueObj,
+ Default => $ARGS{InitialPriority} ? $ARGS{InitialPriority} : $QueueObj->DefaultValue('InitialPriority'),
+ &></div>
+ </div>
+@@
+ <div class="label col-md-3"><&|/l&>Final Priority</&>:</div>
+ <div class="value col-md-9"><& /Elements/SelectPriority,
+ Name => "FinalPriority",
++ QueueObj => $QueueObj,
+ Default => $ARGS{FinalPriority} ? $ARGS{FinalPriority} : $QueueObj->DefaultValue('FinalPriority'),
+ &></div>
+ </div>
+
+diff --git a/share/html/Ticket/Elements/EditBasics b/share/html/Ticket/Elements/EditBasics
+--- a/share/html/Ticket/Elements/EditBasics
++++ b/share/html/Ticket/Elements/EditBasics
+@@
+ comp => '/Elements/SelectPriority',
+ args => {
+ Name => $field,
++ QueueObj => $QueueObj,
+ Default => $defaults{$field} || $TicketObj->$field,
+ }
+ }
+
+diff --git a/share/html/Ticket/Elements/ShowPriority b/share/html/Ticket/Elements/ShowPriority
+--- a/share/html/Ticket/Elements/ShowPriority
++++ b/share/html/Ticket/Elements/ShowPriority
+@@
+ %# those contributions and any derivatives thereof.
+ %#
+ %# END BPS TAGGED BLOCK }}}
+-<% $Ticket->Priority %>/<% $Ticket->FinalPriority || ''%>
++<% $Ticket->PriorityAsString %>/<% $Ticket->FinalPriorityAsString || ''%>
+ <%ARGS>
+ $Ticket => undef
+ </%ARGS>
+
+diff --git a/t/web/mobile.t b/t/web/mobile.t
+--- a/t/web/mobile.t
++++ b/t/web/mobile.t
+@@
+ use warnings;
+ use RT::Test tests => 170;
+
++# we want to check the numerical priorities
++RT::Config->Set( EnablePriorityAsString => 0);
++
+ my ( $url, $m ) = RT::Test->started_ok;
+ my $root = RT::Test->load_or_create_user( Name => 'root' );
+
+
-: ------- > 2: ee5ff87ba Adds tests and removes a warning
More information about the rt-commit
mailing list