[SOLVED] How to output HTML from the plugin
Added by Marcel B over 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¶
Showing the Issue¶
Plugin's files and structure¶
This is an abstract of Classes and Methods useds from Redmine's core.
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
But it doesn't work when the user SHOW a particular Issue:
Screenshot-2020-03-09-15-42-31.png (61.5 KB) Screenshot-2020-03-09-15-42-31.png | The plugin in Issue New/Edit mode | ||
Screenshot-2020-03-09-15-42-54.png (114 KB) Screenshot-2020-03-09-15-42-54.png | Showing the Issue | ||
Screenshot-2020-03-09-16-05-33.png (66.3 KB) Screenshot-2020-03-09-16-05-33.png | Plugin's files | ||
Screenshot-2020-03-09-16-14-47.png (129 KB) Screenshot-2020-03-09-16-14-47.png | List Issues | ||
Screenshot-2020-03-09-16-15-05.png (50.5 KB) Screenshot-2020-03-09-16-15-05.png | Shown an Issue |
Replies (2)
[SOLVED] How to output HTML from the plugin - Added by Marcel B over 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 almost 2 years ago
Hi Marcel, did you finish the plugin? I need same functionality, a custom field where user can select coordinates of point or poligon.