universal_table/lib/universal_table/engine.rb

66 lines
3.1 KiB
Ruby

module UniversalTable
class Engine < ::Rails::Engine
initializer "universal_table" do
if ENV['worker_num']=='0' && File.basename($0) != 'rake' && !Rails.const_defined?('Console')
require File.expand_path('../../../app/models/table_entry', __FILE__)
require File.expand_path('../../../app/models/u_table', __FILE__)
if defined?(TableEntry) && defined?(UTable)
if TableEntry.where(sort_number: nil).count>0
UTable.all.pluck(:id).each do |u_table_id|
table_entries = TableEntry.where(u_table_id: u_table_id).order_by(id: 1)
table_entry_ids = table_entries.pluck(:id)
table_entry_ids.each_with_index do |id,i|
TableEntry.where(id: id).update(sort_number: i)
end
end
end
end
end
OrbitApp.registration "UniversalTable", :type => "ModuleApp" do
module_label "universal_table.universal_table"
base_url File.expand_path File.dirname(__FILE__)
widget_methods ["widget"]
widget_settings [{"data_count"=>30}]
# taggable "Bulletin"
categorizable
authorizable
frontend_enabled
data_count 1..30
side_bar do
head_label_i18n 'universal_table.universal_table', icon_class: "icons-untitled"
available_for "users"
active_for_controllers (['admin/universal_tables'])
head_link_path "admin_universal_tables_path"
context_link 'universal_table.all_tables',
:link_path=>"admin_universal_tables_path" ,
:priority=>1,
:active_for_action=>{'admin/universal_table'=>'index'},
:available_for => 'users'
context_link 'universal_table.new_table',
:link_path=>"new_admin_universal_table_path" ,
:priority=>2,
:active_for_action=>{'admin/universal_tables'=>'new'},
:available_for => 'sub_managers'
context_link 'categories',
:link_path=>"admin_module_app_categories_path" ,
:link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'universal_table').id}",
:priority=>3,
:active_for_action=>{'admin/universal_tables'=>'categories'},
:active_for_category => 'UniversalTable',
:available_for => 'managers'
# context_link 'tags',
# :link_path=>"admin_module_app_tags_path" ,
# :link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'universal_table').id}",
# :priority=>4,
# :active_for_action=>{'admin/universal_table'=>'tags'},
# :active_for_tag => 'Announcement',
# :available_for => 'managers'
end
end
end
end
end