[Rt-commit] [rtir] 01/01: First pass at adding queue selection to RTIR ticket creation

Jesse Vincent jesse at bestpractical.com
Sun Feb 22 02:01:35 EST 2015


This is an automated email from the git hooks/post-receive script.

jesse pushed a commit to branch 3.4/remove_old_constituencies
in repository rtir.

commit d3cfd497a6873505744234a81d8ceeec48dbd61b
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Sat Feb 21 22:54:09 2015 -0800

    First pass at adding queue selection to RTIR ticket creation
---
 html/RTIR/Create.html                   |  3 +-
 html/RTIR/Elements/SelectRTIRQueue      | 84 +++++++++++++++++++++++++++++----
 html/RTIR/Incident/Create.html          | 15 +++++-
 html/RTIR/Investigation/Elements/Create | 16 +++++--
 4 files changed, 104 insertions(+), 14 deletions(-)

diff --git a/html/RTIR/Create.html b/html/RTIR/Create.html
index b95df93..1d5d178 100644
--- a/html/RTIR/Create.html
+++ b/html/RTIR/Create.html
@@ -105,6 +105,7 @@
                 Name => 'Queue',
                 Default => $ARGS{'Queue'} || $QueueObj->Id,
                 ShowNullOption => 0,
+                Lifecycle => $QueueObj->Lifecycle
             }
         },
         {
@@ -378,7 +379,7 @@ foreach my $id ( grep $_, @Incident ) {
     unless ( $inc->id ) {
         push @results, loc("Couldn't load incident #[_1]", $id );
     }
-    elsif ( $inc->QueueObj->Lifecycle ne 'incidents' ) {
+    elsif ( $inc->QueueObj->Lifecycle ne RT::IR->lifecycle_incident ) {
         push @results, loc('Ticket #[_1] is not an Incident', $id );
     }
     else {
diff --git a/html/RTIR/Elements/SelectRTIRQueue b/html/RTIR/Elements/SelectRTIRQueue
index b069c8b..1b0bb60 100644
--- a/html/RTIR/Elements/SelectRTIRQueue
+++ b/html/RTIR/Elements/SelectRTIRQueue
@@ -47,14 +47,80 @@
 %# END BPS TAGGED BLOCK }}}
 %# XXX TODO replace with something that limits by constituency and
 %# XXX TODO Lifecycle
-<& /Elements/SelectObject,
-    %ARGS,
-    ObjectType  => "Queue",
-    CheckRight  => $CheckQueueRight,
-    ShowAll     => $ShowAllQueues,
-    CacheNeedsUpdate => RT->System->QueueCacheNeedsUpdate,
-    &>
+<select name="<%$Name%>" <% ($OnChange) ? 'onchange="'.$OnChange.'"' : '' |n %> class="<%$Class%>">
+%     if ($ShowNullOption) {
+  <option value=""><% $DefaultLabel %></option>
+%     }
+%     for my $object (@{$session{$cache_key}{objects}}) {
+  <option value="<%  $object->{Id} %>"\
+% if ($object->{Id} eq ($Default||'') || $object->{Name} eq ($Default||'')) {
+ selected="selected"\
+% }
+><%$object->{Name}%>\
+</option>
+%     }
+</select>
 <%args>
-$CheckQueueRight => 'CreateTicket'
-$ShowAllQueues => 1
+$CheckRight => 'CreateTicket'
+$ShowNullOption => 0
+$ShowAll => 1
+$Name => undef
+$DefaultLabel => "-"
+$Default => 0
+$OnChange => undef
+$CacheNeedsUpdate => RT->System->QueueCacheNeedsUpdate
+$Lifecycle => undef
 </%args>
+<%init>
+my $Class    = "select-rtir-queue-".$Lifecycle;
+
+# XXX TODO This cache will need to take constituency into account
+my $cache_key = join "---", "SelectObject", 'rtir-queue-'.$Lifecycle,
+    $session{'CurrentUser'}->Id, $CheckRight || "", $ShowAll;
+
+if ( defined $session{$cache_key} && ref $session{$cache_key} eq 'ARRAY') {
+    delete $session{$cache_key};
+}
+if ( defined $session{$cache_key} && defined $CacheNeedsUpdate &&
+     $session{$cache_key}{lastupdated} <= $CacheNeedsUpdate ) {
+    delete $session{$cache_key};
+}
+
+if ( not defined $session{$cache_key} ) {
+    my $collection = RT::Queues->new($session{'CurrentUser'});
+    $collection->Limit(FIELD => 'Lifecycle', VALUE => $Lifecycle);
+    $m->callback( CallbackName => 'ModifyCollection', ARGSRef => \%ARGS,
+                  Collection => $collection );
+
+    if ( $Default ) {
+        my $object = RT::Queue->new($session{'CurrentUser'});
+        $object->Load( $Default );
+        unless ( $ShowAll
+                 or not $CheckRight
+                 or $session{CurrentUser}->HasRight( Object => $object, Right => $CheckRight ) )
+        {
+            if ( $object->id ) {
+                push @{$session{$cache_key}{objects}}, {
+                    Id          => $object->id,
+                    Name        => '#' . $object->id,
+                    Description => '#' . $object->id,
+                };
+            }
+        }
+    }
+
+    while (my $object = $collection->Next) {
+        if ($ShowAll
+            or not $CheckRight
+            or $session{CurrentUser}->HasRight( Object => $object, Right => $CheckRight ))
+        {
+            push @{$session{$cache_key}{objects}}, {
+                Id          => $object->Id,
+                Name        => $object->Name,
+                Description => $object->_Accessible("Description" => "read") ? $object->Description : undef,
+            };
+        }
+    }
+    $session{$cache_key}{lastupdated} = time();
+}
+</%init>
diff --git a/html/RTIR/Incident/Create.html b/html/RTIR/Incident/Create.html
index 2d389f2..5aee5a6 100644
--- a/html/RTIR/Incident/Create.html
+++ b/html/RTIR/Incident/Create.html
@@ -73,7 +73,6 @@ if ( $ChildObj && !$ChildObj->CurrentUserHasRight('ModifyTicket') ) {
 
 <input type="hidden" name="id"           value="new" />
 <input type="hidden" class="hidden" name="Token" value="<% $ARGS{'Token'} %>" />
-<input type="hidden" name="Queue"        value="<% $QueueObj->Name       || '' %>" />
 % if ( $ChildObj ) {
 <input type="hidden" name="Child"        value="<% $Child %>" />
 % }
@@ -101,6 +100,20 @@ if ( $ChildObj && !$ChildObj->CurrentUserHasRight('ModifyTicket') ) {
     <td class="value"><% loc("[_1] #[_2]: [_3]",  RT::IR::TicketType(Lifecycle => $ChildObj->QueueObj->Lifecycle), $ChildObj->Id, $ChildObj->Subject) %></td></tr>
 % }
 
+  
+<tr>
+  <td class="label"><&|/l&>Queue</&>:</td>
+  <td colspan="2">
+      <& /RTIR/Elements/SelectRTIRQueue,
+                Name => 'Queue',
+                Default => $ARGS{'Queue'} || $QueueObj->Id,
+                Lifecycle => RT::IR->lifecycle_incident,
+    &>
+  </td>
+</tr>
+ 
+
+
 <tr>
   <td class="label"><&|/l&>Status</&>:</td>
   <td colspan="2">
diff --git a/html/RTIR/Investigation/Elements/Create b/html/RTIR/Investigation/Elements/Create
index ee0a8ed..25ea346 100644
--- a/html/RTIR/Investigation/Elements/Create
+++ b/html/RTIR/Investigation/Elements/Create
@@ -45,16 +45,26 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-<input type="hidden" name="<% $NamePrefix %>Queue" value="<% $QueueObj->id %>" />
 <input type="hidden" name="<% $NamePrefix %>Status" value="<% $ARGS{ $NamePrefix .'Status' } || $QueueObj->LifecycleObj->DefaultOnCreate %>" />
 
 <div class="ticket-create-basics">
 <&| /Widgets/TitleBox, title => loc("Basics"), class => 'ticket-info-basics' &>
 <table width="100%" border="0">
 
+<tr>
+  <td class="label"><&|/l&>Queue</&>:</td>
+  <td colspan="2">
+      <& /RTIR/Elements/SelectRTIRQueue,
+                Name => $NamePrefix.'Queue',
+                Default => $ARGS{'Queue'} || $QueueObj->Id,
+                Lifecycle => RT::IR->lifecycle_investigation,
+    &>
+  </td>
+</tr>
 % unless ( $SkipField{'Owner'} || $HideField{'Owner'} ) {
-<tr><td class="label"><&|/l&>Owner</&>:</td>
-<td class="value"><& /Elements/SelectOwner,
+<tr>
+    <td class="label"><&|/l&>Owner</&>:</td>
+    <td class="value"><& /Elements/SelectOwner,
     Name     => $NamePrefix ."Owner",
     QueueObj => $QueueObj,
     Default  => $value_cb->('Owner') || $session{'CurrentUser'}->Id,

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the rt-commit mailing list