Modify

Opened 6 years ago

Closed 3 years ago

Last modified 8 months ago

#4201 closed enhancement (fixed)

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

Reported by: georgesoon Owned by: rjollos
Priority: normal Component: KeywordSuggestPlugin
Severity: normal Keywords:
Cc: itamarost, hasienda 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 (4)

keywordsuggest.py (5.7 KB) - added by georgesoon@… 6 years ago.
work with tags
keywords.patch (1.2 KB) - added by rob 6 years ago.
KeywordSuggestPluginPatch.png (6.8 KB) - added by rjollos 5 years ago.
keywordsuggestplugin-4201-itamaro-v1.patch (6.2 KB) - added by itamarost 3 years ago.
patch for #4201 and #3816 with graceful degradation and tag-esaping

Download all attachments as: .zip

Change History (38)

Changed 6 years ago by georgesoon@…

work with tags

comment:1 Changed 6 years ago by anonymous

  • Trac Release changed from 0.10 to 0.11

comment:2 Changed 6 years ago by robbie@…

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.

Changed 6 years ago by rob

comment:3 Changed 6 years ago by robbie@…

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

comment:4 Changed 5 years ago by rjollos

See also ticket #3816.

comment:5 Changed 5 years ago 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.

comment:6 Changed 5 years ago by rjollos

See also ticket #1344 for the TagsPlugin.

comment:7 Changed 5 years ago 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.

comment:8 Changed 5 years ago by rjollos

Ticket #5610 is a duplicate.

Changed 5 years ago by rjollos

comment:9 Changed 5 years ago 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

comment:10 Changed 5 years ago 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.

comment:11 Changed 5 years ago 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].

comment:12 Changed 5 years ago 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

comment:13 Changed 5 years ago 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.

comment:14 follow-up: Changed 5 years ago by ThurnerRupert

  • Cc rjollos added; anonymous removed

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

comment:15 in reply to: ↑ 14 ; follow-up: Changed 5 years ago 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!

comment:16 follow-up: Changed 5 years ago by hugobosscool26@…

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 !

comment:17 in reply to: ↑ 15 Changed 5 years ago 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

comment:18 in reply to: ↑ 16 Changed 5 years ago 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

comment:19 Changed 5 years ago 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 :)

comment:20 Changed 5 years ago 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

comment:21 follow-up: Changed 5 years ago by yoheeb@…

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?

comment:22 in reply to: ↑ 21 Changed 5 years ago 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.

comment:23 Changed 5 years ago 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....

comment:24 Changed 5 years ago by yoheeb@…

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....)

comment:25 Changed 5 years ago 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

comment:26 Changed 4 years ago by anonymous

in order to enable collecting tag on wiki, refer to #4200

Changed 3 years ago by itamarost

patch for #4201 and #3816 with graceful degradation and tag-esaping

comment:27 follow-up: Changed 3 years ago by itamarost

  • Cc itamarost added

I ported the patch from this ticket, so it now works for me with Trac-0.12.3dev and TagsPlugin (trunk with patch from #7857).

It populates the autocomplete by merging the keywords trac.ini ListOption with all existing tags from TagsPlugin, if TagsPlugin is installed (otherwise it just uses the keywords ListOption).

The autocomplete is also available for wiki-tags when TagsPlugin is installed.

Also fixed on the way a problem with tags that contain a quote (need escaping when embedded in inline JS).

comment:28 Changed 3 years ago by rjollos

  • Owner changed from scratcher to rjollos

comment:29 Changed 3 years ago by rjollos

  • Cc hasienda added; rjollos removed
  • Status changed from new to assigned

comment:30 in reply to: ↑ 27 Changed 3 years ago by rjollos

Replying to itamarost:

I ported the patch from this ticket, so it now works for me with Trac-0.12.3dev and TagsPlugin (trunk with patch from #7857).

I'm going to create a new ticket for handling your patch.

comment:31 Changed 3 years ago by rjollos

(In [10935]) Refs #4201, Fixes #7856: Version 0.4: Added support for TagsPlugin. Tags from the TagsPlugin will be used whenever the TagsPlugin is installed. In the future, an option might be added to determine whether or not to use the TagsPlugin when it is installed. The changes here were derived from the source as modified by georgesoon, keywordsuggest.py in #4201.

These changes have been lightly tested, so please open a new ticket if you encounter any issues.

Compatibility note: Previously, the separator option was defined in quotes, e.g. ', '. Now, the separator is just defined as a character, without quotes. A space is added to all separators.

comment:32 Changed 3 years ago by rjollos

  • Resolution set to fixed
  • Status changed from assigned to closed

comment:33 Changed 8 months ago by hasienda

In 13860:

TagsPlugin: Merge code from KeywordSuggestPlugin's current trunk (0.5.0dev), refs #1344, #3816, #4201 and #4503.

Functional overlap of the aforementioned plugin with TagsPlugin is a fact.
TagsPlugin lacking auto-complete-style assistance for 'keyword' alias tag
input fields took a lot from its potential efficiency.

Consequently KeywordSuggestPlugin is getting integrated from now.
Maintaining said plugin separately as another low-profile plugin for users
that dislike TagsPlugin might still happen depending on developer priorities
and user feedback.

PEP8 clean-up and move to TagsPlugin >= 0.7 performance-enhanced API for
querying current tag list has been done on the way.

comment:34 Changed 8 months ago by hasienda

In 13867:

TagsPlugin: Refit of configuration options inherited from KeywordSuggestPlugin, refs #1344, #3816, #4201 and #11690.

Included are minor changes for component doc-strings as follow-up to [13865].

Add Comment

Modify Ticket

Action
as closed The owner will remain rjollos.
The resolution will be deleted. Next status will be 'reopened'.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.