diff --git a/app/controllers/spree/admin/reports_controller_decorator.rb b/app/controllers/spree/admin/reports_controller_decorator.rb index 4cd3936..1827d3a 100644 --- a/app/controllers/spree/admin/reports_controller_decorator.rb +++ b/app/controllers/spree/admin/reports_controller_decorator.rb @@ -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 diff --git a/app/views/spree/admin/reports/stock_requests.csv.erb b/app/views/spree/admin/reports/stock_requests.csv.erb index 956833e..570d1eb 100644 --- a/app/views/spree/admin/reports/stock_requests.csv.erb +++ b/app/views/spree/admin/reports/stock_requests.csv.erb @@ -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 %> \ No newline at end of file diff --git a/app/views/spree/admin/reports/stock_requests.html.haml b/app/views/spree/admin/reports/stock_requests.html.haml index 771f2fc..00332b1 100644 --- a/app/views/spree/admin/reports/stock_requests.html.haml +++ b/app/views/spree/admin/reports/stock_requests.html.haml @@ -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) \ No newline at end of file diff --git a/app/views/spree/admin/shared/_stock_report_criteria.html.haml b/app/views/spree/admin/shared/_stock_report_criteria.html.haml new file mode 100644 index 0000000..606e57b --- /dev/null +++ b/app/views/spree/admin/shared/_stock_report_criteria.html.haml @@ -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' \ No newline at end of file