event_ann/lib/event_ann/engine.rb

117 lines
5.3 KiB
Ruby

require "yaml"
module EventAnn
class Engine < ::Rails::Engine
initializer "event_ann" do
begin
translate_data = Dir["#{EventAnn::Engine.root}/config/locales/*.yml"] .map{|yaml_file| YAML.load(File.read(yaml_file))}
data = {}
key1 = {}
value1 = {}
value2 = {}
value3 = {}
data_item = {}
key_item1 = {}
key_item2 = {}
value_item1 = {}
value_item2 = {}
value_item3 = {}
value2_item1 = {}
value2_item2 = {}
translate_data.each do |t_data|
v = t_data.values
k = t_data.keys[0]
key1[k] = v[0]['event_ann']['picture_showing_size']
value1[k] = v[0]['event_ann']['small_size']
value2[k] = v[0]['event_ann']['medium_size']
value3[k] = v[0]['event_ann']['orignal_size']
key_item1[k] = v[0]['event_ann']['showing_back_and_next']
key_item2[k] = v[0]['event_ann']['enable_search']
value_item1[k] = v[0]['event_ann']['not_show']
value_item2[k] = v[0]['event_ann']['show_bottom']
value_item3[k] = v[0]['event_ann']['show_top']
value2_item1[k] = v[0]['event_ann']['no']
value2_item2[k] = v[0]['event_ann']['yes']
end
data[key1] = [value1,value2,value3]
data_item[key_item1] = [value_item1,value_item2,value_item3]
data_item[key_item2] = [value2_item1,value2_item2]
require File.expand_path('../../../app/models/event_ann_cache', __FILE__)
if defined? EventAnnsCache
EventAnnsCache.destroy_all
end
rescue => e
puts ['error in event_ann',e]
end
OrbitApp.registration "EventAnn", :type => "ModuleApp" do
module_label "event_ann.event_ann"
base_url File.expand_path File.dirname(__FILE__)
widget_methods ["widget","random_event_ann_widget", "tag_cloud"]
widget_settings [{"data_count"=>30}]
taggable "BulletinEvent"
categorizable
authorizable
frontend_enabled
feeds_url "/xhr/event_anns/feeds"
data_count 1..30
begin
show_options data
show_option_items data_item
rescue => e
puts ['there_was_no_show_option_method',e]
end
side_bar do
head_label_i18n 'event_ann.event_ann', icon_class: "icons-megaphone"
available_for "users"
active_for_controllers (['admin/event_anns'])
head_link_path "admin_event_anns_path"
context_link 'event_ann.all_articles',
:link_path=>"admin_event_anns_path" ,
:priority=>1,
:active_for_action=>{'admin/event_anns'=>'index'},
:available_for => 'users'
context_link 'new_',
:link_path=>"new_admin_event_ann_path" ,
:priority=>2,
:active_for_action=>{'admin/event_anns'=>'new'},
:available_for => 'sub_managers'
context_link 'categories',
:link_path=>"admin_module_app_categories_path" ,
:link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'event_ann').id}",
:priority=>3,
:active_for_action=>{'admin/event_anns'=>'categories'},
:active_for_category => 'EventAnn',
:available_for => 'managers'
context_link 'tags',
:link_path=>"admin_module_app_tags_path" ,
:link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'event_ann').id}",
:priority=>4,
:active_for_action=>{'admin/event_anns'=>'tags'},
:active_for_tag => 'EventAnn',
:available_for => 'managers'
context_link 'event_ann.feed_list',
:link_path=>"admin_event_ann_feed_path" ,
:priority=>5,
:active_for_action=>{'admin/event_anns'=>'feed'},
:available_for => 'managers'
context_link 'event_ann.import',
:link_path=>"admin_event_ann_import_path" ,
:priority=>6,
:active_for_action=>{'admin/event_anns'=>'import'},
:available_for => 'managers'
context_link 'event_ann.settings',
:link_path=>"admin_event_ann_settings_path" ,
:priority=>6,
:active_for_action=>{'admin/event_anns'=>'settings'},
:available_for => 'managers'
end
end
# temp = YAML.load_file(File.join(Rails.root,"config","mongoid.yml"))
# dbsettings = temp["production"]["sessions"]["default"]
# s = Moped::Session.new(dbsettings["hosts"])
# s.use dbsettings["database"]
# s[:bulletin_events].indexes.create({expirable_created_at: 1},{ expireAfterSeconds: 180 })
end
end
end