[Rt-commit] rt branch, 3.9-lifecycles_improvments, created. rt-3.9.4-229-g3a09a00

Ruslan Zakirov ruz at bestpractical.com
Sun Oct 31 21:51:41 EDT 2010


The branch, 3.9-lifecycles_improvments has been created
        at  3a09a003dc811e1bf66e2cd3839a62107bf52531 (commit)

- Log -----------------------------------------------------------------
commit 0955a07cd395223cbf729a45e96af63e9324366f
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Mon Nov 1 04:42:21 2010 +0300

    implement Lifecycle->actions
    
    * make it possible to order actions independently
    * make it possible to define more then one action for the same
      transition
    * delete transition_lable and transition_action methods

diff --git a/lib/RT/Lifecycle.pm b/lib/RT/Lifecycle.pm
index b2620e4..ca026e3 100644
--- a/lib/RT/Lifecycle.pm
+++ b/lib/RT/Lifecycle.pm
@@ -77,10 +77,10 @@ __PACKAGE__->register_rights;
 #               'status_y -> status_y' => 'right',
 #               ....
 #            }
-#            actions => {
-#               'status_y -> status_y' => [ transition_label, transition_action ],
+#            actions => [
+#               { from => 'a', to => 'b', label => '...', update => '...' },
 #               ....
-#            }
+#            ]
 #        }
 #    }
 
@@ -167,7 +167,7 @@ Returns name of the laoded lifecycle.
 
 sub name { return $_[0]->{'name'} }
 
-=head2 Getting statuses and validatiing.
+=head2 Getting statuses and validating.
 
 Methods to get statuses in different sets or validating them.
 
@@ -411,45 +411,40 @@ sub register_rights {
     }
 }
 
-=head3 transition_label
-
-Takes two statuses (from -> to) and returns label for the transition,
-if custom label is not defined then default equal to the second status.
+=head3 actions
 
-=cut
-
-sub transition_label {
-    my $self = shift;
-    my $from = shift;
-    my $to = shift;
-    return $self->{'data'}{'actions'}{ $from .' -> '. $to }[0] || $to;
-}
-
-=head3 transition_action
-
-Takes two statuses (from -> to) and returns action for the transition.
-
-At this moment it can be:
+Takes a status and returns list of defined actions for the status. Each
+element in the list is a hash reference with the following key/value
+pairs:
 
 =over 4
 
-=item '' (empty string) - no action (default)
+=item from - either the status or *
 
-=item hide - hide this button from the Web UI
+=item to - next status
 
-=item comment - comment page is shown
+=item label - label of the action
 
-=item respond - reply page is shown
+=item update - 'Respond', 'Comment' or '' (empty string)
 
 =back
 
 =cut
 
-sub transition_action {
+sub actions {
     my $self = shift;
-    my $from = shift;
-    my $to = shift;
-    return $self->{'data'}{'actions'}{ $from .' -> '. $to }[1] || '';
+    my $from = shift || return ();
+
+    $self->fill_cache unless keys %LIFECYCLES_CACHE;
+
+    my @res = grep $_->{'from'} eq $from || ( $_->{'from'} eq '*' && $_->{'to'} ne $from ),
+        @{ $self->{'data'}{'actions'} };
+
+    # skip '* -> x' if there is '$from -> x'
+    foreach my $e ( grep $_->{'from'} eq '*', @res ) {
+        $e = undef if grep $_->{'from'} ne '*' && $_->{'to'} eq $e->{'to'}, @res;
+    }
+    return grep defined, @res;
 }
 
 =head2 Creation and manipulation
@@ -562,6 +557,8 @@ sub fill_cache {
 #    $map = $map->content or return;
 
     %LIFECYCLES_CACHE = %LIFECYCLES = %$map;
+    $_ = { %$_ } foreach values %LIFECYCLES_CACHE;
+
     my %all = (
         '' => [],
         initial => [],
@@ -585,6 +582,24 @@ sub fill_cache {
         push @{ $all{''} }, @{ $all{ $type } } if $type;
     }
     $LIFECYCLES_CACHE{''} = \%all;
+
+    foreach my $lifecycle ( values %LIFECYCLES_CACHE ) {
+        my @res;
+        if ( ref $lifecycle->{'actions'} eq 'HASH' ) {
+            foreach my $k ( sort keys %{ $lifecycle->{'actions'} } ) {
+                push @res, $k, $lifecycle->{'actions'}{ $k };
+            }
+        } elsif ( ref $lifecycle->{'actions'} eq 'ARRAY' ) {
+            @res = @{ $lifecycle->{'actions'} };
+        }
+
+        my @tmp = splice @res;
+        while ( my ($transition, $info) = splice @tmp, 0, 2 ) {
+            my ($from, $to) = split /\s*->\s*/, $transition, 2;
+            push @res, { from => $from, to => $to, label => $info->[0], update => $info->[1] };
+        }
+        $lifecycle->{'actions'} = \@res;
+    }
     return;
 }
 

commit 3e86475cf4183b07d9140ce616314ae33a20953e
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Mon Nov 1 04:44:33 2010 +0300

    show status actions using new API

diff --git a/share/html/Ticket/Elements/Tabs b/share/html/Ticket/Elements/Tabs
index 828396c..a26fe8a 100755
--- a/share/html/Ticket/Elements/Tabs
+++ b/share/html/Ticket/Elements/Tabs
@@ -201,39 +201,37 @@ if ($Ticket) {
         };
     }
 
-    if ( $can{'ModifyTicket'} ) {
-        foreach my $next ( $lifecycle->transitions($current) ) {
-            my $action = $lifecycle->transition_action( $current => $next );
-            next if $action eq 'hide';
-
-            my $check = $lifecycle->check_right( $current => $next );
-            $has{$check} = $Ticket->CurrentUserHasRight($check)
-                unless exists $has{$check};
-            next unless $has{$check};
-
-            my $path = 'Ticket/';
-            if ($action) {
-                $path .= "Update.html?"
-                    . $m->comp(
-                    '/Elements/QueryString',
-                    Action        => $action,
-                    DefaultStatus => $next,
-                    id            => $id
-                    );
-            } else {
-                $path .= "Display.html?"
-                    . $m->comp(
-                    '/Elements/QueryString',
-                    Status => $next,
-                    id     => $id
-                    );
-            }
-            $actions->{ 'G' . $i++ } = {
-                path  => $path,
-                title => loc( $lifecycle->transition_label( $current => $next ) ),
-            };
+    foreach my $info ( $lifecycle->actions( $current ) ) {
+        my $next = $info->{'to'};
+        next unless $lifecycle->is_transition( $current => $next );
+
+        my $check = $lifecycle->check_right( $current => $next );
+        $has{$check} = $Ticket->CurrentUserHasRight($check)
+            unless exists $has{$check};
+        next unless $has{$check};
+
+        my $path = 'Ticket/';
+        my $action = $info->{'update'};
+        if ( $action ) {
+            $path .= "Update.html?". $m->comp(
+                '/Elements/QueryString',
+                Action        => $action,
+                DefaultStatus => $next,
+                id            => $id,
+            );
+        } else {
+            $path .= "Display.html?". $m->comp(
+                '/Elements/QueryString',
+                Status => $next,
+                id     => $id,
+            );
         }
+        $actions->{ 'G'. $i++ } = {
+            path  => $path,
+            title => loc( $info->{'label'} || ucfirst($next) ),
+        };
     }
+
     if ( $can{OwnTicket} ) {
         if ($Ticket->OwnerObj->Id == RT->Nobody->id
             && (   $can{'ModifyTicket'} or $can{'TakeTicket'})

commit 8818caf0a57a4831bf0875d6988621ca2205a8a1
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Mon Nov 1 04:45:22 2010 +0300

    describe new format

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 070544c..ffe3ef4 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -1969,23 +1969,20 @@ apropriate.
 
 =head3 Labeling and defining actions
 
-Each transition can be named, by default it's named as the end state.
+For each transition you can define an action that will be shown in the UI.
 
-Each action may be annotated with B<Comment>, B<Respond> or B<Hidden>.
+Each action annotated with label and update type.
 
-For example, you may want your staff to write a reply to the end user
-when they change status from B<new> to B<open>.
-
-Using B<Hide>, it's possible to hide the B<open> -> B<delete> from the ticket's
-main view, while still allowing it from the basics page and API.
-
-Neither B<Comment> nor B<Respond> are mandatory.
+Update type can be B<Comment>, B<Respond> or absent. For example, you may
+want your staff to write a reply to the end user when they change status
+from B<new> to B<open>. Neither B<Comment> nor B<Respond> are mandatory
+and user may leave message empty.
 
 Use the following format to define labels and actions of transitions:
 
     default => {
         ...
-        actions => {
+        actions => [
             'new -> open'     => ['Open It', 'Respond'],
             'new -> resolved' => ['Resolve', 'Comment'],
             'new -> rejected' => ['Reject',  'Respond'],
@@ -1994,13 +1991,29 @@ Use the following format to define labels and actions of transitions:
             'open -> stalled'  => ['Stall',   'Comment'],
             'open -> resolved' => ['Resolve', 'Comment'],
             'open -> rejected' => ['Reject',  'Respond'],
-            'open -> deleted'  => ['Delete',  'hide'],
 
             'stalled -> open'  => ['Open It',  ''],
             'resolved -> open' => ['Re-open',  'Comment'],
             'rejected -> open' => ['Re-open',  'Comment'],
             'deleted -> open'  => ['Undelete', ''],
-        },
+        ],
+        ...
+    },
+
+In addition you can define multiple actions for the same transition.
+Also, it's possible to use '* -> x' to match more than one transition.
+For example:
+
+    default => {
+        ...
+        actions => [
+            ...
+            'new -> rejected' => ['Reject', 'Respond'],
+            'new -> rejected' => ['Quick Reject'],
+            ...
+            '*   -> deleted'  => ['Delete'],
+            ...
+        ],
         ...
     },
 
@@ -2044,7 +2057,7 @@ Set(%Lifecycles,
             '* -> rejected' => 'ModifyTicket',
             '* -> *'        => 'ModifyTicket',
         },
-        actions => {
+        actions => [
 
             # 'from -> to'    => [action text, Respond/Comment/hide/''],
             'new -> open'     => [ 'Open It', 'Respond' ],
@@ -2062,7 +2075,7 @@ Set(%Lifecycles,
             'rejected -> open' => [ 'Re-open',  'Comment' ],
             'deleted -> open'  => [ 'Undelete', '' ],
             'open -> new'      => [ 'New',      'hide' ],
-        },
+        ],
     },
 );
 

commit 3a09a003dc811e1bf66e2cd3839a62107bf52531
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Mon Nov 1 04:45:37 2010 +0300

    no need to hide actions

diff --git a/t/lifecycles/utils.pl b/t/lifecycles/utils.pl
index 21abeb2..0ea6f77 100644
--- a/t/lifecycles/utils.pl
+++ b/t/lifecycles/utils.pl
@@ -30,7 +30,6 @@ Set(\%Lifecycles,
             'open -> stalled'  => ['Stall',   'Comment'],
             'open -> resolved' => ['Resolve', 'Comment'],
             'open -> rejected' => ['Reject',  'Respond'],
-            'open -> deleted'  => ['Delete',  'hide'],
 
             'stalled -> open'  => ['Open It',  ''],
             'resolved -> open' => ['Re-open',  'Comment'],

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


More information about the Rt-commit mailing list