[Bps-public-commit] RT-Extension-PriorityAsString branch, master, updated. 0.04-4-g69c1881

Alex Vandiver alexmv at bestpractical.com
Tue Jul 24 19:58:27 EDT 2012


The branch, master has been updated
       via  69c1881b04ae6cbff2d470df0f80dcd53e4e3df9 (commit)
      from  58e0424048d996af6ccbd084b2468fadcb9e7bfe (commit)

Summary of changes:
 .../Elements/RT__Ticket/ColumnMap/Once               |  3 +--
 .../Search/Elements/PickBasics/Default               | 15 +++++++++++++--
 .../Ticket/Elements/EditBasics/MassageFields         | 10 ++++++----
 html/Elements/SelectPriority                         |  5 ++---
 html/Elements/SelectPriorityAsString                 |  5 +++--
 html/Ticket/Elements/ShowPriority                    |  3 +--
 lib/RT/Extension/PriorityAsString.pm                 | 20 +++++++++++++++++---
 7 files changed, 43 insertions(+), 18 deletions(-)

- Log -----------------------------------------------------------------
commit 69c1881b04ae6cbff2d470df0f80dcd53e4e3df9
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Tue Jul 24 16:56:43 2012 -0700

    Allow per-queue priority configuration

diff --git a/html/Callbacks/PriorityAsString/Elements/RT__Ticket/ColumnMap/Once b/html/Callbacks/PriorityAsString/Elements/RT__Ticket/ColumnMap/Once
index 9dbb645..ef82e29 100644
--- a/html/Callbacks/PriorityAsString/Elements/RT__Ticket/ColumnMap/Once
+++ b/html/Callbacks/PriorityAsString/Elements/RT__Ticket/ColumnMap/Once
@@ -19,8 +19,7 @@ foreach my $field (qw(Priority InitialPriority FinalPriority)) {
 
     my $method = $field .'AsString';
 
-    my %queues;
-    $queues{$_}++ for @{ RT->Config->Get('PriorityAsStringQueues') || [] };
+    my %queues = %{ RT->Config->Get('PriorityAsStringQueues') || {} };
     if (not keys %queues) {
         $COLUMN_MAP->{ $field }{'value'} = sub {
             return $printer->( $class, $_[0]->$method() );
diff --git a/html/Callbacks/PriorityAsString/Search/Elements/PickBasics/Default b/html/Callbacks/PriorityAsString/Search/Elements/PickBasics/Default
index 7d58601..acfa0c0 100644
--- a/html/Callbacks/PriorityAsString/Search/Elements/PickBasics/Default
+++ b/html/Callbacks/PriorityAsString/Search/Elements/PickBasics/Default
@@ -4,8 +4,7 @@ $Conditions => undef
 <%INIT>
 my %queues = %{ $m->caller_args(1)->{queues} || {} };
 
-my %as_string;
-$as_string{$_}++ for @{ RT->Config->Get('PriorityAsStringQueues') || [] };
+my %as_string = %{ RT->Config->Get('PriorityAsStringQueues') || {} };
 
 # Leave it as-is if all queues use PriorityAsString; the overridden
 # /Elements/SelectPriority catches this case and always shows the
@@ -20,7 +19,19 @@ return unless %queues;
 # PriorityAsString
 return unless scalar(keys %queues) == grep {$as_string{$_}} keys %queues;
 
+# Additionally, all queues in PriorityAsStringQueues must use the _same_
+# values for each name; if "High" is mapped to 10 in one queue and 100
+# in another, we can't use names
+my %values;
+for my $q (keys %queues) {
+    for my $priority (keys %{$as_string{$q}}) {
+        return if exists $values{$priority} and $as_string{$q}{$priority} != $values{$priority};
+        $values{$priority} = $as_string{$q}{$priority};
+    }
+}
+
 # Swap out the /Elements/SelectPriority for /Elements/SelectPriorityAsString
 my ($priority) = grep {$_->{Name} eq "Priority"} @{ $Conditions };
 $priority->{Value}{Path} = "/Elements/SelectPriorityAsString";
+$priority->{Value}{Arguments}{Mapping} = \%values;
 </%INIT>
diff --git a/html/Callbacks/PriorityAsString/Ticket/Elements/EditBasics/MassageFields b/html/Callbacks/PriorityAsString/Ticket/Elements/EditBasics/MassageFields
index ea006f2..ea6dc76 100644
--- a/html/Callbacks/PriorityAsString/Ticket/Elements/EditBasics/MassageFields
+++ b/html/Callbacks/PriorityAsString/Ticket/Elements/EditBasics/MassageFields
@@ -3,8 +3,7 @@ $TicketObj => undef
 $Fields => undef
 </%ARGS>
 <%INIT>
-my %as_string;
-$as_string{$_}++ for @{ RT->Config->Get('PriorityAsStringQueues') || [] };
+my %as_string = %{ RT->Config->Get('PriorityAsStringQueues') || {} };
 
 # Leave it as-is if all queues use PriorityAsString; the overridden
 # /Elements/SelectPriority catches this case and always shows the
@@ -15,6 +14,9 @@ return unless keys %as_string;
 return unless $TicketObj and $as_string{$TicketObj->QueueObj->Name};
 
 # Swap out the /Elements/SelectPriority for /Elements/SelectPriorityAsString
-$_->{comp} = "/Elements/SelectPriorityAsString"
-  for grep {$_->{comp}||'' eq "/Elements/SelectPriority"} @{ $Fields };
+for my $field (@{ $Fields }) {
+    next unless ($field->{comp}||'') eq "/Elements/SelectPriority";
+    $field->{comp} = "/Elements/SelectPriorityAsString";
+    $field->{args}{Mapping} = $as_string{$TicketObj->QueueObj->Name};
+}
 </%INIT>
diff --git a/html/Elements/SelectPriority b/html/Elements/SelectPriority
index fbcbe16..1d83cdc 100644
--- a/html/Elements/SelectPriority
+++ b/html/Elements/SelectPriority
@@ -5,8 +5,7 @@ $Default => undef
 </%ARGS>
 <%INIT>
 
-my %queues;
-$queues{$_}++ for @{ RT->Config->Get('PriorityAsStringQueues') || [] };
+my %queues = %{ RT->Config->Get('PriorityAsStringQueues') || {} };
 
 # If enabled for all queues, always show the drop-down
 return $m->comp("/Elements/SelectPriorityAsString",%ARGS)
@@ -23,7 +22,7 @@ if ( $caller eq "/Admin/Queues/Modify.html") {
 } elsif ( $caller eq "/Ticket/Create.html" or $caller eq "/m/ticket/create" ) {
     $QueueObj->Load( $caller_args->{Queue} );
 }
-return $m->comp("/Elements/SelectPriorityAsString",%ARGS)
+return $m->comp("/Elements/SelectPriorityAsString",%ARGS, Mapping => $queues{$QueueObj->Name})
     if $QueueObj->Id and $queues{$QueueObj->Name};
 
 
diff --git a/html/Elements/SelectPriorityAsString b/html/Elements/SelectPriorityAsString
index bebec4b..de95534 100644
--- a/html/Elements/SelectPriorityAsString
+++ b/html/Elements/SelectPriorityAsString
@@ -17,16 +17,17 @@ foreach my $label ( @order ) {
 <%ARGS>
 $Name => 'Priority'
 $Default => undef
+$Mapping => undef
 </%ARGS>
 <%INIT>
 
-my %map   = RT->Config->Get('PriorityAsString');
+my %map   = $Mapping ? %{ $Mapping } : RT->Config->Get('PriorityAsString');
 my @order = grep defined && length, RT->Config->Get('PriorityAsStringOrder');
 @order = sort { $map{$a} <=> $map{$b} } keys %map
     unless @order;
 
 my $default_label = '';
 if ( defined $Default && length $Default ) {
-    $default_label = RT::Ticket->_PriorityAsString( $Default ) || '';
+    $default_label = RT::Ticket->_PriorityAsString( $Default, \%map ) || '';
 }
 </%INIT>
diff --git a/html/Ticket/Elements/ShowPriority b/html/Ticket/Elements/ShowPriority
index f41be6a..345d4d2 100644
--- a/html/Ticket/Elements/ShowPriority
+++ b/html/Ticket/Elements/ShowPriority
@@ -8,8 +8,7 @@
 $Ticket => undef
 </%ARGS>
 <%INIT>
-my %queues;
-$queues{$_}++ for @{ RT->Config->Get('PriorityAsStringQueues') || [] };
+my %queues = %{ RT->Config->Get('PriorityAsStringQueues') || {} };
 
 my $current = $Ticket->PriorityAsString || '';
 my $final = $Ticket->FinalPriorityAsString || '';
diff --git a/lib/RT/Extension/PriorityAsString.pm b/lib/RT/Extension/PriorityAsString.pm
index 958e368..bc12cf0 100644
--- a/lib/RT/Extension/PriorityAsString.pm
+++ b/lib/RT/Extension/PriorityAsString.pm
@@ -24,8 +24,14 @@ RT::Extension::PriorityAsString - show priorities in RT as strings instead of nu
     # hash will be sorted and displayed
     Set(@PriorityAsStringOrder, qw(Low Medium High));
 
-    # Uncomment if you want to only apply to some queues
-    # Set(@PriorityAsStringQueues, qw( Default ));
+    # Uncomment if you want to apply different configurations to
+    # different queues.  Each key is the name of a different queue;
+    # queues which do not appear in this configuration will use RT's
+    # default numeric scale.
+    # Set(%PriorityAsStringQueues,
+    #    General => { Low => 0, Medium => 50, High => 100 },
+    #    Binary  => { Low => 0, High => 10 },
+    # );
 
 =head1 INSTALLATION
 
@@ -71,7 +77,15 @@ sub _PriorityAsString {
     my $priority = shift;
     return undef unless defined $priority && length $priority;
 
-    my %map = RT->Config->Get('PriorityAsString');
+    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('PriorityAsStringQueues');
+    }
     if ( my ($res) = grep $map{$_} == $priority, keys %map ) {
         return $res;
     }

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list