[Bps-public-commit] rt-extension-assets branch, master, updated. 1.02rc1-3-g18430bb

? sunnavy sunnavy at bestpractical.com
Tue Nov 4 10:40:25 EST 2014


The branch, master has been updated
       via  18430bb862cd932b9f788b2ca3c28615364f1176 (commit)
      from  3cc0bfe57cc007fbcd1a3c9ce49f32211e820643 (commit)

Summary of changes:
 lib/RT/Assets.pm           | 34 +++++++++++++++++++++++++++++++---
 lib/RT/Extension/Assets.pm | 18 +++++++-----------
 2 files changed, 38 insertions(+), 14 deletions(-)

- Log -----------------------------------------------------------------
commit 18430bb862cd932b9f788b2ca3c28615364f1176
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Nov 4 21:57:57 2014 +0800

    refactor to not convert OrderBy cfs to objects
    
    the OrderBy arg is used in /Elements/CollectionAsTable/Header to determine if
    to flip Order or not, converting it to object breaks it.
    
    the reason of conversion was to make sure we load the correct OrderBy cf
    (since we have Catalog info in ProcessAssetsSearchArguments but not so in
    RT::Assets::OrderByCols), to refactor it, I added Catalog id to RT::Assets
    object hash when limiting Catalog so OrderByCols can make use of it.

diff --git a/lib/RT/Assets.pm b/lib/RT/Assets.pm
index 5081ac8..0403bee 100644
--- a/lib/RT/Assets.pm
+++ b/lib/RT/Assets.pm
@@ -77,6 +77,26 @@ sub LimitToActiveStatus {
         for RT::Catalog->LifecycleObj->Valid('initial', 'active');
 }
 
+=head2 LimitCatalog
+
+Limit Catalog
+
+=cut
+
+sub LimitCatalog {
+    my $self = shift;
+    my %args = (
+        FIELD    => 'Catalog',
+        OPERATOR => '=',
+        @_
+    );
+
+    if ( $args{OPERATOR} eq '=' ) {
+        $self->{Catalog} = $args{VALUE};
+    }
+    $self->SUPER::Limit(%args);
+}
+
 =head2 Limit
 
 Defaults CASESENSITIVE to 0
@@ -169,7 +189,7 @@ sub SimpleSearch {
             = $customfield;
     }
 
-    $self->Limit( FIELD => 'Catalog', VALUE => $catalog->id );
+    $self->LimitCatalog( VALUE => $catalog->id );
 
     while (my ($name, $op) = each %{$args{Fields}}) {
         $op = 'STARTSWITH'
@@ -212,8 +232,16 @@ sub OrderByCols {
     my $class = $self->_RoleGroupClass;
 
     for my $row (@_) {
-        if ( blessed($row->{FIELD}) and $row->{FIELD}->isa("RT::CustomField") ) {
-            push @res, $self->_OrderByCF( $row, $row->{FIELD}->id, $row->{FIELD} );
+        if ($row->{FIELD} =~ /^CF\.(?:\{(.*)\}|(.*))$/) {
+            my $name = $1 || $2;
+            my $cf = RT::CustomField->new( $self->CurrentUser );
+            $cf->LoadByNameAndCatalog(
+                Name => $name,
+                Catalog => $self->{'Catalog'},
+            );
+            if ( $cf->id ) {
+                push @res, $self->_OrderByCF( $row, $cf->id, $cf );
+            }
         } elsif ($row->{FIELD} =~ /^(\w+)(?:\.(\w+))?$/) {
             my ($role, $subkey) = ($1, $2);
             if ($class->HasRole($role)) {
diff --git a/lib/RT/Extension/Assets.pm b/lib/RT/Extension/Assets.pm
index 3ec1fc5..83145fa 100644
--- a/lib/RT/Extension/Assets.pm
+++ b/lib/RT/Extension/Assets.pm
@@ -245,7 +245,13 @@ RT->AddJavaScript("RTx-Assets.js");
                         VALUE => $value,
                         ENTRYAGGREGATOR => "AND",
                     );
-                } elsif ($key =~ /^(Catalog|Status)$/) {
+                } elsif ($key eq 'Catalog') {
+                    $args{'Assets'}->LimitCatalog(
+                        OPERATOR => ($negative ? '!=' : '='),
+                        VALUE => $value,
+                        ENTRYAGGREGATOR => "AND",
+                    );
+                } elsif ($key eq 'Status') {
                     $args{'Assets'}->Limit(
                         FIELD => $key,
                         OPERATOR => ($negative ? '!=' : '='),
@@ -304,16 +310,6 @@ RT->AddJavaScript("RTx-Assets.js");
         ];
 
         $ARGSRef->{OrderBy} ||= 'id';
-        if ($ARGSRef->{OrderBy} =~ /^CF\.(?:\{(.*)\}|(.*))$/) {
-            my $name = $1 || $2;
-            my $cf = RT::CustomField->new( $session{'CurrentUser'} );
-            $cf->LoadByNameAndCatalog(
-                Name => $name,
-                Catalog => $args{'Catalog'}->id,
-            );
-            $ARGSRef->{OrderBy} = [ $cf ];
-            $ARGSRef->{Order}   = [ $ARGSRef->{Order} ];
-        }
 
         push @PassArguments, qw/OrderBy Order Page/;
 

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



More information about the Bps-public-commit mailing list