register_modules/app/controllers/admin/register_modules_controller.rb

50 lines
1.3 KiB
Ruby

class Admin::RegisterModulesController < OrbitAdminController
include RegisteredModuleHelper
def index
@table_fields = table_fields
@registered_modules = RegisteredModule.where(:create_user_id => current_user.id).desc(:created_at)
if request.xhr?
render :partial => "my_registered_module"
end
end
def create
rm = RegisteredModule.new
rm.update_attributes(module_params)
rm.create_user_id = current_user.id
rm.update_user_id = current_user.id
rm.save
render :json => {"success" => true, "id" => rm.id.to_s}.to_json
end
def update
rm = RegisteredModule.find(params[:id])
rm.update_attributes(module_params)
rm.update_user_id = current_user.id
rm.save
if module_params[:step_number] == "4"
site = RegisteredSite.find(RegisteredModuleSetting.first.test_site) rescue nil
if !site.nil?
p1 = fork{install_on_server(site, rm)}
Process.detach(p1)
# install_on_server(site, rm)
end
end
render :json => {"success" => true, "id" => rm.id.to_s}.to_json
end
def modulekeys
keys = RegisteredModule.all.collect{|rm| rm.module_key}
render :json => {"keys" => keys}.to_json
end
private
def module_params
params.require(:registered_module).permit!
end
def table_fields
[:module_name_, :status, :actions]
end
end