Module: CampaignsHelper

Defined in:
app/helpers/campaigns_helper.rb

Overview

View helper: campaigns.

Instance Method Summary collapse

Instance Method Details

#audience_for_selectArray<Array(String, Integer)>

Builds sorted select options for every audience, labeled with the
audience's first campaign name and member count.

Returns:

  • (Array<Array(String, Integer)>)

    sorted [label, audience id] pairs



98
99
100
# File 'app/helpers/campaigns_helper.rb', line 98

def audience_for_select
  Audience.all.map { |sl| ["#{sl.campaigns.first.try(:name) || 'No Campaign'} > List: #{sl.name} (#{sl.audience_members.size})", sl.id] }.sort
end

Renders a link to the closed activities search for the campaign.

Parameters:

  • campaign (Campaign)

    the campaign whose closed activities are counted

Returns:

  • (String)

    HTML link to the filtered ActivitySearch



89
90
91
92
# File 'app/helpers/campaigns_helper.rb', line 89

def campaign_closed_activities_link(campaign)
  closed_link, = query_template_link(ActivitySearch, nil, query_params: { campaign_id_in: campaign.id, activity_result_type_id: ['Any'] }, show_zero: true, counter_class: '')
  closed_link
end

#campaign_command_options(campaign) ⇒ Array<String>

Builds the list of action links for a campaign row (state, transitions,
edit, email-marketing actions, and delete when permitted).

Parameters:

  • campaign (Campaign)

    the campaign to build action links for

Returns:

  • (Array<String>)

    HTML-safe action links with nils removed



9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/helpers/campaigns_helper.rb', line 9

def campaign_command_options(campaign)
  actions = []
  actions << campaign.human_state_name.titleize
  actions += available_events_links(campaign)
  actions << link_to(fa_icon('wrench', text: 'Edit'), edit_campaign_path(campaign))
  if campaign.campaign_type == "email_marketing"
    actions << link_to(fa_icon('bullhorn', text: "New Campaign Email"), new_campaign_campaign_email_path(campaign))
    actions << link_to(fa_icon('link', text: "Link Existing Email Template"), link_template_campaign_campaign_emails_path(campaign))
  end
  actions << link_to(fa_icon('trash', text: 'Delete'), campaign_path(campaign), data: { turbo_confirm: "Are you sure?", turbo_method: :delete }) if can?(:destroy, campaign)
  actions.compact
end

Renders a link to the customers search for the campaign.

Parameters:

  • campaign (Campaign)

    the campaign whose customers are counted

Returns:

  • (String)

    HTML link to the filtered CustomerSearch



44
45
46
47
# File 'app/helpers/campaigns_helper.rb', line 44

def campaign_customer_link(campaign)
  customer_link, = query_template_link(CustomerSearch, nil, query_params: { campaign_id_in: [campaign.id] }, show_zero: true, counter_class: '')
  customer_link
end

Renders a link to the leads search for the campaign's source.

Parameters:

  • campaign (Campaign)

    the campaign whose leads are counted

Returns:

  • (String)

    HTML link to the filtered CustomerSearch



35
36
37
38
# File 'app/helpers/campaigns_helper.rb', line 35

def campaign_lead_link(campaign)
  lead_link, = query_template_link(CustomerSearch, nil, query_params: { source_id: [campaign.source_id] }, show_zero: true, counter_class: '')
  lead_link
end

Renders a link to the open activities search for the campaign.

Parameters:

  • campaign (Campaign)

    the campaign whose open activities are counted

Returns:

  • (String)

    HTML link to the filtered ActivitySearch



80
81
82
83
# File 'app/helpers/campaigns_helper.rb', line 80

def campaign_open_activities_link(campaign)
  open_link, = query_template_link(ActivitySearch, nil, query_params: { campaign_id_in: campaign.id, activity_result_type_id: ['Open'] }, show_zero: true, counter_class: '')
  open_link
end

Renders a link to the opportunities search for the campaign's source.

Parameters:

  • campaign (Campaign)

    the campaign whose opportunities are counted

Returns:

  • (String)

    HTML link to the filtered OpportunitySearch



26
27
28
29
# File 'app/helpers/campaigns_helper.rb', line 26

def campaign_opp_link(campaign)
  opp_link, = query_template_link(OpportunitySearch, nil, query_params: { source_id: [campaign.source_id] }, show_zero: true, counter_class: '')
  opp_link
end

Renders a link to the orders search for the campaign's source.

Parameters:

  • campaign (Campaign)

    the campaign whose orders are counted

Returns:

  • (String)

    HTML link to the filtered OrderSearch



53
54
55
56
# File 'app/helpers/campaigns_helper.rb', line 53

def campaign_order_link(campaign)
  order_link, = query_template_link(OrderSearch, nil, query_params: { source_id: [campaign.source_id] }, show_zero: true, counter_class: '')
  order_link
end

Renders a link showing total invoiced profit for the campaign's source.

Parameters:

  • campaign (Campaign)

    the campaign whose profit is summed

Returns:

  • (String)

    HTML link to the filtered InvoiceSearch profit sum



71
72
73
74
# File 'app/helpers/campaigns_helper.rb', line 71

def campaign_profit_link(campaign)
  profit_link, = query_template_link(InvoiceSearch, nil, query_params: { source_id: [campaign.source_id] }, show_zero: true, aggregate_method: :sum, aggregate_column: :profit_consolidated, format: :currency, counter_class: '')
  profit_link
end

Renders a link showing total invoiced revenue for the campaign's source.

Parameters:

  • campaign (Campaign)

    the campaign whose revenue is summed

Returns:

  • (String)

    HTML link to the filtered InvoiceSearch revenue sum



62
63
64
65
# File 'app/helpers/campaigns_helper.rb', line 62

def campaign_revenue_link(campaign)
  revenue_link, = query_template_link(InvoiceSearch, nil, query_params: { source_id: [campaign.source_id] }, show_zero: true, aggregate_method: :sum, aggregate_column: :revenue_consolidated, format: :currency, counter_class: '')
  revenue_link
end