gitcoinco/code_fund_ads

View on GitHub
app/views/campaigns/form/_budget.html.erb

Summary

Maintainability
Test Coverage
<%= render Card::BodyComponent.new classes: "border-top" do %>
  <%= render Card::TitleComponent.new do %>
    Budget <small>for <%= number_with_delimiter campaign.total_operative_days %> operative days <%= " with a total spend of #{campaign.total_budget.format}" if campaign.region_and_audience_pricing_strategy? %></small>
  <% end %>
  <%= render(Card::SubtitleComponent.new(classes: "mb-4")) { "This campaign is using the #{campaign.pricing_strategy.humanize.downcase} based pricing strategy" } %>
  <% if campaign.campaign_pricing_strategy? %>
    <%= tag.div class: "row" do %>
      <div class="col-12 mb-2">
        <div class="media align-items-center mb-3">
          <%= f.label :fixed_ecpm, class: "switcher-control mb-0 mr-3" do %>
            <%= f.check_box(:fixed_ecpm, class: "switcher-input", input_html: {data:{"reflex-permanent": true}}) %>
            <span class="switcher-indicator"></span>
          <% end %>
          <label class="media-body text-muted mb-0">
            <span class="d-block text-dark">Use fixed eCPM pricing? <small class="ml-2 text-muted">Do NOT adjust by country</small></span>
          </label>
        </div>
      </div>
    <% end if authorized_user.can_admin_system? %>
    <div class="row">
      <div class="col-md-6 mb-3">
        <%= f.input(:ecpm,
                    as: :currency,
                    currency: "$",
                    disabled: !authorized_user.can_admin_system?,
                    input_html: {data:{"reflex-permanent": true}}) %>
        <small id="passwordHelpBlock" class="form-text text-muted">Effective cost per thousand impressions</small>
      </div>
      <%= tag.div f.input(:total_budget,
                          label: "Total Budget Cap",
                          as: :currency,
                          currency: "$",
                          disabled: !authorized_user.can_admin_system?,
                          input_html: {data:{"reflex-permanent": true}}
                         ), class: "col-md-6 mb-3" %>
    </div>
    <div class="row">
      <%= tag.div f.input(:hourly_budget,
                          label: "Hourly Budget Cap",
                          as: :currency,
                          currency: "$",
                          disabled: !authorized_user.can_admin_system?,
                          input_html: {data:{"reflex-permanent": true}}
                         ), class: "col-md-6 mb-3" %>
      <%= tag.div f.input(:daily_budget,
                          label: "Daily Budget Cap",
                          as: :currency,
                          currency: "$",
                          disabled: !authorized_user.can_admin_system?,
                          input_html: {data:{"reflex-permanent": true}}
                         ), class: "col-md-6 mb-3" %>
    </div>
  <% else %>
    <div class="row">
      <%= tag.div class: "col-md-4 mb-3" do %>
        <%= tag.div f.input(:ecpm_multiplier, label: "eCPM Multiplier", as: :decimal, input_html: {step: 0.01, data:{"reflex-permanent": true}}), class: "mb-3" %>
        <div class="mb-3">
          <%= f.input(:total_budget, label: "Total Budget Cap", as: :currency, currency: "$", input_html: {data:{"reflex-permanent": true}}) %>
          <small class="ml-2 text-muted"><i class="fas fa-info-circle"></i> Do not change this value unless you know what you're doing.</small>
        </div>
        <%= tag.div f.input(:hourly_budget, label: "Hourly Budget Cap", as: :currency, currency: "$", input_html: {data:{"reflex-permanent": true}}), class: "mb-3" %>
        <%= tag.div f.input(:daily_budget, label: "Daily Budget Cap", as: :currency, currency: "$", input_html: {data:{"reflex-permanent": true}}), class: "mb-3" %>
      <% end if authorized_user.can_admin_system? %>
      <%= tag.div class: classes("col-12": true, "col-md-8": authorized_user.can_admin_system?) do %>
        <p class="mb-2">eCPM by Region & Audience</p>
        <%= table add_class: "table-sm table-hover table-bordered" do %>
          <%= table_head do %>
            <%= table_row header: true do %>
              <%= table_column "Region" %>
              <%= table_column "Audience" %>
              <%= table_column "Base eCPM", add_class: "text-right" %>
              <%= table_column "Adjusted eCPM", add_class: "text-right" %>
            <% end %>
          <% end %>
          <%= table_body do %>
            <% campaign.inventory_summary.inventory_details.map do |inventory_detail| %>
              <%= table_row title: "#{inventory_detail.region.name} + #{inventory_detail.audience.name}" do %>
                <%= table_data do %><small class="text-nowrap"><%= truncate inventory_detail.region.name, length: 30 %></small><% end %>
                <%= table_data do %><small class="text-nowrap"><%= truncate inventory_detail.audience.name, length: 30 %></small><% end %>
                <%= table_data inventory_detail.base_ecpm.format, add_class: "text-right text-monospace" %>
                <%= table_data inventory_detail.adjusted_ecpm.format, add_class: "text-right text-monospace" %>
              <% end %>
            <% end %>
          <% end %>
        <% end %>
      <% end %>
    </div>
  <% end %>
<% end %>