Fix bug.
This commit is contained in:
parent
5f24254ae3
commit
5659e0531e
|
@ -1,15 +1,15 @@
|
||||||
class Admin::PersonalPluginFieldsController < OrbitMemberController
|
class Admin::PersonalPluginFieldsController < OrbitMemberController
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
include Admin::PersonalPluginFieldsHelper
|
include Admin::PersonalPluginFieldsHelper
|
||||||
before_action :set_personal_plugin_field, only: [:show, :edit , :update, :destroy, :fields_setting, :update_fields_setting,:generate_plugin]
|
before_action :set_personal_plugin_field, only: [:show, :edit , :update, :destroy, :fields_setting, :update_fields_setting,:generate_plugin]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@personal_plugin_fields = PersonalPluginField.order_by(:created_at=>'desc').page(params[:page]).per(10)
|
@personal_plugin_fields = PersonalPluginField.order_by(:created_at=>'desc').page(params[:page]).per(10)
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@member = MemberProfile.find_by(:uid=>params['uid']) rescue nil
|
@member = MemberProfile.find_by(:uid=>params['uid']) rescue nil
|
||||||
@personal_plugin_field = PersonalPluginField.new
|
@personal_plugin_field = PersonalPluginField.new
|
||||||
end
|
end
|
||||||
def download
|
def download
|
||||||
zip_path = "tmp/"
|
zip_path = "tmp/"
|
||||||
|
@ -40,7 +40,7 @@ class Admin::PersonalPluginFieldsController < OrbitMemberController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
#render :html => attributes and return
|
#render :html => attributes and return
|
||||||
@personal_plugin_field = PersonalPluginField.new(copy_attributes)
|
@personal_plugin_field = PersonalPluginField.new(copy_attributes)
|
||||||
end
|
end
|
||||||
def create
|
def create
|
||||||
personal_plugin_field = PersonalPluginField.create(personal_plugin_field_params)
|
personal_plugin_field = PersonalPluginField.create(personal_plugin_field_params)
|
||||||
|
@ -226,7 +226,7 @@ class Admin::PersonalPluginFieldsController < OrbitMemberController
|
||||||
"#{@blank_text}members = #{plugin_template}.send(field.pluralize)",
|
"#{@blank_text}members = #{plugin_template}.send(field.pluralize)",
|
||||||
"#{@blank_text}value = members.map{|m|",
|
"#{@blank_text}value = members.map{|m|",
|
||||||
"#{@blank_text*2}path = OrbitHelper.url_to_plugin_show(m.to_param, 'member') rescue '#'",
|
"#{@blank_text*2}path = OrbitHelper.url_to_plugin_show(m.to_param, 'member') rescue '#'",
|
||||||
"#{@blank_text*2}((text_only rescue false) ? m.name : \"<a href='\#{path}'>\#{m.name}</a>\")",
|
"#{@blank_text*2}((text_only rescue false) ? m.name : \"<a href='\#{path}'>\#{m.name}</a>\")",
|
||||||
"#{@blank_text}}",
|
"#{@blank_text}}",
|
||||||
"#{@blank_text}join_text = (text_only rescue false) ? \",\" : \"<br>\"",
|
"#{@blank_text}join_text = (text_only rescue false) ? \",\" : \"<br>\"",
|
||||||
"#{@blank_text}value = value.join(join_text)",
|
"#{@blank_text}value = value.join(join_text)",
|
||||||
|
@ -252,11 +252,11 @@ class Admin::PersonalPluginFieldsController < OrbitMemberController
|
||||||
}
|
}
|
||||||
member_methods_define = primary_modal_fields.select{|f| (f[:field_type] == "member" rescue false)}.map{|field_value|
|
member_methods_define = primary_modal_fields.select{|f| (f[:field_type] == "member" rescue false)}.map{|field_value|
|
||||||
["def #{field_value[:field_name].pluralize}",
|
["def #{field_value[:field_name].pluralize}",
|
||||||
" MemberProfile.find(self.#{field_value[:field_name].singularize}_ids) rescue []",
|
" MemberProfile.find(self.#{field_value[:field_name].singularize}_ids) rescue []",
|
||||||
"end"]
|
"end"]
|
||||||
}.flatten
|
}.flatten
|
||||||
date_time_strftime = {"date"=>"%Y/%m/%d","date_time"=>"%Y/%m/%d %H:%M","year_month"=>"%Y/%m"}
|
date_time_strftime = {"date"=>"%Y/%m/%d","date_time"=>"%Y/%m/%d %H:%M","year_month"=>"%Y/%m"}
|
||||||
periodic_methods_define = primary_modal_fields.select{|f| (f[:periodic_time] == "1" rescue false)}.map{|field_value|
|
periodic_methods_define = primary_modal_fields.select{|f| (f[:periodic_time] == "1" rescue false)}.map{|field_value|
|
||||||
strftime_string = ""
|
strftime_string = ""
|
||||||
if date_time_strftime.keys.include?(field_value[:field_type])
|
if date_time_strftime.keys.include?(field_value[:field_type])
|
||||||
strftime_string = ".strftime(\"#{date_time_strftime[field_value[:field_type]]}\")"
|
strftime_string = ".strftime(\"#{date_time_strftime[field_value[:field_type]]}\")"
|
||||||
|
@ -267,24 +267,24 @@ class Admin::PersonalPluginFieldsController < OrbitMemberController
|
||||||
" \"\#{#{field_value[:field_name]}_start} ~ \#{#{field_value[:field_name]}_end}\"",
|
" \"\#{#{field_value[:field_name]}_start} ~ \#{#{field_value[:field_name]}_end}\"",
|
||||||
"end"]
|
"end"]
|
||||||
}.flatten
|
}.flatten
|
||||||
related_periodic_methods_define = @personal_plugin_field.related_modal_fields.map{|field_values|
|
related_periodic_methods_define = @personal_plugin_field.related_modal_fields.map{|field_values|
|
||||||
field_values.select{|f| (f[:periodic_time] == "1" rescue false)}.map{|field_value|
|
field_values.select{|f| (f[:periodic_time] == "1" rescue false)}.map{|field_value|
|
||||||
strftime_string = ""
|
strftime_string = ""
|
||||||
if date_time_strftime.keys.include? field_value[:field_type]
|
if date_time_strftime.keys.include? field_value[:field_type]
|
||||||
strftime_string = ".strftime(\"#{date_time_strftime[field_value[:field_type]]}\")"
|
strftime_string = ".strftime(\"#{date_time_strftime[field_value[:field_type]]}\")"
|
||||||
end
|
end
|
||||||
["def #{field_value[:field_name]}",
|
["def #{field_value[:field_name]}",
|
||||||
" \"\#{self.#{field_value[:field_name]}_start#{strftime_string}} ~ \#{self.#{field_value[:field_name]}_end#{strftime_string}}\"",
|
" \"\#{self.#{field_value[:field_name]}_start#{strftime_string}} ~ \#{self.#{field_value[:field_name]}_end#{strftime_string}}\"",
|
||||||
"end"]
|
"end"]
|
||||||
}.flatten
|
}.flatten
|
||||||
}
|
}
|
||||||
analysis_field_name = @personal_plugin_field.backend_fields[:analysis][0] rescue ""
|
analysis_field_name = @personal_plugin_field.backend_fields[:analysis][0] rescue ""
|
||||||
analysis_field_name = "year" if analysis_field_name.blank?
|
analysis_field_name = "year" if analysis_field_name.blank?
|
||||||
analysis_field_input_fields = ""
|
analysis_field_input_fields = ""
|
||||||
personal_plugin_template = @personal_plugin_field.module_name
|
personal_plugin_template = @personal_plugin_field.module_name
|
||||||
iterate_step_text = "1.minute"
|
iterate_step_text = "1.minute"
|
||||||
if analysis_field_name.present?
|
if analysis_field_name.present?
|
||||||
field_type = primary_modal_fields.select{|f| f[:field_name] == analysis_field_name}.first[:field_type] rescue "date_time"
|
field_type = primary_modal_fields.select{|f| f[:field_name] == analysis_field_name}.first[:field_type] rescue "date_time"
|
||||||
|
|
||||||
analysis_field_input_fields = ["start","end"].map{|f|
|
analysis_field_input_fields = ["start","end"].map{|f|
|
||||||
"<span><%=t(\"#{personal_plugin_template}.extend_translate.#{f}_#{field_type}\")%></span>" +
|
"<span><%=t(\"#{personal_plugin_template}.extend_translate.#{f}_#{field_type}\")%></span>" +
|
||||||
|
@ -300,15 +300,15 @@ class Admin::PersonalPluginFieldsController < OrbitMemberController
|
||||||
time_fields = primary_modal_fields.select{|f| f[:field_type] == "time"}.map{|f| f[:field_name]}
|
time_fields = primary_modal_fields.select{|f| f[:field_type] == "time"}.map{|f| f[:field_name]}
|
||||||
before_save_codes = ""#time_fields.map{|f| "self.#{f} = parse_time(self.#{f}.strftime('%H:%M'))"}.join("\r\n")
|
before_save_codes = ""#time_fields.map{|f| "self.#{f} = parse_time(self.#{f}.strftime('%H:%M'))"}.join("\r\n")
|
||||||
plugin_template_sort_hash = {}
|
plugin_template_sort_hash = {}
|
||||||
@personal_plugin_field.backend_fields[:sort_asc].to_a.each do |f|
|
@personal_plugin_field.backend_fields[:sort_asc].to_a.each do |f|
|
||||||
plugin_template_sort_hash[f.to_sym] = 1
|
plugin_template_sort_hash[f.to_sym] = 1
|
||||||
end rescue nil
|
end rescue nil
|
||||||
@personal_plugin_field.backend_fields[:sort_desc].to_a.each do |f|
|
@personal_plugin_field.backend_fields[:sort_desc].to_a.each do |f|
|
||||||
plugin_template_sort_hash[f.to_sym] = -1
|
plugin_template_sort_hash[f.to_sym] = -1
|
||||||
end rescue nil
|
end rescue nil
|
||||||
if @personal_plugin_field.backend_fields[:sort_desc].to_a.count != 0
|
if @personal_plugin_field.backend_fields[:sort_desc].to_a.count != 0
|
||||||
plugin_template_sort_hash[:id] = -1
|
plugin_template_sort_hash[:id] = -1
|
||||||
end
|
end
|
||||||
@match_pattern = {"personal_plugin_template" => personal_plugin_template,
|
@match_pattern = {"personal_plugin_template" => personal_plugin_template,
|
||||||
"plugin_template" => plugin_template,
|
"plugin_template" => plugin_template,
|
||||||
"plugin_template_related" => plugin_template_related,
|
"plugin_template_related" => plugin_template_related,
|
||||||
|
@ -689,54 +689,54 @@ class Admin::PersonalPluginFieldsController < OrbitMemberController
|
||||||
render :json => {:can_install => can_install }
|
render :json => {:can_install => can_install }
|
||||||
end
|
end
|
||||||
def add_plugin(extention_file,plugin_name)
|
def add_plugin(extention_file,plugin_name)
|
||||||
txt = File.read(extention_file) rescue nil
|
txt = File.read(extention_file) rescue nil
|
||||||
if txt.nil?
|
if txt.nil?
|
||||||
File.open(extention_file,'w+'){|f| f.write("")}
|
File.open(extention_file,'w+'){|f| f.write("")}
|
||||||
txt = ""
|
txt = ""
|
||||||
end
|
end
|
||||||
txt_scan = txt.scan(/^[\n]*gem\s*["']#{plugin_name}["'].*\n/)
|
txt_scan = txt.scan(/^[\n]*gem\s*["']#{plugin_name}["'].*\n/)
|
||||||
if txt_scan.count != 1
|
if txt_scan.count != 1
|
||||||
delete_plugin(extention_file,plugin_name)
|
delete_plugin(extention_file,plugin_name)
|
||||||
txt = File.read(extention_file) rescue ""
|
txt = File.read(extention_file) rescue ""
|
||||||
txt = txt + "\r\ngem \"#{plugin_name}\", path: \"#{Rails.root}/tmp/#{plugin_name}\"\r\n"
|
txt = txt + "\r\ngem \"#{plugin_name}\", path: \"#{Rails.root}/tmp/#{plugin_name}\"\n"
|
||||||
File.open(extention_file,'w+') do |f|
|
File.open(extention_file,'w+') do |f|
|
||||||
f.write(txt)
|
f.write(txt)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def delete_plugin(extention_file,plugin_name)
|
def delete_plugin(extention_file,plugin_name)
|
||||||
txt = File.read(extention_file) rescue nil
|
txt = File.read(extention_file) rescue nil
|
||||||
return if txt.nil?
|
return if txt.nil?
|
||||||
txt_change = txt.gsub(/^[\n]*gem\s*["']#{plugin_name}["'].*\n/,'')
|
txt_change = txt.gsub(/^[\n]*gem\s*["']#{plugin_name}["'].*\n/,'')
|
||||||
if txt_change != txt
|
if txt_change != txt
|
||||||
File.open(extention_file,'w+') do |f|
|
File.open(extention_file,'w+') do |f|
|
||||||
f.write(txt_change)
|
f.write(txt_change)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def check_modal_name
|
def check_modal_name
|
||||||
primary_modal_names = PersonalPluginField.where(:id.ne=>params[:id]).pluck(:primary_modal_name)
|
primary_modal_names = PersonalPluginField.where(:id.ne=>params[:id]).pluck(:primary_modal_name)
|
||||||
related_modal_names = PersonalPluginField.where(:id.ne=>params[:id]).pluck(:related_modal_name).flatten.uniq
|
related_modal_names = PersonalPluginField.where(:id.ne=>params[:id]).pluck(:related_modal_name).flatten.uniq
|
||||||
other_modal_names = primary_modal_names + related_modal_names
|
other_modal_names = primary_modal_names + related_modal_names
|
||||||
personal_plugin_field = PersonalPluginField.where(:id=>params[:id]).first
|
personal_plugin_field = PersonalPluginField.where(:id=>params[:id]).first
|
||||||
all_modal_names = PersonalPluginField.get_modal_names_cache
|
all_modal_names = PersonalPluginField.get_modal_names_cache
|
||||||
if personal_plugin_field.present?
|
if personal_plugin_field.present?
|
||||||
except_modals = Dir.glob("tmp/#{personal_plugin_field.module_name}/app/models/*.rb").map{|f|
|
except_modals = Dir.glob("tmp/#{personal_plugin_field.module_name}/app/models/*.rb").map{|f|
|
||||||
fn = File.basename(f)
|
fn = File.basename(f)
|
||||||
fn.slice(0,fn.length - 3)
|
fn.slice(0,fn.length - 3)
|
||||||
}
|
}
|
||||||
all_modal_names = all_modal_names - except_modals
|
all_modal_names = all_modal_names - except_modals
|
||||||
end
|
end
|
||||||
all_modal_names = all_modal_names + other_modal_names
|
all_modal_names = all_modal_names + other_modal_names
|
||||||
all_modal_names = all_modal_names.uniq
|
all_modal_names = all_modal_names.uniq
|
||||||
self_modal_names = params[:modal_names]
|
self_modal_names = params[:modal_names]
|
||||||
invalid_modal_names = self_modal_names.select{|n| all_modal_names.include?(n)}
|
invalid_modal_names = self_modal_names.select{|n| all_modal_names.include?(n)}
|
||||||
if invalid_modal_names.count != 0
|
if invalid_modal_names.count != 0
|
||||||
render :json => {:success=>false,:invalid_modal_names=>invalid_modal_names}
|
render :json => {:success=>false,:invalid_modal_names=>invalid_modal_names}
|
||||||
else
|
else
|
||||||
render :json => {:success=>true}
|
render :json => {:success=>true}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
private
|
private
|
||||||
def personal_plugin_field_params
|
def personal_plugin_field_params
|
||||||
personal_plugin_field_params = params.require(:personal_plugin_field).permit! rescue {}
|
personal_plugin_field_params = params.require(:personal_plugin_field).permit! rescue {}
|
||||||
|
@ -759,19 +759,19 @@ class Admin::PersonalPluginFieldsController < OrbitMemberController
|
||||||
|
|
||||||
def set_personal_plugin_field
|
def set_personal_plugin_field
|
||||||
PersonalPluginField.get_modal_names_cache
|
PersonalPluginField.get_modal_names_cache
|
||||||
path = request.path.split('/')
|
path = request.path.split('/')
|
||||||
if path.last.include? '-'
|
if path.last.include? '-'
|
||||||
uid = path[-1].split("-").last
|
uid = path[-1].split("-").last
|
||||||
uid = uid.split("?").first
|
uid = uid.split("?").first
|
||||||
else
|
else
|
||||||
uid = path[-2].split("-").last
|
uid = path[-2].split("-").last
|
||||||
uid = uid.split("?").first
|
uid = uid.split("?").first
|
||||||
end
|
end
|
||||||
@personal_plugin_field = PersonalPluginField.find_by(:uid => uid) rescue PersonalPluginField.find(params[:id] || params[:personal_plugin_field_id])
|
@personal_plugin_field = PersonalPluginField.find_by(:uid => uid) rescue PersonalPluginField.find(params[:id] || params[:personal_plugin_field_id])
|
||||||
end
|
end
|
||||||
def bundle_install
|
def bundle_install
|
||||||
Bundler.with_clean_env { system("cd #{Rails.root} && bundle install") }
|
Bundler.with_clean_env { system("cd #{Rails.root} && bundle install") }
|
||||||
%x(kill -s USR2 `cat tmp/pids/unicorn.pid`)
|
%x(kill -s USR2 `cat tmp/pids/unicorn.pid`)
|
||||||
sleep 2
|
sleep 2
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in New Issue