mirror of
https://github.com/internetee/registry.git
synced 2025-07-22 02:35:57 +02:00
parent
5fdc1938af
commit
5a533e09bf
44 changed files with 1027 additions and 375 deletions
86
app/controllers/admin/billing/prices_controller.rb
Normal file
86
app/controllers/admin/billing/prices_controller.rb
Normal file
|
@ -0,0 +1,86 @@
|
|||
module Admin
|
||||
module Billing
|
||||
class PricesController < AdminController
|
||||
authorize_resource(class: 'Billing::Price')
|
||||
before_action :load_price, only: %i[edit update destroy]
|
||||
helper_method :zones
|
||||
helper_method :operation_categories
|
||||
helper_method :durations
|
||||
|
||||
def index
|
||||
@q = ::Billing::Price.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])
|
||||
end
|
||||
|
||||
def new
|
||||
@price = ::Billing::Price.new
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def create
|
||||
@price = ::Billing::Price.new(price_params)
|
||||
|
||||
if @price.save
|
||||
flash[:notice] = t('.created')
|
||||
redirect_to_index
|
||||
else
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if @price.update_attributes(price_params)
|
||||
flash[:notice] = t('.updated')
|
||||
redirect_to_index
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@price.destroy!
|
||||
flash[:notice] = t('.destroyed')
|
||||
redirect_to_index
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_price
|
||||
@price = ::Billing::Price.find(params[:id])
|
||||
end
|
||||
|
||||
def price_params
|
||||
allowed_params = %i[
|
||||
zone_id
|
||||
operation_category
|
||||
duration
|
||||
price
|
||||
valid_from
|
||||
valid_to
|
||||
]
|
||||
|
||||
params.require(:price).permit(*allowed_params)
|
||||
end
|
||||
|
||||
def redirect_to_index
|
||||
redirect_to admin_prices_url
|
||||
end
|
||||
|
||||
def zones
|
||||
::DNS::Zone.all
|
||||
end
|
||||
|
||||
def operation_categories
|
||||
::Billing::Price::operation_categories
|
||||
end
|
||||
|
||||
def durations
|
||||
::Billing::Price::durations
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue