add filter feature for feed announcement page

This commit is contained in:
chiu 2020-07-22 14:04:27 +08:00
parent 35153a0020
commit 01b2a18415
3 changed files with 82 additions and 52 deletions

View File

@ -1,5 +1,6 @@
class Admin::FeedsController < OrbitAdminController
layout :compute_layout
helper_method :search_all_words
def compute_layout
if action_name== 'annc_content'
false
@ -61,7 +62,17 @@ class Admin::FeedsController < OrbitAdminController
render :text => 'success'
end
def announcements
@filter_fields = {}
@filter_fields['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]
{:title => tp,:id => tp}
end
@all_feed_annc = SiteFeedAnnc.all.order(created_at: 1).to_a rescue []
@source = params[:filters][:source] rescue []
@keywords = params[:keywords] rescue nil
if request.xhr?
render :partial => "announcements"
end
end
def get_category_list
app_key = params[:channel]
@ -150,5 +161,10 @@ class Admin::FeedsController < OrbitAdminController
end
render :json => {"success" => true}.to_json
end
def search_all_words(target, word)
target = target.upcase
words = word.upcase.split(' ')
words.select { |value| target.include? value } == words
end
end

View File

@ -0,0 +1,60 @@
<% available_locales = Site.first.in_use_locales rescue I18n.available_locales %>
<table class="table main-list footable-loaded tablet">
<thead>
<tr class="table-info">
<th scope="row"><%= t('feed.feed_name') %></th>
<th><%= "#{t('title')}(#{available_locales.collect{|v| t(v)}.join('/')})" %></th>
<th><%= "#{t('tags')}(#{available_locales.collect{|v| t(v)}.join('/')})" %></th>
<th></th>
</tr>
</thead>
<tbody>
<% @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.gsub(/http:\/\/|https:\/\//,'').gsub(/\./,'-')) %>
<% Array(feed_annc[:all_contents_for_feed]).each do |annc| %>
<% 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>
<% if (!feed_annc.channel_title.to_s.empty? rescue false) %>
<span class="channel-source-name label"><%= feed_annc.channel_title %></span>
<br>
<% end %>
<%= 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 %>
<% end %>
<% end %>
<% end %>
</tbody>
</table>
<script type="text/javascript">
$(function(){
$(document).trigger('page.ready')
})
</script>

View File

@ -1,4 +1,3 @@
<% available_locales = Site.first.in_use_locales rescue I18n.available_locales %>
<style type="text/css">
.margin_right_1em{
margin-right: 1em;
@ -13,62 +12,17 @@
<link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet">
<script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>
<div>
<h3><% t('feed.all_feeds_announcments') %></h3>
<h3><%= t('feed.all_feeds_announcments') %></h3>
</div>
<div class='content_show_div'>
<%= render_filter @filter_fields, "index_table" %>
</div>
<div class="accordion channel-accordion" id="feedAccordion">
<table class="table main-list footable-loaded tablet">
<thead>
<tr class="table-info">
<th scope="row"><%= t('feed.feed_name') %></th>
<th><%= "#{t('title')}(#{available_locales.collect{|v| t(v)}.join('/')})" %></th>
<th><%= "#{t('tags')}(#{available_locales.collect{|v| t(v)}.join('/')})" %></th>
<th></th>
</tr>
</thead>
<tbody>
<% @all_feed_annc.each do |feed_annc| %>
<% Array(feed_annc[:all_contents_for_feed]).each do |annc| %>
<tr data-annc-feed-id='<%= feed_annc.id.to_s %>' data-annc-uid='<%= annc['id'].to_s %>'>
<td>
<% if !feed_annc.channel_title.to_s.empty? %>
<span class="channel-source-name label"><%= feed_annc.channel_title %></span>
<br>
<% end %>
<%= available_locales.collect{|v| feed_annc[:feed_name][v]}.join(' / ') %>
</td>
<td>
<ul>
<li>
<a class='annc_title'><%= available_locales.collect{|v| annc['title_translations'][v]}.join('/').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'].collect{|tmp| available_locales.collect{|v| tmp['name_translations'][v]}.join(' / ')}.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 %>
<% end %>
</tbody>
</table>
<div class="accordion channel-accordion" id="index_table">
<%= render 'announcements' %>
</div>
<script type="text/javascript">
$(function(){
$(document).on('page.ready',function(){
<% if I18n.locale.to_s == 'zh_tw' %>
var off_top_text = '<%= "#{t('disable')}#{t('is_top')}" %>'
var off_hot_text = '<%= "#{t('disable')}#{t('is_hot')}" %>'