Redmine plugin view hook update when problems change

I wrote a plugin that captures the latest releases and displays them on the main page. Everything seems to work very well, but it only works the first time I restart the server to start it - after that it "caches" problems from that time on, and they don’t get new ones.

I read a little about this, and it seems to me that I should write a patch for questions in order to add additional features to my plugin. It's true? If so, what should I add to the after_save action? The same thing happens with the LatestPostsSetup model - if I change the values ​​for the maximum quantity and the side on which it should be displayed, the home page does not reflect it until I restart the server.

Sorry if this question seems pretty trivial, I'm new to ruby. Please find the helper code like below:

 module LatestPosts class ViewHookListener < Redmine::Hook::ViewListener require 'plugins/latest_posts/app/models/latest_posts_setup.rb' setup = LatestPostsSetup.find_by_id(1) if setup == nil count = LatestPostsSetup::DEFAULT_COUNT side = LatestPostsSetup::DEFAULT_SIDE else count = setup.max_count side = setup.side end issues = Issue.find(:all, :limit => count, :order => "created_on DESC") if side == 'left' render_side = :view_welcome_index_left else render_side = :view_welcome_index_right end render_on render_side, :locals => {:issues => issues}, :partial => "latest_issues/issues" end end 

EDIT

Now I have changed the view assistant for rendering html on the fly, and I don’t need to restart apache for new problems to be displayed, I don’t understand why this should work using the html template? Please find the following code:

 # lib/latest_posts_hook_listener.rb module LatestPosts class ViewHookListener < Redmine::Hook::ViewListener def view_welcome_index_left(context={}) setup = load_setup() if setup[:side] == "left" load_issues(setup[:count]) end end def view_welcome_index_right(context={}) setup = load_setup() if setup[:side] == "right" load_issues(setup[:count]) end end def load_setup() require 'plugins/latest_posts/app/models/latest_posts_setup.rb' setup = LatestPostsSetup.find_by_id(1) if setup == nil count = LatestPostsSetup::DEFAULT_COUNT side = LatestPostsSetup::DEFAULT_SIDE else count = setup.max_count side = setup.side end {:count => count, :side => side} end def load_issues(count) html = '<div class="box" id="statuses">' html += '<h3 class="icon22 icon22-users">Latest Issues</h3><ul>' issues = Issue.find(:all, :limit => count, :order => "created_on DESC") issues.each do |issue| html += <<EOHTML <li> #{link_to h(truncate(issue.subject, :length => 60)), :controller => 'issues', :action => 'show', :id => issue } (#{ format_date(issue.created_on) }) </li> EOHTML end html += '</ul></div>' return html end end end 
+6
source share
1 answer

Let's see if this helps you. I read this tutorial and below in the section Using Hooks there is this paragraph:

To use one or more hooks in the views, you need to create a class that inherits Redmine :: Hook :: ViewListener and implements methods with the name with the hook (s) that you want to use.

In your code that does not work, I see that you created the class, but I do not see the methods implemented for those hooks that you want to use.

As in the example in this section, I went and looked at this view http://www.redmine.org/projects/redmine/repository/entry/tags/2.0.0/app/views/issues/show.html .erb (not sure if this is the view you need) and it shows that there are two available hooks available: one with the name :view_issues_show_details_bottom and one with the name :view_issues_show_description_bottom , and I expect that you will implement the name in your methods which matches the names of the hooks. Will these hooks show what you want in this view? If not, you may have to use a different view.

For reference, I looked at the list of Redmine views: http://www.redmine.org/projects/redmine/repository/show/tags/2.0.0/app/views

+1
source

Source: https://habr.com/ru/post/924703/


All Articles