[Rt-commit] rt branch, 4.4/custom-date-ranges, updated. rt-4.4.1rc1-22-g4ea3602

Shawn Moore shawn at bestpractical.com
Wed Jun 29 12:45:26 EDT 2016


The branch, 4.4/custom-date-ranges has been updated
       via  4ea3602ad271ea27a54e08462320bd1935002f79 (commit)
       via  8ff9c8a4b7d52f642e625dbafd6bee85c83d8ed3 (commit)
      from  5abbfee762ad74a6b92fe53b61e8ec9a57afa6d3 (commit)

Summary of changes:
 docs/customizing/search_result_columns.pod | 38 +++++++++++++++---------------
 1 file changed, 19 insertions(+), 19 deletions(-)

- Log -----------------------------------------------------------------
commit 8ff9c8a4b7d52f642e625dbafd6bee85c83d8ed3
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Wed Jun 29 12:31:43 2016 -0400

    Switch customization doc from date range to message count
    
        Date ranges are now more easily accomplished with the new
        %CustomDateRanges config.

diff --git a/docs/customizing/search_result_columns.pod b/docs/customizing/search_result_columns.pod
index 7eef416..5b9231e 100644
--- a/docs/customizing/search_result_columns.pod
+++ b/docs/customizing/search_result_columns.pod
@@ -12,10 +12,12 @@ them you can add and remove data elements to sort by, change the sort order,
 and add and remove which columns you want to see.
 
 Although the Add Columns box has an extensive list of available columns, there
-are times when you need a value not listed. Sometimes what you want is a
-value calculated based on existing ticket values, like finding the difference
-between two date fields. RT provides a way to add this sort of customization
-using something called a Column Map.
+are times when you need a value not listed. If you want to display a custom
+date range, you can configure the L<RT_Config/%CustomDateRanges> setting.
+
+Sometimes what you want is a novel value calculated based on other ticket
+information, like the number of messages on a ticket. RT provides a way
+to add this sort of customization using something called a Column Map.
 
 =head2 Level of Difficulty
 
@@ -43,11 +45,8 @@ making upgrades much easier. As an example, we'll add a Column Map to the
 ticket display and explain the necessary callbacks. You can read more about
 callbacks in general in the L<writing_extensions/Callbacks> documentation.
 
-For our example, let's assume we want to display a response time column that
-shows the difference between when a ticket is created and when someone
-starts working on it (started date). The two initial values are already
-available on the ticket, but it would be convenient to display the
-calculated value in our search.
+For our example, let's assume we want to display the number of messages
+(comments, correspondences) on a ticket.
 
 =head2 Column Map Callback
 
@@ -76,12 +75,15 @@ where F<Once> is the name of the file where we'll put our code.
 In the F<Once> file, we'll put the following code:
 
     <%init>
-    $COLUMN_MAP->{'TimeToFirstResponse'} = {
-            title     => 'First Response', # loc
-            attribute => 'First Response',
+    $COLUMN_MAP->{'NumberOfMessages'} = {
+            title     => 'Messages', # loc
+            attribute => 'Messages',
             value     => sub {
                 my $ticket = shift;
-                return $ticket->StartedObj->DiffAsString($ticket->CreatedObj);
+                my $txns = $ticket->Transactions;
+                $txns->Limit( FIELD => 'Type', VALUE => 'Comment' );
+                $txns->Limit( FIELD => 'Type', VALUE => 'Correspond' );
+                return $txns->Count;
             }
     };
     </%init>
@@ -139,9 +141,9 @@ each row in the search results, the ticket object for that ticket is made
 available as the first parameter to our subroutine.
 
 This allows us to then call methods on the L<RT::Ticket> object to access
-and process the value. In our case, we can get the L<RT::Date> objects for
-the two dates and use the L<RT::Date/DiffAsString> method to calculate and
-return the difference.
+and process the value. In our case, we can get the L<RT::Transactions>
+collection, limit it to the types we're interested in, and then use the
+C<Count> method to return the number of messages.
 
 When writing code to calculate values, remember that it will be run for each
 row in search results. You should avoid doing things that are too time
@@ -164,7 +166,7 @@ Create the file:
 And put the following code in the F<Default> file:
 
     <%INIT>
-    push @{$Fields}, 'TimeToFirstResponse';
+    push @{$Fields}, 'NumberOfMessages';
     </%INIT>
     <%ARGS>
     $Fields => undef

commit 4ea3602ad271ea27a54e08462320bd1935002f79
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Wed Jun 29 12:32:53 2016 -0400

    Remove "# loc" and description from example
    
        #loc comments like this are used throughout core RT when we want
        to flag the string for localization, but we cannot localize the string
        directly there. We use #loc to tell the localization generator to
        include the commented string in .po files for translation. But the
        actual call to loc() happens later.
    
        For example, we can't localize titles like "New messages" (for
        RT::Ticket's UpdateStatus) in column map because the column map is
        defined only once for performance reasons, so localizing it there
        could serve, at most, one language. We instead run the title through
        loc() at render time in CollectionAsTable/Header. However, by then,
        the original hardcoded string "New messages" has been replaced with
        the variable $title. So without the #loc comment, there would be
        nothing to indicate to the localization generator to put the string
        "New messages" into .po files for translation.
    
        This is a tool for RT's developers rather than for specific
        installations.

diff --git a/docs/customizing/search_result_columns.pod b/docs/customizing/search_result_columns.pod
index 5b9231e..045e180 100644
--- a/docs/customizing/search_result_columns.pod
+++ b/docs/customizing/search_result_columns.pod
@@ -76,7 +76,7 @@ In the F<Once> file, we'll put the following code:
 
     <%init>
     $COLUMN_MAP->{'NumberOfMessages'} = {
-            title     => 'Messages', # loc
+            title     => 'Messages',
             attribute => 'Messages',
             value     => sub {
                 my $ticket = shift;
@@ -110,8 +110,6 @@ The parameters in the hashref are as follows:
 =item title
 
 The title is what will be used in the header row to identify this value.
-The C<# loc> is some special markup that allows RT to replace the value
-with translations in other languages, if they are available.
 
 =item attribute
 

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


More information about the rt-commit mailing list