Fix channel title update and display bug.

This commit is contained in:
BoHung Chiu 2022-06-21 16:04:17 +08:00
parent 1ce77b43e1
commit 967f158612
2 changed files with 28 additions and 20 deletions

View File

@ -106,8 +106,8 @@ class Admin::FeedsController < OrbitAdminController
@filter_fields = {} @filter_fields = {}
@filter_fields['feed.source'] = SiteFeed.all.pluck(:channel_title,:remote_site_url).collect do |a,b| @filter_fields['feed.source'] = SiteFeed.all.pluck(:channel_title,:remote_site_url).collect do |a,b|
tp = (a.blank? || a[I18n.locale].blank?) ? b.gsub(/http:\/\/|https:\/\//,'').gsub(/\./,'-') : a[I18n.locale] tp = (a.blank? || a[I18n.locale].blank?) ? b.gsub(/http:\/\/|https:\/\//,'').gsub(/\./,'-') : a[I18n.locale]
{:title => tp,:id => tp} tp
end end.uniq.map{|tp| {:title => tp,:id => tp}}
@filter_fields['feed.module_name'] = SiteFeed.all.map{|s| s.channel_key}.uniq.map do |key| @filter_fields['feed.module_name'] = SiteFeed.all.map{|s| s.channel_key}.uniq.map do |key|
{:title => I18n.t("module_name.#{key}"),:id => key} {:title => I18n.t("module_name.#{key}"),:id => key}
end end
@ -195,7 +195,7 @@ class Admin::FeedsController < OrbitAdminController
site_feeds = SiteFeed.where(:remote_site_url => params["url"]) site_feeds = SiteFeed.where(:remote_site_url => params["url"])
site_feeds.each do |sf| site_feeds.each do |sf|
sf.channel_title_translations = params["channel_title_translations"] sf.channel_title_translations = params["channel_title_translations"]
sf.instance_variable_set(:@skip_callback) sf.instance_variable_set(:@skip_callback, true)
sf.save sf.save
sf.sync_data_to_annc sf.sync_data_to_annc
end end

View File

@ -4,35 +4,34 @@
<div> <div>
<h3>Channel and feeds</h3> <h3>Channel and feeds</h3>
</div> </div>
<% in_use_locales = ([I18n.locale] + (I18n.available_locales - [I18n.locale])) %>
<div class="accordion channel-accordion" id="feedAccordion"> <div class="accordion channel-accordion" id="feedAccordion">
<% @school_urls.each_with_index do |url,index| %> <% @school_urls.each_with_index do |url,index| %>
<div class="accordion-group channel-accordion-group"> <div class="accordion-group channel-accordion-group">
<div class="accordion-heading channel-accordion-heading"> <div class="accordion-heading channel-accordion-heading">
<% first_record = @site_feeds[url].first %>
<a class="accordion-toggle channel-accordion-toggle collapsed" data-toggle="collapse" data-parent="#feedAccordion" href="#channel_<%= index.to_s %>"> <a class="accordion-toggle channel-accordion-toggle collapsed" data-toggle="collapse" data-parent="#feedAccordion" href="#channel_<%= index.to_s %>">
<span class="channel-url"><%= url %></span> <span class="channel-url"><%= url %></span>
<% if !@site_feeds[url].first.channel_title.nil? && @site_feeds[url].first.channel_title != "" %> <span class="channel-source-name label <%= 'hide' if first_record.channel_title.blank? %>">
<span class="channel-source-name label"><%= @site_feeds[url].first.channel_title %></span> <%= first_record.channel_title %>
<% end %> </span>
</a> </a>
<div class="dropdown channel-dropdown"> <div class="dropdown channel-dropdown">
<a class="channel-edit-form btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#">Edit</a> <a class="channel-edit-form btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#">Edit</a>
<a class="channel-save-form btn btn-primary dropdown-toggle hide" data-toggle="dropdown" href="#">Save</a> <a class="channel-save-form btn btn-primary dropdown-toggle hide" data-toggle="dropdown" href="#">Save</a>
<ul class="dropdown-menu channel-dropdown-menu" role="menu" aria-labelledby="dLabel"> <ul class="dropdown-menu channel-dropdown-menu" role="menu" aria-labelledby="dLabel">
<form class="form-horizontal channel-form-horizontal" method="post" action="/admin/feeds/channel_title" data-remote="true"> <form class="form-<%= first_record.id %> form-horizontal channel-form-horizontal" method="post" action="/admin/feeds/channel_title" data-remote="true">
<h5>Source name</h5> <h5>Source name</h5>
<div class="control-group channel-control-group"> <% channel_title_translations = first_record.channel_title_translations %>
<label class="control-label channel-label" for="inputEnglish">English</label> <% in_use_locales.each do |l| %>
<div class="controls channel-controls"> <div class="control-group channel-control-group">
<input type="text" id="inputEnglish" placeholder="Source" name="channel_title_translations[en]"> <label class="control-label channel-label" for="<%= first_record.id %>-input<%=l%>"><%=t(l)%></label>
</div> <div class="controls channel-controls">
</div> <input type="text" id="<%= first_record.id %>-input<%=l%>" placeholder="Source" name="channel_title_translations[<%=l%>]" value="<%=channel_title_translations[l]%>">
<div class="control-group channel-control-group"> </div>
<label class="control-label channel-label" for="inputChinese">Chinese</label> </div>
<div class="controls channel-controls"> <% end %>
<input type="text" id="inputChinese" placeholder="Source" name="channel_title_translations[zh_tw]"> <input type="hidden" name="url" value="<%= url %>">
</div>
<input type="hidden" name="url" value="<%= url %>" >
</div>
</form> </form>
</ul> </ul>
</div> </div>
@ -70,6 +69,15 @@
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
$('.channel-form-horizontal').bind('ajax:success', function(evt, data, status, xhr){
var title = data['title'];
var el = $(this).parents('.accordion-heading').find('.channel-source-name');
if(title && title.length > 0){
el.text(data["title"]).removeClass('hide');
}else{
el.text(data["title"]).addClass('hide');
}
})
$(".disable-feed-btn").on("click",function(){ $(".disable-feed-btn").on("click",function(){
var disable = null, var disable = null,
el = $(this), el = $(this),