Merge branch 'master' into registry-475

# Conflicts:
#	app/models/billing/price.rb
#	spec/models/billing/price_spec.rb
This commit is contained in:
Artur Beljajev 2017-06-15 09:39:14 +03:00
commit dfdce5dedc
29 changed files with 313 additions and 132 deletions

View file

@ -2,13 +2,30 @@ module Admin
module Billing
class PricesController < AdminController
authorize_resource(class: 'Billing::Price')
before_action :load_price, only: %i[edit update destroy]
before_action :load_price, only: %i[edit update expire]
helper_method :zones
helper_method :operation_categories
helper_method :durations
helper_method :statuses
def self.default_status
'effective'
end
def index
@q = ::Billing::Price.search(params[:q])
@search = OpenStruct.new(search_params)
unless @search.status
@search.status = self.class.default_status
end
prices = ::Billing::Price.all
if @search.status.present?
prices = ::Billing::Price.send(@search.status)
end
@q = prices.search(params[:q])
@q.sorts = ['zone_id asc', 'duration asc', 'operation_category asc',
'valid_from desc', 'valid_to asc'] if @q.sorts.empty?
@prices = @q.result.page(params[:page])
@ -41,9 +58,10 @@ module Admin
end
end
def destroy
@price.destroy!
flash[:notice] = t('.destroyed')
def expire
@price.expire
@price.save!
flash[:notice] = t('.expired')
redirect_to_index
end
@ -66,6 +84,13 @@ module Admin
params.require(:price).permit(*allowed_params)
end
def search_params
allowed_params = %i[
status
]
params.fetch(:search, {}).permit(*allowed_params)
end
def redirect_to_index
redirect_to admin_prices_url
end
@ -82,6 +107,10 @@ module Admin
durations = ::Billing::Price::durations
durations.collect { |duration| [duration.sub('mon', 'month'), duration] }
end
def statuses
::Billing::Price.statuses.map { |status| [status.capitalize, status] }
end
end
end
end

View file

@ -36,12 +36,6 @@ module Admin
end
end
def destroy
@zone.destroy!
flash[:notice] = t('.destroyed')
redirect_to_index
end
private
def load_zone