Class: Crm::BreadcrumbPresenter
- Inherits:
-
BasePresenter
- Object
- BasePresenter
- Crm::BreadcrumbPresenter
- Defined in:
- app/presenters/crm/breadcrumb_presenter.rb
Overview
Presenter: breadcrumb presenter.
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
- #breadcrumb ⇒ Object
- #build_for_activity(obj) ⇒ Object
- #build_for_article_faq(obj) ⇒ Object
- #build_for_article_procedure(obj) ⇒ Object
- #build_for_article_technical(obj) ⇒ Object
- #build_for_article_training(obj) ⇒ Object
- #build_for_budget_group(obj) ⇒ Object
- #build_for_campaign(obj) ⇒ Object
- #build_for_campaign_email(obj) ⇒ Object
- #build_for_catalog_item(obj) ⇒ Object
- #build_for_communication(obj) ⇒ Object
- #build_for_contact(obj) ⇒ Object
- #build_for_contact_point(obj) ⇒ Object
- #build_for_credit_application(obj) ⇒ Object
- #build_for_credit_memo(obj) ⇒ Object
- #build_for_customer(obj) ⇒ Object
- #build_for_delivery(obj) ⇒ Object
- #build_for_invoice(obj) ⇒ Object
- #build_for_item(obj) ⇒ Object
- #build_for_opportunity(obj) ⇒ Object
- #build_for_order(obj) ⇒ Object
- #build_for_outgoing_payment(obj) ⇒ Object
- #build_for_payment(obj) ⇒ Object
- #build_for_post(obj) ⇒ Object
- #build_for_product_line(obj) ⇒ Object
- #build_for_purchase_order(obj) ⇒ Object
- #build_for_quote(obj) ⇒ Object
- #build_for_receipt(obj) ⇒ Object
- #build_for_rma(obj) ⇒ Object
- #build_for_room_configuration(obj) ⇒ Object
- #build_for_sales_forecase(obj) ⇒ Object
- #build_for_shipment(obj) ⇒ Object
- #build_for_shipment_receipt(obj) ⇒ Object
- #build_for_showcase(obj) ⇒ Object
- #build_for_source(obj) ⇒ Object
- #build_for_standalone_delivery(obj) ⇒ Object
- #build_for_supplier(obj) ⇒ Object
- #build_for_support_case(obj) ⇒ Object
- #build_for_topic(obj) ⇒ Object
- #build_for_video(obj) ⇒ Object
- #build_for_visit(obj) ⇒ Object
- #build_for_voucher(obj) ⇒ Object
-
#build_index_breadcrumb_for_action(action) ⇒ Object
Handle special case where we want to show index page breadcrumb for new pages.
- #build_links_list(obj) ⇒ Object
-
#initialize(args, context = {}) ⇒ BreadcrumbPresenter
constructor
A new instance of BreadcrumbPresenter.
Constructor Details
#initialize(args, context = {}) ⇒ BreadcrumbPresenter
Returns a new instance of BreadcrumbPresenter.
8 9 10 11 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 8 def initialize(args, context = {}) @context = context super(args) end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
6 7 8 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 6 def context @context end |
Instance Method Details
#breadcrumb ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 13 def links = [] # Process each argument args.each do |arg| case arg when Hash # Handle hash structure: { href: path, title: 'Title' } if arg[:href] && arg[:title] links << link_to(arg[:title], arg[:href]) elsif arg[:title] # Just a title without href (for active item) links << arg[:title] end when String # Handle string (action/title) - check if we need to add index breadcrumb links << (arg) if links.empty? && (arg) links << arg when nil # Skip nil values next else # Handle object arguments (existing behavior) links += build_links_list(arg) end end # Wrap links in li tags wrapped_links = links.map.with_index do |link, index| is_last = index == links.length - 1 css_class = is_last ? 'breadcrumb-item active' : 'breadcrumb-item' h.content_tag(:li, link, class: css_class) end wrapped_links.join.html_safe end |
#build_for_activity(obj) ⇒ Object
247 248 249 250 251 252 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 247 def build_for_activity(obj) bc = [] mp = obj.resource || obj.party bc += build_links_list(mp) if mp bc end |
#build_for_article_faq(obj) ⇒ Object
425 426 427 428 429 430 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 425 def build_for_article_faq(obj) bc = [] bc << link_to('FAQs', u.article_faqs_path) bc << link_to(obj.subject.truncate(60), u.article_faq_path(obj)) if obj.persisted? bc end |
#build_for_article_procedure(obj) ⇒ Object
446 447 448 449 450 451 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 446 def build_for_article_procedure(obj) bc = [] bc << link_to('Procedures', u.article_procedures_path) bc << link_to(obj.subject.truncate(60), u.article_procedure_path(obj)) if obj.persisted? bc end |
#build_for_article_technical(obj) ⇒ Object
432 433 434 435 436 437 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 432 def build_for_article_technical(obj) bc = [] bc << link_to('Technical Articles', u.article_technicals_path) bc << link_to(obj.subject.truncate(60), u.article_technical_path(obj)) if obj.persisted? bc end |
#build_for_article_training(obj) ⇒ Object
439 440 441 442 443 444 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 439 def build_for_article_training(obj) bc = [] bc << link_to('Training Articles', u.article_trainings_path) bc << link_to(obj.subject.truncate(60), u.article_training_path(obj)) if obj.persisted? bc end |
#build_for_budget_group(obj) ⇒ Object
311 312 313 314 315 316 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 311 def build_for_budget_group(obj) bc = [] bc << link_to('Budget Groups', u.budget_groups_path) bc << link_to(obj.description, u.budget_group_path(obj)) if obj.persisted? bc end |
#build_for_campaign(obj) ⇒ Object
374 375 376 377 378 379 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 374 def build_for_campaign(obj) bc = [] bc << link_to('Campaigns', u.campaigns_path) bc << link_to(obj.name, u.campaign_path(obj)) if obj.persisted? bc end |
#build_for_campaign_email(obj) ⇒ Object
381 382 383 384 385 386 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 381 def build_for_campaign_email(obj) bc = [] bc += build_links_list(obj.campaign) if obj.campaign bc << link_to(obj.name, u.campaign_campaign_email_path(obj.campaign, obj)) if obj.persisted? bc end |
#build_for_catalog_item(obj) ⇒ Object
388 389 390 391 392 393 394 395 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 388 def build_for_catalog_item(obj) bc = [] # Show the catalog first, then the item, then the catalog item bc += build_links_list(obj.catalog) if obj.catalog bc += build_links_list(obj.item) if obj.item bc << link_to("#{obj.sku} (#{obj.state})", u.catalog_item_path(obj)) if obj.persisted? bc end |
#build_for_communication(obj) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 198 def build_for_communication(obj) bc = [] if obj.resource bc += begin build_links_list(obj.resource) rescue StandardError [] end if (resource_comm_path = begin u.polymorphic_path([obj.resource, :communications]) rescue StandardError nil end) bc << link_to('Communications', resource_comm_path) end else bc << link_to('Communications', u.communications_path) end bc << link_to(obj.to_s, u.communication_path(obj)) if obj.persisted? bc end |
#build_for_contact(obj) ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 183 def build_for_contact(obj) bc = [] if obj.customer || obj.supplier bc += build_links_list(obj.customer || obj.supplier) elsif (opp = obj.opportunity_participants.first&.opportunity) # Try a participant query bc += build_links_list(opp) elsif (sc = obj.support_cases.first) # Support case linkup bc += build_links_list(sc) end bc << link_to(obj.full_name, u.contact_path(obj)) if obj.persisted? bc end |
#build_for_contact_point(obj) ⇒ Object
241 242 243 244 245 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 241 def build_for_contact_point(obj) bc = [] bc += build_links_list(obj.party) if obj.party bc end |
#build_for_credit_application(obj) ⇒ Object
304 305 306 307 308 309 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 304 def build_for_credit_application(obj) bc = [] bc += build_links_list(obj.customer) bc << link_to("Credit Application #{obj.reference_number}", u.credit_application_path(obj)) if obj.persisted? bc end |
#build_for_credit_memo(obj) ⇒ Object
291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 291 def build_for_credit_memo(obj) bc = [] if obj.rma bc += build_links_list(obj.rma) elsif obj.original_order bc += build_links_list(obj.original_order) elsif obj.customer bc += build_links_list(obj.customer) end bc << link_to(obj.reference_number, u.credit_memo_path(obj)) if obj.persisted? bc end |
#build_for_customer(obj) ⇒ Object
163 164 165 166 167 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 163 def build_for_customer(obj) bc = [] bc << "#{h.customer_flag_image(obj) || ''} #{link_to("#{obj.name} (#{obj.effective_report_grouping})", u.customer_path(obj.id))}".html_safe if obj.persisted? bc end |
#build_for_delivery(obj) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 132 def build_for_delivery(obj) bc = [] bc += if obj.order build_links_list(obj.order) elsif obj.quote build_links_list(obj.quote) else build_links_list(obj.customer) end bc << link_to("#{obj.name(short: true)} (#{obj.human_state_name})", u.delivery_path(obj)) if obj.persisted? bc end |
#build_for_invoice(obj) ⇒ Object
254 255 256 257 258 259 260 261 262 263 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 254 def build_for_invoice(obj) bc = [] if obj.delivery bc += build_links_list(obj.delivery) elsif obj.customer bc += build_links_list(obj.customer) end bc << link_to(obj.to_s, u.invoice_path(obj)) if obj.persisted? bc end |
#build_for_item(obj) ⇒ Object
356 357 358 359 360 361 362 363 364 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 356 def build_for_item(obj) bc = [] bc << link_to('Items', u.items_path) obj.primary_product_line&.self_and_ancestors&.reverse_each do |pl| bc << link_to(pl.name.presence || pl.name_en, u.product_line_path(pl, tab: "items")) end bc << link_to(obj.sku, u.item_path(obj)) if obj.persisted? bc end |
#build_for_opportunity(obj) ⇒ Object
156 157 158 159 160 161 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 156 def build_for_opportunity(obj) bc = [] bc += build_links_list(obj.primary_party) if obj.primary_party bc << link_to(obj.to_s, u.opportunity_path(obj)) if obj.persisted? bc end |
#build_for_order(obj) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 116 def build_for_order(obj) bc = [] bc += if obj.quote build_links_list(obj.quote) elsif obj.opportunity build_links_list(obj.opportunity) elsif obj.rma build_links_list(obj.rma) else build_links_list(obj.primary_party) end bc << link_to(obj.rma.rma_number, u.rma_path(obj.rma)) unless obj.quote&.rma || obj.rma.nil? bc << link_to("Order ##{obj.reference_number} (#{obj.human_state_name})", u.order_path(obj)) if obj.persisted? bc end |
#build_for_outgoing_payment(obj) ⇒ Object
332 333 334 335 336 337 338 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 332 def build_for_outgoing_payment(obj) bc = [] bc << link_to('Outgoing Payments', u.outgoing_payments_path) bc << link_to(obj.supplier.to_s, u.supplier_path(obj.supplier)) if obj.supplier bc << link_to(obj.to_s, u.outgoing_payment_path(obj)) bc end |
#build_for_payment(obj) ⇒ Object
325 326 327 328 329 330 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 325 def build_for_payment(obj) bc = [] bc += build_links_list(obj.order) if obj.order bc << link_to("Payment ##{obj.id}", u.transactions_payment_path(obj.id)) if obj.persisted? bc end |
#build_for_post(obj) ⇒ Object
418 419 420 421 422 423 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 418 def build_for_post(obj) bc = [] bc << link_to('Posts', u.posts_path) bc << link_to(obj.to_s, u.post_path(obj)) if obj.persisted? bc end |
#build_for_product_line(obj) ⇒ Object
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 453 def build_for_product_line(obj) bc = [] bc << link_to('Product Lines', u.product_lines_path) # Get tab from context if available tab = context[:tab] if context.is_a?(Hash) # Add all ancestors in order (root to parent) obj.ancestors.reverse_each do |pl| = tab ? { tab: tab } : {} bc << link_to(pl.name.presence || pl.name_en, u.product_line_path(pl, )) end # Add current product line = tab ? { tab: tab } : {} bc << link_to(obj.name.presence || obj.name_en, u.product_line_path(obj, )) if obj.persisted? bc end |
#build_for_purchase_order(obj) ⇒ Object
472 473 474 475 476 477 478 479 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 472 def build_for_purchase_order(obj) bc = [] bc << link_to('Suppliers', u.suppliers_path) bc << link_to(obj.supplier.full_name, u.supplier_path(obj.supplier)) if obj.supplier bc << link_to("Order #{obj.order.reference_number}", u.order_path(obj.order)) if obj.order bc << link_to(obj.reference_number, u.purchase_order_path(obj)) if obj.persisted? bc end |
#build_for_quote(obj) ⇒ Object
108 109 110 111 112 113 114 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 108 def build_for_quote(obj) bc = [] bc += build_links_list(obj.opportunity) bc << link_to(obj.rma.rma_number, u.rma_path(obj.rma)) if obj.rma bc << link_to("#{obj.reference_number_with_name} (#{[obj.human_state_name, ('Sold' if obj.sold?)].compact.join(' - ')})", u.quote_path(obj)) if obj.persisted? bc end |
#build_for_receipt(obj) ⇒ Object
265 266 267 268 269 270 271 272 273 274 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 265 def build_for_receipt(obj) bc = [] if obj.payment bc += build_links_list(obj.payment) elsif obj.customer bc += build_links_list(obj.customer) end bc << link_to(obj.to_s, u.receipt_path(obj)) if obj.persisted? bc end |
#build_for_rma(obj) ⇒ Object
276 277 278 279 280 281 282 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 276 def build_for_rma(obj) bc = [] bc += build_links_list(obj.customer) if obj.original_invoice && obj.customer && obj.customer != obj.original_invoice.customer bc += build_links_list(obj.original_invoice || obj.customer) bc << link_to(obj.to_s, u.rma_path(obj)) if obj.persisted? bc end |
#build_for_room_configuration(obj) ⇒ Object
233 234 235 236 237 238 239 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 233 def build_for_room_configuration(obj) bc = [] bc += build_links_list(obj.opportunity) obj.quotes.each { |q| bc << link_to("#{q.reference_number_with_name} - (#{q.human_state_name})", u.quote_path(q)) } bc << link_to(obj.name_with_room, u.room_configuration_path(obj)) if obj.persisted? bc end |
#build_for_sales_forecase(obj) ⇒ Object
318 319 320 321 322 323 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 318 def build_for_sales_forecase(obj) bc = [] bc << link_to('Sales Forecasts', u.sales_forecasts_path) bc << link_to(obj.id, u.sales_forecast_path(obj)) if obj.persisted? bc end |
#build_for_shipment(obj) ⇒ Object
340 341 342 343 344 345 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 340 def build_for_shipment(obj) bc = [] bc += build_links_list(obj.delivery) if obj.delivery bc << link_to("Shipment #{obj.id}", u.shipment_path(obj)) if obj.persisted? bc end |
#build_for_shipment_receipt(obj) ⇒ Object
397 398 399 400 401 402 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 397 def build_for_shipment_receipt(obj) bc = [] bc << link_to('Shipment Receipts', u.shipment_receipts_path) bc << link_to("Shipment Receipt #{obj.id}", u.shipment_receipt_path(obj)) if obj.persisted? bc end |
#build_for_showcase(obj) ⇒ Object
176 177 178 179 180 181 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 176 def build_for_showcase(obj) bc = [] bc << link_to('Showcases', u.showcases_path) bc << link_to(obj.name, u.showcase_path(obj)) if obj.persisted? bc end |
#build_for_source(obj) ⇒ Object
145 146 147 148 149 150 151 152 153 154 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 145 def build_for_source(obj) bc = [] if obj.parent bc += build_links_list(obj.parent) else bc << link_to('Sources', u.sources_path) end bc << link_to(obj.name, u.source_path(obj)) if obj.persisted? bc end |
#build_for_standalone_delivery(obj) ⇒ Object
347 348 349 350 351 352 353 354 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 347 def build_for_standalone_delivery(obj) bc = [] bc << link_to(obj.store.name, u.store_path(obj.store)) if obj.store dest_party = obj.destination_address&.party bc += build_links_list(dest_party) if dest_party bc << link_to(obj.name, u.standalone_delivery_path(obj)) if obj.persisted? bc end |
#build_for_supplier(obj) ⇒ Object
169 170 171 172 173 174 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 169 def build_for_supplier(obj) bc = [] bc << link_to('Suppliers', u.suppliers_path) bc << link_to(obj.name, u.supplier_path(obj)) if obj.persisted? bc end |
#build_for_support_case(obj) ⇒ Object
220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 220 def build_for_support_case(obj) bc = [] bc << link_to('Support Cases', u.support_cases_path(case_type: obj.try(:case_type))) case obj.primary_party.class.name when 'Customer' bc += build_for_customer(obj.primary_party) when 'Contact' bc << link_to(obj.primary_party.full_name, u.contact_path(obj.primary_party)) end bc << link_to(obj.case_number, u.support_case_path(obj)) if obj.persisted? bc end |
#build_for_topic(obj) ⇒ Object
366 367 368 369 370 371 372 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 366 def build_for_topic(obj) bc = [] bc << link_to('Topics', u.topics_path) bc << link_to(obj.topic_category.name, u.topic_category_path(obj.topic_category)) if obj.topic_category bc << link_to(obj.title, u.topic_path(obj)) if obj.persisted? bc end |
#build_for_video(obj) ⇒ Object
404 405 406 407 408 409 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 404 def build_for_video(obj) bc = [] bc << link_to('Videos', u.videos_path) bc << link_to(obj.title, u.video_path(obj)) if obj.persisted? bc end |
#build_for_visit(obj) ⇒ Object
411 412 413 414 415 416 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 411 def build_for_visit(obj) bc = [] bc << link_to('Visits', u.visits_path) bc << link_to("Visit #{obj.id}", u.visit_path(obj)) if obj.persisted? bc end |
#build_for_voucher(obj) ⇒ Object
284 285 286 287 288 289 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 284 def build_for_voucher(obj) bc = [] bc << link_to('Vouchers', u.vouchers_path) bc << link_to(obj.reference_number, u.voucher_path(obj)) if obj.persisted? bc end |
#build_index_breadcrumb_for_action(action) ⇒ Object
Handle special case where we want to show index page breadcrumb for new pages
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 69 def (action) case action when /^New Campaign/ link_to('Campaigns', u.campaigns_path) when /^New Video/ link_to('Videos', u.videos_path) when /^New Visit/ link_to('Visits', u.visits_path) when /^New Supplier/ link_to('Suppliers', u.suppliers_path) when /^New Voucher/ link_to('Vouchers', u.vouchers_path) when /^New Item/ link_to('Items', u.items_path) when /^New Topic/ link_to('Topics', u.topics_path) when /^New Showcase/ link_to('Showcases', u.showcases_path) when /^New Delivery/ link_to('Deliveries', u.deliveries_path) when /^New Shipment/ link_to('Shipments', u.shipments_path) when /^New Contact/ link_to('Contacts', u.contacts_path) when /^New Opportunity/ link_to('Opportunities', u.opportunities_path) when /^New Support Case/ link_to('Support Cases', u.support_cases_path) when /^New Source/ link_to('Sources', u.sources_path) when /^New Campaign Email/ link_to('Campaign Emails', u.campaign_emails_path) when /^New Shipment Receipt/ link_to('Shipment Receipts', u.shipment_receipts_path) when /^Edit Images Uploads/ link_to('Images', u.images_path) end end |
#build_links_list(obj) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 50 def build_links_list(obj) return [] if obj.nil? bc = [] method = "build_for_#{obj.class.name.tableize.singularize}" if respond_to?(method) bc += send(method, obj).compact else link = begin link_to(obj.to_s, u.polymorphic_path(obj)) rescue StandardError nil end bc << link end bc.compact.uniq end |