Module: RedmineExtensions::ApplicationHelper

Includes:
RenderingHelper
Defined in:
app/helpers/redmine_extensions/application_helper.rb

Defined Under Namespace

Classes: EasyBoxRenderer

Instance Method Summary collapse

Methods included from RenderingHelper

#query_outputs, #render_with_fallback

Instance Method Details

#autocomplete_field_tag(name, jsonpath_or_array, selected_values, options = {}) ⇒ Object



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'app/helpers/redmine_extensions/application_helper.rb', line 209

def autocomplete_field_tag(name, jsonpath_or_array, selected_values, options = {})
  options.reverse_merge!({select_first_value: false, show_toggle_button: false, load_immediately: false, preload: true})
  options[:id] ||= sanitize_to_id(name)

  selected_values ||= []

  if jsonpath_or_array.is_a?(Array)
    source = jsonpath_or_array.to_json
  else
    source = "'#{jsonpath_or_array}'"
  end

  (:span, :class => 'easy-multiselect-tag-container') do
    text_field_tag('', '', (options[:html_options] || {}).merge(id: options[:id])) +
      javascript_tag("$('##{options[:id]}').easymultiselect({multiple: true, rootElement: #{options[:rootElement].to_json}, inputName: '#{name}', preload: #{options[:preload]}, source: #{source}, selected: #{selected_values.to_json}, show_toggle_button: #{options[:show_toggle_button]}, select_first_value: #{options[:select_first_value]}, load_immediately: #{options[:load_immediately]}, autocomplete_options: #{(options[:jquery_auto_complete_options]||{}).to_json} });")
  end
end

#detect_hide_elements(uniq_id, user = nil, default = true) ⇒ Object

hide elements for issues and users



33
34
35
36
# File 'app/helpers/redmine_extensions/application_helper.rb', line 33

def detect_hide_elements(uniq_id, user = nil, default = true)
  return ''.html_safe if uniq_id.blank?
  return 'style="display:none"'.html_safe if !toggle_button_expanded?(uniq_id, user, default)
end

#entity_css_icon(entity_or_entity_class) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/helpers/redmine_extensions/application_helper.rb', line 93

def entity_css_icon(entity_or_entity_class)
  return '' if entity_or_entity_class.nil?

  if entity_or_entity_class.is_a?(Class) && entity_or_entity_class.respond_to?(:css_icon)
    entity_or_entity_class.css_icon
  elsif entity_or_entity_class.is_a?(ActiveRecord::Base)
    if entity_or_entity_class.respond_to?(:css_icon)
      entity_or_entity_class.css_icon
    elsif entity_or_entity_class.class.respond_to?(:css_icon)
      entity_or_entity_class.class.css_icon
    else
      "icon icon-#{entity_or_entity_class.class.name.dasherize}"
    end
  else
    "icon icon-#{entity_or_entity_class.class.name.dasherize}"
  end
end

#plugin_settings_path(plugin, *attrs) ⇒ Object

——-= Hack methods =——



7
8
9
10
11
12
13
# File 'app/helpers/redmine_extensions/application_helper.rb', line 7

def plugin_settings_path(plugin, *attrs)
  if plugin.is_a?(Redmine::Plugin) && (plugin.settings[:only_easy] || plugin.settings[:easy_settings])
    edit_easy_setting_path(plugin, *attrs)
  else
    super
  end
end

#present(model, options = {}, &block) ⇒ Object

——-= Rendering and presenting methods =——-



17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/helpers/redmine_extensions/application_helper.rb', line 17

def present(model, options={}, &block)
  if model.is_a?(RedmineExtensions::BasePresenter)
    presenter = model.update_options(options.merge(view_context: self))
  else
    presenter = RedmineExtensions::BasePresenter.present(model, self, options)
  end
  if block_given?
    yield presenter
  else
    presenter
  end
end

#query_for_entity(entity_class) ⇒ Object



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

def query_for_entity(entity_class)
  entity_class_name = entity_class.name
  query_class = "Easy#{entity_class_name}Query".constantize rescue nil
  return query_class if query_class && query_class < EasyQuery
  query_class ||= "#{entity_class_name}Query".constantize rescue nil
end

#render_entity_assignments(entity, target_entity, options = {}, &block) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/helpers/redmine_extensions/application_helper.rb', line 54

def render_entity_assignments(entity, target_entity, options = {}, &block)
  options ||= {}
  collection_name = options.delete(:collection_name) || target_entity.name.pluralize.underscore
  query_class = query_for_entity(target_entity)

  return '' if !query_class || !entity.respond_to?(collection_name)

  project = options.delete(:project)

  query = query_class.new(:name => 'c_query')
  query.project = project
  query.set_entity_scope(entity, collection_name)
  query.column_names = options[:query_column_names] unless options[:query_column_names].blank?

  entities = query.entities

  entities_count = entities.size
  options[:entities_count] = entities_count
  options[:module_name] ||= "entity_#{entity.class.name.underscore}_#{entity.id}_#{collection_name}"
  options[:heading] ||= l("label_#{query.entity}_plural", :default => 'Heading')

  if options[:context_menus_path].nil?
    options[:context_menus_path] = [
      "context_menu_#{collection_name}_path".to_sym,
      "context_menus_#{collection_name}_path".to_sym,
      "#{collection_name}_context_menu_path".to_sym
    ].detect do |m|
      m if respond_to?(m)
    end
  end

  query.output = options[:display_style] || (entities_count > 3 ? 'list' : 'tile')

  render(:partial => 'easy_entity_assignments/assignments_container', :locals => {
    :entity => entity,
    :query => query, :project => project,
    :entities => entities, :entities_count => entities_count, :options => options})
end

#render_module_easy_box(id, heading, options = {}, &block) ⇒ Object

Options

  • class: Hash or String - This option can be used to add custom CSS classes. It can be String or Hash.

    class: {heading: 'heading-additional-css', container: 'container-additional-css'}
    
  • heading_tag: name of HTML element of module heading - By default its its h3

** Aliases for this options are: wrapping_heading_element, header_tag

  • toggle: false - This disable toggle function (collapsible and remember)

** Aliases for this options are: collapsible, no_expander

  • remember: false - This disable remember function of toggle container

** Aliases for this options are: ajax_call



122
123
124
125
126
127
128
129
130
131
# File 'app/helpers/redmine_extensions/application_helper.rb', line 122

def render_module_easy_box(id, heading, options = {}, &block) # with fallback to old
  options[:toggle] = true unless options.key?(:toggle)
  options[:remember] = options.delete(:ajax_call) if options.key?(:ajax_call)
  options[:collapsible] = !options.delete(:no_expander) if options.key?(:no_expander)

  renderer = EasyBoxRenderer.new(self, id, heading, options)
  renderer.content = capture {yield renderer}

  renderer.render
end

#url_to_entity(entity, options = {}) ⇒ Object



38
39
40
41
42
43
44
45
# File 'app/helpers/redmine_extensions/application_helper.rb', line 38

def url_to_entity(entity, options={})
  m = "url_to_#{entity.class.name.underscore}".to_sym
  if respond_to?(m)
    send(m, entity, options)
  else
    nil
  end
end