Class: Crm::BreadcrumbPresenter
- Inherits:
-
BasePresenter
- Object
- BasePresenter
- Crm::BreadcrumbPresenter
- Defined in:
- app/presenters/crm/breadcrumb_presenter.rb
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.
5 6 7 8 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 5 def initialize(args, context = {}) @context = context super(args) end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
3 4 5 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 3 def context @context end |
Instance Method Details
#breadcrumb ⇒ Object
10 11 12 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 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 10 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
244 245 246 247 248 249 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 244 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
423 424 425 426 427 428 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 423 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
444 445 446 447 448 449 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 444 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
430 431 432 433 434 435 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 430 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
437 438 439 440 441 442 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 437 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
307 308 309 310 311 312 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 307 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
372 373 374 375 376 377 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 372 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
379 380 381 382 383 384 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 379 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
386 387 388 389 390 391 392 393 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 386 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
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 195 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
180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 180 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
238 239 240 241 242 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 238 def build_for_contact_point(obj) bc = [] bc += build_links_list(obj.party) if obj.party bc end |
#build_for_credit_application(obj) ⇒ Object
300 301 302 303 304 305 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 300 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
287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 287 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
160 161 162 163 164 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 160 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
129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 129 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
251 252 253 254 255 256 257 258 259 260 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 251 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
352 353 354 355 356 357 358 359 360 361 362 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 352 def build_for_item(obj) bc = [] bc << link_to('Items', u.items_path) if obj.primary_product_line 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 end bc << link_to(obj.sku, u.item_path(obj)) if obj.persisted? bc end |
#build_for_opportunity(obj) ⇒ Object
153 154 155 156 157 158 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 153 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
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 113 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 and obj.quote.rma) or 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
328 329 330 331 332 333 334 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 328 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
321 322 323 324 325 326 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 321 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
416 417 418 419 420 421 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 416 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
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 451 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
470 471 472 473 474 475 476 477 478 479 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 470 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 if obj.order bc << link_to("Order #{obj.order.reference_number}", u.order_path(obj.order)) end bc << link_to(obj.reference_number, u.purchase_order_path(obj)) if obj.persisted? bc end |
#build_for_quote(obj) ⇒ Object
105 106 107 108 109 110 111 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 105 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
262 263 264 265 266 267 268 269 270 271 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 262 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
273 274 275 276 277 278 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 273 def build_for_rma(obj) bc = [] 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
230 231 232 233 234 235 236 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 230 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
314 315 316 317 318 319 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 314 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
336 337 338 339 340 341 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 336 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
395 396 397 398 399 400 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 395 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
173 174 175 176 177 178 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 173 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
142 143 144 145 146 147 148 149 150 151 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 142 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
343 344 345 346 347 348 349 350 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 343 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
166 167 168 169 170 171 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 166 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
217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 217 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
364 365 366 367 368 369 370 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 364 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
402 403 404 405 406 407 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 402 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
409 410 411 412 413 414 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 409 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
280 281 282 283 284 285 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 280 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
66 67 68 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 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 66 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
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/presenters/crm/breadcrumb_presenter.rb', line 47 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 |