#4201 closed enhancement (fixed)
[Patch] Include tags in keyword suggestion and use it also in wiki tag edit box
Reported by: | georgesoon | Owned by: | Ryan J Ollos |
---|---|---|---|
Priority: | normal | Component: | KeywordSuggestPlugin |
Severity: | normal | Keywords: | |
Cc: | Itamar Oren, Steffen Hoffmann | 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)
Change History (38)
Changed 16 years ago by
Attachment: | keywordsuggest.py added |
---|
comment:1 Changed 16 years ago by
Trac Release: | 0.10 → 0.11 |
---|
comment:2 Changed 16 years ago by
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 16 years ago by
Attachment: | keywords.patch added |
---|
comment:3 Changed 16 years ago by
Oops, submitted before I finished typing my email. Hope this helps.
comment:5 Changed 15 years ago by
Summary: | include tags in keyword suggestion and use it also in wiki tag edit → 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:7 Changed 15 years ago by
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.
Changed 15 years ago by
Attachment: | KeywordSuggestPluginPatch.png added |
---|
comment:9 Changed 15 years ago by
Summary: | include tags in keyword suggestion and use it also in wiki tag edit box → Include tags in keyword suggestion and use it also in wiki tag edit box |
---|
comment:10 Changed 15 years ago by
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 15 years ago by
Summary: | Include tags in keyword suggestion and use it also in wiki tag edit box → 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 15 years ago by
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 15 years ago by
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: 15 Changed 15 years ago by
Cc: | Ryan J Ollos added; anonymous removed |
---|
this ticket has nine patches attached, which ones are necessary?
comment:15 follow-up: 17 Changed 15 years ago by
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: 18 Changed 15 years ago by
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 Changed 15 years ago by
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 Changed 15 years ago by
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 15 years ago by
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 15 years ago by
Summary: | Path to include tags in keyword suggestion and use it also in wiki tag edit box → Patch to include tags in keyword suggestion and use it also in wiki tag edit box |
---|
comment:21 follow-up: 22 Changed 15 years ago by
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 Changed 15 years ago by
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 15 years ago by
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 15 years ago by
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 15 years ago by
Summary: | Patch to include tags in keyword suggestion and use it also in wiki tag edit box → [Patch] Include tags in keyword suggestion and use it also in wiki tag edit box |
---|
Changed 13 years ago by
Attachment: | keywordsuggestplugin-4201-itamaro-v1.patch added |
---|
comment:27 follow-up: 30 Changed 13 years ago by
Cc: | Itamar Oren 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 13 years ago by
Owner: | changed from scratcher to Ryan J Ollos |
---|
comment:29 Changed 13 years ago by
Cc: | Steffen Hoffmann added; Ryan J Ollos removed |
---|---|
Status: | new → assigned |
comment:30 Changed 13 years ago by
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 13 years ago by
(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 13 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
work with tags