Class: QuickSearch::PinPresenter
- Inherits:
-
BasePresenter
- Object
- BasePresenter
- QuickSearch::PinPresenter
- Defined in:
- app/presenters/quick_search/pin_presenter.rb
Direct Known Subclasses
ActivityPresenter, AddressPresenter, AmazonVariationPresenter, ArticlePresenter, CatalogItemPresenter, ContactPointPresenter, ContactPresenter, CreditApplicationPresenter, CreditMemoPresenter, CustomerPresenter, DeliveryPresenter, EmailPreferencePresenter, InvoicePresenter, ItemPresenter, OpportunityPresenter, OrderPresenter, PaymentPresenter, PresetJobPresenter, PurchaseOrderPresenter, QuotePresenter, RmaPresenter, SupplierPresenter, SupportCasePresenter, UnknownPresenter, VoucherPresenter
Instance Attribute Summary collapse
-
#invalid ⇒ Object
readonly
Returns the value of attribute invalid.
-
#link ⇒ Object
readonly
Returns the value of attribute link.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#reference_number ⇒ Object
readonly
Returns the value of attribute reference_number.
-
#result_class ⇒ Object
readonly
Returns the value of attribute result_class.
-
#significant_date ⇒ Object
readonly
Returns the value of attribute significant_date.
-
#sub_header ⇒ Object
readonly
Returns the value of attribute sub_header.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
- .build(object, template) ⇒ Object
-
.pin_class(r) ⇒ Object
Instantiate the appropriate search class.
Instance Method Summary collapse
- #as_json(_options = {}) ⇒ Object
-
#initialize(object, template, options = {}) ⇒ PinPresenter
constructor
A new instance of PinPresenter.
- #presenting_context?(context_type, context_id) ⇒ Boolean
-
#profile_image_url ⇒ Object
Override in subclasses that support profile images (Customer, Contact, Supplier).
- #set_attributes ⇒ Object
- #set_result_class(object) ⇒ Object
-
#text_sub_header ⇒ Object
Override in subclasses that have both badges AND text info.
- #to_s ⇒ Object
-
#type_label ⇒ Object
Override in subclasses to customize the type label shown on cards.
Constructor Details
#initialize(object, template, options = {}) ⇒ PinPresenter
Returns a new instance of PinPresenter.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/presenters/quick_search/pin_presenter.rb', line 21 def initialize(object, template, ={}) super(object, template) @options = set_attributes set_result_class(object) @title ||= object.to_s unless @link.present? if object.respond_to? :crm_link @link = object.crm_link else @link = template.polymorphic_path(object) rescue nil end end @reference_number ||= object.try(:reference_number) end |
Instance Attribute Details
#invalid ⇒ Object (readonly)
Returns the value of attribute invalid.
5 6 7 |
# File 'app/presenters/quick_search/pin_presenter.rb', line 5 def invalid @invalid end |
#link ⇒ Object (readonly)
Returns the value of attribute link.
5 6 7 |
# File 'app/presenters/quick_search/pin_presenter.rb', line 5 def link @link end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'app/presenters/quick_search/pin_presenter.rb', line 5 def @options end |
#reference_number ⇒ Object (readonly)
Returns the value of attribute reference_number.
5 6 7 |
# File 'app/presenters/quick_search/pin_presenter.rb', line 5 def reference_number @reference_number end |
#result_class ⇒ Object (readonly)
Returns the value of attribute result_class.
5 6 7 |
# File 'app/presenters/quick_search/pin_presenter.rb', line 5 def result_class @result_class end |
#significant_date ⇒ Object (readonly)
Returns the value of attribute significant_date.
5 6 7 |
# File 'app/presenters/quick_search/pin_presenter.rb', line 5 def significant_date @significant_date end |
#sub_header ⇒ Object (readonly)
Returns the value of attribute sub_header.
5 6 7 |
# File 'app/presenters/quick_search/pin_presenter.rb', line 5 def sub_header @sub_header end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
5 6 7 |
# File 'app/presenters/quick_search/pin_presenter.rb', line 5 def title @title end |
Class Method Details
.build(object, template) ⇒ Object
17 18 19 |
# File 'app/presenters/quick_search/pin_presenter.rb', line 17 def self.build(object, template) pin_class(object).new(object,template) end |
.pin_class(r) ⇒ Object
Instantiate the appropriate search class
8 9 10 11 12 13 14 15 |
# File 'app/presenters/quick_search/pin_presenter.rb', line 8 def self.pin_class(r) klass = "QuickSearch::#{r.class.name}Presenter".constantize rescue nil #Try a parent (e.g. Party if you are a Customer, Supplier, etc.) klass ||= "QuickSearch::#{r.superclass.name}Presenter".constantize rescue nil #Default to unknownpresenter klass ||= "QuickSearch::UnknownPresenter".constantize klass end |
Instance Method Details
#as_json(_options = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/presenters/quick_search/pin_presenter.rb', line 45 def as_json( = {}) { title: self.title, sub_header: self.sub_header, text_sub_header: text_sub_header, url: self.link, ref: self.try(:reference_number), result_class: self.result_class, type_label: type_label, profile_image_url: profile_image_url } end |
#presenting_context?(context_type, context_id) ⇒ Boolean
77 78 79 80 |
# File 'app/presenters/quick_search/pin_presenter.rb', line 77 def presenting_context?(context_type, context_id) return false unless context_type.present? and context_id.present? result.resource_type == context_type.to_s and result.resource_id == context_id.to_i end |
#profile_image_url ⇒ Object
Override in subclasses that support profile images (Customer, Contact, Supplier)
69 70 71 |
# File 'app/presenters/quick_search/pin_presenter.rb', line 69 def profile_image_url nil end |
#set_attributes ⇒ Object
73 74 75 |
# File 'app/presenters/quick_search/pin_presenter.rb', line 73 def set_attributes raise "Not Implemented, you must implement this method in your subclass" end |
#set_result_class(object) ⇒ Object
37 38 39 |
# File 'app/presenters/quick_search/pin_presenter.rb', line 37 def set_result_class(object) @result_class ||= object.class.name.tableize.singularize.to_sym end |
#text_sub_header ⇒ Object
Override in subclasses that have both badges AND text info
59 60 61 |
# File 'app/presenters/quick_search/pin_presenter.rb', line 59 def text_sub_header nil end |
#to_s ⇒ Object
41 42 43 |
# File 'app/presenters/quick_search/pin_presenter.rb', line 41 def to_s [reference_number, title].compact_blank.join(" \u2022 ") end |
#type_label ⇒ Object
Override in subclasses to customize the type label shown on cards
64 65 66 |
# File 'app/presenters/quick_search/pin_presenter.rb', line 64 def type_label nil end |