[PATCH] Show custom field groupings in mobile ticket view

When showing a ticket in the mobile view, we should respect the custom field grouping from RT_SiteConfig.pm. This patch implements that change.

---
 share/html/m/ticket/show | 52 ++++++++++++++++++++++--------------------------
 1 file changed, 24 insertions(+), 28 deletions(-)

diff --git a/share/html/m/ticket/show b/share/html/m/ticket/show
index d7cc6a1..4cd857a 100644
--- a/share/html/m/ticket/show
+++ b/share/html/m/ticket/show
@@ -47,6 +47,7 @@
 %# END BPS TAGGED BLOCK }}}
 <%args>
 $id => undef
+@Groupings => ()
 </%args>
 <%init>
 my $Ticket;
@@ -201,6 +202,8 @@ my $print_value = sub {
     }
 };
 
+@Groupings = (RT::CustomField->CustomGroupings( $Ticket ), '') unless @Groupings;
+
 </%init>
 <&| /m/_elements/wrapper, title => loc("#[_1]: [_2]", $Ticket->Id, $Ticket->Subject || '') &>
 <div id="ticket-show">
@@ -251,37 +254,30 @@ my $print_value = sub {
   </div>
     </&>
 
-% if ($CustomFields->Count) {
-    <&| /Widgets/TitleBox, title => loc('Custom Fields'),
-        class => 'ticket-info-cfs',
-    &>
-
-% while ( my $CustomField = $CustomFields->Next ) {
-% my $Values = $Ticket->CustomFieldValues( $CustomField->Id );
-% my $count = $Values->Count;
-  <div class="entry" id="CF-<%$CustomField->id%>-ShowRow">
-    <div class="label"><% $CustomField->Name %>:</div>
-    <div class="value">
-% unless ( $count ) {
-<i><&|/l&>(no value)</&></i>
-% } elsif ( $count == 1 ) {
-%   $print_value->( $CustomField, $Values->First );
-% } else {
-<ul>
-% while ( my $Value = $Values->Next ) {
-<li>
-% $print_value->( $CustomField, $Value );
-</li>
-% }
-</ul>
-% }
-    </div>
-  </div>
-% }
-
+<%perl>
+my $title_href = "";
+my $css_class = lc(ref($Ticket)||$Ticket);
+$css_class =~ s/^rt:://;
+$css_class =~ s/::/-/g;
+$css_class = CSSClass($css_class);
+$css_class .= '-info-cfs';
+my $TitleBoxARGS = {};
+for my $group ( @Groupings ) {
+    my %grouping_args = (
+        title => $group? loc($group) : loc('Custom Fields'),
+        class => $css_class .' '. ($group? CSSClass("$css_class-$group") : ''),
+        hide_empty => 1,
+        title_href => $title_href ? "$title_href?id=".$Ticket->id.($group?";Grouping=".$m->interp->apply_escapes($group,'u')."#".CSSClass("$css_class-$group") : "#".$css_class) : undef,
+        %$TitleBoxARGS,
+    );
+</%perl>
+<&| /Widgets/TitleBox, %grouping_args &>
+<& /Elements/ShowCustomFields, %ARGS, Object => $
+Ticket, Grouping => $group &>
 </&>
 % }
 
+
     <&| /Widgets/TitleBox, title => loc('People'), class => 'ticket-info-people' &>
 
 
-- 
2.1.4
1 Like

this is excellent thanks @GreenJimll

I had opened a request for the module regarding the grouping in the ticket reply/comment page (for the standard computer view), but never got an answer from the dev.
https://rt.cpan.org/Public/Bug/Display.html?id=123271

Do you think a patch is doable ?

Its not a module we use I’m afraid so I’m not familiar with it. A quick look on CPAN though seems to indicate that its really just a couple of callbacks checking the custom field values are valid when edited. The guts of the display doesn’t appear to be in that extension at all, but in /Elements/EditCustomFields in RT itself. You might want to make a local copy of that and graft in the grouping code from above to see if that gives you what you want.

1 Like