archive/lib/archive/engine.rb

110 lines
4.2 KiB
Ruby
Raw Normal View History

2014-05-08 06:03:33 +00:00
module Archive
class Engine < ::Rails::Engine
2021-01-18 06:36:08 +00:00
2014-05-08 06:03:33 +00:00
initializer "archive" do
2021-01-18 06:36:08 +00:00
require File.expand_path('../../../app/models/archive_category', __FILE__)
2021-09-09 07:27:14 +00:00
require File.expand_path('../../../app/models/archive_sort_order', __FILE__)
if defined?(ArchiveSortOrder)
if ArchiveSortOrder.count == 0
ArchiveSortOrder.create('sort_order' => false)
end
end
2021-01-18 06:36:08 +00:00
require "#{ENV['PWD']}/app/models/category"
require "#{ENV['PWD']}/app/models/module_app"
2021-01-19 03:06:00 +00:00
tmp = OrbitApp.registration "Archive", :type => "ModuleApp" do
2014-05-08 06:03:33 +00:00
module_label "archive.archive"
base_url File.expand_path File.dirname(__FILE__)
feeds_url "/xhr/archive_files/feeds"
begin
feeds_model "ArchiveFile"
feeds_uid_field "feed_uid"
feeds_update_callback "update_feed_data"
feeds_update_statuses_callback "update_feed_statuses"
feeds_time_field "created_at"
feeds_finish_callback "feeds_finish_callback"
rescue => e
puts "orbit kernel need update!"
end
widget_methods ["widget","group_by_category"]
widget_settings [{"data_count"=>30,"enable_custom_widget_data"=>true}]
2023-01-03 04:07:58 +00:00
data_count 0..30
2015-03-30 07:07:27 +00:00
models_to_cache [:archive_file]
begin
avoid_page_cache ArchiveCache
avoid_page_cache ArchiveFileFeed
avoid_page_cache ArchiveFileFeedCache
rescue => e
puts ["avoid_page_cache", e.to_s]
end
if ENV['worker_num']=='0' && File.basename($0) != 'rake' && !Rails.const_defined?('Console')
require File.expand_path('../../../app/models/archive_cache', __FILE__)
if defined?(ArchiveCache)
ArchiveCache.all.delete
end
end
2014-05-08 06:03:33 +00:00
taggable "ArchiveFile"
categorizable
authorizable
frontend_enabled
2014-05-08 06:03:33 +00:00
side_bar do
head_label_i18n 'archive.archive', icon_class: "icons-archive"
2014-07-31 12:40:44 +00:00
available_for "users"
2014-05-14 11:52:06 +00:00
active_for_controllers (['admin/archive_files'])
2014-05-08 06:03:33 +00:00
head_link_path "admin_archive_files_path"
2014-05-16 08:26:43 +00:00
context_link 'all',
2014-05-14 11:52:06 +00:00
:link_path=>"admin_archive_files_path" ,
:priority=>1,
2014-07-31 12:40:44 +00:00
:active_for_action=>{'admin/archive_files'=>"index"},
:available_for => 'users'
2014-05-16 08:26:43 +00:00
context_link 'new_',
2014-05-14 11:52:06 +00:00
:link_path=>"new_admin_archive_file_path" ,
:priority=>2,
2014-07-31 12:40:44 +00:00
:active_for_action=>{'admin/archive_files'=>"new"},
:available_for => 'sub_managers'
2014-05-16 08:26:43 +00:00
context_link 'categories',
:link_path=>"admin_module_app_categories_path" ,
:link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'archive').id}",
:priority=>3,
:active_for_action=>{'admin/archive_files'=>'categories'},
2014-07-31 12:40:44 +00:00
:active_for_category => 'Archive',
:available_for => 'managers'
2014-05-16 08:26:43 +00:00
context_link 'tags',
:link_path=>"admin_module_app_tags_path" ,
:link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'archive').id}",
:priority=>4,
:active_for_action=>{'admin/archive_files'=>'tags'},
2014-07-31 12:40:44 +00:00
:active_for_tag => 'Archive',
:available_for => 'managers'
context_link 'archive.categories_order',
:link_path=>"admin_archive_files_categories_order_path" ,
:priority=>5,
:active_for_action=>{'admin/archive_files'=>'categories_order'},
:available_for => 'managers'
context_link 'archive.feed_list',
:link_path=>"admin_archive_file_feed_path" ,
:priority=>6,
:active_for_action=>{'admin/archive_files'=>'feed'},
:available_for => 'managers'
2014-05-08 06:03:33 +00:00
end
end
2021-01-19 03:06:00 +00:00
categories_temp = ModuleApp.where(:key => "archive").first.categories
categories_temp.each do |category|
archive_cat = ArchiveCategory.where(:category_id => category.id)
if archive_cat.count == 0
ArchiveCategory.create(category_id: category.id.to_s)
else
archive_cat[1..-1].each do |cat|
cat.delete
end
end
end
tmp
2014-05-08 06:03:33 +00:00
end
end
end