internetee/registry

View on GitHub
app/views/admin/auctions/index.html.erb

Summary

Maintainability
Test Coverage
<div class="page-header">
    <h1>Auctions</h1>
</div>

<div class="row">
  <div class="col-md-12">
    <%= form_with url: admin_auctions_path, method: :get, html: { style: 'margin-bottom: 0;', class: 'js-form', autocomplete: 'off' } do |f| %>
      <div class="row">
        <div class="col-md-3">
          <div class="form-group">
            <%= f.label :domain %>
            <%= f.search_field :domain_matches, value: params[:domain_matches], class: 'form-control', placeholder: t(:name) %>
          </div>
          <div class="form-group">
            <%= f.label :status %>
            <%= select_tag :statuses_contains, options_for_select(Auction.statuses.map { |x| [x[0], x[1]] }, params[:q][:status]), { include_blank:true, class: 'form-control' } %>
          </div>
        </div>
        <div class="col-md-3">
          <div class="form-group">
            <%= f.label t(:created_at_from) %>
            <%= f.search_field :created_at_start, value: params[:created_at_start], class: 'form-control js-datepicker', placeholder: t(:created_at_from) %>
          </div>
        </div>
        <div class="col-md-3">
          <div class="form-group">
            <%= f.label t(:created_at_until) %>
            <%= f.search_field :created_at_end, value: params[:created_at_end], class: 'form-control js-datepicker', placeholder: t(:created_at_until) %>
          </div>
        </div>
        <div class="col-md-3">
          <div class="form-group">
            <%= label_tag t(:results_per_page) %>
            <%= text_field_tag :results_per_page_auction, params[:results_per_page_auction], class: 'form-control', placeholder: t(:results_per_page) %>
          </div>
        </div>
        <div class="col-md-4" style="padding-top: 25px; display: flex; flex-direction: row;">
          <button class="btn btn-primary" style="margin-right: 10px;">
            &nbsp;
            <span class="glyphicon glyphicon-search"></span>
            &nbsp;
          </button>
          <div style="margin-right: 10px;">
            <%= link_to('Clear', admin_auctions_path, class: 'btn btn-default') %>
          </div>
          <div style="margin-right: 10px;">
            <%= link_to 'Download auction list', admin_auctions_path(format: :csv, params: params.permit!),
                        "data-toggle" => "tooltip", "data-placement" => "bottom", "title" => 'Download CSV',
                        class: 'btn btn-primary' %>
          </div>
          <div >
            <%= link_to "#", class: "btn btn-warning edit", id: 'reserved-modal',
              data: {
                toggle: "modal",
                url: admin_reserved_domains_path,
                target: "#user-form-edit"} do %>
            <i class="glyphicon glyphicon-menu-right glyphicon-white"></i>
            Get reserved domains
          <% end %>

          <%= render 'modal' %>

          </div>
        </div>
      </div>
    <% end %>
  </div>
</div>

<hr />

    <%= search_form_for [:admin, @q], method: :post, html: { style: 'margin-bottom: 0;', class: 'js-form', autocomplete: 'off' } do |f| %>
        <%= label_tag :new_auction %>

        <div style="display: flex; flex-direction: row; align-items: center;">
          <%= text_field_tag :domain, params[:domain], class: 'form-control', placeholder: 'domain name' %>
          <%= f.submit 'Create', class: 'btn btn-primary', style: 'margin-left: .4rem;', id: 'new-auction-btn' %>
        </div>
    <% end %>

<hr/>

    <div class="row">
        <div class="col-md-12" style='margin: 0 0 10px 0; '>
          <%= search_form_for @q, url: upload_spreadsheet_admin_auctions_path, method: :post, html: { style: 'margin-bottom: 0; display: flex; flex-direction: row; align-items: center;', class: 'js-form', autocomplete: 'off' } do |f| %>
            <%= f.file_field :file,
                              accept: ".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel",
                              direct_upload: true,
                              style: 'width: 200px;' %>
            <%= f.submit 'Upload csv', class: 'btn btn-primary' %>
          <% end %>

        </div>
    </div>

    <div class="row">
        <div class="col-md-12">
            <div class="table-responsive">
                <table class="table table-hover table-bordered table-condensed">
                    <thead>
                        <tr>
                            <th class="col-xs-2">
                                <%= sort_link(@q, 'domain') %>
                            </th>
                            <th class="col-xs-2">
                                <%= sort_link(@q, 'status') %>
                            </th>
                            <th class="col-xs-2">
                                <%= sort_link(@q, 'created_at') %>
                            </th>
                            <th class="col-xs-2" style="width: 100px !important; word-break: break-all;">
                                <%= sort_link(@q, 'registration_code') %>
                            </th>
                            <th class="col-xs-2">
                                <%= sort_link(@q, 'registration_deadline') %>
                            </th>
                            <th class="col-xs-1">
                                <%= sort_link(@q, 'platform', 'Type') %>
                            </th>
                        </tr>
                    </thead>

                    <tbody>
                        <% @auctions.each do |auction|  %>
                        <tr>
                            <td><%= colorize_auction(auction) %></td>
                            <td><%= auction.status %></td>
                            <td><%= auction.created_at %></td>
                            <td style="width: 100px !important; word-break: break-all;"><%= auction.registration_code %></td>
                            <td><%= auction.registration_deadline %></td>
                            <td><%= auction.platform.nil? ? 'auto' : auction.platform %></td>
                            <td><%= link_to(t(:delete), admin_auction_path(auction), method: :delete, data: { confirm: t(:are_you_sure_you_want_to_delete_auction) }, class: 'btn btn-danger', id: "delete-auction-#{auction.id}") %></td>
                        </tr>
                        <% end %>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

  <div class="row">
  <div class="col-md-6">
    <%= paginate @auctions %>
  </div>
  <div class="col-md-6 text-right">
    <div class="pagination">
      <%= t(:result_count, count: @auctions.total_count) %>
    </div>
  </div>
</div>

<script>
  $('#user-form-edit').on("show.bs.modal", function(e) {
      $(this).find('.modal-body').load(e.relatedTarget.dataset.url);
  });
</script>