[Bps-public-commit] RT-Extension-PriorityAsString branch, master, updated. 0.04-3-g58e0424

Alex Vandiver alexmv at bestpractical.com
Thu Jul 12 15:36:06 EDT 2012


The branch, master has been updated
       via  58e0424048d996af6ccbd084b2468fadcb9e7bfe (commit)
      from  7552db8c971ee2c337af9d3dd7bacd53d6a36a74 (commit)

Summary of changes:
 .../Elements/RT__Ticket/ColumnMap/Once             | 16 ++++++--
 .../Search/Elements/PickBasics/Default             | 26 ++++++++++++
 .../Ticket/Elements/EditBasics/MassageFields       | 20 ++++++++++
 html/Elements/SelectPriority                       | 46 +++++++++++-----------
 .../{SelectPriority => SelectPriorityAsString}     |  0
 html/Ticket/Elements/ShowPriority                  |  7 ++++
 lib/RT/Extension/PriorityAsString.pm               |  3 ++
 7 files changed, 92 insertions(+), 26 deletions(-)
 create mode 100644 html/Callbacks/PriorityAsString/Search/Elements/PickBasics/Default
 create mode 100644 html/Callbacks/PriorityAsString/Ticket/Elements/EditBasics/MassageFields
 copy html/Elements/{SelectPriority => SelectPriorityAsString} (100%)

- Log -----------------------------------------------------------------
commit 58e0424048d996af6ccbd084b2468fadcb9e7bfe
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Thu Jul 12 15:35:36 2012 -0400

    Allow restricting PriorityAsString to specific queues by name
    
    Move /Elements/SelectPriority to /Elements/SelectPriorityAsString so we
    can preserve the old behavior at times, and choose when to force the
    dropdown.  Leaving @PriorityAsStringQueues empty preserves the old
    behavior; as soon as it is non-empty, each call site examines their
    queue and calls the appropriate component.

diff --git a/html/Callbacks/PriorityAsString/Elements/RT__Ticket/ColumnMap/Once b/html/Callbacks/PriorityAsString/Elements/RT__Ticket/ColumnMap/Once
index 6615680..9dbb645 100644
--- a/html/Callbacks/PriorityAsString/Elements/RT__Ticket/ColumnMap/Once
+++ b/html/Callbacks/PriorityAsString/Elements/RT__Ticket/ColumnMap/Once
@@ -19,9 +19,19 @@ foreach my $field (qw(Priority InitialPriority FinalPriority)) {
 
     my $method = $field .'AsString';
 
-    $COLUMN_MAP->{ $field }{'value'} = sub {
-        return $printer->( $class, $_[0]->$method() );
-    };
+    my %queues;
+    $queues{$_}++ for @{ 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;
+        };
+    }
 }
 return;
 </%INIT>
diff --git a/html/Callbacks/PriorityAsString/Search/Elements/PickBasics/Default b/html/Callbacks/PriorityAsString/Search/Elements/PickBasics/Default
new file mode 100644
index 0000000..7d58601
--- /dev/null
+++ b/html/Callbacks/PriorityAsString/Search/Elements/PickBasics/Default
@@ -0,0 +1,26 @@
+<%ARGS>
+$Conditions => undef
+</%ARGS>
+<%INIT>
+my %queues = %{ $m->caller_args(1)->{queues} || {} };
+
+my %as_string;
+$as_string{$_}++ for @{ 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 %as_string;
+
+# Display the number input unless we know what queue's we're working
+# with
+return unless %queues;
+
+# Display the number input unless all queues specified use
+# PriorityAsString
+return unless scalar(keys %queues) == grep {$as_string{$_}} keys %queues;
+
+# Swap out the /Elements/SelectPriority for /Elements/SelectPriorityAsString
+my ($priority) = grep {$_->{Name} eq "Priority"} @{ $Conditions };
+$priority->{Value}{Path} = "/Elements/SelectPriorityAsString";
+</%INIT>
diff --git a/html/Callbacks/PriorityAsString/Ticket/Elements/EditBasics/MassageFields b/html/Callbacks/PriorityAsString/Ticket/Elements/EditBasics/MassageFields
new file mode 100644
index 0000000..ea006f2
--- /dev/null
+++ b/html/Callbacks/PriorityAsString/Ticket/Elements/EditBasics/MassageFields
@@ -0,0 +1,20 @@
+<%ARGS>
+$TicketObj => undef
+$Fields => undef
+</%ARGS>
+<%INIT>
+my %as_string;
+$as_string{$_}++ for @{ 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};
+
+# Swap out the /Elements/SelectPriority for /Elements/SelectPriorityAsString
+$_->{comp} = "/Elements/SelectPriorityAsString"
+  for grep {$_->{comp}||'' eq "/Elements/SelectPriority"} @{ $Fields };
+</%INIT>
diff --git a/html/Elements/SelectPriority b/html/Elements/SelectPriority
index bebec4b..fbcbe16 100644
--- a/html/Elements/SelectPriority
+++ b/html/Elements/SelectPriority
@@ -1,32 +1,32 @@
-<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>
+<input name="<% $Name %>" value="<% $Default %>" size="5" />
 <%ARGS>
 $Name => 'Priority'
 $Default => undef
 </%ARGS>
 <%INIT>
 
-my %map   = RT->Config->Get('PriorityAsString');
-my @order = grep defined && length, RT->Config->Get('PriorityAsStringOrder');
- at order = sort { $map{$a} <=> $map{$b} } keys %map
-    unless @order;
+my %queues;
+$queues{$_}++ for @{ RT->Config->Get('PriorityAsStringQueues') || [] };
 
-my $default_label = '';
-if ( defined $Default && length $Default ) {
-    $default_label = RT::Ticket->_PriorityAsString( $Default ) || '';
+# If enabled for all queues, always show the drop-down
+return $m->comp("/Elements/SelectPriorityAsString",%ARGS)
+    unless keys %queues;
+
+# Some callsites we can easily override with callbacks with logic to
+# know when to call SelectPriorityAsString; for ticket create and queue
+# modify, we need to inspect the callstack.
+my $caller      = $m->callers(1)->path;
+my $caller_args = $m->caller_args(1);
+my $QueueObj = RT::Queue->new( $session{'CurrentUser'} );
+if ( $caller eq "/Admin/Queues/Modify.html") {
+    $QueueObj->Load( $caller_args->{id} ) || $QueueObj->Load( $caller_args->{Name} );
+} elsif ( $caller eq "/Ticket/Create.html" or $caller eq "/m/ticket/create" ) {
+    $QueueObj->Load( $caller_args->{Queue} );
 }
+return $m->comp("/Elements/SelectPriorityAsString",%ARGS)
+    if $QueueObj->Id and $queues{$QueueObj->Name};
+
+
+
+$Default = '' unless defined $Default;
 </%INIT>
diff --git a/html/Elements/SelectPriority b/html/Elements/SelectPriorityAsString
similarity index 100%
copy from html/Elements/SelectPriority
copy to html/Elements/SelectPriorityAsString
diff --git a/html/Ticket/Elements/ShowPriority b/html/Ticket/Elements/ShowPriority
index cf6fba5..f41be6a 100644
--- a/html/Ticket/Elements/ShowPriority
+++ b/html/Ticket/Elements/ShowPriority
@@ -1,9 +1,16 @@
+% if (keys %queues and not $queues{$Ticket->QueueObj->Name}) {
+<% $Ticket->Priority %>/<% $Ticket->FinalPriority || ''%>
+% } else {
 <span class="ticket-info-priority-<% lc($current) %>"><% loc($current) %></span>/\
 <span class="ticket-info-final-priority-<% lc($final) %>"><% loc($final) %></span>
+% }
 <%ARGS>
 $Ticket => undef
 </%ARGS>
 <%INIT>
+my %queues;
+$queues{$_}++ for @{ RT->Config->Get('PriorityAsStringQueues') || [] };
+
 my $current = $Ticket->PriorityAsString || '';
 my $final = $Ticket->FinalPriorityAsString || '';
 </%INIT>
diff --git a/lib/RT/Extension/PriorityAsString.pm b/lib/RT/Extension/PriorityAsString.pm
index 6000f3a..958e368 100644
--- a/lib/RT/Extension/PriorityAsString.pm
+++ b/lib/RT/Extension/PriorityAsString.pm
@@ -24,6 +24,9 @@ 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 ));
+
 =head1 INSTALLATION
 
 *NOTE* that it only works with RT 3.8.3 and newer.

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



More information about the Bps-public-commit mailing list