diff --git a/announcement.gemspec b/announcement.gemspec index 35d571b..bb3a79e 100644 --- a/announcement.gemspec +++ b/announcement.gemspec @@ -37,7 +37,7 @@ all_template.each do |folder| i = texts.rindex(s1[-1]) texts[i] = "" end - regex_pattern = /.response-content {\n position: static;\n}|.response-content {\n position: relative;\n}|.response-content[^{]*{[^}]*@media[^{]*{[^{]*}[^{]*@media[^{]*{[^{]*}[^}]*}[^}]*}/m + regex_pattern = /.response-content {\n justify-self: auto;\n}|.response-content {\n position: static;\n}|.response-content {\n position: relative;\n}|.response-content[^{]*{[^}]*@media[^{]*{[^{]*}[^{]*@media[^{]*{[^{]*}[^}]*}[^}]*}/m if !texts.include? "$font-h1:" texts = "$font-h1: 1.5rem;\n$font-h2: 1.35rem;\n$font-h3: 1.2rem;\n$font-h4: 1.1rem;\n$font-h5: 1rem;\n$font-h6: 0.9rem;\n\n" + texts end diff --git a/app/controllers/announcement_feeds_controller.rb b/app/controllers/announcement_feeds_controller.rb index 7073277..edfc61c 100644 --- a/app/controllers/announcement_feeds_controller.rb +++ b/app/controllers/announcement_feeds_controller.rb @@ -13,7 +13,7 @@ class AnnouncementFeedsController < ApplicationController if !@bf.nil? tags = @bf.tag_ids if !tags.empty? - @announcements = Bulletin.can_display.is_approved.filter_by_tags(tags) + @announcements = Bulletin.can_display_and_sorted.is_approved.filter_by_tags(tags) end end respond_to do |format| @@ -74,17 +74,17 @@ class AnnouncementFeedsController < ApplicationController if !dt.nil? dt = DateTime.parse(dt) dtt = dt + 1.day - announcements = Bulletin.where(:postdate.gt => dt, :postdate.lt => dtt).can_display.is_approved.filter_by_tags(tags) + announcements = Bulletin.where(:postdate.gt => dt, :postdate.lt => dtt).can_display_and_sorted.is_approved.filter_by_tags(tags) elsif !startdt.nil? && enddt.nil? startdt = DateTime.parse(startdt) enddt = DateTime.now - announcements = Bulletin.where(:postdate.gt => startdt, :postdate.lt => enddt).can_display.is_approved.filter_by_tags(tags) + announcements = Bulletin.where(:postdate.gt => startdt, :postdate.lt => enddt).can_display_and_sorted.is_approved.filter_by_tags(tags) elsif !startdt.nil? && !enddt.nil? startdt = DateTime.parse(startdt) enddt = DateTime.parse(enddt) + 1.day - announcements = Bulletin.where(:postdate.gt => startdt, :postdate.lt => enddt).can_display.is_approved.filter_by_tags(tags) + announcements = Bulletin.where(:postdate.gt => startdt, :postdate.lt => enddt).can_display_and_sorted.is_approved.filter_by_tags(tags) else - announcements = Bulletin.all.can_display.is_approved.filter_by_tags(tags) + announcements = Bulletin.all.can_display_and_sorted.is_approved.filter_by_tags(tags) end else announcements = [] diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index b9f08d6..22dc728 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -2,9 +2,8 @@ class AnnouncementsController < ApplicationController include AnnouncementsHelper def index Bulletin.remove_expired_status - announcements,sorted,total_pages = get_sorted_annc - anns = [] - sorted.each do |a| + sorted,total_pages = get_sorted_annc + anns = sorted.collect do |a| if !a["source-site"].present? statuses = a.statuses_with_classname.collect do |status| { @@ -22,7 +21,7 @@ class AnnouncementsController < ApplicationController target = a.is_external_link ? "_blank" : "_self" doc = Nokogiri::HTML(a.title) title = doc.text.empty? ? 'no content' : doc.text - anns << { + { "bulletin_links" => links, "bulletin_files" => files, "title" => a.title, @@ -43,11 +42,11 @@ class AnnouncementsController < ApplicationController "view_count" => a.view_count } else - anns << a + a end end #If no data , hide title&table - if announcements.count == 0 + if sorted.count == 0 display = "hide" end # anns = anns.concat(feeds_anns) @@ -75,21 +74,11 @@ class AnnouncementsController < ApplicationController end def random_announcement_widget - uid = OrbitHelper.params[:uid] rescue "" - tags = OrbitHelper.widget_tags - categories = OrbitHelper.widget_categories || [] - announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil],:uid.ne => uid, :category_id.in => categories).and(:title.ne => nil).can_display.is_approved.filter_by_tags(tags).sample(OrbitHelper.widget_data_count) - - pack_data(announcements, []) + pack_data(true) end def widget - Bulletin.remove_expired_status - uid = OrbitHelper.params[:uid] rescue "" - tags = OrbitHelper.widget_tags - announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil],:uid.ne => uid).and(:title.ne => nil, :is_top.ne => true).can_display.is_approved.filter_by_widget_categories([],false).filter_by_tags(tags).to_a - top_anns = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil], :is_top => true, :uid.ne => uid).and(:title.ne => nil).can_display.is_approved.filter_by_widget_categories([],false).filter_by_tags(tags).to_a - pack_data(announcements, top_anns) + pack_data() end def tag_cloud @@ -97,7 +86,7 @@ class AnnouncementsController < ApplicationController temp = [] ma.tags.each do |tag| t1 = tag.taggings.collect{|t| t.taggable_id.to_s} - count = Bulletin.where(:id.in => t1).can_display.count + count = Bulletin.where(:id.in => t1).can_display_and_sorted.count temp << { "tag-name" => tag.name, "count" => count, @@ -120,85 +109,52 @@ class AnnouncementsController < ApplicationController } end - def pack_data(announcements, top_anns = []) - page = Page.where(:module => "announcement").first rescue nil + def pack_data(is_random=false) + t1 = Time.now + tags = OrbitHelper.widget_tags || [] + cats = OrbitHelper.widget_categories || [] subpart = OrbitHelper.get_current_widget - @image_version = 'thumb' - if subpart.methods.include? 'select_options'.to_sym - ModuleApp.all.select{|tmp| tmp.key.to_s=='announcement'}.each do |modile_app| - @show_options = modile_app.show_options rescue nil - end - subpart.select_options.each do |select_option| - if !(@show_options.nil?) && select_option.field_name == @show_options.keys.first.to_s - value = YAML.load(select_option.value) - if value[I18n.locale] == t('announcement.small_size') - @image_version = 'thumb' - elsif value[I18n.locale] == t('announcement.medium_size') - @image_version = 'mobile' - elsif value[I18n.locale] == t('announcement.orignal_size') - @image_version = 'orignal' - end + anns_cache = AnnsCache.where(parent_id: subpart.id) + widget_data_count = OrbitHelper.widget_data_count + if !(defined? SiteFeed).nil? || anns_cache.count != 1 || is_random + page = Page.where(:module => "announcement").first rescue nil + Bulletin.remove_expired_status + uid = OrbitHelper.params[:uid] rescue "" + set_image_version_for_widget + sorted_anns = Bulletin.where(:title.nin => ["",nil],:is_preview.in=>[false,nil], :uid.ne => uid) + .can_display_and_sorted.is_approved + .filter_by_widget_categories(cats,false).filter_by_tags(tags) + if !is_random + sorted_anns = sorted_anns.limit(widget_data_count) + if anns_cache.count > 1 + anns_cache.destroy end - end - end - feeds_anns = get_feed_announcements("widget") - announcements = announcements + feeds_anns - if !feeds_anns.blank? - sorted = announcements.sort{ |k,v| v["postdate"] <=> k["postdate"] } - sorted = top_anns + sorted - sorted = Kaminari.paginate_array(sorted).page(1).per(OrbitHelper.widget_data_count) rescue [] - else - announcements = top_anns + announcements - sorted = Kaminari.paginate_array(announcements).page(1).per(OrbitHelper.widget_data_count) rescue [] - end - anns = [] - sorted.each do |a| - if !a["source-site"].present? - statuses = a.statuses_with_classname.collect do |status| - { - "status" => status["name"], - "status-class" => "status-#{status['classname']}" - } - end - files = a.bulletin_files.map{|file| { "file_url" => file.file.url, "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title rescue '') } if file.enabled_for?(locale) } rescue [] - files.delete(nil) - links = a.bulletin_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue [] - author = User.find(a.create_user_id).member_profile.name rescue "" - desc = a.image_description - desc = (desc.nil? || desc == "" ? "announcement image" : desc) - link_to_show = a.is_external_link ? a.external_link : OrbitHelper.widget_item_url(a.to_param) - target = a.is_external_link ? "_blank" : "_self" - if @image_version == 'thumb' - image_url = a.image.thumb.url - elsif @image_version == 'mobile' - image_url = a.image.mobile.url - else - image_url = a.image.url - end - anns << { - "bulletin_links" => links, - "bulletin_files" => files, - "title" => a.title, - "source-site" => "", - "source-site-title" => "", - "source-site-link" => "", - "subtitle" => a.subtitle, - "statuses" => statuses, - "category" => a.category.title, - "postdate" => a.postdate, - "author" => author, - "link_to_show" => link_to_show, - "target" => target, - "img_src" => image_url || "/assets/announcement-default.jpg", - "img_description" => desc - } + AnnsCache.create(parent_id: subpart.id,filter_result: sorted_anns.map{|v| v.id}) else - anns << a + sorted_anns = sorted_anns.sample(widget_data_count) + end + else + sorted_anns = Bulletin.find(anns_cache.first.filter_result) + sorted_anns = sorted_anns.sort_by{|v| [(v.is_top==true ? 1 : 0),v['postdate']]}.reverse + end + if (defined? SiteFeed).nil? || is_random + anns = sorted_anns.map{|v| data_to_human_type(v)} + else + top_anns = sorted_anns.select{|v| v.is_top}.map{|v| data_to_human_type(v)} + rest_count = widget_data_count - top_anns.count + if rest_count <= 0 + anns = top_anns + else + feeds_anns = get_feed_announcements("widget") + rest_all_anns = feeds_anns + sorted_anns.select{|v| !v.is_top}.take(rest_count).map{|v| data_to_human_type(v)} + rest_anns = rest_all_anns.sort_by{|v| v["postdate"]}.take(rest_count) + anns = top_anns + rest_anns end end mp = (anns[0]["img_src"] rescue "") mpd = (anns[0]["img_description"] rescue "") - + t2 = Time.now + puts ['anns',tags,t2-t1] { "announcements" => anns, "extras" => { @@ -223,7 +179,7 @@ class AnnouncementsController < ApplicationController if is_preview announcement = Bulletin.where(:uid => uid).first else - announcement = Bulletin.can_display.where(:uid => uid).first + announcement = Bulletin.can_display_and_sorted.where(:uid => uid).first end url_to_edit = OrbitHelper.user_can_edit?(announcement) ? "/admin/announcements/#{announcement.id.to_s}/edit" : "" diff --git a/app/helpers/announcements_helper.rb b/app/helpers/announcements_helper.rb index f372776..db9fbb1 100644 --- a/app/helpers/announcements_helper.rb +++ b/app/helpers/announcements_helper.rb @@ -1,4 +1,65 @@ module AnnouncementsHelper + def set_image_version_for_widget + subpart = OrbitHelper.get_current_widget + @image_version = 'thumb' + if subpart.methods.include? 'select_options'.to_sym + ModuleApp.all.select{|tmp| tmp.key.to_s=='announcement'}.each do |modile_app| + @show_options = modile_app.show_options rescue nil + end + subpart.select_options.each do |select_option| + if !(@show_options.nil?) && select_option.field_name == @show_options.keys.first.to_s + value = YAML.load(select_option.value) + if value[I18n.locale] == t('announcement.small_size') + @image_version = 'thumb' + elsif value[I18n.locale] == t('announcement.medium_size') + @image_version = 'mobile' + elsif value[I18n.locale] == t('announcement.orignal_size') + @image_version = 'orignal' + end + end + end + end + end + def data_to_human_type(a) + statuses = a.statuses_with_classname.collect do |status| + { + "status" => status["name"], + "status-class" => "status-#{status['classname']}" + } + end + files = a.bulletin_files.map{|file| { "file_url" => file.file.url, "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title rescue '') } if file.enabled_for?(locale) } rescue [] + files.delete(nil) + links = a.bulletin_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue [] + author = User.find(a.create_user_id).member_profile.name rescue "" + desc = a.image_description + desc = (desc.nil? || desc == "" ? "announcement image" : desc) + link_to_show = a.is_external_link ? a.external_link : OrbitHelper.widget_item_url(a.to_param) + target = a.is_external_link ? "_blank" : "_self" + if @image_version == 'thumb' + image_url = a.image.thumb.url + elsif @image_version == 'mobile' + image_url = a.image.mobile.url + else + image_url = a.image.url + end + { + "bulletin_links" => links, + "bulletin_files" => files, + "title" => a.title, + "source-site" => "", + "source-site-title" => "", + "source-site-link" => "", + "subtitle" => a.subtitle, + "statuses" => statuses, + "category" => a.category.title, + "postdate" => a.postdate, + "author" => author, + "link_to_show" => link_to_show, + "target" => target, + "img_src" => image_url || "/assets/announcement-default.jpg", + "img_description" => desc + } + end def get_feed_announcements(type,site_source=nil) feed_anns = OrbitHelper.get_feed_for_module(type) fans = [] @@ -39,77 +100,65 @@ module AnnouncementsHelper end fans end - def test - 123 + def filter_by_keywords(sorted,keywords,postdate) + sorted.select{|anns| + flag1 = true + if !keywords.nil? + if anns["source-site"].present? + title = Nokogiri::HTML(anns["title"].to_s).text + else + title = Nokogiri::HTML(anns.title.to_s).text + end + flag1 = title.include?(keywords.to_s) + end + flag1 + } end def get_sorted_annc + t1 = Time.now params = OrbitHelper.params locale = OrbitHelper.get_site_locale.to_s page = Page.where(url:params['url']).first + page_number = OrbitHelper.page_number.to_i + page_number = 1 if page_number == 0 + page_data_count = OrbitHelper.page_data_count.to_i feeds_anns = [] tags = page.tags - if !tags.blank? - announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).and(:title.ne => nil).can_display.is_approved.filter_by_categories(page.categories || [],false).filter_by_tags(tags).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count).to_a - else - if !params["source"].present? - announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).and(:title.ne => nil, :is_top.ne => true).can_display.is_approved.filter_by_categories(page.categories || [],false).filter_by_tags.to_a + categories = params['category']=='all' ? (page.categories || []) : ([Category.find(params['category'])] rescue (page.categories || [])) + if !params["source"].present? + announcements = Bulletin.where(:title.nin => ["",nil],:is_preview.in=>[false,nil]) + .can_display_and_sorted.is_approved + .filter_by_categories(categories,false).filter_by_tags(tags).to_a + if (defined? SiteFeed).nil? feeds_anns = get_feed_announcements("index") - else - announcements = [] - feeds_anns = get_feed_announcements("index",params["source"]) end - end - # (OrbitHelper.page_number == 1 or OrbitHelper.page_number.nil?) && - if !feeds_anns.blank? - announcements = announcements.concat(feeds_anns) - sorted = announcements.sort{ |k,v| v["postdate"] <=> k["postdate"] } - if params["keywords"].present? - sorted = sorted.find_all{|anns| - if anns["source-site"].present? - /#{params[:keywords].to_s}/i.match anns["title"] - else - /#{params[:keywords].to_s}/i.match anns.title - end - } - end - if params["postdate"].present? - sorted = sorted.find_all{|anns| - if anns["source-site"].present? - /#{params[:postdate].to_s}/i.match anns["postdate"].strftime("%Y-%m") if !anns["postdate"].nil? - else - /#{params[:postdate].to_s}/i.match anns.postdate.strftime("%Y-%m") if !anns.postdate.nil? - end - } - end - sorted = Kaminari.paginate_array(sorted).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count) rescue [] else - if params["keywords"].present? - announcements = announcements.find_all{|anns| /#{params[:keywords].to_s}/i.match anns.title} - end - if params["postdate"].present? - announcements = announcements.find_all{|anns| - if !anns.postdate.nil? - /#{params[:postdate].to_s}/i.match anns.postdate.strftime("%Y-%m") - end - } - end - sorted = Kaminari.paginate_array(announcements).page(1).per(OrbitHelper.page_data_count) rescue [] + announcements = [] + feeds_anns = get_feed_announcements("index",params["source"]) end - begin - if !tags.blank? - annc_count = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).and(:title.ne => nil).can_display.is_approved.filter_by_categories(page.categories || [],false).filter_by_tags(tags).count + if !feeds_anns.blank? + if announcements.count != 0 + top_anns = announcements.select{|v| v.is_top} + rest_all_anns = feeds_anns + announcements.select{|v| !v.is_top} + rest_anns = rest_all_anns.sort_by{|v| v["postdate"]} + anns = top_anns + rest_anns + all_sorted = anns.sort_by{|v| v["postdate"] } else - if !params["source"].present? - annc_count = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).and(:title.ne => nil, :is_top.ne => true).can_display.is_approved.filter_by_categories(page.categories || [],false).filter_by_tags.count - annc_count += get_feed_announcements("index").count - else - annc_count = get_feed_announcements("index",params["source"]).count - end + all_sorted = feeds_anns.sort_by{|v| v["postdate"] } end - total_pages = (annc_count * 1.0 / OrbitHelper.page_data_count).ceil - rescue - total_pages = 1 + all_filter = filter_by_keywords(all_sorted,params[:keywords],params[:postdate]) + else + all_filter = filter_by_keywords(announcements,params[:keywords],params[:postdate]) end - [announcements,sorted,total_pages] + if page_data_count != 0 + sorted = all_filter[(page_number-1)*page_data_count...page_number*page_data_count] + else + sorted = all_filter + end + annc_count = all_filter.count + total_pages = page_data_count == 0 ? 1 : (annc_count.to_f / page_data_count).ceil + t2 = Time.now + puts ['get_sorted_annc',t2-t1] + [sorted,total_pages] end end diff --git a/app/models/anns_cache.rb b/app/models/anns_cache.rb new file mode 100644 index 0000000..444b620 --- /dev/null +++ b/app/models/anns_cache.rb @@ -0,0 +1,7 @@ +class AnnsCache + include Mongoid::Document + field :parent_id + field :filter_result,type: Array,default: [] + field :tag_ids,type: Array,default: [] + field :cat_ids,type: Array,default: [] +end \ No newline at end of file diff --git a/app/models/bulletin.rb b/app/models/bulletin.rb index 6619aa0..77cbb89 100644 --- a/app/models/bulletin.rb +++ b/app/models/bulletin.rb @@ -8,6 +8,9 @@ class Bulletin include OrbitTag::Taggable include OrbitCategory::Categorizable include Slug + require 'bulletin_model/cache' + include BulletinModel::Cache + SubPart.class_eval { include BulletinModel::Cache } field :title, type: String, localize: true field :subtitle, localize: true @@ -47,10 +50,11 @@ class Bulletin before_destroy :destroy_email - scope :can_display, ->{where(:is_hidden=>false,:is_preview => false).any_of({:postdate.lt=>Time.now, :deadline.gt=>Time.now},{:postdate.lt=>Time.now, :deadline=>nil}).order_by([:is_top, :desc],[:postdate, :desc])} + scope :can_display_and_sorted, ->{where(:is_hidden=>false,:is_preview => false).any_of({:postdate.lte=>Time.now, :deadline.gte=>Time.now},{:postdate.lte=>Time.now, :deadline=>nil}).order(is_top: :desc,postdate: :desc)} scope :is_approved, ->{where(:approved => true)} before_create :set_expire + def slug_title doc = Nokogiri::HTML(self.title) title = doc.text.gsub('/','-') diff --git a/app/views/announcements/index.html.erb b/app/views/announcements/index.html.erb index 648b75c..f767ddb 100644 --- a/app/views/announcements/index.html.erb +++ b/app/views/announcements/index.html.erb @@ -1 +1,62 @@ +<% params = OrbitHelper.params + page = Page.where(url:params['url']).first + enable_search_flag = false + if page.methods.include? 'select_option_items'.to_sym + ModuleApp.all.select{|tmp| tmp.key.to_s=='announcement'}.each do |modile_app| + @show_option_items = modile_app.show_option_items rescue nil + end + page.select_option_items.each do |select_option_item| + if !(@show_option_items.nil?) && select_option_item.field_name == @show_option_items.keys[1].to_s + value = YAML.load(select_option_item.value) + if value[I18n.locale] == t('announcement.yes') + enable_search_flag = true + end + end + end + end +%> +<% if enable_search_flag %> + +
+<% end %> <%= render_view %> \ No newline at end of file diff --git a/app/views/announcements/show.html.erb b/app/views/announcements/show.html.erb index fc08394..df74886 100644 --- a/app/views/announcements/show.html.erb +++ b/app/views/announcements/show.html.erb @@ -1,6 +1,6 @@ <% - require 'announcements_helper' - params = OrbitHelper.params + require 'announcements_helper' + params = OrbitHelper.params page = Page.where(url:params['url']).first @show_back_and_next_flag = 0 if page.methods.include? 'select_option_items'.to_sym @@ -22,7 +22,7 @@ end if @show_back_and_next_flag != 0 uid = params['uid'] - announcements,sorted = get_sorted_annc + sorted,total_pages = get_sorted_annc now_index = sorted.to_enum.with_index.select{|v| v[0].uid==uid}[0][1] if now_index != 0 prev_result = sorted[now_index-1] diff --git a/config/locales/en.yml b/config/locales/en.yml index c5117c0..87f0310 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3,6 +3,12 @@ en: feed: Feed import: Import announcement: + select_prompt: --select category-- + all: All + keywords: Keywords + enable_search: Enable search feature + 'yes': 'Yes' + 'no': 'No' image: Cover Image picture_showing_size: Picture Showing Size orignal_size: Original Size diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index f85f8cc..971ee3d 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -3,6 +3,12 @@ zh_tw: feed: 供給 import: 匯入 announcement: + select_prompt: --選取類別-- + all: 全部 + keywords: 關鍵字 + enable_search: 開啟搜尋功能 + 'yes': 是 + 'no': 否 image: 封面圖片 picture_showing_size: 圖片顯示大小 orignal_size: 原圖大小 diff --git a/lib/announcement.rb b/lib/announcement.rb index 1feec47..ac70c46 100644 --- a/lib/announcement.rb +++ b/lib/announcement.rb @@ -1,4 +1,4 @@ require "announcement/engine" - module Announcement + end diff --git a/lib/announcement/engine.rb b/lib/announcement/engine.rb index 0f63de2..8daa015 100644 --- a/lib/announcement/engine.rb +++ b/lib/announcement/engine.rb @@ -2,31 +2,42 @@ require "yaml" module Announcement class Engine < ::Rails::Engine initializer "announcement" do - translate_data = Dir["#{Announcement::Engine.root}/config/locales/*.yml"] .map{|yaml_file| YAML.load(File.read(yaml_file))} - data = {} - key1 = {} - value1 = {} - value2 = {} - value3 = {} - translate_data.each do |t_data| - key1[t_data.keys[0]] = t_data.values[0]['announcement']['picture_showing_size'] - value1[t_data.keys[0]] = t_data.values[0]['announcement']['small_size'] - value2[t_data.keys[0]] = t_data.values[0]['announcement']['medium_size'] - value3[t_data.keys[0]] = t_data.values[0]['announcement']['orignal_size'] + begin + translate_data = Dir["#{Announcement::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]['announcement']['picture_showing_size'] + value1[k] = v[0]['announcement']['small_size'] + value2[k] = v[0]['announcement']['medium_size'] + value3[k] = v[0]['announcement']['orignal_size'] + 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 + data[key1] = [value1,value2,value3] + data_item[key_item1] = [value_item1,value_item2,value_item3] + data_item[key_item2] = [value2_item1,value2_item2] + rescue => e + puts ['error in announcement',e] end - data[key1] = [value1,value2,value3] - data_item = {} - key_item1 = {} - value_item1 = {} - value_item2 = {} - value_item3 = {} - translate_data.each do |t_data| - key_item1[t_data.keys[0]] = t_data.values[0]['announcement']['showing_back_and_next'] - value_item1[t_data.keys[0]] = t_data.values[0]['announcement']['not_show'] - value_item2[t_data.keys[0]] = t_data.values[0]['announcement']['show_bottom'] - value_item3[t_data.keys[0]] = t_data.values[0]['announcement']['show_top'] - end - data_item[key_item1] = [value_item1,value_item2,value_item3] OrbitApp.registration "Announcement", :type => "ModuleApp" do module_label "announcement.announcement" base_url File.expand_path File.dirname(__FILE__) diff --git a/lib/bulletin_model/cache.rb b/lib/bulletin_model/cache.rb new file mode 100644 index 0000000..3928cd3 --- /dev/null +++ b/lib/bulletin_model/cache.rb @@ -0,0 +1,16 @@ +module BulletinModel + module Cache + require 'active_support/concern' + extend ActiveSupport::Concern + included do + before_save :do_before_save + end + def do_before_save + if self.class == SubPart + AnnsCache.where(parent_id:self.id).destroy + elsif self.class == Bulletin + AnnsCache.all.destroy + end + end + end +end \ No newline at end of file diff --git a/temp_file/app/controllers/admin/sites_controller.rb b/temp_file/app/controllers/admin/sites_controller.rb index a341eeb..74e9270 100644 --- a/temp_file/app/controllers/admin/sites_controller.rb +++ b/temp_file/app/controllers/admin/sites_controller.rb @@ -14,17 +14,17 @@ class Admin::SitesController < OrbitAdminController end end end - layout "structure" + layout "structure" def send_email - params_to_send = {'store_token' => current_site.store_token} - uri = URI.parse(OrbitStore::URL) - http = Net::HTTP.new(uri.host,uri.port) - request = Net::HTTP::Get.new("/site/send_email") - request.body = params_to_send.to_query - response = http.request(request) - data = JSON.parse(response.body) - %x(kill -s USR2 `cat tmp/pids/unicorn.pid`) - sleep 5 + params_to_send = {'store_token' => current_site.store_token} + uri = URI.parse(OrbitStore::URL) + http = Net::HTTP.new(uri.host,uri.port) + request = Net::HTTP::Get.new("/site/send_email") + request.body = params_to_send.to_query + response = http.request(request) + data = JSON.parse(response.body) + %x(kill -s USR2 `cat tmp/pids/unicorn.pid`) + sleep 5 end def index @first_run = dashboard_is_first_run? @@ -48,7 +48,7 @@ class Admin::SitesController < OrbitAdminController @types << [tt["title_translations"][locale],tt["id"]] end end - send_email if !@store_permissions["permission_granted"] rescue nil #Resend confirmation email if not confirmed + send_email if !@store_permissions["permission_granted"] rescue nil #Resend confirmation email if not confirmed end user_name = current_user.user_name rescue '' network = ONetwork.new(OrbitStore::URL,"post") @@ -57,16 +57,16 @@ class Admin::SitesController < OrbitAdminController end - def mail_setting - end + def mail_setting + end - def site_info + def site_info @pages = Page.where(:module=>"page_content") - end + end - def responsive_setting + def responsive_setting @module = ModuleApp.find_by_key("announcement") - end + end def search_engine end @@ -168,11 +168,11 @@ class Admin::SitesController < OrbitAdminController git = 'git_1.9.1/usr/bin/git' end git_add_except_public = Dir['*'].select{|v| v!= 'public' && v!= 'log'}.collect do |v| - "#{git} add -f '#{v}'" - end.join(' && ') + "#{git} add -f --all --ignore-errors '#{v}'" + end.join(' ; ') git_add_custom = (Dir['*'].select{|v| v !='app' && v != 'lib' && v != 'config' && v != 'public' && v!= 'log'} + ['app/templates','config/mongoid.yml']).collect do |v| - "#{git} add -f --all '#{v}'" - end.join(' && ') + "#{git} add -f --all --ignore-errors '#{v}'" + end.join(' ; ') git_restore = "#{git} checkout ." time_now = Time.now.strftime('%Y_%m_%d_%H_%M') if %x[#{git} config user.name].empty? @@ -181,7 +181,7 @@ class Admin::SitesController < OrbitAdminController if %x[#{git} config user.email].empty? %x[#{git} config --global user.email "orbit@rulingcom.com"] end - Bundler.with_clean_env{system("#{git_add_except_public} && #{git} commit -m auto_backup_before_#{type}_#{time_now} && #{git} reset #{commit} --mixed && #{git_add_custom} && #{git_restore} && #{git_add_except_public}&& #{git} commit -m complete_#{type}_#{time_now}")} + Bundler.with_clean_env{system("#{git_add_except_public} ; #{git} commit -m auto_backup_before_#{type}_#{time_now} && #{git} reset #{commit} --mixed ; #{git_add_custom} ; #{git_restore} ; #{git_add_except_public} ; #{git} commit -m complete_#{type}_#{time_now}")} mul.update_attributes(status: 'finish') end end @@ -252,7 +252,7 @@ class Admin::SitesController < OrbitAdminController end - def set_git_branch - @branch = %x(git rev-parse --abbrev-ref HEAD).gsub("\n","") - end + def set_git_branch + @branch = %x(git rev-parse --abbrev-ref HEAD).gsub("\n","") + end end