[Rt-commit] rt branch, custom_fields_application, updated. rt-3.8.7-192-gc36dfb6

Ruslan Zakirov ruz at bestpractical.com
Thu Feb 25 23:58:41 EST 2010


The branch, custom_fields_application has been updated
       via  c36dfb67061ed7d1e056b18428da8347a73da9e0 (commit)
       via  b6b85d8e0ea1d975974ac32dd3dc446a136b4ccd (commit)
       via  ed42b4a9ba0562c051b13e76cbf498f54061575b (commit)
       via  c3be37cc6f281d294f423ca2c6bcab2039ac4cbd (commit)
       via  78d66a7404f645a960c02483645ffc5451ee889c (commit)
       via  056a0468baf500df6aec26303a4d8b60bfd62dd2 (commit)
       via  80295ad5258cce7ed6c0d7f036091d627d783827 (commit)
       via  2d43d74931150b7ede6b84fdfdb1087515aa4322 (commit)
      from  c367a2fb7285d8388adc188b1fa70bcb9b1eabc7 (commit)

Summary of changes:
 lib/RT/CustomField_Overlay.pm                 |    4 +-
 lib/RT/CustomFields_Overlay.pm                |   29 ++++--
 lib/RT/ObjectCustomField_Overlay.pm           |  142 +++++++++++++++++++++++++
 share/html/Admin/Elements/EditCustomFields    |   78 ++++++--------
 share/html/Elements/CollectionList            |    2 +-
 share/html/Elements/RT__CustomField/ColumnMap |   32 ++++++
 6 files changed, 228 insertions(+), 59 deletions(-)

- Log -----------------------------------------------------------------
commit 2d43d74931150b7ede6b84fdfdb1087515aa4322
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Feb 26 07:17:48 2010 +0300

    delete doesn't return status/msg pair

diff --git a/lib/RT/CustomField_Overlay.pm b/lib/RT/CustomField_Overlay.pm
index 324cc24..32f8193 100755
--- a/lib/RT/CustomField_Overlay.pm
+++ b/lib/RT/CustomField_Overlay.pm
@@ -1055,9 +1055,7 @@ sub AddToObject {
         my $applied = RT::ObjectCustomFields->new( $self->CurrentUser );
         $applied->LimitToCustomField( $self->id );
         while ( my $record = $applied->Next ) {
-            my ($status, $msg) = $record->Delete;
-            $RT::Logger->error($msg);
-            return (0, $self->loc("Couldn't remove custom field from an object"));
+            $record->Delete;
         }
     }
 

commit 80295ad5258cce7ed6c0d7f036091d627d783827
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Feb 26 07:20:47 2010 +0300

    account globaly applied when we generate sort order on create

diff --git a/lib/RT/ObjectCustomField_Overlay.pm b/lib/RT/ObjectCustomField_Overlay.pm
index e95161b..39d79b1 100644
--- a/lib/RT/ObjectCustomField_Overlay.pm
+++ b/lib/RT/ObjectCustomField_Overlay.pm
@@ -81,6 +81,7 @@ sub Create {
     unless ( defined $args{'SortOrder'} ) {
         my $ObjectCFs = RT::ObjectCustomFields->new( $RT::SystemUser );
         $ObjectCFs->LimitToObjectId( $args{'ObjectId'} );
+        $ObjectCFs->LimitToObjectId( 0 ) if $args{'ObjectId'};
         $ObjectCFs->LimitToLookupType( $cf->LookupType );
         $ObjectCFs->OrderBy( FIELD => 'SortOrder', ORDER => 'DESC' );
         if ( my $first = $ObjectCFs->First ) {

commit 056a0468baf500df6aec26303a4d8b60bfd62dd2
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Feb 26 07:30:43 2010 +0300

    ApplySortOrder method, don't do it by default

diff --git a/lib/RT/CustomFields_Overlay.pm b/lib/RT/CustomFields_Overlay.pm
index c4cb323..7e802f3 100755
--- a/lib/RT/CustomFields_Overlay.pm
+++ b/lib/RT/CustomFields_Overlay.pm
@@ -141,15 +141,6 @@ sub LimitToGlobalOrObjectId {
                  OPERATOR        => '=',
                  VALUE           => 0,
                  ENTRYAGGREGATOR => 'OR' ) unless $global_only;
-
-    $self->OrderByCols(
-	{ ALIAS => $self->_OCFAlias, FIELD => 'ObjectId', ORDER => 'DESC' },
-	{ ALIAS => $self->_OCFAlias, FIELD => 'SortOrder' },
-    );
-
-    # This doesn't work on postgres.
-    #$self->OrderBy( ALIAS => $class_cfs , FIELD => "SortOrder", ORDER => 'ASC');
-
 }
 
 =head2 LimitToNotApplied
@@ -248,6 +239,26 @@ sub LimitToGlobal  {
 }
 
 
+=head2 ApplySortOrder
+
+Sort custom fields according to thier order application to objects. It's
+expected that collection contains only records of one
+L<RT::CustomField/LookupType> and applied to one object or globally
+(L</LimitToGlobalOrObjectId>), otherwise sorting makes no sense.
+
+=cut
+
+sub ApplySortOrder {
+    my $self = shift;
+    my $order = shift || 'ASC';
+    $self->OrderByCols( {
+        ALIAS => $self->_OCFAlias,
+        FIELD => 'SortOrder',
+        ORDER => $order,
+    } );
+}
+
+
 =head2 ContextObject
 
 Returns context object for this collection of custom fields,

commit 78d66a7404f645a960c02483645ffc5451ee889c
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Feb 26 07:53:43 2010 +0300

    MoveUp and MoveDown methods

diff --git a/lib/RT/ObjectCustomField_Overlay.pm b/lib/RT/ObjectCustomField_Overlay.pm
index 39d79b1..719fad0 100644
--- a/lib/RT/ObjectCustomField_Overlay.pm
+++ b/lib/RT/ObjectCustomField_Overlay.pm
@@ -124,4 +124,145 @@ sub CustomFieldObj {
     return $CF;
 }
 
+=head2 Sorting custom fields applications
+
+Custom fields sorted on multiple layers. First of all custom
+fields with different lookup type are sorted indepedantly. All
+global custom fields have fixed order for all objects, but you
+can insert object specific custom fields between them. Object
+specific custom fields can be applied to several objects and
+be on different place. For example you have GCF1, GCF2, LCF1,
+LCF2 and LCF3 that applies to tickets. You can place GCF2
+above GCF1, but they will be in the same order in all queues.
+However, LCF1 and other local can be placed at any place
+for particular queue: above global, between them or below.
+
+=head3 MoveDown
+
+Moves custom field up. See </Sorting custom fields applications>.
+
+=cut
+
+sub MoveUp {
+    my $self = shift;
+
+    my $ocfs = RT::ObjectCustomFields->new( $self->CurrentUser );
+
+    my $oid = $self->ObjectId;
+    $ocfs->LimitToObjectId( $oid );
+    if ( $oid ) {
+        $ocfs->LimitToObjectId( 0 );
+    }
+
+    my $cf = $self->CustomFieldObj;
+    $ocfs->LimitToLookupType( $cf->LookupType );
+
+    $ocfs->Limit( FIELD => 'SortOrder', OPERATOR => '<', VALUE => $self->SortOrder );
+    $ocfs->OrderByCols( { FIELD => 'SortOrder', ORDER => 'DESC' } );
+
+    my @above = ($ocfs->Next, $ocfs->Next);
+    unless ($above[0]) {
+        return (0, "Can not move up. It's already at the top");
+    }
+
+    my $new_sort_order;
+    if ( $above[0]->ObjectId == $self->ObjectId ) {
+        $new_sort_order = $above[0]->SortOrder;
+        my ($status, $msg) = $above[0]->SetSortOrder( $self->SortOrder );
+        unless ( $status ) {
+            return (0, "Couldn't move custom field");
+        }
+    }
+    elsif ( $above[1] && $above[0]->SortOrder == $above[1]->SortOrder + 1 ) {
+        my $move_ocfs = RT::ObjectCustomFields->new( $RT::SystemUser );
+        $move_ocfs->LimitToLookupType( $cf->LookupType );
+        $move_ocfs->Limit(
+            FIELD => 'SortOrder',
+            OPERATOR => '>=',
+            VALUE => $above[0]->SortOrder,
+        );
+        $move_ocfs->OrderByCols( { FIELD => 'SortOrder', ORDER => 'DESC' } );
+        while ( my $record = $move_ocfs->Next ) {
+            my ($status, $msg) = $record->SetSortOrder( $record->SortOrder + 1 );
+            unless ( $status ) {
+                return (0, "Couldn't move custom field");
+            }
+        }
+        $new_sort_order = $above[0]->SortOrder;
+    } else {
+        $new_sort_order = $above[0]->SortOrder - 1;
+    }
+
+    my ($status, $msg) = $self->SetSortOrder( $new_sort_order );
+    unless ( $status ) {
+        return (0, "Couldn't move custom field");
+    }
+
+    return (1,"Moved custom field up");
+}
+
+=head3 MoveDown
+
+Moves custom field down. See </Sorting custom fields applications>.
+
+=cut
+
+sub MoveDown {
+    my $self = shift;
+
+    my $ocfs = RT::ObjectCustomFields->new( $self->CurrentUser );
+
+    my $oid = $self->ObjectId;
+    $ocfs->LimitToObjectId( $oid );
+    if ( $oid ) {
+        $ocfs->LimitToObjectId( 0 );
+    }
+
+    my $cf = $self->CustomFieldObj;
+    $ocfs->LimitToLookupType( $cf->LookupType );
+
+    $ocfs->Limit( FIELD => 'SortOrder', OPERATOR => '>', VALUE => $self->SortOrder );
+    $ocfs->OrderByCols( { FIELD => 'SortOrder', ORDER => 'ASC' } );
+
+    my @below = ($ocfs->Next, $ocfs->Next);
+    unless ($below[0]) {
+        return (0, "Can not move down. It's already at the bottom");
+    }
+
+    my $new_sort_order;
+    if ( $below[0]->ObjectId == $self->ObjectId ) {
+        $new_sort_order = $below[0]->SortOrder;
+        my ($status, $msg) = $below[0]->SetSortOrder( $self->SortOrder );
+        unless ( $status ) {
+            return (0, "Couldn't move custom field");
+        }
+    }
+    elsif ( $below[1] && $below[0]->SortOrder + 1 == $below[1]->SortOrder ) {
+        my $move_ocfs = RT::ObjectCustomFields->new( $RT::SystemUser );
+        $move_ocfs->LimitToLookupType( $cf->LookupType );
+        $move_ocfs->Limit(
+            FIELD => 'SortOrder',
+            OPERATOR => '<=',
+            VALUE => $below[0]->SortOrder,
+        );
+        $move_ocfs->OrderByCols( { FIELD => 'SortOrder', ORDER => 'ASC' } );
+        while ( my $record = $move_ocfs->Next ) {
+            my ($status, $msg) = $record->SetSortOrder( $record->SortOrder - 1 );
+            unless ( $status ) {
+                return (0, "Couldn't move custom field");
+            }
+        }
+        $new_sort_order = $below[0]->SortOrder;
+    } else {
+        $new_sort_order = $below[0]->SortOrder + 1;
+    }
+
+    my ($status, $msg) = $self->SetSortOrder( $new_sort_order );
+    unless ( $status ) {
+        return (0, "Couldn't move custom field");
+    }
+
+    return (1,"Moved custom field down");
+}
+
 1;

commit c3be37cc6f281d294f423ca2c6bcab2039ac4cbd
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Feb 26 07:54:53 2010 +0300

    don't apply order if arg exists, but sorting is not allowed

diff --git a/share/html/Elements/CollectionList b/share/html/Elements/CollectionList
index 6f21420..8dbeb92 100644
--- a/share/html/Elements/CollectionList
+++ b/share/html/Elements/CollectionList
@@ -54,7 +54,7 @@ if (!$Collection && $Class eq 'RT::Tickets') {
 my $TotalFound = $Collection->CountAll();
 return '' if !$TotalFound && !$ShowEmpty;
 
-if ( @OrderBy ) {
+if ( @OrderBy && $AllowSorting ) {
     if ( $OrderBy[0] =~ /\|/ ) {
         @OrderBy = split /\|/, $OrderBy[0];
         @Order = split /\|/,$Order[0];

commit ed42b4a9ba0562c051b13e76cbf498f54061575b
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Feb 26 07:56:18 2010 +0300

    AppliedTo collection can be undef, for example if RTFM plugin has been disabled

diff --git a/share/html/Elements/RT__CustomField/ColumnMap b/share/html/Elements/RT__CustomField/ColumnMap
index a318c81..db16cc6 100644
--- a/share/html/Elements/RT__CustomField/ColumnMap
+++ b/share/html/Elements/RT__CustomField/ColumnMap
@@ -94,7 +94,10 @@ my $COLUMN_MAP = {
             }
 
             my $collection = $_[0]->AppliedTo;
+            return '' unless $collection;
+
             $collection->RowsPerPage(10);
+
             my $found = 0;
             my $res = '';
             while ( my $record = $collection->Next ) {

commit b6b85d8e0ea1d975974ac32dd3dc446a136b4ccd
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Feb 26 07:57:37 2010 +0300

    MoveCF column map for CustomFields

diff --git a/share/html/Elements/RT__CustomField/ColumnMap b/share/html/Elements/RT__CustomField/ColumnMap
index db16cc6..759ac40 100644
--- a/share/html/Elements/RT__CustomField/ColumnMap
+++ b/share/html/Elements/RT__CustomField/ColumnMap
@@ -140,6 +140,35 @@ my $COLUMN_MAP = {
             return \qq{<input type="checkbox" name="$name" value="$id" $checked />}
         },
     },
+    MoveCF => {
+        title => 'Move',
+        value => sub {
+            my $id = $_[0]->id;
+            
+            my $context = $_[2] || 0;
+            return '' unless $_[0]->IsApplied( $context );
+
+            my $name = 'MoveCustomField';
+            my $args = $m->caller_args( 1 );
+            my @pass = ref $args->{'PassArguments'}
+                ? @{$args->{'PassArguments'}}
+                : ($args->{'PassArguments'});
+            my %pass = map { $_ => $args->{$_} } grep exists $args->{$_}, @pass;
+
+            my $uri = RT->Config->Get('WebPath') . $m->request_path;
+
+            my @res = (
+                \'<a href="',
+                $uri .'?'. $m->comp("/Elements/QueryString", %pass, MoveCustomFieldUp => $id ),
+                \'">', loc('[Up]'), \'</a>',
+                \' <a href="',
+                $uri .'?'. $m->comp("/Elements/QueryString", %pass, MoveCustomFieldDown => $id ),
+                \'">', loc('[Down]'), \'</a>'
+            );
+
+            return @res;
+        },
+    },
 };
 
 </%ONCE>

commit c36dfb67061ed7d1e056b18428da8347a73da9e0
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Feb 26 07:58:13 2010 +0300

    implement custom fields moving

diff --git a/share/html/Admin/Elements/EditCustomFields b/share/html/Admin/Elements/EditCustomFields
index c839ee0..0767e4a 100755
--- a/share/html/Admin/Elements/EditCustomFields
+++ b/share/html/Admin/Elements/EditCustomFields
@@ -54,17 +54,15 @@
 
 <h2><&|/l&>Selected Custom Fields</&></h2>
 <& /Elements/CollectionList,
-    OrderBy       => 'Name',
-    Order         => 'ASC',
     %ARGS,
     Collection    => $applied_cfs,
     Rows          => 0,
     Page          => 1,
     Format        => $format,
     DisplayFormat =>
-        $Object->id
-            ? "'__RemoveCheckBox.{". $Object->id ."}__',". $format
-            : "'__CheckBox.{RemoveCustomField}__',". $format,
+        $id
+            ? ("'__RemoveCheckBox.{$id}__',". $format .", '__MoveCF.{$id}__'")
+            : ("'__CheckBox.{RemoveCustomField}__',". $format .", '__MoveCF.{$id}__'"),
     AllowSorting  => 0,
     ShowEmpty     => 0,
     PassArguments => [
@@ -95,7 +93,7 @@
 
 
 <%INIT>
-my $id = $Object->Id;
+my $id = $Object->Id || 0;
 if ($id and !$Object->CurrentUserHasRight('AssignCustomFields')) {
     $m->out('<p><i>', loc('(No custom fields)'), '</i></p>');
     return;
@@ -107,43 +105,28 @@ my $lookup = $ObjectType;
 $lookup .= "-$SubType" if $SubType;
 
 ## deal with moving sortorder of custom fields
-#if ($CustomField and $Move) {
-#    my $SourceObj = RT::ObjectCustomField->new($session{'CurrentUser'});
-#    $SourceObj->LoadByCols( ObjectId => $id, CustomField => $CustomField );
-#
-#    my $TargetObj;
-#    my $target_order = $SourceObj->SortOrder + $Move;
-#    while (my $ObjectCF = $applied_cfs->Next) { 
-#	my $this_order = $ObjectCF->SortOrder;
-#
-#	# if we have an exact match, finish the loop now
-#	($TargetObj = $ObjectCF, last) if $this_order == $target_order;
-#
-#	# otherwise, we need to apropos toward the general direction
-#	# ... first, check the sign is correct
-#	next unless ($this_order - $SourceObj->SortOrder) * $Move > 0;
-#
-#	# ... next, see if we already have a candidate
-#	if ($TargetObj) {
-#	    # ... if yes, compare the delta and choose the smaller one
-#	    my $orig_delta = abs($TargetObj->SortOrder - $target_order);
-#	    my $this_delta = abs($this_order - $target_order);
-#	    next if $orig_delta < $this_delta;
-#	}
-#
-#	$TargetObj = $ObjectCF;
-#    }
-#
-#    if ($TargetObj) {
-#	# swap their sort order
-#	my ($s, $t) = ($SourceObj->SortOrder, $TargetObj->SortOrder);
-#	$TargetObj->SetSortOrder($s);
-#	$SourceObj->SetSortOrder($t);
-#	# because order changed, we must redo search for subsequent uses
-#    }
-#
-#    $applied_cfs->GotoFirstItem;
-#}
+if ( $MoveCustomFieldUp ) { {
+    my $record = RT::ObjectCustomField->new( $session{'CurrentUser'} );
+    $record->LoadByCols( ObjectId => $id, CustomField => $MoveCustomFieldUp );
+    unless ( $record->id ) {
+        push @results, loc("Custom field #[_1] is not applied to this object", $MoveCustomFieldUp);
+        last;
+    }
+
+    my ($status, $msg) = $record->MoveUp;
+    push @results, $msg;
+} }
+if ( $MoveCustomFieldDown ) { {
+    my $record = RT::ObjectCustomField->new( $session{'CurrentUser'} );
+    $record->LoadByCols( ObjectId => $id, CustomField => $MoveCustomFieldDown );
+    unless ( $record->id ) {
+        push @results, loc("Custom field #[_1] is not applied to this object", $MoveCustomFieldDown);
+        last;
+    }
+
+    my ($status, $msg) = $record->MoveDown;
+    push @results, $msg;
+} }
 
 if ( $UpdateCFs ) {
     foreach my $cf_id ( @AddCustomField ) {
@@ -171,6 +154,7 @@ if ( $UpdateCFs ) {
 my $applied_cfs = RT::CustomFields->new( $session{'CurrentUser'} );
 $applied_cfs->LimitToLookupType($lookup);
 $applied_cfs->LimitToGlobalOrObjectId($id);
+$applied_cfs->ApplySortOrder;
 
 my $not_applied_cfs = RT::CustomFields->new( $session{'CurrentUser'} );
 $not_applied_cfs->LimitToLookupType($lookup);
@@ -184,7 +168,9 @@ $Object
 $ObjectType
 $SubType => ''
 
-$UpdateCFs         => undef
- at RemoveCustomField => ()
- at AddCustomField    => ()
+$UpdateCFs           => undef
+ at RemoveCustomField   => ()
+ at AddCustomField      => ()
+$MoveCustomFieldUp   => undef
+$MoveCustomFieldDown => undef
 </%ARGS>

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


More information about the Rt-commit mailing list