[Rt-commit] r8048 - in
rt/branches/3.7-EXPERIMENTAL-TUNIS/html/Search: Elements
ruz at bestpractical.com
ruz at bestpractical.com
Mon Jul 2 18:39:38 EDT 2007
Author: ruz
Date: Mon Jul 2 18:39:37 2007
New Revision: 8048
Modified:
rt/branches/3.7-EXPERIMENTAL-TUNIS/html/Search/Build.html
rt/branches/3.7-EXPERIMENTAL-TUNIS/html/Search/Elements/EditQuery
Log:
* move code from Build.html to EditQuery
* fix togling and deleting nested clauses
Modified: rt/branches/3.7-EXPERIMENTAL-TUNIS/html/Search/Build.html
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-TUNIS/html/Search/Build.html (original)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/html/Search/Build.html Mon Jul 2 18:39:37 2007
@@ -238,20 +238,7 @@
Value => $value
};
- my $newnode = RT::Interface::Web::QueryBuilder::Tree->new($clause);
- if (@current_values) {
- foreach my $value (@current_values) {
- my $newindex = $value->getIndex + 1;
- $value->insertSibling( $newindex, $newnode );
- $value = $newnode;
- push @new_values, $newnode;
- }
- }
- else {
- $tree->addChild($newnode);
- push @new_values, $newnode;
- }
- $newnode->getParent->setNodeValue( $ARGS{'AndOr'} );
+ push @new_values, RT::Interface::Web::QueryBuilder::Tree->new($clause);
}
}
@@ -259,12 +246,11 @@
push @actions, $m->comp('Elements/EditQuery:Process',
%ARGS,
- Tree => $tree,
+ Tree => $tree,
Selected => \@current_values,
+ New => \@new_values,
);
-push @current_values, @new_values;
-
# {{{ Rebuild $Query based on the additions / movements
my $optionlist_arrayref;
Modified: rt/branches/3.7-EXPERIMENTAL-TUNIS/html/Search/Elements/EditQuery
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-TUNIS/html/Search/Elements/EditQuery (original)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/html/Search/Elements/EditQuery Mon Jul 2 18:39:37 2007
@@ -71,10 +71,14 @@
<%METHOD Process>
<%ARGS>
-$Tree => undef,
-$Selected => [],
+$Tree
+$Selected
+ at New => ()
</%ARGS>
<%INIT>
+
+my @NewSelection = ();
+
my @results;
if ( $ARGS{'Up'} || $ARGS{'Down'} ) {
if (@$Selected) {
@@ -148,12 +152,34 @@
}
elsif ( $ARGS{"DeleteClause"} ) {
if (@$Selected) {
- while( my $node = shift @$Selected ) {
+ my (@top);
+ my %Selected = map { $_ => 1 } @$Selected;
+ foreach my $node ( @$Selected ) {
+ my $tmp = $node->getParent;
+ while ( !$Selected{ $tmp } && !$tmp->isRoot ) {
+ $tmp = $tmp->getParent;
+ }
+ next if $Selected{ $tmp };
+ push @top, $node;
+ }
+
+ foreach ( @New ) {
+ my $add = $_->clone;
+ foreach my $selected( @top ) {
+ my $newindex = $selected->getIndex + 1;
+ $selected->insertSibling( $newindex, $add );
+ }
+ $add->getParent->setNodeValue( $ARGS{'AndOr'} );
+ push @NewSelection, $add;
+ }
+ @New = ();
+
+ while( my $node = shift @top ) {
my $parent = $node->getParent;
- next unless $parent;
$parent->removeChild($node);
$node->DESTROY;
}
+ @$Selected = ();
}
else {
push( @results, [ loc("error: nothing to delete"), -1 ] );
@@ -161,14 +187,17 @@
}
elsif ( $ARGS{"Toggle"} ) {
if (@$Selected) {
- foreach my $value (@$Selected) {
- my $parent = $value->getParent;
-
- if ( $parent->getNodeValue eq 'AND' ) {
- $parent->setNodeValue('OR');
+ my %seen;
+ my @unique_nodes = grep !$seen{ $_ + 0 }++,
+ map ref $_->getNodeValue? $_->getParent: $_,
+ @$Selected;
+
+ foreach my $node ( @unique_nodes ) {
+ if ( $node->getNodeValue eq 'AND' ) {
+ $node->setNodeValue('OR');
}
else {
- $parent->setNodeValue('AND');
+ $node->setNodeValue('AND');
}
}
}
@@ -177,6 +206,29 @@
}
}
+if ( @New && @$Selected ) {
+ foreach ( @New ) {
+ my $add = $_->clone;
+ foreach my $selected( @$Selected ) {
+ my $newindex = $selected->getIndex + 1;
+ $selected->insertSibling( $newindex, $add );
+ }
+ $add->getParent->setNodeValue( $ARGS{'AndOr'} );
+ push @NewSelection, $add;
+ }
+}
+elsif ( @New ) {
+ foreach ( @New ) {
+ my $add = $_->clone;
+ $Tree->addChild( $add );
+ push @NewSelection, $add;
+ }
+ $Tree->setNodeValue( $ARGS{'AndOr'} );
+}
+$_->DESTROY foreach @New;
+
+push @$Selected, @NewSelection;
+
$Tree->PruneChildlessAggregators;
return @results;
More information about the Rt-commit
mailing list