2015-02-11 20:34:41 -05:00
|
|
|
class Admin::ServicesController < Admin::ApplicationController
|
2015-04-16 08:03:37 -04:00
|
|
|
before_action :service, only: [:edit, :update]
|
2015-02-11 20:34:41 -05:00
|
|
|
|
|
|
|
def index
|
|
|
|
@services = services_templates
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
unless service.present?
|
|
|
|
redirect_to admin_application_settings_services_path,
|
|
|
|
alert: "Service is unknown or it doesn't exist"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
if service.update_attributes(application_services_params[:service])
|
|
|
|
redirect_to admin_application_settings_services_path,
|
|
|
|
notice: 'Application settings saved successfully'
|
|
|
|
else
|
|
|
|
render :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def services_templates
|
|
|
|
templates = []
|
|
|
|
|
2015-02-12 13:57:08 -05:00
|
|
|
Service.available_services_names.each do |service_name|
|
|
|
|
service_template = service_name.concat("_service").camelize.constantize
|
2015-02-11 20:34:41 -05:00
|
|
|
templates << service_template.where(template: true).first_or_create
|
|
|
|
end
|
|
|
|
|
|
|
|
templates
|
|
|
|
end
|
|
|
|
|
|
|
|
def service
|
|
|
|
@service ||= Service.where(id: params[:id], template: true).first
|
|
|
|
end
|
|
|
|
|
|
|
|
def application_services_params
|
2015-10-13 05:29:57 -04:00
|
|
|
application_services_params = params.permit(:id,
|
2015-04-24 11:33:24 -04:00
|
|
|
service: Projects::ServicesController::ALLOWED_PARAMS)
|
2015-10-13 05:29:57 -04:00
|
|
|
if application_services_params[:service].is_a?(Hash)
|
|
|
|
Projects::ServicesController::FILTER_BLANK_PARAMS.each do |param|
|
|
|
|
application_services_params[:service].delete(param) if application_services_params[:service][param].blank?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
application_services_params
|
2015-02-11 20:34:41 -05:00
|
|
|
end
|
|
|
|
end
|