Base filter options from initial authorizer object

This commit is contained in:
Kristina Lim
2018-10-11 02:36:59 +08:00
committed by luisramos0
parent bd2b4c0134
commit 34dc16f8c9
4 changed files with 56 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
require "open_food_network/reports"
require "order_management/reports/enterprise_fee_summary/parameters"
require "order_management/reports/enterprise_fee_summary/report_authorizer"
require "order_management/reports/enterprise_fee_summary/report_service"
require "order_management/reports/enterprise_fee_summary/renderers/csv_renderer"
@@ -8,6 +9,7 @@ module Spree
module Reports
class EnterpriseFeeSummaryReportController < BaseController
before_filter :load_report_parameters, only: [:index]
before_filter :load_report_authorizer, only: [:index]
def index
return render_report_form if params[:report].blank?
@@ -40,6 +42,10 @@ module Spree
@report_parameters = report_klass::Parameters.new(params[:report] || {})
end
def load_report_authorizer
@report_authorizer = report_klass::ReportAuthorizer.new(spree_current_user)
end
def report_renderer_klass
case params[:report_format]
when "csv"

View File

@@ -16,31 +16,31 @@
.row
.sixteen.columns.alpha
= f.label :distributor_ids
= f.collection_select(:distributor_ids, [], :id, :name, {}, {class: "select2 fullwidth", multiple: true})
= f.collection_select(:distributor_ids, @report_authorizer.allowed_distributors, :id, :name, {}, {class: "select2 fullwidth", multiple: true})
.row
.sixteen.columns.alpha
= f.label :producer_ids
= f.collection_select(:producer_ids, [], :id, :name, {}, {class: "select2 fullwidth", multiple: true})
= f.collection_select(:producer_ids, @report_authorizer.allowed_producers, :id, :name, {}, {class: "select2 fullwidth", multiple: true})
.row
.sixteen.columns.alpha
= f.label :order_cycle_ids
= f.collection_select(:order_cycle_ids, [], :id, :name, {}, {class: "select2 fullwidth", multiple: true})
= f.collection_select(:order_cycle_ids, @report_authorizer.allowed_order_cycles, :id, :name, {}, {class: "select2 fullwidth", multiple: true})
.row
.eight.columns.alpha
= f.label :enterprise_fee_ids
= f.collection_select(:enterprise_fee_ids, [], :id, :name, {}, {class: "select2 fullwidth", multiple: true})
= f.collection_select(:enterprise_fee_ids, @report_authorizer.allowed_enterprise_fees, :id, :name, {}, {class: "select2 fullwidth", multiple: true})
.eight.columns.omega
= f.label :shipping_method_ids
= f.collection_select(:shipping_method_ids, [], :id, :name, {}, {class: "select2 fullwidth", multiple: true})
= f.collection_select(:shipping_method_ids, @report_authorizer.allowed_shipping_methods, :id, :name, {}, {class: "select2 fullwidth", multiple: true})
.row
.eight.columns.alpha &nbsp;
.eight.columns.omega
= f.label :payment_method_ids
= f.collection_select(:payment_method_ids, [], :id, :name, {}, {class: "select2 fullwidth", multiple: true})
= f.collection_select(:payment_method_ids, @report_authorizer.allowed_payment_methods, :id, :name, {}, {class: "select2 fullwidth", multiple: true})
.row
.sixteen.columns.alpha

View File

@@ -0,0 +1,11 @@
module OpenFoodNetwork
module Reports
class ReportAuthorizer
attr_accessor :user
def initialize(user)
@user = user
end
end
end
end

View File

@@ -0,0 +1,33 @@
require "open_food_network/reports/report_authorizer"
module OrderManagement
module Reports
module EnterpriseFeeSummary
class ReportAuthorizer < OpenFoodNetwork::Reports::ReportAuthorizer
def allowed_distributors
[]
end
def allowed_producers
[]
end
def allowed_order_cycles
[]
end
def allowed_enterprise_fees
[]
end
def allowed_shipping_methods
[]
end
def allowed_payment_methods
[]
end
end
end
end
end