add feature for setting whether to use source url for annc
This commit is contained in:
parent
430c673fdf
commit
9007a0c51b
|
@ -14,6 +14,22 @@ class Admin::FeedsController < OrbitAdminController
|
||||||
redirect_to new_admin_feed_path and return if @site_feeds.count == 0
|
redirect_to new_admin_feed_path and return if @site_feeds.count == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def settings
|
||||||
|
@setting = SiteFeedSetting.first
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_settings
|
||||||
|
@setting = SiteFeedSetting.first
|
||||||
|
p = params.require(:site_feed_setting).permit!
|
||||||
|
@setting.update_attributes(p)
|
||||||
|
Thread.new do
|
||||||
|
sleep 3
|
||||||
|
content = "UNICORN_PID=\"`fuser tmp/pids/unicorn.sock tmp/sockets/unicorn.sock tmp/unicorn.sock` `cat tmp/pids/unicorn.pid `\" && kill -s USR2 $UNICORN_PID ; n=20; while (kill -0 $UNICORN_PID > /dev/null 2>&1) && test $n -ge 0; do printf '.' && sleep 1 && n=$(( $n - 1 )); done ; if test $n -lt 0; then kill -s TERM $UNICORN_PID; sleep 3; bundle exec unicorn_rails -c config/unicorn.rb -D -E #{Rails.env}; else kill -s QUIT $UNICORN_PID; fi"
|
||||||
|
system(content)
|
||||||
|
end
|
||||||
|
redirect_to admin_feeds_settings_path
|
||||||
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
class SiteFeedAnnc
|
class SiteFeedAnnc
|
||||||
include Mongoid::Document
|
include Mongoid::Document
|
||||||
include Mongoid::Timestamps
|
include Mongoid::Timestamps
|
||||||
|
UseSourceUrl = SiteFeedSetting.first.use_source_url rescue false
|
||||||
field :top_list,type: Array,default: []
|
field :top_list,type: Array,default: []
|
||||||
field :hot_list,type: Array,default: []
|
field :hot_list,type: Array,default: []
|
||||||
field :all_contents_for_feed
|
field :all_contents_for_feed
|
||||||
|
@ -186,9 +187,9 @@ class SiteFeedAnnc
|
||||||
tmp = data['data']
|
tmp = data['data']
|
||||||
if tmp["link_to_show"].nil?
|
if tmp["link_to_show"].nil?
|
||||||
if !is_widget
|
if !is_widget
|
||||||
tmp["link_to_show"] = OrbitHelper.url_to_show(tmp["params"]) rescue ''
|
tmp["link_to_show"] = UseSourceUrl && tmp["show_url"] ? tmp["show_url"] : OrbitHelper.url_to_show(tmp["params"]) rescue ''
|
||||||
else
|
else
|
||||||
tmp["link_to_show"] = OrbitHelper.widget_item_url(tmp["params"]) rescue ''
|
tmp["link_to_show"] = UseSourceUrl && tmp["show_url"] ? tmp["show_url"] : OrbitHelper.widget_item_url(tmp["params"]) rescue ''
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
tmp
|
tmp
|
||||||
|
@ -208,9 +209,9 @@ class SiteFeedAnnc
|
||||||
next if tmp["is_hidden"] || (!tmp["postdate"].nil? && tmp["postdate"]<Time.now) || tmp['title'].blank?
|
next if tmp["is_hidden"] || (!tmp["postdate"].nil? && tmp["postdate"]<Time.now) || tmp['title'].blank?
|
||||||
if tmp["link_to_show"].nil?
|
if tmp["link_to_show"].nil?
|
||||||
if !is_widget
|
if !is_widget
|
||||||
tmp["link_to_show"] = OrbitHelper.url_to_show(tmp["params"]) rescue ''
|
tmp["link_to_show"] = UseSourceUrl && tmp["show_url"] ? tmp["show_url"] : OrbitHelper.url_to_show(tmp["params"]) rescue ''
|
||||||
else
|
else
|
||||||
tmp["link_to_show"] = OrbitHelper.widget_item_url(tmp["params"]) rescue ''
|
tmp["link_to_show"] = UseSourceUrl && tmp["show_url"] ? tmp["show_url"] : OrbitHelper.widget_item_url(tmp["params"]) rescue ''
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
tmp
|
tmp
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
class SiteFeedSetting
|
||||||
|
include Mongoid::Document
|
||||||
|
include Mongoid::Timestamps
|
||||||
|
field :use_source_url, type: Boolean, default: false
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,15 @@
|
||||||
|
<link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet">
|
||||||
|
<script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>
|
||||||
|
<%= form_for @setting, url: "/admin/feeds/update_settings", html: {class: "form-horizontal main-forms"} do |f| %>
|
||||||
|
<div class="input-area">
|
||||||
|
<div class="control-group">
|
||||||
|
<%= f.label :top_limit, t("feed.use_source_url"), :class => "control-label muted" %>
|
||||||
|
<div class="controls">
|
||||||
|
<%= f.check_box :use_source_url, "data-toggle" => "toggle", "data-onstyle"=>"primary","data-on"=>"#{t("feed.yes")}", "data-off"=> "#{t("feed.no")}", "data-height" => "25", "data-size" => "mini" %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-actions">
|
||||||
|
<%= f.submit t('submit'), class: 'btn btn-primary' %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
|
@ -13,4 +13,8 @@ en:
|
||||||
disable: Disable
|
disable: Disable
|
||||||
force_refresh: Force Refresh
|
force_refresh: Force Refresh
|
||||||
unsubscribe: Unsubscribe
|
unsubscribe: Unsubscribe
|
||||||
successful: Successful!
|
successful: Successful!
|
||||||
|
use_source_url: Use Source Url
|
||||||
|
'yes': 'Yes'
|
||||||
|
'no': 'No'
|
||||||
|
settings: Settings
|
|
@ -13,4 +13,8 @@ zh_tw:
|
||||||
disable: 關閉
|
disable: 關閉
|
||||||
force_refresh: 強制刷新
|
force_refresh: 強制刷新
|
||||||
unsubscribe: 解除訂閱
|
unsubscribe: 解除訂閱
|
||||||
successful: 刷新成功
|
successful: 刷新成功
|
||||||
|
use_source_url: 使用來源連結
|
||||||
|
'yes': 是
|
||||||
|
'no': 否
|
||||||
|
settings: 設定
|
|
@ -53,6 +53,8 @@ Rails.application.routes.draw do
|
||||||
post "/feeds/disable", to: 'feeds#disable'
|
post "/feeds/disable", to: 'feeds#disable'
|
||||||
post "/feeds/channel_title", to: 'feeds#channel_title'
|
post "/feeds/channel_title", to: 'feeds#channel_title'
|
||||||
resources :feeds,only: ['new','index']
|
resources :feeds,only: ['new','index']
|
||||||
|
get '/feeds/settings' => 'feeds#settings'
|
||||||
|
patch '/feeds/update_settings' => 'feeds#update_settings'
|
||||||
get '/feeds/announcements' => 'feeds#announcements'
|
get '/feeds/announcements' => 'feeds#announcements'
|
||||||
post '/feeds/process_annc' => 'feeds#process_annc'
|
post '/feeds/process_annc' => 'feeds#process_annc'
|
||||||
get '/feeds/annc_content' => 'feeds#annc_content'
|
get '/feeds/annc_content' => 'feeds#annc_content'
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
module Feeds
|
module Feeds
|
||||||
class Engine < ::Rails::Engine
|
class Engine < ::Rails::Engine
|
||||||
initializer "feeds" do
|
initializer "feeds" do
|
||||||
|
if ENV['worker_num']=='0' && File.basename($0) != 'rake' && !Rails.const_defined?('Console')
|
||||||
|
require File.expand_path('../../../app/models/site_feed_setting', __FILE__)
|
||||||
|
if defined?(SiteFeedSetting)
|
||||||
|
if SiteFeedSetting.count==0
|
||||||
|
SiteFeedSetting.create
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
OrbitApp.registration "Feeds", :type => "ModuleApp" do
|
OrbitApp.registration "Feeds", :type => "ModuleApp" do
|
||||||
module_label "feed.feed"
|
module_label "feed.feed"
|
||||||
base_url File.expand_path File.dirname(__FILE__)
|
base_url File.expand_path File.dirname(__FILE__)
|
||||||
|
@ -28,6 +36,12 @@ module Feeds
|
||||||
:priority=>3,
|
:priority=>3,
|
||||||
:active_for_action=>{'admin/feeds'=>'announcements'},
|
:active_for_action=>{'admin/feeds'=>'announcements'},
|
||||||
:available_for => 'managers'
|
:available_for => 'managers'
|
||||||
|
context_link 'feed.settings',
|
||||||
|
:link_path=>"admin_feeds_settings_path" ,
|
||||||
|
:priority=>3,
|
||||||
|
:active_for_action=>{'admin/feeds'=>'settings'},
|
||||||
|
:available_for => 'managers'
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue