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,6 +86,10 @@ 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 []

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,6 +19,8 @@
<% 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) %>
<% 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>
@ -45,6 +50,8 @@
<% end %>
</td>
</tr>
<% end %>
<% total_count += 1 %>
<% end %>
<% end %>
<% end %>
@ -62,3 +69,8 @@
})
})
</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>