Project

General

Profile

Trying to create a custom field type

Added by Jens Persson over 12 years ago

Hello

I'm trying to integrate Redmine to our corporate issue handling system (Nilex) so that each Issue in redmine will have a field that contains a issue reference number that will link it to the "parent" issue in Nilex. To do this I think the best solution is to create custom field that contains a issue number, but that renders as a link that will take you into the Nilex webinterface.

I found the Extended fields plugin that does something similar but not quite so I decided to roll a special plugin (most likely there will creep in some strange business rules in the field later anyway).

I have managed to create a instance in the menu when creating a new custom field by adding a custom class extending Redmine::CustomFieldFormat like this in init.rb for the plugin.

Rails.configuration.to_prepare do
    Redmine::CustomFieldFormat.map do |fields|
        fields.register    NilexCustomFieldFormat.new('NilexLink',    :label => :label_nilex_link)
    end
end

I then try to patch in special functionality into CustomFieldsHelper with:

unless CustomFieldsHelper.included_modules.include?(NilexLinkHelperPatch)
    CustomFieldsHelper.send(:include, NilexLinkHelperPatch)
end

where NilexLinkHelperPatch contain something like:
    def self.included(base)
        base.send(:include, InstanceMethods)
        base.class_eval do
            unloadable
            alias_method       :show_value,       :show_extended_value
            alias_method_chain :custom_field_tag, :extended
        end
    end
    module InstanceMethods
        def show_extended_value(custom_value)
           ...
        def custom_field_tag_with_extended(name, custom_value)
           ...
        def custom_field_tag_for_bulk_edit_with_extended(name, custom_field, projects = nil)
           ...

This leads to show_extended_value being called for all custom fields that is not of the type NilexLink, but for the field I want, no luck :-(

My thoughts is that there needs to be some more glue that makes NilexLink fields be rendered, but I can't find it ether in the Extended Fields Plugin or in the documentation.


Replies (4)

RE: Trying to create a custom field type - Added by Andriy Lesyuk over 12 years ago

You need to add NilexCustomFieldFormat model, e.g.: http://projects.andriylesyuk.com/projects/extended-fields/repository/entry/app/models/link_custom_field_format.rb

And you could do what you need with the Extended Fields plugin... The workaround is something like this:
  • You add new custom field of String type and name it "Nilex Link"
  • In app/view/custom_values/string of the Extended Fields plugin you create _nilex_link.html.rb where you specify how values should be rendered

See also: http://projects.andriylesyuk.com/projects/extended-fields/wiki/Custom-fields-view-customization

P.S. In show_extended_value you also need to check custom_value.custom_field.name - it should be "NilexLink" for you field

RE: Trying to create a custom field type - Added by Jens Persson over 12 years ago

Thanks Andriy!

I have already created the NilexCustomFieldFormat class, but unfortunately it does not help :-(

I have added one NilexLink field and one standard text field to a project but when rendering an issue show_extended_value gets called only once (for the text field)

Regarding using your plugin, it would solve this part of the problem but the strange "business rules" like "Issues with odd numbers should be rendered in red during full moon" have started to creep in :-) I'm trying to keep them at bay but fear that I will have to give in to allow Redmine to be used.

RE: Trying to create a custom field type - Added by Jens Persson over 12 years ago

By the way I'm using the BitNami Redmine Stack with the following versions:

  • Redmine 2.0.3
  • Apache 2.2.22
  • ImageMagick 6.7.5
  • MySQL 5.5.21
  • Subversion 1.7.4
  • Ruby 1.8.7-p358
  • Rails 2.3.14
  • RubyGems 1.6.2

but have made some experiments with slightly other versions still having the same problems.

RE: Trying to create a custom field type - Added by Andriy Lesyuk over 12 years ago

Regarding using your plugin, it would solve this part of the problem but the strange "business rules" like "Issues with odd numbers should be rendered in red during full moon" have started to creep in :-) I'm trying to keep them at bay but fear that I will have to give in to allow Redmine to be used.

It's still possible... You need to define view file which supports eRuby. That is, you can write:

<% if custom_field.value.to_i % 2 > 0 %>
...
<% else %>
...
<% end %>

I have added one NilexLink field and one standard text field to a project but when rendering an issue show_extended_value gets called only once (for the text field)

I'm not sure what can cause this... Maybe try using lowercase nilexlink.

    (1-4/4)