register_modules/app/controllers/admin/admin_modules_controller.rb

184 lines
5.0 KiB
Ruby
Raw Normal View History

2014-12-30 11:52:45 +00:00
class Admin::AdminModulesController < OrbitAdminController
include RegisteredModuleHelper
def initialize
super
@app_title = "register_module"
end
def index
2022-06-30 04:17:47 +00:00
@filter_fields = {}
@registered_modules = RegisteredModule.where(:completed => true)
2014-12-30 11:52:45 +00:00
@table_fields = table_fields
2022-06-30 04:17:47 +00:00
@registered_modules = search_data(@registered_modules,[:name, :module_key]).page(params[:page]).per(10)
2014-12-30 11:52:45 +00:00
if request.xhr?
render :partial => "index"
end
end
def uploadfiles
@rm = RegisteredModule.find(params[:module_id])
@categories = @module_app.categories.enabled
@tags = @module_app.tags
end
2014-12-30 11:52:45 +00:00
def approve_modules
@rm = RegisteredModule.find(params[:module_id])
@categories = @module_app.categories.enabled
@tags = @module_app.tags
render :layout => false
end
def install_site_list
rm = RegisteredModule.find(params[:id]) rescue nil
@registered_sites = site_list_without_module(rm)
render :layout => false
end
def uninstall_site_list
rm = RegisteredModule.find(params[:id]) rescue nil
2016-07-13 07:08:37 +00:00
slwm = site_list_with_module(rm, nil)
2016-01-05 07:43:55 +00:00
@registered_sites = slwm.first
@times = slwm.last
2014-12-30 11:52:45 +00:00
render :layout => false
end
def revoke_list
rm = RegisteredModule.find(params[:id]) rescue nil
2016-01-05 07:37:45 +00:00
slwm = site_list_with_module(rm, true)
@registered_sites = slwm.first
@times = slwm.last
2014-12-30 11:52:45 +00:00
render :layout => false
end
def grant_list
rm = RegisteredModule.find(params[:id]) rescue nil
2016-07-13 07:03:23 +00:00
slwm = site_list_with_module(rm, false)
2016-01-05 07:43:55 +00:00
@registered_sites = slwm.first
@times = slwm.last
2014-12-30 11:52:45 +00:00
render :layout => false
end
def update
rm = RegisteredModule.find(params[:id])
p = registered_module_params
p[:module_show_files] = rm.module_show_files + p[:module_show_files]
rm.update_attributes(p)
2014-12-30 11:52:45 +00:00
rm.save
if !params[:images_to_destroy].blank?
images = ModuleShowFile.where(:id.in => params[:images_to_destroy])
images.destroy_all
end
if request.xhr?
render :json => {"success" => true}.to_json
else
redirect_to admin_admin_modules_path
end
2014-12-30 11:52:45 +00:00
end
def install_module
websites = params[:websites]
rm = RegisteredModule.find(params[:module]) rescue nil
if !websites.blank?
p1 = fork{install_modules_on_websites(websites,rm)}
Process.detach(p1)
end
render :json=>{"success" => true}.to_json
end
def uninstall_module
websites = params[:websites]
rm = RegisteredModule.find(params[:module]) rescue nil
if !websites.blank?
# uninstall_modules_on_websites(websites,rm)
p1 = fork{uninstall_modules_on_websites(websites,rm)}
Process.detach(p1)
end
render :json=>{"success" => true}.to_json
end
def revoke_module
websites = params[:websites]
rm = RegisteredModule.find(params[:module]) rescue nil
websites.each do |website|
im = InstalledModule.where(:registered_site_id => website,:r_module => rm.id).first rescue nil
if !im.nil?
im.permission_granted = false
im.save
end
end
render :json=>{"success" => true}.to_json
end
def grant_module
websites = params[:websites]
rm = RegisteredModule.find(params[:module]) rescue nil
websites.each do |website|
im = InstalledModule.where(:registered_site_id => website,:r_module => rm.id).first rescue nil
if !im.nil?
im.permission_granted = true
im.save
end
end
render :json=>{"success" => true}.to_json
end
def upload_module_image
file = ModuleShowFile.create(show_file_params)
render :json => {"success" => true,"id" => file.id.to_s}.to_json
end
private
2014-12-30 11:52:45 +00:00
def show_file_params
params.require(:module_show_file).permit!
end
2014-12-30 11:52:45 +00:00
def site_list_without_module(rm)
registered_sites = []
if !rm.nil?
active_ids = RegisteredSite.active.pluck(:id)
already_installed_ids = InstalledModule.where(:r_module => rm.id, :registered_site_id.in => active_ids).pluck(:registered_site_id)
registered_sites = RegisteredSite.where(:id.in=>active_ids - already_installed_ids).order_by(:id=>-1).to_a
2014-12-30 11:52:45 +00:00
end
registered_sites
end
def site_list_with_module(rm,access=nil)
registered_sites = []
2016-01-05 07:37:45 +00:00
times = []
2014-12-30 11:52:45 +00:00
if !rm.nil?
if access.nil?
ims = InstalledModule.where(:r_module => rm.id, :registered_site_id.in => RegisteredSite.active.pluck(:id))
else
ims = InstalledModule.where(:r_module => rm.id, :registered_site_id.in => RegisteredSite.active.pluck(:id), :permission_granted => access)
2014-12-30 11:52:45 +00:00
end
ims_info = ims.pluck(:registered_site_id, :created_at)
ims_info.uniq!{|rs_id, created_at| rs_id}
ims_info = ims_info.to_h
registered_sites = RegisteredSite.where(:id.in=>ims_info.keys).order_by(:id=>-1).to_a
times = registered_sites.map{|rs| ims_info[rs.id].strftime("%Y-%m-%d %H:%M") rescue ""}
2014-12-30 11:52:45 +00:00
end
2016-01-05 07:37:45 +00:00
[registered_sites, times]
2014-12-30 11:52:45 +00:00
end
def registered_module_params
p = params.require(:registered_module).permit!
if p[:module_show_files].present?
images = []
p[:module_show_files].each do |id|
image = ModuleShowFile.find(id) rescue nil
images << image if !image.nil?
end
p[:module_show_files] = images
2018-01-31 06:47:47 +00:00
else
p[:module_show_files] = []
end
p
2014-12-30 11:52:45 +00:00
end
def table_fields
[:module_name_, :category, :developed_by, :actions]
end
end