add force refresh button

This commit is contained in:
chiu 2021-09-15 16:43:19 +08:00
parent 77da0ef641
commit 6510d67c35
6 changed files with 38 additions and 6 deletions

View File

@ -185,6 +185,15 @@ class Admin::FeedsController < OrbitAdminController
end
render :json => {"success" => true}.to_json
end
def force_refresh
sf = SiteFeed.find_by(:feed_uid => params[:feed_uid]) rescue nil
if !sf.nil?
sf.get_annc(true)
end
render :json => {"success" => true}.to_json
end
def search_all_words(target, word)
target = target.upcase
words = word.upcase.split(' ')

View File

@ -31,10 +31,10 @@ class SiteFeed
end
end
scope :enabled, ->{where(:disabled => false)}
def get_annc
def get_annc(force_refresh=false)
main_directory = File.join("#{Rails.root}","public","site_feeds")
feed_directory = File.join(main_directory.to_s, self.id.to_s)
if File.exists?(feed_directory)
if !force_refresh && File.exists?(feed_directory)
anns = JSON.parse(File.read(File.join(feed_directory.to_s, self.feed_uid + ".json")))[self.channel_key.pluralize] rescue []
else
uri = URI(self.feed_url)

View File

@ -53,8 +53,9 @@
<span class="channel-feedname"><%= channel.feed_name %></span>
<span class="label label-info"><%= channel.category.title rescue "" %></span>
<span class="channel-actions">
<button class="btn <%= channel.disabled ? "btn-info" : "btn-warning" %> btn-small disable-feed-btn" data-feed-id="<%= channel.id.to_s %>"><%= channel.disabled ? "Enable" : "Disable" %></button>
<button class="btn btn-danger btn-small unsubscribe-btn" data-feed-uid="<%= channel.feed_uid %>" data-feed-name="<%= channel.feed_name %>">Unsubscribe</button>
<button class="btn <%= channel.disabled ? "btn-info" : "btn-warning" %> btn-small disable-feed-btn" data-feed-id="<%= channel.id.to_s %>"><%= channel.disabled ? t("feed.enable") : t("feed.disable") %></button>
<button class="btn btn-danger btn-small force-refresh-btn" data-feed-uid="<%= channel.feed_uid %>" data-feed-name="<%= channel.feed_name %>"><%= t("feed.force_refresh") %></button>
<button class="btn btn-danger btn-small unsubscribe-btn" data-feed-uid="<%= channel.feed_uid %>" data-feed-name="<%= channel.feed_name %>"><%= t("feed.unsubscribe") %></button>
</span>
</li>
</ul>
@ -129,7 +130,18 @@
el.parent().remove();
})
}
})
});
$(".force-refresh-btn").on("click",function(){
var el = $(this);
$.ajax({
url : "/admin/feeds/force_refresh",
data : {"feed_uid": el.data("feed-uid")},
dataType : "json",
type : "post"
}).done(function(){
alert("<%= t("feed.successful") %>")
});
});
</script>

View File

@ -9,3 +9,8 @@ en:
display: Display
all_feeds_announcments: All feeds announcments
feed_name: Channel name
enable: Enable
disable: Disable
force_refresh: Force Refresh
unsubscribe: Unsubscribe
successful: Successful!

View File

@ -9,3 +9,8 @@ zh_tw:
display: 顯示
all_feeds_announcments: 全部訂閱公告
feed_name: 訂閱名稱
enable: 開啟
disable: 關閉
force_refresh: 強制刷新
unsubscribe: 解除訂閱
successful: 刷新成功

View File

@ -15,6 +15,7 @@ Rails.application.routes.draw do
get '/feeds/announcements' => 'feeds#announcements'
post '/feeds/process_annc' => 'feeds#process_annc'
get '/feeds/annc_content' => 'feeds#annc_content'
post "/feeds/force_refresh", to: 'feeds#force_refresh'
end
end