184 lines
5.0 KiB
Ruby
184 lines
5.0 KiB
Ruby
class Admin::AdminModulesController < OrbitAdminController
|
|
include RegisteredModuleHelper
|
|
def initialize
|
|
super
|
|
@app_title = "register_module"
|
|
end
|
|
|
|
def index
|
|
@filter_fields = {}
|
|
@registered_modules = RegisteredModule.where(:completed => true)
|
|
@table_fields = table_fields
|
|
@registered_modules = search_data(@registered_modules,[:name, :module_key]).page(params[:page]).per(10)
|
|
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
|
|
|
|
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
|
|
slwm = site_list_with_module(rm, nil)
|
|
@registered_sites = slwm.first
|
|
@times = slwm.last
|
|
render :layout => false
|
|
end
|
|
|
|
def revoke_list
|
|
rm = RegisteredModule.find(params[:id]) rescue nil
|
|
slwm = site_list_with_module(rm, true)
|
|
@registered_sites = slwm.first
|
|
@times = slwm.last
|
|
render :layout => false
|
|
end
|
|
|
|
def grant_list
|
|
rm = RegisteredModule.find(params[:id]) rescue nil
|
|
slwm = site_list_with_module(rm, false)
|
|
@registered_sites = slwm.first
|
|
@times = slwm.last
|
|
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)
|
|
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
|
|
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
|
|
|
|
def show_file_params
|
|
params.require(:module_show_file).permit!
|
|
end
|
|
|
|
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
|
|
end
|
|
registered_sites
|
|
end
|
|
|
|
def site_list_with_module(rm,access=nil)
|
|
registered_sites = []
|
|
times = []
|
|
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)
|
|
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 ""}
|
|
end
|
|
[registered_sites, times]
|
|
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
|
|
else
|
|
p[:module_show_files] = []
|
|
end
|
|
p
|
|
end
|
|
|
|
def table_fields
|
|
[:module_name_, :category, :developed_by, :actions]
|
|
end
|
|
end |