Module: TimelogHelper

Includes:
ApplicationHelper
Included in:
TimelogController
Defined in:
app/helpers/timelog_helper.rb

Overview

Redmine - project management software Copyright © 2006-2022 Jean-Philippe Lang

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Constant Summary

Constants included from ApplicationHelper

ApplicationHelper::ATTACHMENT_CONTAINER_LINK, ApplicationHelper::HEADING_RE, ApplicationHelper::LINKS_RE, ApplicationHelper::MACROS_RE, ApplicationHelper::MACRO_SUB_RE, ApplicationHelper::RECORD_LINK, ApplicationHelper::TOC_RE

Instance Method Summary collapse

Methods included from ApplicationHelper

#accesskey, #actions_dropdown, #anchor, #api_meta, #authoring, #authorize_for, #back_url_hidden_field_tag, #body_css_classes, #breadcrumb, #bulk_edit_error_messages, #calendar_for, #cancel_button_tag, #catch_macros, #check_all_links, #checked_image, #context_menu, #copy_object_url_link, #default_search_project_scope, #delete_link, #due_date_distance_in_words, #email_delivery_enabled?, #error_messages_for, #export_csv_encoding_select_tag, #favicon, #favicon_path, #favicon_url, #form_tag_html, #format_activity_day, #format_activity_description, #format_activity_title, #format_changeset_comments, #format_object, #format_version_name, #get_tab_action, #heads_for_auto_complete, #html_hours, #html_title, #image_tag, #include_calendar_headers_tags, #include_in_api_response?, #inject_macros, #javascript_heads, #javascript_include_tag, #labelled_fields_for, #labelled_form_for, #lang_options_for_select, #link_to_attachment, #link_to_attachment_container, #link_to_context_menu, #link_to_function, #link_to_group, #link_to_if_authorized, #link_to_issue, #link_to_message, #link_to_month, #link_to_next_month, #link_to_previous_month, #link_to_principal, #link_to_project, #link_to_project_settings, #link_to_record, #link_to_revision, #link_to_user, #link_to_version, #markdown_formatter, #option_tag, #other_formats_links, #page_header_title, #parse_headings, #parse_hires_images, #parse_inline_attachments, #parse_non_pre_blocks, #parse_redmine_links, #parse_sections, #parse_wiki_links, #principals_check_box_tags, #principals_options_for_select, #progress_bar, #project_tree, #project_tree_options_for_select, #projects_for_jump_box, #raw_json, #render_error_messages, #render_flash_messages, #render_if_exist, #render_page_hierarchy, #render_project_jump_box, #render_project_nested_lists, #render_projects_for_jump_box, #render_tabs, #reorder_handle, #replace_toc, #robot_exclusion_tag, #sanitize_anchor_name, #sidebar_content?, #simple_format_without_paragraph, #stylesheet_link_tag, #syntax_highlight, #syntax_highlight_lines, #textilizable, #thumbnail_tag, #time_tag, #title, #to_path_param, #toggle_checkboxes_link, #toggle_link, #truncate_lines, #truncate_single_line_raw, #update_data_sources_for_auto_complete, #view_layouts_base_sidebar_hook_response, #wiki_page_path

Methods included from Redmine::Helpers::URL

#uri_with_link_safe_scheme?, #uri_with_safe_scheme?

Methods included from Redmine::Hook::Helper

#call_hook

Methods included from Redmine::Themes::Helper

#current_theme, #heads_for_theme

Methods included from Redmine::SudoMode::Helper

#hash_to_hidden_fields

Methods included from Redmine::Pagination::Helper

#pagination_links_each, #pagination_links_full, #per_page_links, #per_page_options

Methods included from Redmine::I18n

#current_language, #day_letter, #day_name, #find_language, #format_date, #format_hours, #format_time, included, #l, #l_hours, #l_hours_short, #l_or_humanize, #languages_options, #ll, #lu, #month_name, #set_language_if_valid, #valid_languages

Methods included from Redmine::WikiFormatting::Macros::Definitions

#exec_macro, #extract_macro_options, #macro_exists?

Instance Method Details

#activity_collection_for_select_options(time_entry = nil, project = nil) ⇒ Object

Returns a collection of activities for a select field. time_entry is optional and will be used to check if the selected TimeEntryActivity is active.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/helpers/timelog_helper.rb', line 26

def activity_collection_for_select_options(time_entry=nil, project=nil)
  project ||= time_entry.try(:project)
  project ||= @project
  if project.nil?
    activities = TimeEntryActivity.shared.active
  else
    activities = project.activities
  end

  collection = []
  if time_entry && time_entry.activity && !time_entry.activity.active?
    collection << ["--- #{l(:actionview_instancetag_blank_option)} ---", '']
  else
    unless activities.detect(&:is_default)
      collection << ["--- #{l(:actionview_instancetag_blank_option)} ---", '']
    end
  end
  activities.each {|a| collection << [a.name, a.id]}
  collection
end

#cancel_button_tag_for_time_entry(project) ⇒ Object



141
142
143
144
# File 'app/helpers/timelog_helper.rb', line 141

def cancel_button_tag_for_time_entry(project)
  fallback_path = project ? project_time_entries_path(project) : time_entries_path
  cancel_button_tag(fallback_path)
end

#format_criteria_value(criteria_options, value, html = true) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/helpers/timelog_helper.rb', line 71

def format_criteria_value(criteria_options, value, html=true)
  if value.blank?
    "[#{l(:label_none)}]"
  elsif k = criteria_options[:klass]
    obj = k.find_by_id(value.to_i)
    if obj.is_a?(Issue)
      if obj.visible?
        html ? link_to_issue(obj) : "#{obj.tracker} ##{obj.id}: #{obj.subject}"
      else
        "##{obj.id}"
      end
    else
      format_object(obj, html)
    end
  elsif cf = criteria_options[:custom_field]
    format_value(value, cf)
  else
    value.to_s
  end
end

#report_criteria_to_csv(csv, available_criteria, columns, criteria, periods, hours, level = 0) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'app/helpers/timelog_helper.rb', line 119

def report_criteria_to_csv(csv, available_criteria, columns, criteria, periods, hours, level=0)
  hours.collect {|h| h[criteria[level]].to_s}.uniq.each do |value|
    hours_for_value = select_hours(hours, criteria[level], value)
    next if hours_for_value.empty?

    row = [''] * level
    row << format_criteria_value(available_criteria[criteria[level]], value, false).to_s
    row += [''] * (criteria.length - level - 1)
    total = 0
    periods.each do |period|
      sum = sum_hours(select_hours(hours_for_value, columns, period.to_s))
      total += sum
      row << (sum > 0 ? sum : '')
    end
    row << total
    csv << row
    if criteria.length > level + 1
      report_criteria_to_csv(csv, available_criteria, columns, criteria, periods, hours_for_value, level + 1)
    end
  end
end

#report_to_csv(report) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'app/helpers/timelog_helper.rb', line 92

def report_to_csv(report)
  Redmine::Export::CSV.generate(:encoding => params[:encoding]) do |csv|
    # Column headers
    headers =
      report.criteria.collect do |criteria|
        l_or_humanize(report.available_criteria[criteria][:label])
      end
    headers += report.periods
    headers << l(:label_total_time)
    csv << headers
    # Content
    report_criteria_to_csv(csv, report.available_criteria, report.columns,
                           report.criteria, report.periods, report.hours)
    # Total row
    str_total = l(:label_total_time)
    row = [str_total] + [''] * (report.criteria.size - 1)
    total = 0
    report.periods.each do |period|
      sum = sum_hours(select_hours(report.hours, report.columns, period.to_s))
      total += sum
      row << (sum > 0 ? sum : '')
    end
    row << total
    csv << row
  end
end

#select_hours(data, criteria, value) ⇒ Object



55
56
57
58
59
60
61
# File 'app/helpers/timelog_helper.rb', line 55

def select_hours(data, criteria, value)
  if value.to_s.empty?
    data.select {|row| row[criteria].blank?}
  else
    data.select {|row| row[criteria].to_s == value.to_s}
  end
end

#sum_hours(data) ⇒ Object



63
64
65
66
67
68
69
# File 'app/helpers/timelog_helper.rb', line 63

def sum_hours(data)
  sum = 0
  data.each do |row|
    sum += row['hours'].to_f
  end
  sum
end

#user_collection_for_select_options(time_entry) ⇒ Object



47
48
49
50
51
52
53
# File 'app/helpers/timelog_helper.rb', line 47

def user_collection_for_select_options(time_entry)
  collection = time_entry.assignable_users
  if time_entry.user && !collection.include?(time_entry.user)
    collection << time_entry.user
  end
  principals_options_for_select(collection, time_entry.user_id.to_s)
end