Project

General

Profile

[SOLVED] How to output HTML from the plugin

Added by Marcel B about 4 years ago

Hi. I'm finishing a plugin that is a Custom Field for Geographical Localization. This new Custom Field has two fields (latitude and longitude).

It is working. But I would like to output a map to the user, instead of raw text, when the Issue is shown to the user.

My question is: Am I developing in the wrong way? Or Am I missing some other method that should be used to output safe HTML ? Because it seems the method cast_single_value do not allow to output HTML, just text.

I think the images illustrates the plugin and the question.

The plugin in Issue New/Edit mode

The plugin in Issue New/Edit mode

Showing the Issue

Showing the Issue

Plugin's files and structure

This is an abstract of Classes and Methods useds from Redmine's core.

Plugin's files

Things I Tried

If cast_single_value return something like below, the List Issues/Tasks outputs the result as HTML.

def cast_single_value(custom_field, value, customized=nil)
        o_custom_value=(JSON::parse(value.gsub("=>",":")) rescue {})#.values
        str = "" 
        if not value.empty? and o_custom_value.has_key?('latitude')
          str = "Latitude: " << o_custom_value['latitude'] << " (#{dec2dms(o_custom_value['latitude'])})" << " Longitude: "  << o_custom_value['longitude'] << " (#{dec2dms(o_custom_value['longitude'])})" 
        end
        "<p><strong>" + str + "<strong/><p/><p><img src=\"http://rosm:8080/osm_tiles/10/368/587.png\">" 
      end

List Issues

But it doesn't work when the user SHOW a particular Issue:

Shown an Issue


Replies (2)

[SOLVED] How to output HTML from the plugin - Added by Marcel B about 4 years ago

It was a lack of knowledge in rubyonrails. For the SHOW route, I missed html_safe method :

h="<p><strong>" + str + "<strong/><p/><p><img src=\"http://rosm:8080/osm_tiles/10/368/587.png\">" 
h.html_safe

RE: [SOLVED] How to output HTML from the plugin - Added by Yury Zhukovskiy over 1 year ago

Hi Marcel, did you finish the plugin? I need same functionality, a custom field where user can select coordinates of point or poligon.

    (1-2/2)