Module: ApplicationHelper

Included in:
ApplicationController, ControlsController, DashboardController, EvidenceController, EvidenceHelper, NavigationController, ProgramsController, SectionsController, TestingController, TestreportController
Defined in:
app/helpers/application_helper.rb

Defined Under Namespace

Classes: ProjectModule

Constant Summary

ADMIN_MODULES =
%w(accounts biz_processes business_areas cycles sections controls documents document_descriptors programs people systems)
WORKFLOW_MODULES =
%w(programs_dash controls dashboard evidence testing testreport)

Instance Method Summary (collapse)

Instance Method Details

- (Object) access_control_roles

Roles



25
26
27
# File 'app/helpers/application_helper.rb', line 25

def access_control_roles
  [:superuser, :admin, :analyst, :guest]
end

- (Object) admin_project_modules

The set of modules shown as tabs on the admin application page (aka admin pages)



20
21
22
# File 'app/helpers/application_helper.rb', line 20

def admin_project_modules
  ADMIN_MODULES.map { |id| ProjectModule.new(id.humanize, url_for({:controller => "/admin/" + id, :only_path => true})) }
end

- (Object) display_compact(model, object, prop)

Display a compact version of an object property



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

def display_compact(model, object, prop)
  value = object.send(prop.name)
  if prop.name == :modified_by
    author = Account.find(value)
    link_to author.display_name, url_for(author)
  elsif prop.name.to_s.end_with?('_id')
    relation = prop.name.to_s.sub(/_id$/, '').to_sym
    other = model.relationships[relation].parent_model.find(value)
    if other
      link_to other.display_name, url_for(other)
    else
      "-"
    end
  elsif value.is_a? DateTime
    display_time(value)
  else
    value
  end
end

- (Object) display_time(time)

Default time display (localize at some point)



103
104
105
# File 'app/helpers/application_helper.rb', line 103

def display_time(time)
  time.strftime("%Y-%m-%d %H:%M") rescue "-"
end

- (Object) equal_ids(ids, objects)

Check if the set of ids coming from a form is already equal to the set of objects in an association.

This is important for versioning so that we don't create a no-change versions.



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

def equal_ids(ids, objects)
  return (ids.map {|x| x.to_i}).sort == (objects.map {|x| x.id}).sort
end

- (Object) filter_biz_processes(collection)

Filter Biz Processes by slug and/or the program of their attached controls.

This is used for the respective filtering widgets. The widgets store their state in the session.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/helpers/application_helper.rb', line 70

def filter_biz_processes(collection)
  co_search = {}
  unless session[:slugfilter].blank?
    co_search[:slug.like] = "#{session[:slugfilter]}%"
  end

  if session[:program_id]
    @program = Program.find(session[:program_id])
    co_search[:program_id] = @program
  end

  return collection.where({}) if co_search.empty?
  return collection.
    joins(:biz_process_sections => :section).
    where(:biz_process_sections => { :sections => co_search})
end

- (Object) filter_system_controls(collection)

Filter SystemControl relationship objects by slug and/or program.

This is used for the respective filtering widgets. The widgets store their state in the session.



33
34
35
36
37
38
39
40
41
42
43
# File 'app/helpers/application_helper.rb', line 33

def filter_system_controls(collection)
  collection = collection.slugfilter(session[:slugfilter])
  if session[:program_id]
    @program = Program.find(session[:program_id])
    collection = collection.
      joins(:control).
      where({:control => { :program_id => @program.id }})
  end

  return collection
end

- (Object) filter_systems(collection)

Filter Systems by slug and/or the program of their attached controls.

This is used for the respective filtering widgets. The widgets store their state in the session.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/helpers/application_helper.rb', line 49

def filter_systems(collection)
  control_search = {}
  unless session[:slugfilter].blank?
    control_search[:slug.like] = "#{session[:slugfilter]}%"
  end

  if session[:program_id]
    @program = Program.find(session[:program_id])
    control_search[:program_id] = @program
  end

  return collection if control_search.empty?
  return collection.
    joins(:system_controls => :control).
    where(:system_controls => {:controls => control_search})
end

- (Object) mat(sym1, sym2)

Shorthand humanized text for admin pages



98
99
100
# File 'app/helpers/application_helper.rb', line 98

def mat(sym1, sym2)
  sym2.to_s.humanize
end

- (Object) mt(sym)

Shorthand humanized text for admin pages



93
94
95
# File 'app/helpers/application_helper.rb', line 93

def mt(sym)
  sym.to_s.humanize
end

- (Object) pat(sym)

Shorthand humanized text for admin pages



88
89
90
# File 'app/helpers/application_helper.rb', line 88

def pat(sym)
  sym.to_s.humanize
end

- (Object) program_display(program)

Display of program type



108
109
110
# File 'app/helpers/application_helper.rb', line 108

def program_display(program)
  program.company? ? 'Company' : 'Program'
end

- (Object) project_modules

The set of modules shown as tabs on the main application page (aka workflow pages)



15
16
17
# File 'app/helpers/application_helper.rb', line 15

def project_modules
  WORKFLOW_MODULES.map { |id| ProjectModule.new(id.humanize, url_for({:controller => "/" + id, :only_path => true})) }
end

- (Object) render_for(tag, opts = {})



112
113
114
115
116
# File 'app/helpers/application_helper.rb', line 112

def render_for(tag, opts = {})
  content_for tag do
    render opts
  end
end

- (Object) typecast_params(params, model)

Typecast form parameters into the right primitive to work around a DataMapper dirty-detection bug.

If we don't do this, the persistence layer thinks all non-strings params are modifications where in fact we might just have changed false => 0, which is a no-op. This is important for versioning so we don't create no-change versions when nothing was changed.



151
152
153
154
155
156
157
158
159
160
161
# File 'app/helpers/application_helper.rb', line 151

def typecast_params(params, model)
  results = {}
  params.each do |key, value|
    property = model.properties[key.to_sym]
    if property && property.respond_to?(:typecast)
      value = property.typecast(value)
    end
    results[key] = value
  end
  results
end

- (Object) yield_content!(name)

Use instead of 'yield :name' or 'content_for(:name)' in layouts for partials. References: http://mikemayo.org/2012/rendering-a-collection-of-partials-with-content_for https://gist.github.com/rails/rails/pull/4226



167
168
169
# File 'app/helpers/application_helper.rb', line 167

def yield_content!(name)
  view_flow.content.delete(name)
end