[SOLVED] How to output HTML from the plugin

Added by Marcel B almost 3 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'])})" 
        "<p><strong>" + str + "<strong/><p/><p><img src=\"http://rosm:8080/osm_tiles/10/368/587.png\">" 

List Issues

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

Shown an Issue

Screenshot-2020-03-09-15-42-31.png - The plugin in Issue New/Edit mode (61.5 KB)

Screenshot-2020-03-09-15-42-54.png - Showing the Issue (114 KB)

Screenshot-2020-03-09-16-05-33.png - Plugin's files (66.3 KB)

Screenshot-2020-03-09-16-14-47.png - List Issues (129 KB)

Screenshot-2020-03-09-16-15-05.png - Shown an Issue (50.5 KB)

Replies (2)

[SOLVED] How to output HTML from the plugin - Added by Marcel B almost 3 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\">" 

RE: [SOLVED] How to output HTML from the plugin - Added by Yury Zhukovskiy 24 days ago

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