apsmir / custom_field_sql

redmine sql custom field
14 stars 8 forks source link

Enable "Link values to URL" and "Text formatting" #5

Open jankokert opened 3 years ago

jankokert commented 3 years ago

This plugin offers some great new possibilities! E.g. creating drop-down lists with values from other database tables.

Unfortunately, the output of the label will not be rendered as HTML. Consider the case, where I want to create a dropdown menu of all DMS files and then generate a clickable link to the document.

my query is: select name as value, CONCAT('<a href="http://172.16.32.41/dmsf/files/', id, '/view">', name, '</a>') as label from dmsf_files

Result: The HTML anchor tag is not rendered.

Could you please add an option for this?

apsmir commented 3 years ago

A good idea. I will think about implementation

jankokert commented 3 years ago

Great! Thanks!

I took a deeper look at your source code. I have no experience with Ruby, but I seems that you derive the sql field from the StringFormatand from List (lib/custom_field_sql/custom_fields/formats/sql.rb line 5 and 11).

To make the value "clickable", there is already a mechanism in Redmine, called "Link values to URL" which is applicable to boolean, date, list, integer and text format fields. See here: https://www.redmine.org/projects/redmine/wiki/RedmineCustomFields#Link-values-to-URL

So the only thing you need to do is to provide that input field (Link values to URL) and then pass it to the original field and let Redmine to the rest.

I think you need to add the input field here, don't you? app/views/custom_fields/formats/_sql.html.erb

Furthermore, you could also pass the "Text formatting" input field to the base class in the same manner.

jankokert commented 3 years ago

I checked the Redmine database and the field for "Link values to URL" is stored in the column format_store of the table custom_fields. The field contains multiple lines:

--- 
!ruby/hash:ActiveSupport::HashWithIndifferentAccess
text_formatting: ''
url_pattern: ''

The line with the key url_pattern is relevant for linking the values to an URL.

Hope this helps to implement this. Cheers.

jankokert commented 3 years ago

Unfortunately, I cannot see any activity on this issue. Are you working on it? It would be a tremendous benefit for my installation! Thanks in advance! Also, can you please answer my question in #1 ?