ngelx/solidus_import_products

View on GitHub
app/views/spree/admin/product_imports/index.html.erb

Summary

Maintainability
Test Coverage
<% content_for :page_title do %>
  <%= t('form.product_import.heading') %>
<% end %>

<div class="row">
<div class="col-sm-6">
<%= form_for([:admin, @product_import], :method => :post, :html => { :multipart => true }) do |f| %>
  <fieldset class="no-border-top">
  <%= f.field_container :data_file, class: ['form-group'] do  %>
    <%= f.label :data_file, t('form.product_import.new.data_file') %><br />
    <%= f.file_field :data_file %>
    <%= f.error_message_on :data_file %>
  <% end %>
  <div class="field">
    <%= f.label :separatorChar, t('form.product_import.separator_char') %><br />
    <%= f.text_field :separatorChar, class: 'form-control required',:id =>  "separatorChar",:value => ";" ,:size => 1, :maxlength => 1 %>
  </div>
  <div class="field">
    <%= f.label :encoding_csv, t('form.product_import.encoding') %><br />
    <%= f.select(:encoding_csv,
                   options_from_collection_for_select(Spree::ProductImport::ENCODINGS, :to_s, :to_s, 'UTF-8'),
                   {:class => 'select2', :prompt => false}) %>
  </div>
  <div data-hook="buttons" class="form-actions">
    <%= button Spree.t('actions.import'), 'ok', 'submit', {class: 'btn-success'} %>
  </div>
  </fieldset>

<% end %>
</div>
</div>
<table class="table">
  <colgroup>
    <col style="width: 15%">
    <col style="width: 20%">
    <col style="width: 10%">
    <col style="width: 15%">
    <col style="width: 10%">
    <col style="width: 20%">
    <col style="width: 5%">
  </colgroup>
  <thead>
  <tr>
    <th>Date creation</th>
    <th>CSV Name</th>
    <th>Status</th>
    <th>Date Status</th>
    <th>Imported</th>
    <th>Error Message</th>
    <th class="actions">Actions</th>
  </tr>
  </thead>
  <tbody>
  <% Spree::ProductImport.order("created_at DESC").all.each do |import| %>
    <tr class="<%= cycle('odd', 'even') %>" id="<%= dom_id import %>">
      <td><%= I18n.l(import.created_at.to_datetime,format: :short)%></td>
      <td><%= link_to import.data_file_file_name, import.data_file.url -%></td>
      <td><span class="label-<%= import.state.downcase %>"><%= t(import.state, :scope => "product_import.state")%></span></td>
      <td><%= I18n.l(import.state_datetime.to_datetime,format: :short) %></td>
      <td><%= import.product_ids.size -%></td>
      <td><%= import.error_message%></td>
      <td class="actions text-center">
        <%= link_to_edit import, :url => admin_product_import_path(import), :no_text => true -%>
      </td>
      <td class="actions text-center">
        <%= link_to_delete import, :url => admin_product_import_path(import), :no_text => true -%>
      </td>
    </tr>
  <% end %>
  </tbody>
</table>