Module: EffectiveLoggingHelper
- Included in:
- Effective::Datatables::Logs
- Defined in:
- app/helpers/effective_logging_helper.rb
Constant Summary collapse
- ALLOWED_TAGS =
ActionView::Base..to_a + ['table', 'thead', 'tbody', 'tfoot', 'tr', 'td', 'th']
- ALLOWED_ATTRIBUTES =
ActionView::Base.sanitized_allowed_attributes.to_a + ['colspan', 'rowspan']
Instance Method Summary collapse
- #bootstrap_class_for_status(status) ⇒ Object
-
#effective_logging_object_link_to(obj, action = :show) ⇒ Object
This is called on the Logs#show Admin page, and is intended for override by the application.
- #format_log_details_value(value) ⇒ Object
- #parents_of_log(log) ⇒ Object
- #render_log(log) ⇒ Object
-
#tableize_hash(hash, options = {}) ⇒ Object
Call me with :th => true, :sub_th => false Any other options are sent to the table tag.
Instance Method Details
#bootstrap_class_for_status(status) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'app/helpers/effective_logging_helper.rb', line 5 def bootstrap_class_for_status(status) case status when 'success' ; 'success' when 'info' ; 'info' when 'warning' ; 'warning' when 'error' ; 'danger' else 'primary' end end |
#effective_logging_object_link_to(obj, action = :show) ⇒ Object
This is called on the Logs#show Admin page, and is intended for override by the application
51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/helpers/effective_logging_helper.rb', line 51 def effective_logging_object_link_to(obj, action = :show) if obj.kind_of?(User) return ( if action == :show && defined?(admin_user_path) link_to('View', admin_user_path(obj)) elsif action == :edit && defined?(edit_admin_user_path) link_to('Edit', edit_admin_user_path(obj)) end ) end end |
#format_log_details_value(value) ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'app/helpers/effective_logging_helper.rb', line 63 def format_log_details_value(value) if value.kind_of?(Hash) tableize_hash(value, :class => 'table', :style => 'width: 50%', :th => true) elsif value.kind_of?(Array) value.map { |value| simple_format(sanitize(value.to_s, :tags => ALLOWED_TAGS, :attributes => ALLOWED_ATTRIBUTES), {}, :sanitize => false) }.join('').html_safe else simple_format(sanitize(value.to_s, :tags => ALLOWED_TAGS, :attributes => ALLOWED_ATTRIBUTES), {}, :sanitize => false) end end |
#parents_of_log(log) ⇒ Object
19 20 21 22 23 |
# File 'app/helpers/effective_logging_helper.rb', line 19 def parents_of_log(log) parents = [log.parent] parents << parents.last.parent while(parents.last.try(:parent_id).present?) parents.compact.reverse end |
#render_log(log) ⇒ Object
15 16 17 |
# File 'app/helpers/effective_logging_helper.rb', line 15 def render_log(log) render(:partial => 'effective/logs/log', :locals => {:log => log}) end |
#tableize_hash(hash, options = {}) ⇒ Object
Call me with :th => true, :sub_th => false Any other options are sent to the table tag
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/helpers/effective_logging_helper.rb', line 27 def tableize_hash(hash, = {}) if hash.present? && hash.kind_of?(Hash) content_tag(:table, ) do hash.map do |k, v| content_tag(:tr) do content_tag(([:th] ? :th : :td), k) + content_tag(:td) do if v.kind_of?(Hash) tableize_hash(v, .merge({:class => 'table table-bordered', :th => (.key?(:sub_th) ? [:sub_th] : [:th])})) elsif v.kind_of?(Array) '[' + v.join(', ') + ']' else v end end end end.join('').html_safe end.html_safe else hash.to_s.html_safe end end |