jclem/active_record_rollout

View on GitHub
app/views/detour/flags/index.html.erb

Summary

Maintainability
Test Coverage
<h1><%= params[:flaggable_type].classify %> Flags</h1>

<% if @flag_form.errors? %>
  <div class="panel panel-danger">
    <div class="panel-heading">Whoops! There were some errors saving your flags:</div>

    <div class="panel-body">
      <ul>
        <% @flag_form.features.each do |feature| %>
          <% feature.errors.full_messages.each do |msg| %>
              <li><strong><%= feature.name %>:</strong> <%= msg %></li>
          <% end %>
        <% end %>
      </ul>
    </div>
  </div>
<% end %>

<%= form_tag do %>
  <%= table do %>
    <thead>
      <tr>
        <th></th>
        <th>Feature</th>
        <th>In Code?</th>

        <%= render partial: "detour/shared/spacer_cells", locals: { tag: "th" } %>

        <% @flag_form.groups.each do |group| %>
          <th>
            <span class="group-header">
              <% if group.is_a? Detour::Group %>
                <%= link_to group, group %>
              <% else %>
                <%= group %>
              <% end %>
            </span>
          </th>
        <% end %>

        <th class="percentage-header">Percentage</th>
        <th class="counter-header">Flag-ins</th>
        <th class="counter-header">Opt-outs</th>
      </tr>
    </thead>

    <tbody>
      <%= render partial: "feature_form", collection: @flag_form.features, as: :feature %>
    </tbody>
  <% end %>

  <%= content_tag :span, "Create a Feature", class: "btn btn-default pull-left", data: { toggle: "modal", target: "#create-feature" } %>

  <div class="btn-group pull-right">
    <% if @flag_form.errors? %>
      <%= link_to "Cancel", request.path, class: "btn btn-default" %>
    <% end %>

    <%= submit_tag "Save Changes", class: "btn btn-primary" %>
  </div>
<% end %>

<%= modal title: "Delete Feature", id: "delete-feature" do %>
  <p>Are you sure you want to delete <span class="feature-name"></span>?</p>

  <%= modal_footer do %>
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
    <%= link_to "Delete Feature", "javascript:void(0)", method: :delete, class: "btn btn-danger" %>
  <% end %>
<% end %>

<%= modal title: "Create a Feature", id: "create-feature", fade: true do %>
  <%= form_for Detour::Feature.new, remote: true do |form| %>
    <%= form.text_field :name, class: "form-control", placeholder: "feature_name" %>

    <%= modal_footer do %>
      <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      <%= form.submit "Create Feature", class: "btn btn-primary" %>
    <% end %>
  <% end %>
<% end %>