gitcoinco/code_fund_ads

View on GitHub
app/views/campaign_bundles/campaigns/_form.html.erb

Summary

Maintainability
Test Coverage
<% cache [Digest::MD5.hexdigest(campaign.attributes.to_s), campaign.date_range, Campaign.sold.premium], expires_in: 1.day do %>
  <%= f.fields_for "campaigns_attributes[#{campaign.temporary_id}]", campaign do |cf| %>
    <div id="campaign-<%= campaign_iteration.index %>-fields" class="row">
      <div class="col-4">
        <%= render CardComponent.new do %>
          <%= render Card::HeaderComponent.new do %>
            <%= render Card::TitleComponent.new do %>
              <div class="d-flex justify-content-between align-items-center">
                <span>
                  Campaign <%= campaign_iteration.index + 1 %>
                <small><%= " spend of #{campaign.total_budget.format no_cents: true} over #{number_with_delimiter campaign.total_operative_days} days" %></small>
                </span>
                <%= link_to "Remove", "#", class: "btn btn-link", data: {reflex: "click->CampaignBundlesReflex#remove_campaign", temporary_id: campaign.temporary_id} %>
              </div>
            <% end %>
            <%= render Card::SubtitleComponent.new do %>
              <%= table add_class: "table-sm table-bordered mt-2" do %>
                <%= table_head add_class: "bg-light" do %>
                  <%= table_row header: true do %>
                    <%= table_column add_class: "text-right" do %><small class="d-block opacity-60">Estimated</small>Total Impressions<% end %>
                    <%= table_column add_class: "text-right" do %><small class="d-block opacity-60">Estimated</small>Daily Impressions<% end %>
                    <%= table_column add_class: "text-right" do %><small class="d-block opacity-60">Estimated</small>Total Clicks<% end %>
                    <%= table_column add_class: "text-right" do %><small class="d-block opacity-60">Estimated</small>Daily Clicks<% end %>
                    <%= table_column add_class: "text-right" do %><small class="d-block opacity-60">Estimated</small>Average CPM<% end %>
                    <%= table_column add_class: "text-right" do %><small class="d-block opacity-60">Estimated</small>Average CPC<% end %>
                  <% end %>
                <% end %>
                <%= table_body add_class: "bg-success-light" do %>
                  <%= table_column number_with_delimiter(campaign.inventory_summary.estimated_impressions_count), add_class: "font-weight-normal text-dark text-right" %>
                  <%= table_column number_with_delimiter((campaign.inventory_summary.estimated_impressions_count / campaign.total_operative_days.to_f).round), add_class: "font-weight-normal text-dark text-right" %>
                  <%= table_column number_with_delimiter(campaign.inventory_summary.estimated_clicks_count), add_class: "font-weight-normal text-dark text-right" %>
                  <%= table_column number_with_delimiter((campaign.inventory_summary.estimated_clicks_count / campaign.total_operative_days.to_f).round), add_class: "font-weight-normal text-dark text-right" %>
                  <%= table_column campaign.inventory_summary.estimated_cpm.format, add_class: "font-weight-normal text-dark text-right" %>
                  <%= table_column campaign.inventory_summary.estimated_cpc.format, add_class: "font-weight-normal text-dark text-right" %>
                <% end %>
              <% end %>
              You won't pay more than your daily budget times the total number of days that the bundle is configured to run.
              Some days you might spend more or less than your daily budget.
            <% end %>
          <% end %>
          <%= render Card::BodyComponent.new do %>
            <div class="row">
              <div class="col form-group">
                <%= cf.label :name %>
                <%= cf.text_field :name, class: "form-control", required: true,
                  data: {reflex: "cf:value-committed->CampaignBundlesReflex#update_campaign_name", temporary_id: campaign.temporary_id} %>
              </div>
            </div>

            <div class="row">
              <div class="col form-group">
                <%= cf.label "Date Range" %>
                <%= cf.text_field(:date_range, class: "js-range-datepicker form-control bg-white rounded-right",
                                  data: {reflex: "cf:date-range-selected->CampaignBundlesReflex#update_campaign_date_range", controller: "select-date-range", temporary_id: campaign.temporary_id}) %>
              </div>
            </div>

            <div class="row">
              <div class="col form-group">
                <%= cf.label :url, "URL" %>
                <%= cf.text_field :url, class: "form-control", required: true, placeholder: "https://example.com/?utm_source=codefund&utm_campaign={{campaign_id}}",
                  data: {reflex: "cf:value-committed->CampaignBundlesReflex#update_campaign_url", temporary_id: campaign.temporary_id} %>
                <details class="mt-2">
                  <summary>Use any of the following variables in the URL</summary>
                  <%= render(UtmTableComponent.new(campaign: campaign)) %>
                </details>
              </div>
            </div>

            <div class="row">
              <div class="col-6 form-group">
                <%= cf.label :daily_budget, "Daily Budget" %>
                <%= cf.text_field :daily_budget, value: campaign.daily_budget.format(symbol: false), step: 0.01, class: "form-control", required: true,
                  data: {reflex: "cf:value-committed->CampaignBundlesReflex#update_campaign_daily_budget", temporary_id: campaign.temporary_id} %>
                <small class="form-text text-muted">
                  The average you want to spend each day
                </small>
              </div>
              <div class="col-6 form-group">
                <%= cf.label :ecpm_multiplier, "eCPM Multiplier" %>
                <%= cf.number_field :ecpm_multiplier, class: "form-control", required: true, step: 0.01,
                  data: {reflex: "cf:value-committed->CampaignBundlesReflex#update_campaign_ecpm_multiplier", temporary_id: campaign.temporary_id} %>
              </div>
            </div>

            <div class="row" data-controller="checkboxes" data-reflex-name="CampaignBundlesReflex#update_campaign_audience_ids" data-temporary-id="<%= campaign.temporary_id %>">
              <div class="col">
                <%= cf.label :audiences, "Audiences" %>
                <% Audience.order(:name).each do |audience| %>
                  <div class="custom-control custom-checkbox ml-1">
                    <%= cf.check_box :audience_ids,
                      {id: campaign_audience_dom_id(campaign, audience), class: "custom-control-input", multiple: true, data: {action: "change->checkboxes#invokeReflex"}},
                      audience.id, campaign.audience_ids.include?(audience.id) %>
                    <%= cf.label audience.name, audience.name, for: campaign_audience_dom_id(campaign, audience), class: "custom-control-label" %>
                  </div>
                <% end %>
                <div class="mt-2">
                  <a href="#" class="btn btn-link btn-light border" data-action="click->checkboxes#checkAll">Select All</a>
                  <a href="#" class="btn btn-link btn-light border" data-action="click->checkboxes#uncheckAll">Clear Selections</a>
                </div>
              </div>
            </div>
          </div>
        <% end %>
      <% end %>
      <div class="col-8">
        <%= render "/shared/errors", record: campaign %>
        <%= render "/campaign_bundles/campaigns/inventory", campaign: campaign if campaign.start_date && campaign.region_ids.present? && campaign.audience_ids.present? %>
      </div>
    </div>
  <% end %>
<% end %>