[Rt-commit] [svn] r1300 - in rtfm/branches/2.1-TESTING: html/RTFM html/RTFM/Article html/RTFM/Article/Elements html/RTFM/Elements lib/RT/FM

alexmv at pallas.eruditorum.org alexmv at pallas.eruditorum.org
Tue Aug 3 12:49:38 EDT 2004


Author: alexmv
Date: Tue Aug  3 12:49:37 2004
New Revision: 1300

Modified:
   rtfm/branches/2.1-TESTING/html/RTFM/Article/Edit.html
   rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/EditTopics
   rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/ShowSearchCriteria
   rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/ShowSearchResults
   rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/ShowTopics
   rtfm/branches/2.1-TESTING/html/RTFM/Article/Search.html
   rtfm/branches/2.1-TESTING/html/RTFM/Elements/GotoArticle
   rtfm/branches/2.1-TESTING/html/RTFM/Elements/Tabs
   rtfm/branches/2.1-TESTING/html/RTFM/Topics.html
   rtfm/branches/2.1-TESTING/lib/RT/FM/ArticleCollection_Overlay.pm
Log:
 * Topic search functionality


Modified: rtfm/branches/2.1-TESTING/html/RTFM/Article/Edit.html
==============================================================================
--- rtfm/branches/2.1-TESTING/html/RTFM/Article/Edit.html	(original)
+++ rtfm/branches/2.1-TESTING/html/RTFM/Article/Edit.html	Tue Aug  3 12:49:37 2004
@@ -43,7 +43,6 @@
                               %ARGS &>
 <& Elements/EditTopics, ArticleObj => $ArticleObj,
                         ClassObj => $ArticleObj->Id ? $ArticleObj->ClassObj : $ClassObj,
-                        id => $id,
                         %ARGS &>
 <& Elements/EditLinks, ArticleObj => $ArticleObj, 
                         id => $id,

Modified: rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/EditTopics
==============================================================================
--- rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/EditTopics	(original)
+++ rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/EditTopics	Tue Aug  3 12:49:37 2004
@@ -16,21 +16,25 @@
 %# 
 %# END LICENSE BLOCK
 
+% if ($ClassObj->Id) {
 <table>
 <tr>
 <td>Fields in this class:</td>
 <td>
+% }
 
 <input type="hidden" name="EditTopics" value="1" />
 <select multiple size="10" name="Topics">
-  <optgroup label="Current class (<% $ClassObj->Name%>)"> 
-% $inTree->traverse(sub {
-%   my $tree = shift;
-%   my $topic = $tree->getNodeValue;
-%   $m->print("<option value=\"".$topic->Id."\""
-%     .(exists $topics{$topic->Id} ? " selected" : "").">"
-%     .("&nbsp;" x ($tree->getDepth*5)).$topic->Name."</option>\n");
-% });
+% if ($ClassObj->Id) {
+%   $m->print("<optgroup label=\"Current class (".$ClassObj->Name.")\">");
+%   $inTree->traverse(sub {
+%     my $tree = shift;
+%     my $topic = $tree->getNodeValue;
+%     $m->print("<option value=\"".$topic->Id."\""
+%       .(exists $topics{$topic->Id} ? " selected" : "").">"
+%       .("&nbsp;" x ($tree->getDepth*5)).$topic->Name."</option>\n");
+%   });
+% }
 % my $class = $ClassObj->Id;
 % $otherTree->traverse(sub {
 %   my $tree = shift;
@@ -48,8 +52,10 @@
 % });
 </optgroup>
 </select>
+% if ($ClassObj->Id) {
 </td>
 </tr>
+% }
 
 <%INIT>
 use Tree::Simple;
@@ -60,16 +66,21 @@
 my $inTree = buildTree($inClass);
 
 my $otherClass = new RT::FM::TopicCollection($session{'CurrentUser'});
-$otherClass->Limit(FIELD => 'ObjectType', VALUE => 'RT::FM::Class');
-$otherClass->Limit(FIELD => 'ObjectId', OPERATOR => '!=', VALUE => $ClassObj->Id);
+if ($ClassObj->Id) {
+    $otherClass->Limit(FIELD => 'ObjectType', VALUE => 'RT::FM::Class');
+    $otherClass->Limit(FIELD => 'ObjectId', OPERATOR => '!=', VALUE => $ClassObj->Id);
+} else {
+    $otherClass->UnLimit;
+}
 my $otherTree = buildTree($otherClass);
 
 my $articleTopics = new RT::FM::ObjectTopicCollection($session{'CurrentUser'});
 $articleTopics->LimitToObject($ArticleObj);
 my %topics;
 while (my $topicObj = $articleTopics->Next) {
-    $topics{$topicObj->Topic} = $topicObj;
+    $topics{$topicObj->Topic} = 1;
 }
+$topics{$_} = 1 for @Topics;
 
 
 sub buildTree {
@@ -103,7 +114,7 @@
 
 </%INIT>
 <%ARGS>
-$id => undef
-$ArticleObj => undef
-$ClassObj => undef
+$ArticleObj => new RT::FM::Article($session{'CurrentUser'})
+$ClassObj => new RT::FM::Class($session{'CurrentUser'})
+ at Topics => undef
 </%ARGS>

Modified: rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/ShowSearchCriteria
==============================================================================
--- rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/ShowSearchCriteria	(original)
+++ rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/ShowSearchCriteria	Tue Aug  3 12:49:37 2004
@@ -40,6 +40,8 @@
 </td>
 </tr>
 </table>
+<br><&|/l&>Has topic</&><& /RTFM/Article/Elements/EditTopics, %ARGS &>
+<br /><&|/l&>Include subtopics of selected topics</&> <input type="checkbox" name="ExpandTopics" <% $ARGS{'ExpandTopics'} ? 'checked="checked"' : "" %> />
 <br><&|/l&>Name matches</&>
 <input name="Name~" value="<%$ARGS{'Name~'}%>">
 <&|/l&>and not</&>

Modified: rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/ShowSearchResults
==============================================================================
--- rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/ShowSearchResults	(original)
+++ rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/ShowSearchResults	Tue Aug  3 12:49:37 2004
@@ -41,7 +41,7 @@
 CLASS="evenline"
 % }
 >
-<TD ROWSPAN="2">
+<TD ROWSPAN="3">
 <B>
 <a href="Display.html?id=<%$article->Id%>">#<%$article->id%></a>
 </B></TD>
@@ -60,6 +60,19 @@
 % }
 ><TD COLSPAN="4"><small><%$article->Summary%></small></TD>
 </TR>
+<TR
+% if ($i%2) {
+CLASS="oddline"
+% } else {
+CLASS="evenline"
+% }
+><TD COLSPAN="4"><small>
+% my $Topics = $article->Topics;
+% while (my $t = $Topics->Next) {
+<& /RTFM/Article/Elements/ShowTopic, topic => $t->TopicObj &><br />
+% }
+</small></TD>
+</TR>
 </SPAN>
 % }
 </table>

Modified: rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/ShowTopics
==============================================================================
--- rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/ShowTopics	(original)
+++ rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/ShowTopics	Tue Aug  3 12:49:37 2004
@@ -23,23 +23,7 @@
 <ul>
 % my @topics;
 % while (my $t = $topics->Next) {
-%   my @path;
-%   my $t = $t->TopicObj;
-%   while ($t->Id) {
-%     unshift @path, $t;
-%     $t = $t->ParentObj;
-%   }
-%   push @topics, \@path;
-% }
-% for (sort @topics) {
-<li>
-% for (@{$_}) {
-% if ($_->ParentObj->Id) {
- : 
-% }
-<a href="<% $RT::WebPath %>/RTFM/Topics.html?class=<% $_->ObjectId %>&id=<% $_->Id %>"><% $_->Name %></a>
-% }
-</li>
+<li><& ShowTopic, topic => $t->TopicObj &></li>
 % }
 </ul>
 % } else {

Modified: rtfm/branches/2.1-TESTING/html/RTFM/Article/Search.html
==============================================================================
--- rtfm/branches/2.1-TESTING/html/RTFM/Article/Search.html	(original)
+++ rtfm/branches/2.1-TESTING/html/RTFM/Article/Search.html	Tue Aug  3 12:49:37 2004
@@ -26,6 +26,7 @@
 my $articles = RT::FM::ArticleCollection->new( $session{'CurrentUser'} );
 
 
+# Don't want to search for a null class when there is no class specced
 my $customfields = RT::FM::CustomFieldCollection->new( $session{'CurrentUser'} );
 if ( $ARGS{'Class'} ) {
     my @Classes =
@@ -41,7 +42,6 @@
 
 }
 
-# Don't want to search for a null class when there is no class specced
 my %dates;
 foreach my $date qw(Created< Created> LastUpdated< LastUpdated>) {
     next unless ( $ARGS{$date} );
@@ -69,6 +69,28 @@
     $articles->LimitReferredToBy($link);
 }
 
+if ($ARGS{'Topics'}) {
+    my @Topics =
+      ( ref $ARGS{'Topics'} eq 'ARRAY' )
+      ? @{ $ARGS{'Topics'} }
+      : ( $ARGS{'Topics'} );
+    @Topics = map {split} @Topics;
+    if ($ARGS{'ExpandTopics'}) {
+        my %topics;
+        while (@Topics) {
+            my $id = shift @Topics;
+            next if $topics{$id};
+            my $Topics = RT::FM::TopicCollection->new($session{'CurrentUser'});
+            $Topics->Limit(FIELD => 'Parent', VALUE => $id);
+            push @Topics, $_->Id while $_ = $Topics->Next;
+            $topics{$id}++;
+        }
+        @Topics = keys %topics;
+        $ARGS{'Topics'} = \@Topics;
+    }
+    $articles->LimitTopics(@Topics);
+}
+
 my %cfs;
 my $all_cfs = RT::FM::CustomFieldCollection->new($session{'CurrentUser'});
 $all_cfs->UnLimit();

Modified: rtfm/branches/2.1-TESTING/html/RTFM/Elements/GotoArticle
==============================================================================
--- rtfm/branches/2.1-TESTING/html/RTFM/Elements/GotoArticle	(original)
+++ rtfm/branches/2.1-TESTING/html/RTFM/Elements/GotoArticle	Tue Aug  3 12:49:37 2004
@@ -16,4 +16,29 @@
 %# 
 %# END LICENSE BLOCK
 
-<FORM ACTION="<%$RT::WebPath%>/RTFM/Article/Search.html"><input type="hidden" name="HideOptions" value=1><input type=submit value="<&|/l&>Search</&>">&nbsp;<input size=15 name="Summary~" accesskey="0"></FORM>
+<FORM ACTION="<%$RT::WebPath%>/RTFM/Article/Search.html">
+<input type="hidden" name="HideOptions" value="1">
+<input size="12" name="Summary~" accesskey="0">
+% if ($class or $topic) {
+<input type="hidden" name="ExpandTopics" value="1">
+<select name="Topics">
+% if ($topic) {
+<option value="<% $topic %>">in this topic</option>
+% }
+% if ($class) {
+% my $Topics = RT::FM::TopicCollection->new($session{'CurrentUser'});
+% $Topics->Limit(FIELD => 'ObjectType', VALUE => 'RT::FM::Class');
+% $Topics->Limit(FIELD => 'ObjectId',   VALUE => $class);
+% my @topics;
+% push @topics, $_->Id while $_ = $Topics->Next;
+<option value="<% join(' ', @topics) %>">in this hierarchy</option>
+% }
+<option value="">in all topics</option>
+</select>
+% }
+<input type="submit" value="<&|/l&>Search</&>">&nbsp;
+</FORM>
+<%args>
+$topic => ""
+$class => ""
+</%args>
\ No newline at end of file

Modified: rtfm/branches/2.1-TESTING/html/RTFM/Elements/Tabs
==============================================================================
--- rtfm/branches/2.1-TESTING/html/RTFM/Elements/Tabs	(original)
+++ rtfm/branches/2.1-TESTING/html/RTFM/Elements/Tabs	Tue Aug  3 12:49:37 2004
@@ -49,7 +49,7 @@
                   };
 
 my $topactions = {
-        B => { html => $m->scomp('/RTFM/Elements/GotoArticle') }
+        B => { html => $m->scomp('/RTFM/Elements/GotoArticle', %ARGS) }
         };
 
                     

Modified: rtfm/branches/2.1-TESTING/html/RTFM/Topics.html
==============================================================================
--- rtfm/branches/2.1-TESTING/html/RTFM/Topics.html	(original)
+++ rtfm/branches/2.1-TESTING/html/RTFM/Topics.html	Tue Aug  3 12:49:37 2004
@@ -16,15 +16,20 @@
 %# 
 %# END LICENSE BLOCK
 
-<& /RTFM/Elements/Tabs, current_toptab => "RTFM/Topics.html", Title => loc('Topic hierarchy') &>
+<& /RTFM/Elements/Tabs, current_toptab => "RTFM/Topics.html", Title => loc('Topic hierarchy'), class => $class, topic => $id &>
 
+<a href="Topics.html">Root</a>
 % if (defined $class) {
+% my $c = RT::FM::Class->new($session{'CurrentUser'});
+% $c->Load($class);
+&gt; <a href="Topics.html?class=<% $c->Id %>"><% $c->Name %></a>
 
 % if ($id != 0) {
 % my $t = RT::FM::Topic->new($session{'CurrentUser'});
 % $t->Load($id);
-<a href="Topics.html?class=<% $class %>&id=<% $t->Parent %>">Parent</a><br />
+&gt; <& /RTFM/Article/Elements/ShowTopic, topic => $t &>
 % }
+<br />
 
 <& /Elements/TitleBoxStart, title => loc('Topics') &>
 % my $Topics = RT::FM::TopicCollection->new($session{'CurrentUser'});
@@ -64,7 +69,8 @@
 % }
 
 % } else {
-Choose a class to examine:
+<br />
+<& /Elements/TitleBoxStart, title => loc('Classes') &>
 <ul>
 % my $Classes = RT::FM::ClassCollection->new($session{'CurrentUser'});
 % $Classes->UnLimit;
@@ -72,6 +78,7 @@
 <li><a href="Topics.html?class=<%$c->Id%>"><% $c->Name %></li>
 % }
 </ul>
+<& /Elements/TitleBoxEnd &>
 
 % }
 

Modified: rtfm/branches/2.1-TESTING/lib/RT/FM/ArticleCollection_Overlay.pm
==============================================================================
--- rtfm/branches/2.1-TESTING/lib/RT/FM/ArticleCollection_Overlay.pm	(original)
+++ rtfm/branches/2.1-TESTING/lib/RT/FM/ArticleCollection_Overlay.pm	Tue Aug  3 12:49:37 2004
@@ -27,9 +27,9 @@
 =head2 Next
 
 Returns the next article that this user can see.
-   
+
 =cut
-   
+
 sub Next {
     my $self = shift;
    
@@ -37,18 +37,18 @@
     my $Object = $self->SUPER::Next();
     if ((defined($Object)) and (ref($Object))) {
 
-    if ($Object->CurrentUserHasRight('ShowArticle')) {
-        return($Object);
-    }
+        if ($Object->CurrentUserHasRight('ShowArticle')) {
+            return($Object);
+        }
 
-    #If the user doesn't have the right to show this Object
-    else {
-        return($self->Next());
-    }
+        #If the user doesn't have the right to show this Object
+        else {
+            return($self->Next());
+        }
     }
     #if there never was any queue
     else {
-    return(undef);
+        return(undef);
     }  
 
 }
@@ -68,15 +68,15 @@
                 @_);
 
     if (ref( $ARGS{'VALUE'} )) {
-      my @values = $ARGS{'VALUE'};
+        my @values = $ARGS{'VALUE'};
         delete $ARGS{'VALUE'};
         foreach my $v (@values) {
             $self->SUPER::Limit(%ARGS, VALUE => $v);
         } 
     }
     else {
-    $RT::Logger->debug(ref($self). " Limit called :".join(" ",%ARGS));
-       $self->SUPER::Limit(%ARGS);
+        $RT::Logger->debug(ref($self). " Limit called :".join(" ",%ARGS));
+        $self->SUPER::Limit(%ARGS);
     }
 }
 
@@ -296,33 +296,32 @@
       ref( $args{'VALUE'} ) ? @{ $args{'VALUE'} } : ( $args{'VALUE'} );
 
     foreach my $value (@values) {
-    next unless $value; #strip out total blank wildcards
-    my $ObjectValuesAlias = $self->Join(
-        TYPE   => 'left',
-        ALIAS1 => 'main',
-        FIELD1 => 'id',
-        TABLE2 => 'FM_ArticleCFValues',
-        FIELD2 => 'Article'
-    );
-
-    if ( $args{'FIELD'} ) {
-        $self->SUPER::Limit(
-            ALIAS           => $ObjectValuesAlias,
-            FIELD           => 'CustomField',
-            VALUE           => $args{'FIELD'},
-            ENTRYAGGREGATOR => 'OR'
+        next unless $value; #strip out total blank wildcards
+        my $ObjectValuesAlias = $self->Join(
+            TYPE   => 'left',
+            ALIAS1 => 'main',
+            FIELD1 => 'id',
+            TABLE2 => 'FM_ArticleCFValues',
+            FIELD2 => 'Article'
         );
-    
 
-        $self->SUPER::Limit(
-            ALIAS           => $ObjectValuesAlias,
-            FIELD           => 'CustomField',
-            OPERATOR        => 'IS',
-            VALUE           => 'NULL',
-            QUOTEVALUE      => 0,
-            ENTRYAGGREGATOR => 'OR',
-        );
-    }
+        if ( $args{'FIELD'} ) {
+            $self->SUPER::Limit(
+                ALIAS           => $ObjectValuesAlias,
+                FIELD           => 'CustomField',
+                VALUE           => $args{'FIELD'},
+                ENTRYAGGREGATOR => 'OR'
+            );
+
+            $self->SUPER::Limit(
+                ALIAS           => $ObjectValuesAlias,
+                FIELD           => 'CustomField',
+                OPERATOR        => 'IS',
+                VALUE           => 'NULL',
+                QUOTEVALUE      => 0,
+                ENTRYAGGREGATOR => 'OR',
+            );
+        }
 
         #If we're trying to find articles where a custom field value doesn't match
         # something, be sure to find  things where it's null
@@ -341,14 +340,14 @@
                 $op = 'LIKE';
             }
 
-        $self->SUPER::Limit(
-            LEFTJOIN           => $ObjectValuesAlias,
-            FIELD           => 'Content',
-            OPERATOR        => $op,
-            VALUE           => $value,
-            QUOTEVALUE      => $args{'QUOTEVALUE'},
-            ENTRYAGGREGATOR => $args{'ENTRYAGGREGATOR'},
-        );
+            $self->SUPER::Limit(
+                LEFTJOIN           => $ObjectValuesAlias,
+                FIELD           => 'Content',
+                OPERATOR        => $op,
+                VALUE           => $value,
+                QUOTEVALUE      => $args{'QUOTEVALUE'},
+                ENTRYAGGREGATOR => $args{'ENTRYAGGREGATOR'},
+            );
             $self->SUPER::Limit(
                 ALIAS           => $ObjectValuesAlias,
                 FIELD           => 'Content',
@@ -359,56 +358,50 @@
             );
         }
         else { 
-        $self->SUPER::Limit(
-            ALIAS           => $ObjectValuesAlias,
-            FIELD           => 'Content',
-            OPERATOR        => $args{'OPERATOR'},
-            VALUE           => $value,
-            QUOTEVALUE      => $args{'QUOTEVALUE'},
-            ENTRYAGGREGATOR => $args{'ENTRYAGGREGATOR'},
-        );
-    }
-
+            $self->SUPER::Limit(
+                ALIAS           => $ObjectValuesAlias,
+                FIELD           => 'Content',
+                OPERATOR        => $args{'OPERATOR'},
+                VALUE           => $value,
+                QUOTEVALUE      => $args{'QUOTEVALUE'},
+                ENTRYAGGREGATOR => $args{'ENTRYAGGREGATOR'},
+            );
+        }
     }
-
-
 }
 
 # }}}
 
-# {{{ LimitRefersTo
-
-=head2 LimitRefersTo URI
-
-Limit the result set to only articles which refers to the URI passed in.
-
-=cut
-
-sub LimitRefersTo {
-
+# {{{ LimitTopics
+sub LimitTopics {
     my $self = shift;
-    my $uri  = shift;
+    my @topics = @_;
 
-    my $links = $self->NewAlias('Links');
+    my $topics = $self->NewAlias('FM_ObjectTopics');
     $self->Limit(
-        ALIAS => $links,
-        FIELD => 'Target',
-        VALUE => $uri
+        ALIAS => $topics,
+        FIELD => 'Topic',
+        VALUE => $_,
+        ENTRYAGGREGATOR => 'OR'
+    ) for @topics;
+    
+    $self->Limit(
+        ALIAS => $topics,
+        FIELD => 'ObjectType',
+        VALUE => 'RT::FM::Article',
     );
-
     $self->Join(
         ALIAS1 => 'main',
-        FIELD1 => 'URI',
-        ALIAS2 => $links,
-        FIELD2 => 'Base'
+        FIELD1 => 'id',
+        ALIAS2 => $topics,
+        FIELD2 => 'ObjectId',
     );
-
 }
 # }}}
 
-# {{{ LimitReferredToBy URI
+# {{{ LimitRefersTo URI
 
-=head2 LimitReferredToBy URI
+=head2 LimitRefersTo URI
 
 Limit the result set to only articles which are referred to by the URI passed in.
 
@@ -419,7 +412,7 @@
 ok($ac->isa('RT::FM::ArticleCollection'));
 ok($ac->isa('RT::FM::SearchBuilder'));
 ok ($ac->isa('DBIx::SearchBuilder'));
-ok ($ac->LimitReferredToBy('http://dead.link'));
+ok ($ac->LimitRefersTo('http://dead.link'));
 ok ($ac->Count == 0);
 
 =end testing
@@ -428,14 +421,14 @@
 
 =cut
 
-sub LimitReferredToBy {
+sub LimitRefersTo {
     my $self = shift;
     my $uri  = shift;
 
     my $links = $self->NewAlias('Links');
     $self->Limit(
         ALIAS => $links,
-        FIELD => 'Base',
+        FIELD => 'Target',
         VALUE => $uri
     );
 
@@ -443,15 +436,15 @@
         ALIAS1 => 'main',
         FIELD1 => 'URI',
         ALIAS2 => $links,
-        FIELD2 => 'Target'
+        FIELD2 => 'Base'
     );
 
 }
 # }}}
 
-# {{{ LimitRefersTo URI
+# {{{ LimitReferredToBy URI
 
-=head2 LimitRefersTo URI
+=head2 LimitReferredToBy URI
 
 Limit the result set to only articles which are referred to by the URI passed in.
 
@@ -462,7 +455,7 @@
 ok($ac->isa('RT::FM::ArticleCollection'));
 ok($ac->isa('RT::FM::SearchBuilder'));
 ok ($ac->isa('DBIx::SearchBuilder'));
-ok ($ac->LimitRefersTo('http://dead.link'));
+ok ($ac->LimitReferredToBy('http://dead.link'));
 ok ($ac->Count == 0);
 
 =end testing
@@ -471,14 +464,14 @@
 
 =cut
 
-sub LimitRefersTo {
+sub LimitReferredToBy {
     my $self = shift;
     my $uri  = shift;
 
     my $links = $self->NewAlias('Links');
     $self->Limit(
         ALIAS => $links,
-        FIELD => 'Target',
+        FIELD => 'Base',
         VALUE => $uri
     );
 
@@ -486,7 +479,7 @@
         ALIAS1 => 'main',
         FIELD1 => 'URI',
         ALIAS2 => $links,
-        FIELD2 => 'Base'
+        FIELD2 => 'Target'
     );
 
 }


More information about the Rt-commit mailing list