Edit feed feature.(Add categories filter)
This commit is contained in:
parent
2bfedbceb4
commit
f34be54da0
|
@ -64,7 +64,7 @@ class Admin::AnnouncementsController < OrbitAdminController
|
|||
end
|
||||
|
||||
def feed
|
||||
@table_feed_fields = ["announcement.feed_name", :tags, "announcement.rssfeed", "announcement.jsonfeed"]
|
||||
@table_feed_fields = ["announcement.feed_name",:tags , :category , "announcement.rssfeed", "announcement.jsonfeed"]
|
||||
@feeds = BulletinFeed.all.asc(:created_at)
|
||||
|
||||
end
|
||||
|
|
|
@ -28,6 +28,10 @@ class AnnouncementFeedsController < ApplicationController
|
|||
if !tags.empty?
|
||||
@announcements = Bulletin.can_display_and_sorted.is_approved.filter_by_tags(tags)
|
||||
end
|
||||
categories = @bf.category_ids
|
||||
if !categories.empty?
|
||||
@announcements = @announcements.filter_by_categories(categories)
|
||||
end
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html {redirect_to "/xhr/announcements/rssfeed/#{@bf.uid}.rss"}
|
||||
|
@ -72,21 +76,28 @@ class AnnouncementFeedsController < ApplicationController
|
|||
dt = params[:date]
|
||||
if !bf.nil?
|
||||
tags = bf.tag_ids
|
||||
if !tags.empty?
|
||||
categories = bf.category_ids
|
||||
if !(categories.empty? && tags.empty?)
|
||||
if !dt.nil?
|
||||
dt = DateTime.parse(dt)
|
||||
dtt = dt + 1.day
|
||||
announcements = Bulletin.where(:postdate.gt => dt, :postdate.lt => dtt).can_display_and_sorted.is_approved.filter_by_tags(tags)
|
||||
announcements = Bulletin.where(:postdate.gt => dt, :postdate.lt => dtt).can_display_and_sorted.is_approved
|
||||
elsif !startdt.nil? && enddt.nil?
|
||||
startdt = DateTime.parse(startdt)
|
||||
enddt = DateTime.now
|
||||
announcements = Bulletin.where(:postdate.gt => startdt, :postdate.lt => enddt).can_display_and_sorted.is_approved.filter_by_tags(tags)
|
||||
announcements = Bulletin.where(:postdate.gt => startdt, :postdate.lt => enddt).can_display_and_sorted.is_approved
|
||||
elsif !startdt.nil? && !enddt.nil?
|
||||
startdt = DateTime.parse(startdt)
|
||||
enddt = DateTime.parse(enddt) + 1.day
|
||||
announcements = Bulletin.where(:postdate.gt => startdt, :postdate.lt => enddt).can_display_and_sorted.is_approved.filter_by_tags(tags)
|
||||
announcements = Bulletin.where(:postdate.gt => startdt, :postdate.lt => enddt).can_display_and_sorted.is_approved
|
||||
else
|
||||
announcements = Bulletin.all.can_display_and_sorted.is_approved.filter_by_tags(tags)
|
||||
announcements = Bulletin.all.can_display_and_sorted.is_approved
|
||||
end
|
||||
if !tags.empty?
|
||||
announcements = announcements.filter_by_tags(tags)
|
||||
end
|
||||
if !categories.empty?
|
||||
announcements = announcements.filter_by_categories(categories)
|
||||
end
|
||||
else
|
||||
announcements = []
|
||||
|
@ -94,7 +105,9 @@ class AnnouncementFeedsController < ApplicationController
|
|||
end
|
||||
all_anns = []
|
||||
tag_names = []
|
||||
category_titles = []
|
||||
tag_ids = []
|
||||
category_ids = []
|
||||
announcements.each do |anns|
|
||||
user = User.find(anns.create_user_id) rescue nil
|
||||
if !user.nil?
|
||||
|
@ -117,6 +130,7 @@ class AnnouncementFeedsController < ApplicationController
|
|||
a["image"]["thumb"] = ("#{request.base_url}" + anns.image.thumb.url rescue "")
|
||||
a["image"]["mobile"] = ("#{request.base_url}" + anns.image.mobile.url rescue "")
|
||||
a["tags"] = []
|
||||
a["category"] = {}
|
||||
a["author"] = author
|
||||
a["params"] = anns.to_param
|
||||
a["subtitle_ann"] = anns.subtitle if anns.display_subtitle?
|
||||
|
@ -130,6 +144,12 @@ class AnnouncementFeedsController < ApplicationController
|
|||
end
|
||||
a["tags"] << {"name_translations" => tag.name_translations}
|
||||
end
|
||||
cat = anns.category
|
||||
if (!category_ids.include?(cat.id.to_s) rescue false)
|
||||
category_ids << cat.id.to_s
|
||||
category_titles << {"title_translations" => cat.title_translations}
|
||||
end
|
||||
a["category"] = {"title_translations" => cat.title_translations}
|
||||
anns.bulletin_links.each do |bl|
|
||||
b = {}
|
||||
b["url"] = bl.url
|
||||
|
|
|
@ -5,6 +5,7 @@ class BulletinFeed
|
|||
|
||||
field :title, as: :slug_title, type: String, localize: true
|
||||
field :tag_ids, type: Array, default: []
|
||||
field :category_ids, type: Array, default: []
|
||||
before_save do
|
||||
BulletinFeedCache.where(uid: self.uid).destroy
|
||||
end
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
<% end %>
|
||||
<hr />
|
||||
<div class="tags">
|
||||
<h4><%=t(:tags)%></h4>
|
||||
<div id="tags-list">
|
||||
<ul class="tags-groups checkbox-card module-tags">
|
||||
<% @module_app.tags.each do |tag| %>
|
||||
|
@ -32,6 +33,28 @@
|
|||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="categories">
|
||||
<h4><%=t(:category)%></h4>
|
||||
<div id="categories-list">
|
||||
<ul class="tags-groups checkbox-card module-categories">
|
||||
<% @module_app.categories.each do |category| %>
|
||||
<li class="filter-item module">
|
||||
<p class="card pull-left <%= @announcement_feed.category_ids.include?(category.id.to_s) ? "active" : "" %>">
|
||||
<input type="checkbox" class="tag-checkbox" <%= @announcement_feed.category_ids.include?(category.id.to_s) ? "checked=checked" : "" %> value="<%= category.id.to_s %>" name="bulletin_feed[category_ids][]">
|
||||
</p>
|
||||
<a href="#" onclick="return false;">
|
||||
<% @site_in_use_locales.each_with_index do |locale,index| %>
|
||||
<span class="tag"><%= category.title_translations[locale] %></span>
|
||||
<% if index < (@site_in_use_locales.count - 1) %>
|
||||
/
|
||||
<% end %>
|
||||
<% end %>
|
||||
</a>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
<% end %>
|
||||
|
||||
|
|
|
@ -42,6 +42,38 @@
|
|||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="categories">
|
||||
<div id="categories-list">
|
||||
<ul class="tags-groups checkbox-card module-categories">
|
||||
<% categories_to_remove = [] %>
|
||||
<% feed.category_ids.each do |c| %>
|
||||
<% category = Category.find(c) rescue nil %>
|
||||
<% if !category.nil? %>
|
||||
<li class="filter-item module">
|
||||
<a href="#" onclick="return false;">
|
||||
<% @site_in_use_locales.each_with_index do |locale,index| %>
|
||||
<span class="tag"><%= category.title_translations[locale] %></span>
|
||||
<% if index < (@site_in_use_locales.count - 1) %>
|
||||
/
|
||||
<% end %>
|
||||
<% end %>
|
||||
</a>
|
||||
</li>
|
||||
<% else %>
|
||||
<% categories_to_remove << c %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if !categories_to_remove.blank?
|
||||
categories_to_remove.each do |c|
|
||||
feed.category_ids.delete(c)
|
||||
end
|
||||
feed.save
|
||||
end %>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<a href="/xhr/announcements/rssfeed/<%= feed.uid %>.rss" target="_blank">RSS Feed</a>
|
||||
</td>
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
<% end %>
|
||||
<hr />
|
||||
<div class="tags">
|
||||
<h4><%=t(:tags)%></h4>
|
||||
<div id="tags-list">
|
||||
<ul class="tags-groups checkbox-card module-tags">
|
||||
<% @module_app.tags.each do |tag| %>
|
||||
|
@ -32,6 +33,28 @@
|
|||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="categories">
|
||||
<h4><%=t(:category)%></h4>
|
||||
<div id="categories-list">
|
||||
<ul class="tags-groups checkbox-card module-categories">
|
||||
<% @module_app.categories.each do |category| %>
|
||||
<li class="filter-item module">
|
||||
<p class="card pull-left">
|
||||
<input type="checkbox" class="tag-checkbox" value="<%= category.id.to_s %>" name="bulletin_feed[category_ids][]">
|
||||
</p>
|
||||
<a href="#" onclick="return false;">
|
||||
<% @site_in_use_locales.each_with_index do |locale,index| %>
|
||||
<span class="tag"><%= category.title_translations[locale] %></span>
|
||||
<% if index < (@site_in_use_locales.count - 1) %>
|
||||
/
|
||||
<% end %>
|
||||
<% end %>
|
||||
</a>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
<% end %>
|
||||
|
||||
|
|
Loading…
Reference in New Issue