Module: Workbench::NavigationHelper
- Defined in:
- app/helpers/workbench/navigation_helper.rb
Overview
Methods for 1) generating paths; or 2) generating links For helper methods that return individual instances based on some parameters see corresponding helpers.
Constant Summary collapse
- NO_NEW_FORMS =
%w{Confidence Attribution ObservationMatrixRowItem ObservationMatrixColumnItem ObservationMatrixRow ObservationMatrixColumn Note Tag Citation Identifier DataAttribute AlternateValue TaxonNameClassification GeographicArea ContainerItem ProtocolRelationship Download}.freeze
- NOT_DATA_PATHS =
%w{/project /administration /user}.freeze
Instance Method Summary collapse
- #a_to_z_links(targets = []) ⇒ Object
- #batch_load_link ⇒ Object
- #class_navigation_json(klass) ⇒ Object
- #destroy_object_link(object) ⇒ Object
- #download_for_model_link(model) ⇒ Object
- #download_path_for_model(model) ⇒ Object
-
#edit_object_link(object) ⇒ Object
return [A tag, nil] a link, or disabled link.
- #edit_object_path(object) ⇒ Object
-
#edit_object_path_string(object) ⇒ Object
Determine wether an edit or destroy route exists Custom routes can be added per Class by adding a corresponding ‘_string` postfixed method.
- #forward_back_links(instance) ⇒ Object
-
#has_route_for_edit?(object) ⇒ Boolean
return [Boolean] true if there is a route to edit for the object (some objects are not editable, like Tags).
- #list_for_model_link(model) ⇒ Object
- #list_path_for_model(model) ⇒ Object
- #new_for_model_link(model) ⇒ Object
- #new_path_for_model(model) ⇒ Object
-
#next_link(instance, text: 'Next', target: nil) ⇒ Object
Used in show/REST A next record link.
-
#object_home_link(object) ⇒ Object
If a “home” is provided, use it instead of show link See also over ride in object_link - which we might need to merge.
- #object_link(object) ⇒ Object
- #on_workbench? ⇒ Boolean
-
#previous_link(instance, text: 'Previous', target: nil) ⇒ Object
Used in show/REST A previous record link.
- #quick_bar ⇒ Object
- #quick_bar_link(related_model) ⇒ Object
- #radial_navigation_tag(object, teleport = nil) ⇒ Object
- #recent_route_link(hsh) ⇒ Object
-
#related_data_link_tag(object) ⇒ <a> tag?
A link to the related data page.
- #safe_object_from_attributes(hsh) ⇒ Object
- #slideout_clipboard ⇒ Object
- #slideout_pdf_viewer ⇒ Object
- #slideout_pinboard ⇒ Object
- #slideout_recent ⇒ Object
-
#slideouts ⇒ Object
Slideout panels.
- #task_bar ⇒ Object
- #title_tag ⇒ Object
Instance Method Details
#a_to_z_links(targets = []) ⇒ Object
280 281 282 283 284 285 286 287 |
# File 'app/helpers/workbench/navigation_helper.rb', line 280 def a_to_z_links(targets = []) letters = targets.empty? ? ('A'..'Z') : ('A'..'Z').to_a & targets content_tag(:div, class: 'navigation-bar-left', id: 'alphabet_nav') do content_tag(:ul, class: 'left_justified_navbar context-menu') do letters.collect{|l| content_tag(:li, link_to("#{l}", "\##{l}")) }.join.html_safe end end end |
#batch_load_link ⇒ Object
235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'app/helpers/workbench/navigation_helper.rb', line 235 def batch_load_link content = safe_join([ content_tag(:span, '', class: 'icon', data: { icon: 'batch' }), 'Batch load'], '') if self.controller.respond_to?(:batch_load) link_to(content, { action: :batch_load, controller: self.controller_name }) else content_tag(:span, content, class: 'disabled') end end |
#class_navigation_json(klass) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/helpers/workbench/navigation_helper.rb', line 12 def (klass) k = klass b = {} %w{new edit home}.each do |t| if OBJECT_RADIALS[k] if c = OBJECT_RADIALS[k][t] b[t] = send(OBJECT_RADIALS[k][t] + '_path') end end end return { klass: k, id: k.tableize.singularize + '_id', tasks: OBJECT_RADIALS[k]['tasks'].inject({}){|hsh, t| hsh[t] = send(t + '_path'); hsh }, base: b } end |
#destroy_object_link(object) ⇒ Object
225 226 227 228 229 230 231 232 233 |
# File 'app/helpers/workbench/navigation_helper.rb', line 225 def destroy_object_link(object) content = safe_join([content_tag(:span, '', data: { icon: 'trash' }, class: 'small-icon'), 'Destroy'], '') if object.is_destroyable?(sessions_current_user) link_to(content, object., method: :delete, data: {confirm: 'Are you sure?'}, class: 'navigation-item') else content_tag(:div, content, class: 'navigation-item disable') end end |
#download_for_model_link(model) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'app/helpers/workbench/navigation_helper.rb', line 149 def download_for_model_link(model) content = safe_join([ content_tag(:span, '', class: 'icon', data: { icon: :download }), 'Download'], '') if self.controller.respond_to?(:download) link_to(content, download_path_for_model(model), data: { turbolinks: false }) else content_tag(:em, 'Download not yet available.') end end |
#download_path_for_model(model) ⇒ Object
162 163 164 165 166 167 168 169 |
# File 'app/helpers/workbench/navigation_helper.rb', line 162 def download_path_for_model(model) if model.name == 'Documentation' # some weirdness with ninflections download_documentation_index_path else send("download_#{model.name.tableize}_path") end end |
#edit_object_link(object) ⇒ Object
return [A tag, nil]
a link, or disabled link
215 216 217 218 219 220 221 222 223 |
# File 'app/helpers/workbench/navigation_helper.rb', line 215 def edit_object_link(object) content = safe_join([content_tag(:span, '', data: { icon: 'edit' }, class: 'small-icon'), 'Edit'], '') if has_route_for_edit?(object) && object.is_editable?(sessions_current_user) link_to(content, edit_object_path((object)), class: 'navigation-item') else content_tag(:div, content, class: 'navigation-item disable') end end |
#edit_object_path(object) ⇒ Object
186 187 188 |
# File 'app/helpers/workbench/navigation_helper.rb', line 186 def edit_object_path(object) send(edit_object_path_string(object), object) end |
#edit_object_path_string(object) ⇒ Object
Determine wether an edit or destroy route exists Custom routes can be added per Class by adding a corresponding ‘_string` postfixed method.
194 195 196 197 198 199 200 201 202 |
# File 'app/helpers/workbench/navigation_helper.rb', line 194 def edit_object_path_string(object) default = "edit_#{(object).class.base_class.name.underscore}_path" specific = default + '_string' if self.respond_to?(specific) self.send(specific, object) else default end end |
#forward_back_links(instance) ⇒ Object
76 77 78 |
# File 'app/helpers/workbench/navigation_helper.rb', line 76 def forward_back_links(instance) content_tag(:span, (previous_link(instance) + ' | ' + next_link(instance)).html_safe) end |
#has_route_for_edit?(object) ⇒ Boolean
return [Boolean]
true if there is a route to edit for the object (some objects are not editable, like Tags)
206 207 208 |
# File 'app/helpers/workbench/navigation_helper.rb', line 206 def has_route_for_edit?(object) self.respond_to?(edit_object_path_string(object)) end |
#list_for_model_link(model) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'app/helpers/workbench/navigation_helper.rb', line 131 def list_for_model_link(model) content = safe_join([ content_tag(:span, '', class: 'icon', data: { icon: 'list'}), 'List'], '') has_records = model.has_attribute?(:project_id) ? model.where(project_id: sessions_current_project_id).exists? : model.any? if has_records link_to(content, list_path_for_model(model)) else content_tag(:span, safe_join([ content_tag(:span, '', data: { icon: :list }), content_tag(:span, "No #{model.name} to list") ], ''), class: :disabled) end end |
#list_path_for_model(model) ⇒ Object
112 113 114 |
# File 'app/helpers/workbench/navigation_helper.rb', line 112 def list_path_for_model(model) url_for(controller: model.name.tableize.pluralize.downcase, action: :list) end |
#new_for_model_link(model) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'app/helpers/workbench/navigation_helper.rb', line 116 def new_for_model_link(model) content = safe_join([ content_tag(:span, '', class: 'icon', data: { icon: 'new' }), 'New'], '') if NO_NEW_FORMS.include?(model.name) nil elsif model.name == 'ProjectSource' link_to(content, new_source_path) else link_to(content, new_path_for_model(model), 'class' => 'navigation-item') end end |
#new_path_for_model(model) ⇒ Object
108 109 110 |
# File 'app/helpers/workbench/navigation_helper.rb', line 108 def new_path_for_model(model) send("new_#{model.name.tableize.singularize}_path") end |
#next_link(instance, text: 'Next', target: nil) ⇒ Object
Used in show/REST A next record link.
96 97 98 99 100 101 102 103 104 105 106 |
# File 'app/helpers/workbench/navigation_helper.rb', line 96 def next_link(instance, text: 'Next', target: nil) link_text = safe_join([text, content_tag(:span, '', class: 'small-icon margin-small-left', data: { icon: 'arrow-right' })], '') link_object = instance.next return content_tag(:div, link_text, class: 'navigation-item disable') if link_object.nil? if target.nil? target ||= link_object. else target = send(target, id: link_object.id) end link_to(link_text, target, data: { arrow: 'next' }, class: 'navigation-item') end |
#object_home_link(object) ⇒ Object
If a “home” is provided, use it instead of show link See also over ride in object_link - which we might need to merge
300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'app/helpers/workbench/navigation_helper.rb', line 300 def object_home_link(object) k = object.class klass = OBJECT_RADIALS[k.name] ? k.name : k.base_class.name p = OBJECT_RADIALS[klass] if p && p['home'] link_to( object_tag(object), send("#{p['home']}_path", "#{klass.tableize.singularize}_id" => object.id) ) else object_link(object) end end |
#object_link(object) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'app/helpers/workbench/navigation_helper.rb', line 171 def object_link(object) return nil if object.nil? klass_name = object.class.base_class.name.underscore link_method = klass_name + '_link' # If a customized link to method is available use that, otherwise use a generic if self.respond_to?(link_method) send(link_method, object) else t = object_tag(object) return "Unable to link to data #{object.class.name} id:#{object.id}." if t.blank? link_to(t.html_safe, (object)) end end |
#on_workbench? ⇒ Boolean
58 59 60 |
# File 'app/helpers/workbench/navigation_helper.rb', line 58 def on_workbench? !(request.path =~ /#{NOT_DATA_PATHS.join('|')}/) end |
#previous_link(instance, text: 'Previous', target: nil) ⇒ Object
Used in show/REST A previous record link.
82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/helpers/workbench/navigation_helper.rb', line 82 def previous_link(instance, text: 'Previous', target: nil) link_text = safe_join([content_tag(:span, '', data: { icon: 'arrow-left' }, class: 'small-icon'), text], '') link_object = instance.previous return content_tag(:div, link_text, class: 'navigation-item disable') if link_object.nil? if target.nil? target ||= link_object. else target = send(target, id: link_object.id) end link_to(link_text, target, data: { arrow: 'back' }, class: 'navigation-item') end |
#quick_bar ⇒ Object
62 63 64 |
# File 'app/helpers/workbench/navigation_helper.rb', line 62 def render(partial: '/workbench/navigation/quick_bar') if sessions_signed_in? end |
#quick_bar_link(related_model) ⇒ Object
66 67 68 69 70 |
# File 'app/helpers/workbench/navigation_helper.rb', line 66 def () model = Hub::Data::BY_NAME[ .kind_of?(Hash) ? .keys.first : ] return nil if model.nil? content_tag(:li, data_link(model)) end |
#radial_navigation_tag(object, teleport = nil) ⇒ Object
294 295 296 |
# File 'app/helpers/workbench/navigation_helper.rb', line 294 def (object, teleport = nil) content_tag(:span, '', data: { 'global-id': object.to_global_id.to_s, 'radial-navigation': 'true', 'teleport': teleport}) end |
#recent_route_link(hsh) ⇒ Object
259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'app/helpers/workbench/navigation_helper.rb', line 259 def recent_route_link(hsh) route = hsh.keys.first o = safe_object_from_attributes(hsh[route]) if o.nil? link_to(route.parameterize(separator: ' - ').humanize.capitalize, route) elsif o o = o. if o.respond_to?(:metamorphosize) link_to(object_tag(o) + " [#{hsh[route]['object_type']}]", route) else content_tag(:em, 'Data no longer available.', class: :warning) end end |
#related_data_link_tag(object) ⇒ <a> tag?
Returns a link to the related data page.
274 275 276 277 278 |
# File 'app/helpers/workbench/navigation_helper.rb', line 274 def (object) return nil if object.nil? p = "related_#{member_base_path((object))}_path" content_tag(:li, link_to('Related data', send(p, object))) if controller.respond_to?(p) end |
#safe_object_from_attributes(hsh) ⇒ Object
248 249 250 251 252 253 254 255 256 257 |
# File 'app/helpers/workbench/navigation_helper.rb', line 248 def safe_object_from_attributes(hsh) if hsh['object_type'] && hsh['object_type'] begin return hsh['object_type'].constantize.find(hsh['object_id']) rescue ActiveRecord::RecordNotFound return false end end nil end |
#slideout_clipboard ⇒ Object
41 42 43 |
# File 'app/helpers/workbench/navigation_helper.rb', line 41 def render(partial: '/shared/data/slideout/clipboard') end |
#slideout_pdf_viewer ⇒ Object
53 54 55 |
# File 'app/helpers/workbench/navigation_helper.rb', line 53 def render(partial: '/shared/data/slideout/document') end |
#slideout_pinboard ⇒ Object
45 46 47 |
# File 'app/helpers/workbench/navigation_helper.rb', line 45 def render(partial: '/shared/data/slideout/pinboard') end |
#slideout_recent ⇒ Object
49 50 51 |
# File 'app/helpers/workbench/navigation_helper.rb', line 49 def render(partial: '/shared/data/slideout/recent') end |
#slideouts ⇒ Object
Slideout panels
33 34 35 36 37 38 39 |
# File 'app/helpers/workbench/navigation_helper.rb', line 33 def if sessions_current_project && sessions_signed_in? && on_workbench? [ , , ].join.html_safe end end |
#task_bar ⇒ Object
72 73 74 |
# File 'app/helpers/workbench/navigation_helper.rb', line 72 def render(partial: '/workbench/navigation/task_bar') if is_task_controller? end |
#title_tag ⇒ Object
289 290 291 292 |
# File 'app/helpers/workbench/navigation_helper.rb', line 289 def title_tag splash = request.path =~ /task/ ? request.path.demodulize.humanize : request.path.split('/')&.second&.humanize content_tag(:title, ['TaxonWorks', splash].compact.join(' - ') ) end |