Module: MegaBar::ApplicationHelper
- Defined in:
- app/helpers/mega_bar/application_helper.rb
Instance Method Summary collapse
- #block_action_interpreter(block) ⇒ Object
- #block_admin? ⇒ Boolean
- #block_help_links ⇒ Object
- #data_display_help_links(field) ⇒ Object
- #data_format_locals(mega_record, displayable_field, value = nil, mega_bar = nil?) ) ⇒ Object
- #field_class(d_f) ⇒ Object
- #field_help_links(field) ⇒ Object
- #field_wrapper(d_f) ⇒ Object
- #filter_contains ⇒ Object
- #layout_help_links ⇒ Object
- #layout_settings_header(layout = nil) ⇒ Object
- #link_path(action = nil, id = nil) ⇒ Object
- #mega_field_id(d_f) ⇒ Object
- #model_display_classnames ⇒ Object
- #model_display_collection_help_links ⇒ Object
- #model_display_help_links ⇒ Object
- #page_help_links ⇒ Object
- #param_from_tablename(model_props, tablename) ⇒ Object
- #param_separator(record) ⇒ Object
- #pre_render ⇒ Object
- #record_class(mega_record) ⇒ Object
- #record_id(mega_record) ⇒ Object
- #reorder_block_down(block) ⇒ Object
- #reorder_block_up(block) ⇒ Object
- #reorder_down(field, direction) ⇒ Object
- #reorder_up(field, direction) ⇒ Object
- #sortable(column, title = nil) ⇒ Object
Instance Method Details
#block_action_interpreter(block) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'app/helpers/mega_bar/application_helper.rb', line 198 def block_action_interpreter(block) case block.actions when 'show' "(used on show)" when 'sine' "(used on all displays)" when "current" "(uses current action)" else 'not sure when this block would be used' end end |
#block_admin? ⇒ Boolean
221 222 223 224 225 |
# File 'app/helpers/mega_bar/application_helper.rb', line 221 def block_admin? return false unless defined?(Devise) && user_signed_in? current_user.has_role?('Mega Role') session[:admin_blocks].include?(@block.id.to_s) end |
#block_help_links ⇒ Object
114 115 116 117 118 119 |
# File 'app/helpers/mega_bar/application_helper.rb', line 114 def block_help_links links = [] # links << ['/mega-bar/blocks/' + @block.id.to_s + '?return_to=' + request.env['PATH_INFO'], 'Model Displays for the "' + @block.name + '" Block'] if @block.name # links << ['/mega-bar/blocks/' + @block.id.to_s + '/edit', 'Edit Block'] links.map{ |l| link_to l[1], l[0], target: :_blank}.join(' | ') end |
#data_display_help_links(field) ⇒ Object
143 144 145 146 147 148 |
# File 'app/helpers/mega_bar/application_helper.rb', line 143 def data_display_help_links(field) links = [] links << [MegaBar::Engine.routes.url_for(controller: field[:data_format].controller_name, action: 'edit', id: field[:data_format].id, only_path: true) + '?return_to=' + request.env['PATH_INFO'], field[:field_display].format.capitalize + ' settings' ] # links << [MegaBar::Engine.routes.url_for(controller: '/mega_bar/' + field[:field_display].format.pluralize, action: 'edit', id: field[:data_format].id, :only_path=> true), 'Edit ' + field[:field_display].format.capitalize] links.map{ |l| link_to l[1], l[0], target: :_blank}.join(' | ') end |
#data_format_locals(mega_record, displayable_field, value = nil, mega_bar = nil?) ) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'app/helpers/mega_bar/application_helper.rb', line 184 def data_format_locals(mega_record, displayable_field, value=nil, =nil?) local = {obj: mega_record, displayable_field: displayable_field, field: displayable_field[:field], field_display: displayable_field[:field_display], options: displayable_field[:options], mega_bar: , value: value } if displayable_field[:data_format].present? local[displayable_field[:data_format].class.name.downcase.sub('::', '_').sub('megabar_', '').to_sym] = displayable_field[:data_format] else # Create empty data format object for the template if none exists format_name = displayable_field[:field_display].format.downcase.to_sym local[format_name] = {} end local end |
#field_class(d_f) ⇒ Object
11 12 13 14 15 16 |
# File 'app/helpers/mega_bar/application_helper.rb', line 11 def field_class(d_f) classes = [] classes << "format-#{d_f[:field_display].format}" classes << "#{d_f[:field].tablename}--#{d_f[:field].field}" classes.join(" ") end |
#field_help_links(field) ⇒ Object
136 137 138 139 140 141 142 |
# File 'app/helpers/mega_bar/application_helper.rb', line 136 def field_help_links(field) links = [] styleClass = field[:field].model.mega_model == 'mega' ? 'megaSetting' : '' links << ['/mega-bar/models/' + field[:field].model_id.to_s + '/fields/' + field[:field].id.to_s + '?return_to=' + request.env['PATH_INFO'], 'Field'] links << ['/mega-bar/field_displays/' + field[:field_display].id.to_s, 'Field Display'] links.map{ |l| link_to l[1], l[0], target: :_blank, class: styleClass}.join(' | ') end |
#field_wrapper(d_f) ⇒ Object
23 24 25 26 27 28 29 |
# File 'app/helpers/mega_bar/application_helper.rb', line 23 def field_wrapper(d_f) # byebug return 'td' if @mf.name =='ProfileTable' or @mf.name == 'GridHtml' return d_f[:field_display].wrapper if d_f[:field_display].wrapper.present? # note wrapper should be refactored to be just wrapper. @mf.field_wrapper end |
#filter_contains ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/helpers/mega_bar/application_helper.rb', line 84 def filter_contains # Get current filter value from session current_value = '' if session[:mega_filters] && session[:mega_filters][@kontroller_inst.to_sym] filters = session[:mega_filters][@kontroller_inst.to_sym] if filters['contains'] filters['contains'].each do |filter_hash| if filter_hash[@displayable_field[:field].field] current_value = filter_hash[@displayable_field[:field].field] break end end end end filterr = text_field_tag(param_from_tablename(@mega_model_properties, @displayable_field[:field].tablename) + "[" + @displayable_field[:field].field + "___filter]", current_value, size: 15 ) end |
#layout_help_links ⇒ Object
120 121 122 123 124 125 126 127 128 |
# File 'app/helpers/mega_bar/application_helper.rb', line 120 def layout_help_links links = [] # Only show Layout Settings link if user has admin permissions and is administering the page if defined?(Devise) && user_signed_in? && current_user.has_role?('Mega Role') && session[:admin_pages]&.include?(@mega_page[:page_id].to_s) links << ['/mega-bar/pages/' + @mega_page[:page_id].to_s + '/layouts/' + @mega_layout.id.to_s + '?return_to=' + request.env['PATH_INFO'], 'Layout Settings'] unless @mega_page.blank? end # links << ['/mega-bar/layouts/' + @mega_layout.id.to_s + '/edit', 'Edit Layout'] links.map{ |l| link_to l[1], l[0], target: :_blank}.join(' | ') end |
#layout_settings_header(layout = nil) ⇒ Object
211 212 213 214 215 |
# File 'app/helpers/mega_bar/application_helper.rb', line 211 def layout_settings_header(layout = nil) if layout.present? "<h2>Layout Sections</h2>".html_safe end end |
#link_path(action = nil, id = nil) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/helpers/mega_bar/application_helper.rb', line 69 def link_path(action = nil, id = nil) # application helper param_hash = {} @nested_ids.each do |param| param_hash = param_hash.merge(param) end param_hash = param_hash.merge(@p_params) param_hash[:action] = action param_hash[:id] = id if id param_hash[:controller] = params[:controller] url_for(param_hash) end |
#mega_field_id(d_f) ⇒ Object
18 19 20 21 |
# File 'app/helpers/mega_bar/application_helper.rb', line 18 def mega_field_id(d_f) data_format_id = d_f[:data_format]&.id || 'none' "fd-#{d_f[:field_display].id}-f-#{d_f[:field].id}-df-#{data_format_id}" end |
#model_display_classnames ⇒ Object
46 47 48 49 50 51 |
# File 'app/helpers/mega_bar/application_helper.rb', line 46 def model_display_classnames classnames = [] classnames << @mf.main_classname if @mf.main_classname.present? classnames << @mega_display[:model_display].classname if @mega_display[:model_display].classname.present? classnames.join(" ") end |
#model_display_collection_help_links ⇒ Object
109 110 111 112 113 |
# File 'app/helpers/mega_bar/application_helper.rb', line 109 def model_display_collection_help_links links = [] links << ['/mega-bar/model-display-collections/' + @mega_display[:collection_settings].id.to_s + '/edit?return_to=' + request.env['PATH_INFO'], 'Pagination Settings'] links.map{ |l| link_to l[1], l[0], target: :_blank }.join(' | ') end |
#model_display_help_links ⇒ Object
102 103 104 105 106 107 108 |
# File 'app/helpers/mega_bar/application_helper.rb', line 102 def model_display_help_links links = [] styleClass = @mega_display[:model_display].model.mega_model == 'mega' ? 'admin-links' : '' links << ['/mega-bar/model_displays/' + @mega_display[:model_display].id.to_s + '?return_to=' + request.env['PATH_INFO'], 'Field Displays for the "' + @mega_display[:model_display].header.to_s + '" model display'] # links << ['/mega-bar/model_displays/' + @mega_display[:model_display].id.to_s + '/edit' , 'Edit Model Display'] links.map{ |l| link_to l[1], l[0], target: :_blank, class: styleClass}.join(' | ') end |
#page_help_links ⇒ Object
129 130 131 132 133 134 135 |
# File 'app/helpers/mega_bar/application_helper.rb', line 129 def page_help_links links = [] styleClass = @mega_page[:page_path].starts_with?('/mega-bar/') ? 'megaSetting' : '' links << ['/mega-bar/pages/' + @mega_page[:page_id].to_s + '?return_to=' + request.env['PATH_INFO'], 'Layouts on the "' + @mega_page[:name] + '" Page'] links << ['/mega-bar/pages/' + @mega_page[:page_id].to_s + '/edit/', 'Edit Page'] links.map{ |l| link_to l[1], l[0], target: :_blank, class: "#{styleClass} admin-links"}.join(' <span class="admin-links">|</span> ') end |
#param_from_tablename(model_props, tablename) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/helpers/mega_bar/application_helper.rb', line 53 def param_from_tablename(model_props, tablename) # used in data_display stuff. but might could be replaced with env[:mega_env] stuff # if tablename starts with the module from the model_props, then chop it. # else just use it and hope for the best. # Joining to foreign modules not supported and what will happen is forms won't save if the table # additional possible logic: # else if you can find that the table couldn't be namespaced, then use that # elseif theres a module out there for it use it #todo: # else use as is.... prefix = model_props.modyule.nil? || model_props.modyule.empty? ? '8675309' : model_props.modyule.split('::').map { | m | m.underscore }.join('_') + '_' tablename.start_with?(prefix) ? tablename[prefix.size..-1].singularize : tablename.singularize end |
#param_separator(record) ⇒ Object
217 218 219 |
# File 'app/helpers/mega_bar/application_helper.rb', line 217 def param_separator(record) link_path('move', record.id).include?('?') ? '&' : '?' end |
#pre_render ⇒ Object
82 83 |
# File 'app/helpers/mega_bar/application_helper.rb', line 82 def pre_render end |
#record_class(mega_record) ⇒ Object
3 4 5 |
# File 'app/helpers/mega_bar/application_helper.rb', line 3 def record_class(mega_record) mega_record.class.to_s.downcase + '-record' end |
#record_id(mega_record) ⇒ Object
7 8 9 |
# File 'app/helpers/mega_bar/application_helper.rb', line 7 def record_id(mega_record) mega_record.class.to_s.downcase + '-record-' + mega_record.id.to_s if mega_record.id.present? end |
#reorder_block_down(block) ⇒ Object
175 176 177 178 179 180 181 182 |
# File 'app/helpers/mega_bar/application_helper.rb', line 175 def reorder_block_down(block) return '' if @layable.layout_section.blocks.last.position == block.position links = [] arrow = 'v' links << ["/mega-bar/blocks/move/#{block.id}?method=move_lower&return_to=" + request.env['PATH_INFO'] , arrow] links.map { |l| link_to l[1], l[0], {data: { turbolinks: false }, class: 'admin-links'}}.join(' | ') end |
#reorder_block_up(block) ⇒ Object
166 167 168 169 170 171 172 173 |
# File 'app/helpers/mega_bar/application_helper.rb', line 166 def reorder_block_up(block) return '' if @layable.layout_section.blocks.first.position == block.position links = [] arrow = '^' links << ["/mega-bar/blocks/move/#{block.id}?method=move_higher&return_to=" + request.env['PATH_INFO'] , arrow] links.map { |l| link_to l[1], l[0], {data: { turbolinks: false }, class: 'admin-links'}}.join(' | ') end |
#reorder_down(field, direction) ⇒ Object
157 158 159 160 161 162 163 164 |
# File 'app/helpers/mega_bar/application_helper.rb', line 157 def reorder_down(field, direction) # return '' unless @authorizations[:block_administrator] return '' if @mega_display[:displayable_fields].last[:field_display].position == field[:field_display].position links = [] arrow = direction == 'right' ? '->' : 'v' links << ["/mega-bar/field_displays/move/#{field[:field_display].id}?method=move_lower&return_to=" + request.env['PATH_INFO'] , arrow] links.map{ |l| link_to l[1], l[0], {data: { turbolinks: false }, class: 'admin-links'}}.join(' | ') end |
#reorder_up(field, direction) ⇒ Object
149 150 151 152 153 154 155 156 |
# File 'app/helpers/mega_bar/application_helper.rb', line 149 def reorder_up(field, direction) # return '' unless @authorizations[:block_administrator] return '' if @mega_display[:displayable_fields].first[:field_display].position == field[:field_display].position links = [] arrow = direction == 'left' ? '<-' : '^' links << ["/mega-bar/field_displays/move/#{field[:field_display].id}?method=move_higher&return_to=" + request.env['PATH_INFO'], arrow] links.map{ |l| link_to l[1], l[0], {data: { turbolinks: false }, class: 'admin-links'}}.join(' | ') end |
#sortable(column, title = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/helpers/mega_bar/application_helper.rb', line 31 def sortable(column, title=nil) #422pm. return title if !params[:id].blank? title ||= column.titleize css_class = column == sort_column(@mega_class, @mega_model_properties, params) ? 'current ' + sort_direction(params, @mega_model_properties) : nil direction = column == sort_column(@mega_class, @mega_model_properties, params) && sort_direction(params, @mega_model_properties) == 'asc' ? 'desc' : 'asc' hsh = {sort: column, direction: direction} action = !['show', 'index'].include?(@mega_rout[:action]) ? "/#{@mega_rout[:action]}" : '' path = url_for([*@nested_instance_variables, @kontroller_inst.pluralize.to_sym ]) + action + '?' + hsh.to_param link_to title, path, class: css_class # link_to title, hsh, class: css_class # link_to best_in_place sort_column, title, {:sort => column, :direction => direction, controller: @kontroller_path}, class: css_class end |