announcement-test/lib/announcement/engine.rb

168 lines
7.4 KiB
Ruby
Raw Normal View History

2015-03-05 11:48:38 +00:00
require "yaml"
2014-04-01 07:12:43 +00:00
module Announcement
class Engine < ::Rails::Engine
initializer "announcement" do
begin
translate_data = Dir["#{Announcement::Engine.root}/config/locales/*.yml"] .map{|yaml_file| YAML.load(File.read(yaml_file))}
data = {}
key1 = {}
key2 = {}
2021-04-07 12:00:15 +00:00
key3 = {}
key4 = {}
2021-04-07 12:00:15 +00:00
key1_attr = []
key2_attr = []
key3_attr = []
key4_attr = []
data_item = {}
key_item1 = {}
key_item2 = {}
key_item3 = {}
value_item1 = {}
value_item2 = {}
value_item3 = {}
value2_item1 = {}
value2_item2 = {}
2021-04-07 12:00:15 +00:00
key1_options = ['small_size','medium_size','orignal_size']
key2_options = ['not_enable_tabs','enable_tabs_with_categories_include_all','enable_tabs_with_categories']
key3_options = ['default','upper_left','lower_left','upper_right','lower_right']
key4_options = ['the_same_as_data_count','display_all_in_other_tabs']
2021-04-07 12:00:15 +00:00
key1_options.each_with_index do |k,i|
key1_attr[i] = {}
end
key2_options.each_with_index do |k,i|
key2_attr[i] = {}
end
key3_options.each_with_index do |k,i|
key3_attr[i] = {}
end
key4_options.each_with_index do |k,i|
key4_attr[i] = {}
end
translate_data.each do |t_data|
v = t_data.values
k = t_data.keys[0]
key1[k] = v[0]['announcement']['picture_showing_size']
key2[k] = v[0]['announcement']['tabs_options']
2021-04-07 12:00:15 +00:00
key3[k] = v[0]['announcement']['read_more_position_options']
key4[k] = v[0]['announcement']['all_tabs_setting']
2021-04-07 12:00:15 +00:00
key1_options.each_with_index do |kk,i|
key1_attr[i][k] = v[0]['announcement'][kk]
end
key2_options.each_with_index do |kk,i|
key2_attr[i][k] = v[0]['announcement'][kk]
end
key3_options.each_with_index do |kk,i|
key3_attr[i][k] = v[0]['announcement'][kk]
end
key4_options.each_with_index do |kk,i|
key4_attr[i][k] = v[0]['announcement'][kk]
end
key_item1[k] = v[0]['announcement']['showing_back_and_next']
key_item2[k] = v[0]['announcement']['enable_search']
value_item1[k] = v[0]['announcement']['not_show']
value_item2[k] = v[0]['announcement']['show_bottom']
value_item3[k] = v[0]['announcement']['show_top']
value2_item1[k] = v[0]['announcement']['no']
value2_item2[k] = v[0]['announcement']['yes']
end
2021-04-07 12:00:15 +00:00
data[key1] = key1_attr
data[key2] = key2_attr
data[key3] = key3_attr
data[key4] = key4_attr
data_item[key_item1] = [value_item1,value_item2,value_item3]
data_item[key_item2] = [value2_item1,value2_item2]
2022-02-27 05:12:50 +00:00
data_item[key1] = key1_attr
2021-08-13 04:42:14 +00:00
if ENV['worker_num']=='0' && File.basename($0) != 'rake' && !Rails.const_defined?('Console')
require File.expand_path('../../../app/models/anns_cache', __FILE__)
if defined?(AnnsCache)
2022-03-29 06:25:10 +00:00
AnnsCache.all.delete
2021-08-13 04:42:14 +00:00
end
2020-03-04 10:39:21 +00:00
end
rescue => e
puts ['error in announcement',e]
end
2014-04-18 11:37:31 +00:00
OrbitApp.registration "Announcement", :type => "ModuleApp" do
module_label "announcement.announcement"
base_url File.expand_path File.dirname(__FILE__)
2017-06-29 08:03:39 +00:00
widget_methods ["widget","random_announcement_widget", "tag_cloud"]
2015-05-05 07:46:10 +00:00
widget_settings [{"data_count"=>30}]
2014-04-18 11:37:31 +00:00
taggable "Bulletin"
2014-04-20 12:23:52 +00:00
categorizable
authorizable
frontend_enabled
2015-07-08 10:11:25 +00:00
feeds_url "/xhr/announcements/feeds"
2015-05-05 07:46:10 +00:00
data_count 1..30
begin
show_options data
show_option_items data_item
rescue => e
puts ['there_was_no_show_option_method',e]
end
begin
avoid_page_cache AnnsCache
avoid_page_cache BulletinFeedCache
avoid_page_cache BulletinFeed
rescue => e
puts ["avoid_page_cache", e.to_s]
end
2014-04-18 11:37:31 +00:00
side_bar do
head_label_i18n 'announcement.announcement', icon_class: "icons-megaphone"
2014-07-31 09:12:13 +00:00
available_for "users"
2014-05-12 08:16:46 +00:00
active_for_controllers (['admin/announcements'])
2014-04-18 11:37:31 +00:00
head_link_path "admin_announcements_path"
2014-05-01 08:41:00 +00:00
context_link 'announcement.all_articles',
:link_path=>"admin_announcements_path" ,
:priority=>1,
2014-05-12 08:16:46 +00:00
:active_for_action=>{'admin/announcements'=>'index'},
2014-07-31 09:12:13 +00:00
:available_for => 'users'
2022-03-29 06:25:10 +00:00
context_link 'announcement.manually_sort',
:link_path=>"edit_sort_admin_announcement_path" ,
:priority=>2,
:active_for_action=>{'admin/announcement'=>'edit_sort'},
:available_for => 'sub_managers'
2014-05-13 07:06:23 +00:00
context_link 'new_',
2014-05-01 08:41:00 +00:00
:link_path=>"new_admin_announcement_path" ,
2022-03-29 06:25:10 +00:00
:priority=>3,
2014-05-12 08:16:46 +00:00
:active_for_action=>{'admin/announcements'=>'new'},
2014-07-31 09:12:13 +00:00
:available_for => 'sub_managers'
2014-05-13 07:06:23 +00:00
context_link 'categories',
2014-05-12 08:16:46 +00:00
:link_path=>"admin_module_app_categories_path" ,
2014-05-14 07:39:40 +00:00
:link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'announcement').id}",
2022-03-29 06:25:10 +00:00
:priority=>4,
2014-05-12 08:16:46 +00:00
:active_for_action=>{'admin/announcements'=>'categories'},
:active_for_category => 'Announcement',
2014-07-31 09:12:13 +00:00
:available_for => 'managers'
2014-05-12 08:16:46 +00:00
context_link 'tags',
:link_path=>"admin_module_app_tags_path" ,
2014-05-14 07:39:40 +00:00
:link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'announcement').id}",
2022-03-29 06:25:10 +00:00
:priority=>5,
2014-05-12 08:16:46 +00:00
:active_for_action=>{'admin/announcements'=>'tags'},
:active_for_tag => 'Announcement',
2014-07-31 09:12:13 +00:00
:available_for => 'managers'
2015-07-08 10:11:25 +00:00
context_link 'announcement.feed_list',
:link_path=>"admin_announcement_feed_path" ,
2022-03-29 06:25:10 +00:00
:priority=>6,
2015-07-08 10:11:25 +00:00
:active_for_action=>{'admin/announcements'=>'feed'},
:available_for => 'managers'
2016-04-21 17:28:37 +00:00
context_link 'announcement.import',
:link_path=>"admin_announcement_import_path" ,
2022-03-29 06:25:10 +00:00
:priority=>7,
2016-04-21 17:28:37 +00:00
:active_for_action=>{'admin/announcements'=>'import'},
:available_for => 'managers'
context_link 'announcement.settings',
:link_path=>"admin_announcement_settings_path" ,
2022-03-29 06:25:10 +00:00
:priority=>8,
:active_for_action=>{'admin/announcements'=>'settings'},
:available_for => 'managers'
2014-04-18 11:37:31 +00:00
end
2014-05-01 08:41:00 +00:00
2014-04-18 11:37:31 +00:00
end
2015-05-28 11:01:17 +00:00
# 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[:bulletins].indexes.create({expirable_created_at: 1},{ expireAfterSeconds: 180 })
2014-04-18 11:37:31 +00:00
end
2014-04-01 07:12:43 +00:00
end
end