Can a plugin modify the view of the projects page?

Added by Chris Peterson almost 9 years ago

I am wanting to create a custom view of the projects page to meet the needs of the users here. I am running the current trunk as of Feb 24, 2009.

Replies (14)

RE: Can a plugin modify the view of the projects page? - Added by Eric Davis almost 9 years ago

Yes, just create a view file named exactly after the one in app/views/ and Redmine will use it. For example to override the project index page add a file to my_plugin/app/views/projects/index.rhtml

This is how I customized the look of my Redmine

Eric

RE: Can a plugin modify the view of the projects page? - Added by Chris Peterson almost 9 years ago

Thanks for the reply Eric.

I have created an empty plugin. I have added the file index.rhtml with some changes to my_plugin/app/views/projects/index.rhtml. The plugin shows up on the Admin -> Plugins page. However I do not see the changes when I goto Projects. I migrated the plugin database and restarted redmine to no avail. Is there an extra step that I am missing?

I am currently following the plugin tutorial to see if I can glean some information from that.

Thanks,
Chris

RE: Can a plugin modify the view of the projects page? - Added by Brad Beattie almost 9 years ago

Might not be doable, but I figured it's a related question. Any idea if it's possible to create another my page block in a plugin?

In my_controller.rb, it specifies a set of blocks and it doesn't seem flexible.

  BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
             'issuesreportedbyme' => :label_reported_issues,
             'issueswatched' => :label_watched_issues,
             'news' => :label_news_latest,
             'calendar' => :label_calendar,
             'documents' => :label_document_plural,
             'timelog' => :label_spent_time
           }.freeze

Thoughts on that?

RE: Can a plugin modify the view of the projects page? - Added by Eric Davis almost 9 years ago

Chris Peterson wrote:

I have created an empty plugin. I have added the file index.rhtml with some changes to my_plugin/app/views/projects/index.rhtml. The plugin shows up on the Admin -> Plugins page. However I do not see the changes when I goto Projects. I migrated the plugin database and restarted redmine to no avail. Is there an extra step that I am missing?

Looks like the view overriding code isn't working. (merge issue from the 2.2.x branch?) Could you open a bug report for it with the revision your running on and the plugin attached?

Eric

RE: Can a plugin modify the view of the projects page? - Added by Eric Davis almost 9 years ago

Brad Beattie wrote:

Might not be doable, but I figured it's a related question. Any idea if it's possible to create another my page block in a plugin?

In my_controller.rb, it specifies a set of blocks and it doesn't seem flexible.

Thoughts on that?

My page blocks are not modifiable. I've had a todo item to open a feature request for this but haven't been able to think it through 100%. I just opened #2840 with the start of my thoughts, could you add your support (+1)?

Eric

RE: Can a plugin modify the view of the projects page? - Added by Chris Peterson almost 9 years ago

Ok, I created a defect as suggested above. Here is a link

RE: Can a plugin modify the view of the projects page? - Added by Chris Peterson almost 9 years ago

Finally had time to test, and the the fix works. Good Work, Thank You!

I do have one more question. I want to override some of the functionality in projects_controller.rb. I thought I could just create a new file in my_plugin/app/controllers/projects_controller.rb and it would work. However it does not seem to ever access the file. I have been searching on the web for quite some time and cannot seem to find any examples on how to do this, just statements saying it is possible.

Thanks,

Chris

RE: Can a plugin modify the view of the projects page? - Added by Mischa The Evil almost 9 years ago

Chris Peterson wrote:

I do have one more question. I want to override some of the functionality in projects_controller.rb. I thought I could just create a new file in my_plugin/app/controllers/projects_controller.rb and it would work.

As far as I know overriding controllers (nor models) through plugins is not possible / wanted. You can (and should) only override the view-layer.

See this (http://www.redmine.org/boards/3/topics/show/4095#message-4136) superb forum-message by Eric Davis explaining how plugins can be used to extend/modify the Redmine Core using some more advanced ways.

HTH...

RE: Can a plugin modify the view of the projects page? - Added by Eric Davis almost 9 years ago

Mischa The Evil wrote:

As far as I know overriding controllers (nor models) through plugins is not possible / wanted. You can (and should) only override the view-layer.

Mischa's correct. You can override views but not controllers or models in Redmine. Here's how Redmine/Rails works if you try to override a model and a view:

Controller (or Model)

  1. Rails bootstraps and loads all it's framework
  2. Rails starts to load code in the plugins
  3. Rails finds IssueController in MyPlugin and see it defines a show action
  4. Rails loads all the other plugins
  5. Rails then loads the application from app
  6. Rails finds IssueController again and see it also defines a show action
  7. Rails (or rather Ruby) overwrites the show action from the plugin with the one from app
  8. Rails finishes loading and serves up requests

View

View loading is very similar but with one small difference (because of Redmine's patch to Engines)

  1. Rails bootstraps and loads all it's framework
  2. Rails starts to load code in the plugins
  3. Rails finds a views directory in vendor/plugins/my_plugin/app/views and pre-pends it to the views path
  4. Rails loads all the other plugins
  5. Rails then loads the application from app
  6. Rails finishes loading and serves up requests
  7. Request comes in, and a view needs to be rendered
  8. Rails looks for a matching template and loads the plugin's template since it was pre-pended to the views path
  9. Rails renders the plugins' view

In my opinion, it's so easy to extend Models and Controllers the Ruby way (via including modules), Redmine shouldn't maintain an API for that. Views on the other hand are tricky (because of Rails magic) so an API for overriding them is way more useful.

(Would someone mind collecting all this plugin development documentation and putting in on the wiki?)

Eric

RE: Can a plugin modify the view of the projects page? - Added by Mischa The Evil over 8 years ago

Eric Davis wrote:

(Would someone mind collecting all this plugin development documentation and putting in on the wiki?)

This has been done, see Plugin_Internals. Please review if it is correct... ;-)

RE: Can a plugin modify the view of the projects page? - Added by Jérémie Delaitre almost 8 years ago

Is it possible to override only a part of a view ?
For example, want is the best way if I want to add some information after the "Spent time" label in the issue's show view ?

I don't like the idea of overriding the entire view as if another plugin override the same view, it will be problematic. Moreover, I'll need to update my overrided view everytime the official redmine one is changed.

Jérémie

RE: Can a plugin modify the view of the projects page? - Added by Ingolf Steinhardt almost 8 years ago

Hi!

I have a similar question - see at http://www.redmine.org/boards/3/topics/12229

How can I replace different parts at a view or partial eg.
in redmine-0.8/app/views/issues/_form.rhtml

my_pluginA: replace the default partial with

# new row
<% @issue.assigned_to ||= User.find_by_id(8)  %>
<% if User.current.allowed_to?(:manage_issue_assignment, @project) -%>
<p><%= f.select :assigned_to_id, (@issue.assignable_users.collect {|m| [m.name, m.id]}), {:include_blank => true} %></p>
<% else %>
<p><label><%=l(:field_assigned_to)%></label><%= @issue.assigned_to ? link_to_user(@issue.assigned_to) : "-" %></p>
<% end %>

and

my_pluginB: replace the default partial with

<div class="splitcontentright">
<p><%= f.text_field :start_date, :size => 10 %><%= calendar_for('issue_start_date') %></p>
<p><%= f.text_field :due_date, :size => 10 %><%= calendar_for('issue_due_date') %></p>
# new row
<p><%= f.text_field :done_date, :size => 10 %><%= calendar_for('issue_due_date') %></p>
<p><%= f.text_field :estimated_hours, :size => 3 %> <%= l(:field_hours) %></p>
<p><%= f.select :done_ratio, ((0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %></p>
</div>

Its possible to "cutting" the default form/partial and replace with different plugins?

Thanks
query1

RE: Can a plugin modify the view of the projects page? - Added by whoiam whoiam almost 7 years ago

I would like to write a plugin that raises the project name's maxlength from 30 to 60. Please give some advices to write it. Thanks

(1-14/14)