From 6836aaf6cddc72ca025c0f0bf1b0f937fffecf68 Mon Sep 17 00:00:00 2001 From: chiu Date: Sun, 8 Mar 2020 20:32:05 +0800 Subject: [PATCH] remove the option of widget method and auto send to the correct method --- app/controllers/e_papers_controller.rb | 16 +++++++++++++++- lib/e_paper/engine.rb | 17 +++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/app/controllers/e_papers_controller.rb b/app/controllers/e_papers_controller.rb index 07799d9..71da12c 100644 --- a/app/controllers/e_papers_controller.rb +++ b/app/controllers/e_papers_controller.rb @@ -99,7 +99,21 @@ class EPapersController < ApplicationController "extras" => {} } end - + def widget + subpart = OrbitHelper.get_current_widget + case subpart.widget_type + when /criteria_list.*/ + criteria_list + when /category_wise_articles.*/ + category_wise_articles + when /latest_criteria.*/ + latest_criteria + when /latest_slider.*/ + latest_slider + else + subscribe + end + end def criteria_list params = OrbitHelper.params criterias = PaperCriteria.all.desc(:start_date).limit(OrbitHelper.widget_data_count) diff --git a/lib/e_paper/engine.rb b/lib/e_paper/engine.rb index f84e572..651be4e 100644 --- a/lib/e_paper/engine.rb +++ b/lib/e_paper/engine.rb @@ -1,10 +1,23 @@ module EPaper class Engine < ::Rails::Engine - initializer "e_paper" do + initializer "e_paper" do + env_pwd = ENV['PWD'] + begin + require File.expand_path('app/models/sub_part.rb', env_pwd) + if defined? SubPart + SubPart.where(:module => 'e_paper',:widget_method.ne => 'widget').each do |sub_part| + sub_part.widget_method = 'widget' + sub_part.save + end + end + rescue => e + puts ["can't find subpart",e] + end OrbitApp.registration "EPaper", :type => "ModuleApp" do module_label "e_paper.e_paper" base_url File.expand_path File.dirname(__FILE__) - widget_methods ["criteria_list","category_wise_articles","latest_criteria", "latest_slider", "subscribe"] + #widget_methods ["criteria_list","category_wise_articles","latest_criteria", "latest_slider", "subscribe"] + widget_methods ["widget"] widget_settings [{"data_count"=>30}] taggable "EPaperCriteria" categorizable