Ticket #4201 (new enhancement)

Opened 1 year ago

Last modified 2 months ago

[Patch] Include tags in keyword suggestion and use it also in wiki tag edit box

Reported by: georgesoon Assigned to: scratcher
Priority: normal Component: KeywordSuggestPlugin
Severity: normal Keywords:
Cc: rjollos Trac Release: 0.11

Description

features:

  • include tags in keyword suggestion
  • use it also in wiki tag editing
  • working with TracTags plugin 0.6

changeset

  • keywordsuggest.py

Attachments

keywordsuggest.py (5.7 kB) - added by georgesoon@hotmail.com on 12/04/08 01:52:50.
work with tags
keywords.patch (1.2 kB) - added by rob on 12/12/08 04:26:38.
KeywordSuggestPluginPatch.png (6.8 kB) - added by rjollos on 08/07/09 02:27:16.
keywordsuggest.patch (7.0 kB) - added by rjollos on 08/07/09 03:26:58.
Patch file for ticket author's keywordsuggest.py
keywordsuggest.2.patch (7.0 kB) - added by rjollos on 08/07/09 03:28:16.
Patch file for ticket author's keywordsuggest.py
keywordsuggest.3.patch (10.0 kB) - added by rjollos on 08/07/09 03:32:55.
Patch file for ticket author's keywordsuggest.py
keywordsuggest.4.patch (7.0 kB) - added by rjollos on 08/07/09 03:42:39.
Patch file for ticket author's keywordsuggest.py
keywordsuggest.5.patch (7.0 kB) - added by rjollos on 08/07/09 03:42:51.
Patch file for ticket author's keywordsuggest.py
keywordsuggest.6.patch (7.0 kB) - added by rjollos on 08/07/09 03:43:06.
Patch file for ticket author's keywordsuggest.py
keywordsuggest.7.patch (5.7 kB) - added by rjollos on 08/26/09 06:27:37.
Just a test - having trouble uploading files

Change History

12/04/08 01:52:50 changed by georgesoon@hotmail.com

  • attachment keywordsuggest.py added.

work with tags

12/04/08 02:44:34 changed by anonymous

  • release changed from 0.10 to 0.11.

12/12/08 04:25:37 changed by robbie@rail.com

I actually just re-implemented this by mistake because the functionality is missing from the keyword complete module.

I added the ability to select the new or old behavior with a boolean preference, as well.

12/12/08 04:26:38 changed by rob

  • attachment keywords.patch added.

12/12/08 04:28:55 changed by robbie@rail.com

Oops, submitted before I finished typing my email. Hope this helps.

08/03/09 23:13:22 changed by rjollos

See also ticket #3816.

08/03/09 23:36:25 changed by rjollos

  • summary changed from include tags in keyword suggestion and use it also in wiki tag edit to include tags in keyword suggestion and use it also in wiki tag edit box.

Another nice feature would the trac.ini configuration option: helppage = tags. The TagsPlugin creates the \tags page. It would be nice if the Keywords label linked directly to that page when the TagsPlugin was installed.

The behavior I have seen thus far is that the Keywords label will only like to a page when the list of keywords is defined in the keywords parameter.

It seems we might need a separate plug-in, such as AutocompleteTagsPlugin?, to accomplish all of the features.

08/03/09 23:51:12 changed by rjollos

See also ticket #1344 for the TagsPlugin.

08/07/09 02:10:51 changed by rjollos

After installing this patch, with the following configuration the Keywords label links to /ticket/wiki/TicketKeywords.

[keywordsuggest]
helppage = TicketKeywords

I might try to modify the code so that the keywords link can link to /tags.

08/07/09 02:22:29 changed by rjollos

Ticket #5610 is a duplicate.

08/07/09 02:27:16 changed by rjollos

  • attachment KeywordSuggestPluginPatch.png added.

08/07/09 02:27:37 changed by anonymous

  • summary changed from include tags in keyword suggestion and use it also in wiki tag edit box to Include tags in keyword suggestion and use it also in wiki tag edit box.

Here is a screen capture of what this patch provides, given the following trac.ini parameters:

[keywordsuggest]
helppage = TicketKeywords
helppage.newwindow = False
matchcontains = True

08/07/09 02:39:44 changed by rjollos

When using the path keywords.patch, if you wish to pull keywords from the TagsPlugin, it looks like it is necessary to include in trac.ini:

[keywordsuggest]
usetagsplugin = 1

I've installed this plugin and it does not appear to affect the wiki tag edit box, as the ticket author's changes claim to do. I'm going to try to generate a patch file from the author's keywordsuggest.py.

08/07/09 02:52:25 changed by rjollos

  • summary changed from Include tags in keyword suggestion and use it also in wiki tag edit box to Path to include tags in keyword suggestion and use it also in wiki tag edit box.

Patch file for the ticket author's keywordsuggest.py. The patch was made relative to the current trunk [4357].

08/07/09 03:26:58 changed by rjollos

  • attachment keywordsuggest.patch added.

Patch file for ticket author's keywordsuggest.py

08/07/09 03:28:16 changed by rjollos

  • attachment keywordsuggest.2.patch added.

Patch file for ticket author's keywordsuggest.py

08/07/09 03:32:55 changed by rjollos

  • attachment keywordsuggest.3.patch added.

Patch file for ticket author's keywordsuggest.py

08/07/09 03:42:39 changed by rjollos

  • attachment keywordsuggest.4.patch added.

Patch file for ticket author's keywordsuggest.py

08/07/09 03:42:51 changed by rjollos

  • attachment keywordsuggest.5.patch added.

Patch file for ticket author's keywordsuggest.py

08/07/09 03:43:06 changed by rjollos

  • attachment keywordsuggest.6.patch added.

Patch file for ticket author's keywordsuggest.py

08/07/09 04:02:07 changed by rjollos

Index: keywordsuggest.py
===================================================================
--- keywordsuggest.py	(revision 896)
+++ keywordsuggest.py	(working copy)
@@ -8,22 +8,39 @@
 from trac.web.chrome import ITemplateProvider, add_stylesheet, add_script
 from pkg_resources import resource_filename
 from trac.web import IRequestFilter
+from tractags.api import TagSystem
+import re
 
 class KeywordSuggestModule(Component):
     implements (ITemplateStreamFilter, ITemplateProvider, IRequestFilter)
 
     # ITemplateStreamFilter
     def filter_stream(self, req, method, filename, stream, data):
-        if (filename <> 'ticket.html'):
+        if (filename <> 'ticket.html' and filename <> 'wiki_edit.html'):
             return stream
-       
+
+# 2008-12-03 modified by george to get keywords from tag system then from suggest list in trac.ini
+
         keywords = self.config.getlist('keywordsuggest','keywords')
-        if not keywords:
-            self.log.debug('List of keywords not found in trac.ini. '\
+# merge with tags
+        query_result = TagSystem(self.env).query(req, '')
+        for resource, tags in query_result:
+            for _tag in tags:
+                if (_tag not in keywords):
+                    keywords.append(_tag)
+
+        if keywords:
+            keywords = ','.join(("'%s'" % keyword for keyword in keywords))
+        else:
+            keywords = ''
+        
+#        self.log.debug("[george is debugging] %s" % keywords)
+
+        if keywords == '':
+            self.log.debug('List of keywords not found in trac.ini. and no tags found'\
                            'Plugin keywordsuggest disabled.')
             return stream
 
-        keywords = ','.join(("'%s'" % keyword for keyword in keywords))
         mustmatch = 'mustMatch: true,'
         if not self.config.getbool('keywordsuggest','mustmatch'):
             mustmatch = ""
@@ -32,32 +49,56 @@
         if not self.config.getbool('keywordsuggest','matchcontains',True):
             matchcontains = ""
 
-        # inject transient part of javascript directly into ticket.html template
-        js = """
-        $(function($) {
-          var sep = '%s'
-          $('#field-keywords').autocomplete([%s], {multiple: true, %s
-                                            %s multipleSeparator: sep, autoFill: true}); 
-          $("form").submit(function() {
-              // remove trail separator if any
-              keywords = $("input#field-keywords").attr('value')
-              if (keywords.lastIndexOf(sep) + sep.length == keywords.length) {
-                  $("input#field-keywords").attr('value', keywords.substring(0, keywords.length-sep.length))
-              }
-          });
-        });""" % (sep, keywords, matchcontains, mustmatch)
-        stream = stream | Transformer('.//head').append \
-                          (tag.script(Markup(js), type='text/javascript'))
+#        self.log.debug('[george is debugging] path %s' % req.path_info)
+       # inject transient part of javascript directly into ticket.html template
+        if req.path_info.startswith('/ticket/') or \
+           req.path_info.startswith('/newticket'):
+#            self.log.debug('[george is debugging] javascript for ticket before loading')
+            js_ticket = """
+            $(function($) {
+              var sep = '%s'
+              $('#field-keywords').autocomplete([%s], {multiple: true, %s
+                                                %s multipleSeparator: sep, autoFill: true}); 
+              $("form").submit(function() {
+                  // remove trail separator if any
+                  keywords = $("input#field-keywords").attr('value')
+                  if (keywords.lastIndexOf(sep) + sep.length == keywords.length) {
+                      $("input#field-keywords").attr('value', keywords.substring(0, keywords.length-sep.length))
+                  }
+              });
+            });""" % (sep, keywords, matchcontains, mustmatch)
+            stream = stream | Transformer('.//head').append \
+                              (tag.script(Markup(js_ticket), type='text/javascript'))
 
-        # turn keywords field label into link to wiki page
-        helppage = self.config.get('keywordsuggest','helppage')
-        if helppage:
-            link = tag.a(href='wiki/%s' % helppage, target='blank')
-            if not self.config.getbool('keywordsuggest','helppage.newwindow',
-                                       'false'):
-                link.attrib -= 'target'
-            stream = stream | Transformer\
-                         ('//label[@for="field-keywords"]/text()').wrap(link)
+            # turn keywords field label into link to wiki page
+            helppage = self.config.get('keywordsuggest','helppage')
+            if helppage:
+                link = tag.a(href='wiki/%s' % helppage, target='blank')
+                if not self.config.getbool('keywordsuggest','helppage.newwindow',
+                                           'false'):
+                    link.attrib -= 'target'
+                stream = stream | Transformer\
+                             ('//label[@for="field-keywords"]/text()').wrap(link)
+
+        elif req.path_info.startswith('/wiki/'):
+#            self.log.debug('[george is debugging] javascript for wiki before loading')
+            js_wiki = """
+            $(function($) {
+              var sep = '%s'
+              $('#tags').autocomplete([%s], {multiple: true, %s
+                                                %s multipleSeparator: sep, autoFill: true}); 
+              $("form").submit(function() {
+                  // remove trail separator if any
+                  keywords = $("input#tags").attr('value')
+                  if (keywords.lastIndexOf(sep) + sep.length == keywords.length) {
+                      $("input#tags").attr('value', keywords.substring(0, keywords.length-sep.length))
+                  }
+              });
+            });""" % (sep, keywords, matchcontains, mustmatch)
+            stream = stream | Transformer('.//head').append \
+                              (tag.script(Markup(js_wiki), type='text/javascript'))
+#            self.log.debug('[george is debugging] javascript for wiki after loading')
+
         return stream
 
     # ITemplateProvider methods
@@ -76,8 +117,9 @@
     
     def post_process_request(self, req, template, data, content_type):
         if req.path_info.startswith('/ticket/') or \
-           req.path_info.startswith('/newticket'):
+           req.path_info.startswith('/newticket') or \
+           req.path_info.startswith('/wiki/'):
             add_script(req, 'keywordsuggest/jquery.bgiframe.min.js')
             add_script(req, 'keywordsuggest/jquery.autocomplete.pack.js')
             add_stylesheet(req, 'keywordsuggest/autocomplete.css')
-        return template, data, content_type
\ No newline at end of file
+        return template, data, content_type

08/07/09 04:03:35 changed by rjollos

I made several attempts at uploading the patch file with no luck, so I just pasted it into the email above.

It appears that the ticket author's patch includes support for the wiki edit box, as he stated, but I haven't tested this out yet.

If someone can successfully upload the patch as an attachment, that would be cool.

(follow-up: ↓ 15 ) 08/07/09 12:48:29 changed by ThurnerRupert

  • cc set to rjollos.

this ticket has nine patches attached, which ones are necessary?

(in reply to: ↑ 14 ; follow-up: ↓ 17 ) 08/07/09 20:26:39 changed by rjollos

Replying to ThurnerRupert:

this ticket has nine patches attached, which ones are necessary?

The only relevant files are:

keywords.patch - provides the functionality in the graphic I attached to this thread. I've tested this patch and it works.

keywordsuggest.py - says it additionally provides keyword completion for the wiki tags edit box on a wiki page. I haven't tested this.

I tried to created and upload patch files for keywordsuggest.py, but the upload kept failing. I couldn't delete the uploaded empty files. Sorry!

(follow-up: ↓ 18 ) 08/11/09 17:54:57 changed by hugobosscool26@msn.com

Hello,

I want to use this patch for enabling tag list. But I don't know what to do with the keywordsuggest.py (download KeywordSuggestPlugin and replace the file ?).

Can you explain please ?

Thanks !

(in reply to: ↑ 15 ) 08/11/09 18:52:35 changed by lizadri

Replying to rjollos:

I tried to created and upload patch files for keywordsuggest.py, but the upload kept failing. I couldn't delete the uploaded empty files. Sorry!

hi rjollos, If you run trac with mod_python (3.1.3 or 3.1.4) on Windows, uploading attachments will not work. See here http://trac-hacks.org/wiki/TracModPython in the Win32 issues section for more details

(in reply to: ↑ 16 ) 08/12/09 08:05:59 changed by rjollos

Replying to hugobosscool26@msn.com:

Hello, I want to use this patch for enabling tag list. But I don't know what to do with the keywordsuggest.py (download KeywordSuggestPlugin and replace the file ?). Can you explain please ?

You could checkout the plug-in and replace that file. I haven't tested keywordsuggest.py, so I can't say for sure that it works.

Alternatively, you could checkout the plug-in and apply the patch file keywords.patch, which as I mentioned earlier has slightly less functionality (assuming both contributions work).

One way to apply a patch file is using an SVN client such as TortoiseSVN. See the documentation (1) for details.

(1) http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-dug-patch.html

- Ryan

08/14/09 15:45:35 changed by anonymous

TO sum up,

If you want tag + ticket auto select, just download the file in top : eywordsuggest.py (5.7 kB)

It works perfectly for me.

Just for tickets, apply the patch like rjollos said :)

08/26/09 06:26:18 changed by rjollos

  • summary changed from Path to include tags in keyword suggestion and use it also in wiki tag edit box to Patch to include tags in keyword suggestion and use it also in wiki tag edit box.

08/26/09 06:27:37 changed by rjollos

  • attachment keywordsuggest.7.patch added.

Just a test - having trouble uploading files

(follow-up: ↓ 22 ) 09/24/09 20:44:31 changed by yoheeb@gmail.com

I applied the keywordsuggest.py file. I get keyword suggest in tags, but NOT in tickets. Trac log shows a WARNING:: File ticket.js not found in any of []

So, it's close, but not quite there. I think I squashed something when installing some other plugins. Any ideas?

(in reply to: ↑ 21 ) 09/25/09 22:31:42 changed by rjollos

Replying to yoheeb@gmail.com:

I applied the keywordsuggest.py file. I get keyword suggest in tags, but NOT in tickets. Trac log shows a WARNING:: File ticket.js not found in any of []

You may need to configure the tags plugin, TagsPlugin#ConfiguringTagsPlugin, with ticket_fields = keywords.

09/28/09 16:19:10 changed by anonymous

no dice, but I do have more info. before I had ticket_fields = keywords,component

I changed it to the suggestion with no success. However, I did notice this in the trac log, it may of been there all along, but I never noticed it:

Trac[ticket_webui] DEBUG: TicketWebUiAddon executing
Trac[ticket_webui] DEBUG: TicketWebUiAddon not the correct template

as the most recent entries. Searching back as far as I could (I removed this recently to get a clean view) it is indeed repeating. The Plot Thickens....

09/28/09 16:37:25 changed by yoheeb@gmail.com

Amazing what a good nights rest and a fresh cup of coffee will do for you:

  • I found the issue after a little thought and testing.

The TicketDeletePlugin was the culprit. As a quick glance, it looks like this plugin just applies an overwrite to the ticket template, which was killing the keywordsuggest plugin. Since I really don't need to delete a ticket (or the real reason it is needed, change a ticket comment) all to often, I just disabled those plugins. I can enable them on-demand as needed.

thanks for the support. I may consider trying to make a patch in the future to the TicketDeletePlugin, but it is a really low use plugin, so my return on effort makes it hard to do, when I can just enable it the one time a month (or less) when I actually need it, use it, and turn off. (wonder if that's what my wife says about me....)

12/28/09 04:16:12 changed by anonymous

  • summary changed from Patch to include tags in keyword suggestion and use it also in wiki tag edit box to [Patch] Include tags in keyword suggestion and use it also in wiki tag edit box.

Add/Change #4201 ([Patch] Include tags in keyword suggestion and use it also in wiki tag edit box)




Change Properties
Action