Forums » Development »
How to view custom field is 2.000.000
Added by anhkhoa Michel about 10 years ago
I create a custom field value integer.example : Money 20000000
I want to view custom filed 2.000.000
Please help me!!!
Replies (11)
RE: How to view custom field is 2.000.000 - Added by Martin Denizet (redmine.org team member) about 10 years ago
Hello Ankhoa,
Not to make a dedicated plugin for this small feature, I'd use the Custom JS plugin
And I'd configure the plugin to inject JavaScript such as:
var format = function(num){
var str = num.toString().replace("$", ""), parts = false, output = [], i = 1, formatted = null;
if(str.indexOf(".") > 0) {
parts = str.split(".");
str = parts[0];
}
str = str.split("").reverse();
for(var j = 0, len = str.length; j < len; j++) {
if(str[j] != ",") {
output.push(str[j]);
if(i%3 == 0 && j < (len - 1)) {
output.push(",");
}
i++;
}
}
formatted = output.reverse().join("");
return("$" + formatted + ((parts) ? "." + parts[1].substr(0, 2) : ""));
};
$( document ).ready(function() {
$('td.cf_1').html(format($('.cf_1').html));
});
Note that you have the replace cf_1 with the class relevant to your setup.
Note also that I didn't test that code.
RE: How to view custom field is 2.000.000 - Added by anhkhoa Michel about 10 years ago
Hi. When I add this code js into my_plugin\view\issues\show.html.rb. It 's show
Money:$fun,cti,on ,(e),{re,tur,n v.ac
RE: How to view custom field is 2.000.000 - Added by anhkhoa Michel about 10 years ago
code
<script> var format = function(num){ var str = num.toString().replace("$", ""), parts = false, output = [], i = 1, formatted = null; if(str.indexOf(".") > 0) { parts = str.split("."); str = parts[0]; } str = str.split("").reverse(); for(var j = 0, len = str.length; j < len; j++) { if(str[j] != ",") { output.push(str[j]); if(i%3 == 0 && j < (len - 1)) { output.push(","); } i++; } } formatted = output.reverse().join(""); return("$" + formatted + ((parts) ? "." + parts[1].substr(0, 2) : "")); }; $( document ).ready(function() { $('td.cf_1').html(format($('.cf_1').html)); }); </script> <% if @issue.tracker_id ==2 %> <%= render :partial => 'action_menu' %> <h2><%= issue_heading(@issue) %></h2> <div class="<%= @issue.css_classes %> details"> <% if @prev_issue_id || @next_issue_id %> <div class="next-prev-links contextual"> <%= link_to_if @prev_issue_id, "\xc2\xab #{l(:label_previous)}", (@prev_issue_id ? issue_path(@prev_issue_id) : nil), :title => "##{@prev_issue_id}" %> | <% if @issue_position && @issue_count %> <span class="position"><%= l(:label_item_position, :position => @issue_position, :count => @issue_count) %></span> | <% end %> <%= link_to_if @next_issue_id, "#{l(:label_next)} \xc2\xbb", (@next_issue_id ? issue_path(@next_issue_id) : nil), :title => "##{@next_issue_id}" %> </div> <% end %> <%= avatar(@issue.author, :size => "50") %> <div class="subject"> <%= render_issue_subject_with_tree(@issue) %> </div> <p class="author"> <%= authoring @issue.created_on, @issue.author %>. <% if @issue.created_on != @issue.updated_on %> <%= l(:label_updated_time, time_tag(@issue.updated_on)).html_safe %>. <% end %> </p> <table class="attributes"> <%= issue_fields_rows do |rows| rows.left l(:field_status), h(@issue.status.name), :class => 'status' #rows.left l(:field_priority), h(@issue.priority.name), :class => 'priority' #deleted assign_to unless @issue.disabled_core_fields.include?('fixed_version_id') rows.left l(:field_fixed_version), (@issue.fixed_version ? link_to_version(@issue.fixed_version) : "-"), :class => 'fixed-version' end unless @issue.disabled_core_fields.include?('start_date') rows.right l(:field_start_date), format_date(@issue.start_date), :class => 'start-date' end unless @issue.disabled_core_fields.include?('due_date') rows.left l(:field_due_date), format_date(@issue.due_date), :class => 'due-date' end #unless @issue.disabled_core_fields.include?('done_ratio') #rows.right l(:field_done_ratio), progress_bar(@issue.done_ratio, :width => '80px', :legend => "#{@issue.done_ratio}%"), :class => 'progress' #end #unless @issue.disabled_core_fields.include?('estimated_hours') # unless @issue.estimated_hours.nil? # rows.right l(:field_estimated_hours), l_hours(@issue.estimated_hours), :class => 'estimated-hours' #end #end if User.current.allowed_to?(:view_time_entries, @project) rows.left l(:label_spent_time), (@issue.total_spent_hours > 0 ? link_to(l_hours(@issue.total_spent_hours), project_issue_time_entries_path(@project, @issue)) : "-"), :class => 'spent-time' end #unless @issue.disabled_core_fields.include?('category_id') #rows.left l(:field_category), h(@issue.category ? @issue.category.name : "-"), :class => 'category' #end end %> <tr> <th><%= l(:field_category) %></th> <td colspan="3"><%= h(@issue.category ? @issue.category.name : "-")%></td> </tr> <%= render_custom_fields_rows1(@issue, 1) %> <%= call_hook(:view_issues_show_details_bottom, :issue => @issue) %> </table> <% if @issue.description? || @issue.attachments.any? -%> <hr /> <% if @issue.description? %> <div class="description"> <div class="contextual"> <%= link_to l(:button_quote), quoted_issue_path(@issue), :remote => true, :method => 'post', :class => 'icon icon-comment' if authorize_for('issues', 'edit') %> </div> <p><strong><%=l(:field_description)%></strong></p> <div class="wiki"> <%= textilizable @issue, :description, :attachments => @issue.attachments %> </div> </div> <% end %> <%= link_to_attachments @issue, :thumbnails => true %> <% end -%> <%= call_hook(:view_issues_show_description_bottom, :issue => @issue) %> </div> <% if @changesets.present? %> <div id="issue-changesets"> <h3><%=l(:label_associated_revisions)%></h3> <%= render :partial => 'changesets', :locals => { :changesets => @changesets} %> </div> <% end %> <% if @journals.present? %> <div id="history"> <h3><%=l(:label_history)%></h3> <%= render :partial => 'history_duan', :locals => { :issue => @issue, :journals => @journals } %> </div> <% end %> <div style="clear: both;"></div> <%= render :partial => 'action_menu' %> <div style="clear: both;"></div> <% if @issue.editable? %> <div > <h3><%= l(:button_edit) %></h3> <%= render :partial => 'note_duan' %> </div> <% end %> <% other_formats_links do |f| %> <%= f.link_to 'Atom', :url => {:key => User.current.rss_key} %> <%= f.link_to 'PDF' %> <% end %> <% html_title "#{@issue.tracker.name} ##{@issue.id}: #{@issue.subject}" %> <% content_for :sidebar do %> <%= render :partial => 'issues/sidebar_duan' %> <% if User.current.allowed_to?(:add_issue_watchers, @project) || (@issue.watchers.present? && User.current.allowed_to?(:view_issue_watchers, @project)) %> <div id="watchers"> <%= render :partial => 'watchers/watchers', :locals => {:watched => @issue} %> </div> <% end %> <% end %> <% content_for :header_tags do %> <%= auto_discovery_link_tag(:atom, {:format => 'atom', :key => User.current.rss_key}, :title => "#{@issue.project} - #{@issue.tracker} ##{@issue.id}: #{@issue.subject}") %> <% end %> <%= context_menu issues_context_menu_path %> <% else %> <%= render :partial => 'action_menu' %> <h2><%= issue_heading(@issue) %></h2> <div class="<%= @issue.css_classes %> details"> <% if @prev_issue_id || @next_issue_id %> <div class="next-prev-links contextual"> <%= link_to_if @prev_issue_id, "\xc2\xab #{l(:label_previous)}", (@prev_issue_id ? issue_path(@prev_issue_id) : nil), :title => "##{@prev_issue_id}" %> | <% if @issue_position && @issue_count %> <span class="position"><%= l(:label_item_position, :position => @issue_position, :count => @issue_count) %></span> | <% end %> <%= link_to_if @next_issue_id, "#{l(:label_next)} \xc2\xbb", (@next_issue_id ? issue_path(@next_issue_id) : nil), :title => "##{@next_issue_id}" %> </div> <% end %> <%= avatar(@issue.author, :size => "50") %> <div class="subject"> <%= render_issue_subject_with_tree(@issue) %> </div> <p class="author"> <%= authoring @issue.created_on, @issue.author %>. <% if @issue.created_on != @issue.updated_on %> <%= l(:label_updated_time, time_tag(@issue.updated_on)).html_safe %>. <% end %> </p> <table class="attributes"> <%= issue_fields_rows do |rows| rows.left l(:field_status), h(@issue.status.name), :class => 'status' rows.left l(:field_priority), h(@issue.priority.name), :class => 'priority' unless @issue.disabled_core_fields.include?('assigned_to_id') rows.left l(:field_assigned_to), avatar(@issue.assigned_to, :size => "14").to_s.html_safe + (@issue.assigned_to ? link_to_user(@issue.assigned_to) : "-"), :class => 'assigned-to' end unless @issue.disabled_core_fields.include?('category_id') rows.left l(:field_category), h(@issue.category ? @issue.category.name : "-"), :class => 'category' end unless @issue.disabled_core_fields.include?('fixed_version_id') rows.left l(:field_fixed_version), (@issue.fixed_version ? link_to_version(@issue.fixed_version) : "-"), :class => 'fixed-version' end unless @issue.disabled_core_fields.include?('start_date') rows.right l(:field_start_date), format_date(@issue.start_date), :class => 'start-date' end unless @issue.disabled_core_fields.include?('due_date') rows.right l(:field_due_date), format_date(@issue.due_date), :class => 'due-date' end unless @issue.disabled_core_fields.include?('done_ratio') rows.right l(:field_done_ratio), progress_bar(@issue.done_ratio, :width => '80px', :legend => "#{@issue.done_ratio}%"), :class => 'progress' end unless @issue.disabled_core_fields.include?('estimated_hours') unless @issue.estimated_hours.nil? rows.right l(:field_estimated_hours), l_hours(@issue.estimated_hours), :class => 'estimated-hours' end end #if User.current.allowed_to?(:view_time_entries, @project) # rows.right l(:label_spent_time), (@issue.total_spent_hours > 0 ? link_to(l_hours(@issue.total_spent_hours), project_issue_time_entries_path(@project, @issue)) : "-"), :class => 'spent-time' #end end %> <%= render_custom_fields_rows(@issue) %> <%= call_hook(:view_issues_show_details_bottom, :issue => @issue) %> </table> <% if @issue.description? || @issue.attachments.any? -%> <hr /> <% if @issue.description? %> <div class="description"> <div class="contextual"> <%= link_to l(:button_quote), quoted_issue_path(@issue), :remote => true, :method => 'post', :class => 'icon icon-comment' if authorize_for('issues', 'edit') %> </div> <p><strong><%=l(:field_description)%></strong></p> <div class="wiki"> <%= textilizable @issue, :description, :attachments => @issue.attachments %> </div> </div> <% end %> <%= link_to_attachments @issue, :thumbnails => true %> <% end -%> <%= call_hook(:view_issues_show_description_bottom, :issue => @issue) %> <% if !@issue.leaf? || User.current.allowed_to?(:manage_subtasks, @project) %> <hr /> <div id="issue_tree"> <div class="contextual"> <%= link_to_new_subtask(@issue) if User.current.allowed_to?(:manage_subtasks, @project) %> </div> <p><strong><%=l(:label_subtask_plural)%></strong></p> <%= render_descendants_tree(@issue) unless @issue.leaf? %> </div> <% end %> <% if @relations.present? || User.current.allowed_to?(:manage_issue_relations, @project) %> <hr /> <div id="relations"> <%= render :partial => 'relations' %> </div> <% end %> </div> <% if @changesets.present? %> <div id="issue-changesets"> <h3><%=l(:label_associated_revisions)%></h3> <%= render :partial => 'changesets', :locals => { :changesets => @changesets} %> </div> <% end %> <% if @journals.present? %> <div id="history"> <h3><%=l(:label_history)%></h3> <%= render :partial => 'history', :locals => { :issue => @issue, :journals => @journals } %> </div> <% end %> <div style="clear: both;"></div> <%= render :partial => 'action_menu' %> <div style="clear: both;"></div> <% if @issue.editable? %> <div id="update" style="display:none;"> <h3><%= l(:button_edit) %></h3> <%= render :partial => 'edit' %> </div> <% end %> <% other_formats_links do |f| %> <%= f.link_to 'Atom', :url => {:key => User.current.rss_key} %> <%= f.link_to 'PDF' %> <% end %> <% html_title "#{@issue.tracker.name} ##{@issue.id}: #{@issue.subject}" %> <% content_for :sidebar do %> <%= render :partial => 'issues/sidebar' %> <% if User.current.allowed_to?(:add_issue_watchers, @project) || (@issue.watchers.present? && User.current.allowed_to?(:view_issue_watchers, @project)) %> <div id="watchers"> <%= render :partial => 'watchers/watchers', :locals => {:watched => @issue} %> </div> <% end %> <% end %> <% content_for :header_tags do %> <%= auto_discovery_link_tag(:atom, {:format => 'atom', :key => User.current.rss_key}, :title => "#{@issue.project} - #{@issue.tracker} ##{@issue.id}: #{@issue.subject}") %> <% end %> <%= context_menu issues_context_menu_path %> <% end %>
RE: How to view custom field is 2.000.000 - Added by Martin Denizet (redmine.org team member) about 10 years ago
I tested, the correct code is :
$('td.cf_1').html(format($('td.cf_1').html()));
Cheers,
RE: How to view custom field is 2.000.000 - Added by anhkhoa Michel about 10 years ago
Thank you very much. This code is true with show.html.erb. But with http://localhost:3000/projects/du-an-mua-sam-thiet-bi-2014/issues
I insert this code into file my_plugin\app\view\issue\index.html.erb This code cannot resovle proplem. When I ctrl +U. html is:<td class=\"cf_1 int style="text-align:right">2000000</td>
RE: How to view custom field is 2.000.000 - Added by Martin Denizet (redmine.org team member) about 10 years ago
I suggest you follow my advise to use the Custom JS plugin .
It should simply solve your problem without having to make a custom plugin overriding Redmine's many templates where you would need to inject JS.
RE: How to display links from custom, fields value - Added by Tomasz O about 10 years ago
Hi Martin,
I am attaching to this thread, because my problem is very similar.
I used your plugin, and code example to format my custom field.
I would like to have links for some external system.
My javascript code looks as below:
var formatMR = function(mrNumber){ var newText=null; if (mrNumber == null || mrNumber.length==0) { newText=""; } else { newText="<a href='some_http_address?txtMR="+mrNumber+"' target=_blank>" +mrNumber+"</a>"; } return (newText); }; $( document ).ready(function() { $('td.cf_5').html(formatMR($('td.cf_5').html())); });
Link is created fine, but unfortunatelly all rows in the table has the value of first row.
Only issue #44 should have value with link in the column "MR number"
Greetings,
Tomek
RE: How to display links from custom, fields value - Added by Tomasz O about 10 years ago
Answering to itself - it may be be usefull to someone else.
I got what I wanted with the following code:
var formatMR = function(mrNumber){ var newText=null; if (mrNumber == null || mrNumber.length==0) { newText=""; } else { newText="<a href='some_http_address?txtMR="+mrNumber+"' target=_blank>" +mrNumber+"</a>"; } return (newText); }; $( document ).ready(function() { // $('td.cf_5').html(formatMR($('td.cf_5').html())); //var ttable = document.getElementsByClassName("list issues"); //the above does not work for old IE, the below one is better var ttable = $( 'table.list'); for(var i=0; i<ttable[0].tBodies[0].rows.length; i+=1) { var rrow = ttable[0].tBodies[0].rows[i]; for(var j=0; j<rrow.cells.length; j+=1) { var ccell = rrow.cells[j]; if (ccell.className == "cf_5 string") { $(ccell).html(formatMR($(ccell).html())); } } } });
Next question is:
How to do the same on the Issue details form?
There is no class associated with custom fields.
Greetings,
Tomek
RE: How to view custom field is 2.000.000 - Added by Martin Denizet (redmine.org team member) about 10 years ago
Hi Tomek,
You can easily catch the custom fields with their id, for example for the custom field id=1:
id="issue_custom_field_values_1"
Cheers,
RE: How to view custom field is 2.000.000 - Added by anhkhoa Michel about 10 years ago
Hi Martin Denizet. Can you sent to me link download plugin import issue by excel for redmine 2.5.1
RE: How to view custom field is 2.000.000 - Added by Tomasz O about 10 years ago
Martin Denizet (redmine.org team member) wrote:
Hi Tomek,
You can easily catch the custom fields with their id, for example for the custom field id=1:
[...]Cheers,
Hi Martin,
Unfortunately table cells that keep values of custom fields do not have id, name or any other differentiator.
<tr>
...
<th>MR number:</th><td>mynumber</td>
</tr>
The id that you referenced is used in hidden form needed for updating record, and in fact the formatted value is put into the text field, but it is not what I wanted.
The only possibility that I can see at the moment is searching for table header with particular label in it (i.e. <th>MR number:</th>) and modify the value in corresponding <td></td> tags.
But maybe there is simpler method?
thanks
Tomek