Skip to content

Commit

Permalink
Update Reports
Browse files Browse the repository at this point in the history
  • Loading branch information
ddomingues committed Dec 13, 2014
1 parent 2d6f50f commit eb2d835
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 60 deletions.
16 changes: 4 additions & 12 deletions app/controllers/spree/admin/reports_controller_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
Spree::Admin::ReportsController.add_available_report! :stock_requests

Spree::Admin::ReportsController.class_eval do

def stock_requests
@search = Spree::StockRequest.search(params[:search])
add_available_report! :stock_requests

respond_to do |format|
format.html do
@stock_requests = @search.page(params[:page])
end
format.csv do
@stock_requests = @search.all
end
end
def stock_requests
@search = Spree::StockRequest.ransack(params[:search])
@stock_requests = @search.result
end

end
16 changes: 8 additions & 8 deletions app/views/spree/admin/reports/stock_requests.csv.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<%= %w(email sku product variant status requested).collect{|h| "\"#{t(h)}\""}.join(',').html_safe %>
<%= %w(email sku product variant status requested).collect{|h| "\"#{t(h)}\""}.join(',').html_safe %>
<% @stock_requests.each do |request| %>
<%= [request.email,
request.variant ? request.variant.sku : request.product.sku,
request.product.name,
request.variant ? request.variant.options_text : '',
request.status.titleize,
request.created_at.to_s(:short)].collect{|cell| "\"#{cell}\"" }.join(",").html_safe %>
<% end %>
<%= [request.email,
request.variant ? request.variant.sku : request.product.sku,
request.product.name,
request.variant ? request.variant.options_text : '',
request.status.titleize,
request.created_at.to_s(:short)].collect{|cell| "\"#{cell}\"" }.join(",").html_safe %>
<% end %>
67 changes: 27 additions & 40 deletions app/views/spree/admin/reports/stock_requests.html.haml
Original file line number Diff line number Diff line change
@@ -1,40 +1,27 @@
.toolbar
%ul.actions
%li
= button_link_to Spree.t(:download), stock_requests_admin_reports_path(@search.search_attributes.merge(:format => :csv)), {:icon => 'xls'}
%br.clear

%h1= Spree.t(:stock_requests)

%table.index
%tr
%th= sort_link @search, :email
%th= Spree.t(:product)
%th= Spree.t(:variant)
%th= sort_link @search, :status
%th= sort_link @search, :created_at, Spree.t(:requested)

- @stock_requests.each do |stock_request|
%tr{:class => cycle('even','odd')}
%td= stock_request.email
%td= link_to stock_request.product.name, edit_admin_product_path(stock_request.product)
%td= stock_request.variant.options_text if stock_request.variant
%td= stock_request.status.titleize
%td
= time_ago_in_words(stock_request.created_at)
= Spree.t(:ago)

= paginate @stock_requests

- content_for :sidebar do
= form_for @search, :url => stock_requests_admin_reports_path do |f|
.box
%h3= Spree.t(:search)
%p
= f.label :product_variants_sku_contains, Spree.t(:sku)
= f.text_field :product_variants_sku_contains, :size => 15
%p
= f.label :status_equals, Spree.t(:status)
= f.select :status_equals, %w(new notified).collect {|s| [s.titleize,s]}, :include_blank => Spree.t(:show_all)
%p.form-buttons
= button Spree.t(:search)
- content_for :page_title do
= Spree.t(:stock_requests)
- content_for :page_actions do
%li= link_to_with_icon 'icon-arrow-left', Spree.t(:back_to_reports_list), spree.admin_reports_url, :class => 'button'
- content_for :table_filter_title do
= Spree.t(:date_range)
- content_for :table_filter do
= render :partial => 'spree/admin/shared/stock_report_criteria', :locals => {}
%table.admin-report{"data-hook" => "stock_requests"}
%thead
%tr
%th= sort_link @search, :email
%th= Spree.t(:product)
%th= Spree.t(:variant)
%th= sort_link @search, :status
%th= sort_link @search, :created_at, Spree.t(:requested)
%tbody
- @stock_requests.each do |stock_request|
- next if stock_request.product.nil?
%tr{:class => "cycle('even', 'odd')"}
%td= stock_request.email
%td= link_to stock_request.product.name, edit_admin_product_path(stock_request.product)
%td= stock_request.variant.options_text if stock_request.variant
%td= stock_request.status.titleize
%td
= time_ago_in_words(stock_request.created_at)
= Spree.t(:ago)
10 changes: 10 additions & 0 deletions app/views/spree/admin/shared/_stock_report_criteria.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
= search_form_for @search, :url => spree.stock_requests_admin_reports_path do |s|
.date-range-filter.field.align-center
= label_tag nil, Spree.t(:start), :class => 'inline'
= s.text_field :created_at_gt, :class => 'datepicker datepicker-from'
%span.range-divider
%i.icon-arrow-right
= s.text_field :created_at_lt, :class => 'datepicker datepicker-to'
= label_tag nil, Spree.t(:end), :class => 'inline'
.actions.filter-actions
= button Spree.t(:search), 'icon-search'

0 comments on commit eb2d835

Please sign in to comment.