From 7a113e94bd89ac1160bb139af6c836df873e0ad9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=8D=9A=E4=BA=9E?= Date: Thu, 6 Jan 2022 13:13:43 +0800 Subject: [PATCH] add paginator for announcements page --- app/controllers/admin/feeds_controller.rb | 8 ++- app/views/admin/feeds/_announcements.html.erb | 72 +++++++++++-------- app/views/admin/feeds/announcements.html.erb | 3 + 3 files changed, 51 insertions(+), 32 deletions(-) diff --git a/app/controllers/admin/feeds_controller.rb b/app/controllers/admin/feeds_controller.rb index dd4cb7a..7731c03 100644 --- a/app/controllers/admin/feeds_controller.rb +++ b/app/controllers/admin/feeds_controller.rb @@ -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] diff --git a/app/views/admin/feeds/_announcements.html.erb b/app/views/admin/feeds/_announcements.html.erb index 29a2175..ddf9f09 100644 --- a/app/views/admin/feeds/_announcements.html.erb +++ b/app/views/admin/feeds/_announcements.html.erb @@ -9,6 +9,9 @@ + <% 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) %> - '> - - <%= (feed_annc.channel_title.include?("translation missing") || feed_annc.channel_title.blank?) ? t("feed.source") : feed_annc.channel_title %> -
- <%= feed_name %> - - - - - - <%= annc_tags.join('
').html_safe %> - - - <% display_flag = feed_annc[:hidden_annc].count==0 || feed_annc[:hidden_annc].exclude?(annc['id']) ? true : false %> - <% if display_flag %> - - <% else %> - - <% end %> - - + <% if total_count >= @skip_count && data_count < @max_content_count %> + <% data_count += 1 %> + '> + + <%= (feed_annc.channel_title.include?("translation missing") || feed_annc.channel_title.blank?) ? t("feed.source") : feed_annc.channel_title %> +
+ <%= feed_name %> + + + + + + <%= annc_tags.join('
').html_safe %> + + + <% display_flag = feed_annc[:hidden_annc].count==0 || feed_annc[:hidden_annc].exclude?(annc['id']) ? true : false %> + <% if display_flag %> + + <% else %> + + <% end %> + + + <% end %> + <% total_count += 1 %> <% end %> <% end %> <% end %> @@ -61,4 +68,9 @@ process_annc(this) }) }) - \ No newline at end of file + +<%= + 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 +%> \ No newline at end of file diff --git a/app/views/admin/feeds/announcements.html.erb b/app/views/admin/feeds/announcements.html.erb index f91fc7c..28185d1 100644 --- a/app/views/admin/feeds/announcements.html.erb +++ b/app/views/admin/feeds/announcements.html.erb @@ -8,6 +8,9 @@ a{ cursor: pointer; } + #main-wrap { + margin-bottom: 5em; + }