add force refresh button
This commit is contained in:
parent
77da0ef641
commit
6510d67c35
|
@ -185,6 +185,15 @@ class Admin::FeedsController < OrbitAdminController
|
||||||
end
|
end
|
||||||
render :json => {"success" => true}.to_json
|
render :json => {"success" => true}.to_json
|
||||||
end
|
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)
|
def search_all_words(target, word)
|
||||||
target = target.upcase
|
target = target.upcase
|
||||||
words = word.upcase.split(' ')
|
words = word.upcase.split(' ')
|
||||||
|
|
|
@ -31,10 +31,10 @@ class SiteFeed
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
scope :enabled, ->{where(:disabled => false)}
|
scope :enabled, ->{where(:disabled => false)}
|
||||||
def get_annc
|
def get_annc(force_refresh=false)
|
||||||
main_directory = File.join("#{Rails.root}","public","site_feeds")
|
main_directory = File.join("#{Rails.root}","public","site_feeds")
|
||||||
feed_directory = File.join(main_directory.to_s, self.id.to_s)
|
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 []
|
anns = JSON.parse(File.read(File.join(feed_directory.to_s, self.feed_uid + ".json")))[self.channel_key.pluralize] rescue []
|
||||||
else
|
else
|
||||||
uri = URI(self.feed_url)
|
uri = URI(self.feed_url)
|
||||||
|
|
|
@ -53,8 +53,9 @@
|
||||||
<span class="channel-feedname"><%= channel.feed_name %></span>
|
<span class="channel-feedname"><%= channel.feed_name %></span>
|
||||||
<span class="label label-info"><%= channel.category.title rescue "" %></span>
|
<span class="label label-info"><%= channel.category.title rescue "" %></span>
|
||||||
<span class="channel-actions">
|
<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 <%= 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 unsubscribe-btn" data-feed-uid="<%= channel.feed_uid %>" data-feed-name="<%= channel.feed_name %>">Unsubscribe</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>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -129,7 +130,18 @@
|
||||||
el.parent().remove();
|
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>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,3 +9,8 @@ en:
|
||||||
display: Display
|
display: Display
|
||||||
all_feeds_announcments: All feeds announcments
|
all_feeds_announcments: All feeds announcments
|
||||||
feed_name: Channel name
|
feed_name: Channel name
|
||||||
|
enable: Enable
|
||||||
|
disable: Disable
|
||||||
|
force_refresh: Force Refresh
|
||||||
|
unsubscribe: Unsubscribe
|
||||||
|
successful: Successful!
|
|
@ -9,3 +9,8 @@ zh_tw:
|
||||||
display: 顯示
|
display: 顯示
|
||||||
all_feeds_announcments: 全部訂閱公告
|
all_feeds_announcments: 全部訂閱公告
|
||||||
feed_name: 訂閱名稱
|
feed_name: 訂閱名稱
|
||||||
|
enable: 開啟
|
||||||
|
disable: 關閉
|
||||||
|
force_refresh: 強制刷新
|
||||||
|
unsubscribe: 解除訂閱
|
||||||
|
successful: 刷新成功
|
|
@ -15,6 +15,7 @@ Rails.application.routes.draw do
|
||||||
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'
|
||||||
|
post "/feeds/force_refresh", to: 'feeds#force_refresh'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue