add paginator for announcements page

This commit is contained in:
邱博亞 2022-01-06 13:13:43 +08:00
parent bba15315c4
commit 7a113e94bd
3 changed files with 51 additions and 32 deletions

View File

@ -86,14 +86,18 @@ class Admin::FeedsController < OrbitAdminController
@filter_fields['feed.module_name'] = SiteFeed.all.map{|s| s.channel_key}.uniq.map do |key|
{:title => I18n.t("module_name.#{key}"),:id => key}
end
@max_content_count = 100
@page_no = params[:page].to_i
@page_no = 1 if @page_no==0
@skip_count = (@page_no-1)*@max_content_count
@module_name = params[:filters][:module_name].to_a rescue []
@module_name = SiteFeed.all.map{|s| s.channel_key}.uniq if @module_name == []
@all_feed_annc = SiteFeedAnnc.where(:channel_key.in => @module_name).order(created_at: 1).to_a rescue []
@source = params[:filters][:source] rescue []
@keywords = params[:keywords] rescue nil
if request.xhr?
render :partial => "announcements"
end
render :partial => "announcements"
end
end
def get_category_list
app_key = params[:channel]

View File

@ -9,6 +9,9 @@
</tr>
</thead>
<tbody>
<% data_count = 0
total_count = 0
%>
<% @all_feed_annc.each do |feed_annc| %>
<% feed_name = available_locales.collect{|v| feed_annc[:feed_name][v]}.join(' / ') %>
<% if @source.blank? || (@source.include?(feed_annc.channel_title) rescue false) || @source.include?(feed_annc.remote_site_url.to_s.gsub(/http:\/\/|https:\/\//,'').gsub(/\./,'-')) %>
@ -16,35 +19,39 @@
<% annc_title = available_locales.collect{|v| annc['title_translations'][v]}.join('/') %>
<% annc_tags = annc['tags'].collect{|tmp| available_locales.collect{|v| tmp['name_translations'][v]}.join(' / ')} %>
<% if @keywords.blank? || search_all_words(Nokogiri.HTML(annc_title).text()+' '+feed_name+' '+annc_tags.join(' '),@keywords) %>
<tr data-annc-feed-id='<%= feed_annc.id.to_s %>' data-annc-uid='<%= annc['id'].to_s %>'>
<td>
<span class="channel-source-name label"><%= (feed_annc.channel_title.include?("translation missing") || feed_annc.channel_title.blank?) ? t("feed.source") : feed_annc.channel_title %></span>
<br>
<%= feed_name %>
</td>
<td>
<ul>
<li>
<a class='annc_title'><%= annc_title.html_safe %></a>
</li>
<li style="display: flex;width: 100%;flex-wrap: wrap;">
<%= check_box_tag nil,nil,feed_annc[:top_list].include?(annc['id']),'class' => 'is_top' %>
<%= check_box_tag nil,nil,feed_annc[:hot_list].include?(annc['id']),'class' => 'is_hot' %>
</li>
</ul>
</td>
<td>
<%= annc_tags.join('<br>').html_safe %>
</td>
<td>
<% display_flag = feed_annc[:hidden_annc].count==0 || feed_annc[:hidden_annc].exclude?(annc['id']) ? true : false %>
<% if display_flag %>
<button class='btn-info hidden_btn'><%= t('is_hidden') %></button>
<% else %>
<button class='btn-primary display_btn'><%= t('feed.display') %></button>
<% end %>
</td>
</tr>
<% if total_count >= @skip_count && data_count < @max_content_count %>
<% data_count += 1 %>
<tr data-annc-feed-id='<%= feed_annc.id.to_s %>' data-annc-uid='<%= annc['id'].to_s %>'>
<td>
<span class="channel-source-name label"><%= (feed_annc.channel_title.include?("translation missing") || feed_annc.channel_title.blank?) ? t("feed.source") : feed_annc.channel_title %></span>
<br>
<%= feed_name %>
</td>
<td>
<ul>
<li>
<a class='annc_title'><%= annc_title.html_safe %></a>
</li>
<li style="display: flex;width: 100%;flex-wrap: wrap;">
<%= check_box_tag nil,nil,feed_annc[:top_list].include?(annc['id']),'class' => 'is_top' %>
<%= check_box_tag nil,nil,feed_annc[:hot_list].include?(annc['id']),'class' => 'is_hot' %>
</li>
</ul>
</td>
<td>
<%= annc_tags.join('<br>').html_safe %>
</td>
<td>
<% display_flag = feed_annc[:hidden_annc].count==0 || feed_annc[:hidden_annc].exclude?(annc['id']) ? true : false %>
<% if display_flag %>
<button class='btn-info hidden_btn'><%= t('is_hidden') %></button>
<% else %>
<button class='btn-primary display_btn'><%= t('feed.display') %></button>
<% end %>
</td>
</tr>
<% end %>
<% total_count += 1 %>
<% end %>
<% end %>
<% end %>
@ -61,4 +68,9 @@
process_annc(this)
})
})
</script>
</script>
<%=
content_tag :div, class: "bottomnav clearfix" do
content_tag(:div, paginate(Kaminari.paginate_array([]).page(1).per(1),total_pages: (total_count/@max_content_count.to_f).ceil,current_page: @page_no), class: "pagination pagination-centered")
end
%>

View File

@ -8,6 +8,9 @@
a{
cursor: pointer;
}
#main-wrap {
margin-bottom: 5em;
}
</style>
<link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet">
<script src="/assets/feeds/bootstrap-toggle.min.js"></script>