[Rt-commit] rt branch, 4.6/priority-as-string, created. rt-4.4.2-96-gb2f029ac4
Brian Duggan
brian at bestpractical.com
Fri Jun 15 19:05:22 EDT 2018
The branch, 4.6/priority-as-string has been created
at b2f029ac4c1cd33289f752882316c453214fc284 (commit)
- Log -----------------------------------------------------------------
commit b2f029ac4c1cd33289f752882316c453214fc284
Author: Brian C. Duggan <brian at bestpractical.com>
Date: Tue May 29 19:08:30 2018 -0400
Core RT::Extension::PriorityAsString
Port functionality of RT::Extension::PriorityAsString. Replicate
existing behavior of extension.
diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index fae0d46d4..0395da501 100644
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -1813,6 +1813,66 @@ to Articles when they are included in a message.
Set($LinkArticlesOnInclude, 1);
+=item C<%NumericalPriority>
+
+Disable string priorities
+
+ Set($NumericalPriority, 0);
+
+=cut
+
+Set($NumericalPriority, 0);
+
+=item C<%PriorityAsString>
+
+RT can assign a priority value to tickets. Priority is stored as an
+integer in the database, but RT supports mapping strings to numerical
+values. For example, the default mapping is:
+
+ Set(%PriorityAsString, (Low => 0, Medium => 50, High => 100));
+
+Redefine C<%PriorityAsString> in C<RT_SiteConfig.pm> to set site
+priority strings.
+
+=cut
+
+Set(%DefaultPriorityAsString, (Low => 0, Medium => 50, High => 100));
+
+=item C<%PriorityAsStringOrder>
+
+Administrators can alter the order of priority strings as they appear
+in selection drop-downs with C<@PriorityStringOrder>. Administrators
+can also use this setting to limit the available priority strings on
+ticket update pages. When this options is defined, scrips and other RT
+code will still have access to all of the priority strings defined in
+C<%PriorityAsString>. To set a priority string order:
+
+ Set(@PriorityAsStringOrder, qw(Low Medium High));
+
+=cut
+
+=item C<%PriorityAsStringQueues>
+
+RT supports different priority string mappings for individual queues
+with C<%PriorityAsStringQueues>. Use queue names as keys in this
+hash. Then define priority string-number hash maps for each queue's
+value. Tickets in queues that aren't defined in this hash will fall
+back to RT's numerical priorities.
+
+When C<%PriorityAsStringQueues> is set, RT ignores both
+C<%PriorityAsString> and C<@PriorityAsStringOrder>. Administrators do
+not need to define C<%PriorityAsStringQueues> or C<%PriorityAsString>
+when they set C<%PriorityAsStringQueues>.
+
+To set per-queue priority strings:
+
+ Set(%PriorityAsStringQueues,
+ General => { Low => 0, Medium => 50, High => 100 },
+ Binary => { Low => 0, High => 10 },
+ );
+
+=cut
+
=back
=head1 Assets
diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index e73273012..0b60bd64a 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -1199,6 +1199,37 @@ our %META;
ServiceAgreements => {
Type => 'HASH',
},
+
+ PriorityAsStringQueues => {
+ Type => 'HASH',
+ PostLoadCheck => sub {
+ my $self = shift;
+
+ my $numerical_priority = $self->Get('NumericalPriority');
+ my %default_config = $self->Get('DefaultPriorityAsString');
+ my %user_config = $self->Get('PriorityAsString');
+ my %config = $self->Get('PriorityAsStringQueues');
+
+ if ($numerical_priority) {
+ %default_config = undef;
+ } elsif (%user_config) {
+ %default_config = %user_config;
+ }
+
+ my $queues = RT::Queues->new(RT->SystemUser);
+ $queues->Limit(
+ FIELD => 'Name',
+ OPERATOR => '!=',
+ VALUE => '___Approvals',
+ );
+ my @queue_configs = keys %config;
+ while (my $queue = $queues->Next) {
+ $config{$queue->Name} = {%default_config} unless defined $config{$queue->Name};
+ }
+
+ $self->Set( 'PriorityAsStringQueues', %config );
+ },
+ },
);
my %OPTIONS = ();
my @LOADED_CONFIGS = ();
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index 08169fb9c..1302cf764 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -3316,7 +3316,9 @@ Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
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
@@ -3334,7 +3336,9 @@ Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
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
@@ -3352,7 +3356,9 @@ Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
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
@@ -3697,6 +3703,45 @@ sub Serialize {
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 $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;
+ 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');
+ }
+
+ # Count from high down to low until we find one that our number is
+ # greater than or equal to.
+ foreach my $label ( sort { $map{$b} <=> $map{$a} } keys %map ) {
+ return $label if $priority >= $map{ $label };
+ }
+ return "unknown";
+}
+
RT::Base->_ImportOverlays();
1;
diff --git a/share/html/Elements/RT__Ticket/ColumnMap b/share/html/Elements/RT__Ticket/ColumnMap
index 089ccea11..925139ddc 100644
--- a/share/html/Elements/RT__Ticket/ColumnMap
+++ b/share/html/Elements/RT__Ticket/ColumnMap
@@ -352,6 +352,43 @@ if(RT->Config->Get('DisplayTotalTimeWorked')) {
}
}
+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>} );
+
+};
+
+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';
+
+ my %queues = RT->Config->Get('PriorityAsStringQueues');
+ 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}
+ ? $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
index 078d85df7..c48b573ff 100644
--- a/share/html/Elements/SelectPriority
+++ b/share/html/Elements/SelectPriority
@@ -45,11 +45,58 @@
%# those contributions and any derivatives thereof.
%#
%# END BPS TAGGED BLOCK }}}
+% if (%map) {
+<select class="select-priority" 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" />
+% }
<%ARGS>
$Name => 'Priority'
-$Default => ''
+$Default => undef
+$QueueObj => undef
+$PriorityStringMap => undef
</%ARGS>
<%INIT>
+
+my $priority_is_string = undef;
+my @order;
+my $default_label = '';
+my %map = undef;
+
+use Data::Dumper;
+if ($PriorityStringMap) {
+ %map = %{$PriorityStringMap};
+} elsif ($QueueObj) {
+ my %config = RT->Config->Get('PriorityAsStringQueues');
+ %map = %{$config{$QueueObj->Name}};
+}
+
+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 ) || '';
+ }
+}
+
$Default = '' unless defined $Default;
</%INIT>
diff --git a/share/html/Search/Elements/PickBasics b/share/html/Search/Elements/PickBasics
index 3f2ed237a..a404073c9 100644
--- a/share/html/Search/Elements/PickBasics
+++ b/share/html/Search/Elements/PickBasics
@@ -223,6 +223,18 @@ my @lines = (
},
);
+my %priority_strings = RT->Config->Get('PriorityAsStringQueues');
+if ( !RT->Config->Get('NumericalPriority') ) {
+ 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};
+ }
+ }
+ $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
index 26dc216b0..9352eefc1 100644
--- a/share/html/Ticket/Create.html
+++ b/share/html/Ticket/Create.html
@@ -271,11 +271,13 @@
<td><& /Elements/SelectPriority,
Name => "InitialPriority",
Default => $ARGS{InitialPriority} ? $ARGS{InitialPriority} : $QueueObj->DefaultValue('InitialPriority'),
+ QueueObj => $QueueObj,
&></td></tr>
<tr><td class="label"><&|/l&>Final Priority</&>:</td>
<td><& /Elements/SelectPriority,
Name => "FinalPriority",
Default => $ARGS{FinalPriority} ? $ARGS{FinalPriority} : $QueueObj->DefaultValue('FinalPriority'),
+ QueueObj => $QueueObj,
&></td></tr>
<tr><td class="label"><&|/l&>Time Estimated</&>:</td>
<td>
diff --git a/share/html/Ticket/Elements/EditBasics b/share/html/Ticket/Elements/EditBasics
index c4505e770..042c28f1f 100644
--- a/share/html/Ticket/Elements/EditBasics
+++ b/share/html/Ticket/Elements/EditBasics
@@ -58,6 +58,16 @@ if ($TicketObj) {
$QueueObj ||= $TicketObj->QueueObj;
}
+#my %queue_priority_strings = RT->Config->Get('PriorityAsStringQueues');
+#
+## Leave it as-is if all queues use PriorityAsString; the overridden
+## /Elements/SelectPriority catches this case and always shows the
+## drop-down
+##return unless keys %as_string;
+#
+## Only applies if the ticket is in a PriorityAsString queue
+##return unless $TicketObj and $as_string{$TicketObj->QueueObj->Name};
+
unless ( @fields ) {
my $subject = $defaults{'Subject'} || $TicketObj->Subject;
@fields = (
@@ -128,6 +138,7 @@ unless ( @fields ) {
args => {
Name => $field,
Default => $defaults{$field} || $TicketObj->$field,
+ QueueObj => $QueueObj,
}
}
} ('Priority', 'Final Priority')
diff --git a/share/html/Ticket/Elements/ShowPriority b/share/html/Ticket/Elements/ShowPriority
index c465d4875..2d450ce8c 100644
--- a/share/html/Ticket/Elements/ShowPriority
+++ b/share/html/Ticket/Elements/ShowPriority
@@ -45,7 +45,22 @@
%# those contributions and any derivatives thereof.
%#
%# END BPS TAGGED BLOCK }}}
+% if ( !RT->Config->Get('NumericalPriority') ) {
+% my $current = $Ticket->PriorityAsString || '';
+% my $final = $Ticket->FinalPriorityAsString || '';
+<span class="ticket-info-priority-<% $CSSClass->(lc($current)) %>"><% loc($current) %></span>/\
+<span class="ticket-info-final-priority-<% $CSSClass->(lc($final)) %>"><% loc($final) %></span>
+% } else {
<% $Ticket->Priority %>/<% $Ticket->FinalPriority || ''%>
+% }
<%ARGS>
$Ticket => undef
</%ARGS>
+<%INIT>
+my $CSSClass = sub {
+ my $value = shift;
+ return '' unless defined $value;
+ $value =~ s/[^A-Za-z0-9_-]/_/g;
+ return $value;
+};
+</%INIT>
diff --git a/t/web/mobile.t b/t/web/mobile.t
index 3f32e49e6..831bf6652 100644
--- a/t/web/mobile.t
+++ b/t/web/mobile.t
@@ -82,7 +82,7 @@ $m->content_contains( 'ticket1', 'subject' );
$m->content_contains( 'open', 'status' );
$m->content_contains( 'cc at example.com', 'cc' );
$m->content_contains( 'admincc at example.com', 'admincc' );
-$m->content_contains( '13/93', 'priority' );
+$m->text_contains( 'Low/Medium', 'priority' );
$m->content_contains( '2 hour', 'time estimates' );
$m->content_contains( '30 min', 'time worked' );
$m->content_contains( '60 min', 'time left' );
-----------------------------------------------------------------------
More information about the rt-commit
mailing list