update for expire time and also limit setting for user
This commit is contained in:
parent
5ecd24c977
commit
4ae6d34216
|
@ -11,6 +11,7 @@ class Admin::AnnouncementsController < OrbitAdminController
|
|||
end
|
||||
|
||||
def index
|
||||
Bulletin.remove_expired_status
|
||||
@tags = @module_app.tags
|
||||
@categories = @module_app.categories.enabled
|
||||
@filter_fields = filter_fields(@categories, @tags)
|
||||
|
@ -35,6 +36,26 @@ class Admin::AnnouncementsController < OrbitAdminController
|
|||
|
||||
end
|
||||
|
||||
def settings
|
||||
@setting = AnnouncementSetting.first rescue nil
|
||||
if @setting.nil?
|
||||
@setting = AnnouncementSetting.new
|
||||
end
|
||||
end
|
||||
|
||||
def createsettings
|
||||
setting = AnnouncementSetting.new(settings_params)
|
||||
setting.save
|
||||
redirect_to admin_announcement_settings_path
|
||||
end
|
||||
|
||||
def updatesettings
|
||||
setting = AnnouncementSetting.first
|
||||
setting.update_attributes(settings_params)
|
||||
setting.save
|
||||
redirect_to admin_announcement_settings_path
|
||||
end
|
||||
|
||||
def feedform
|
||||
if params[:type] == "new"
|
||||
@announcement_feed = BulletinFeed.new
|
||||
|
@ -75,18 +96,24 @@ class Admin::AnnouncementsController < OrbitAdminController
|
|||
end
|
||||
|
||||
def create
|
||||
if !bulletin_params['bulletin_links_attributes'].nil?
|
||||
bulletin_params['bulletin_links_attributes'].each do |idx,link|
|
||||
bulletin_params['bulletin_links_attributes'].delete(idx.to_s) if link['url'].blank?
|
||||
bps = bulletin_params
|
||||
if !bps['bulletin_links_attributes'].nil?
|
||||
bps['bulletin_links_attributes'].each do |idx,link|
|
||||
bps['bulletin_links_attributes'].delete(idx.to_s) if link['url'].blank?
|
||||
end
|
||||
end
|
||||
if bps[:is_top] == "1" && !AnnouncementSetting.check_limit_for_user(current_user.id)
|
||||
bps[:is_top] = "0"
|
||||
bps[:top_end_date] = nil
|
||||
end
|
||||
|
||||
bulletin = Bulletin.new(bulletin_params)
|
||||
bulletin = Bulletin.new(bps)
|
||||
bulletin.create_user_id = current_user.id
|
||||
bulletin.update_user_id = current_user.id
|
||||
# if user_can_approve?
|
||||
bulletin.approved = true
|
||||
# end
|
||||
|
||||
bulletin.save
|
||||
build_email(bulletin)
|
||||
redirect_to params['referer_url']
|
||||
|
@ -114,16 +141,22 @@ class Admin::AnnouncementsController < OrbitAdminController
|
|||
def update
|
||||
uid = params[:id].split('-').last
|
||||
bulletin = Bulletin.find_by(:uid=>uid)
|
||||
bulletin_params[:tags] = bulletin_params[:tags].blank? ? [] : bulletin_params[:tags]
|
||||
bulletin_params[:email_member_ids] = bulletin_params[:email_member_ids].blank? ? [] : bulletin_params[:email_member_ids]
|
||||
bps = bulletin_params
|
||||
bps[:tags] = bps[:tags].blank? ? [] : bps[:tags]
|
||||
bps[:email_member_ids] = bps[:email_member_ids].blank? ? [] : bps[:email_member_ids]
|
||||
|
||||
if !bulletin_params['bulletin_links_attributes'].nil?
|
||||
bulletin_params['bulletin_links_attributes'].each do |idx,link|
|
||||
bulletin_params['bulletin_links_attributes'].delete(idx.to_s) if link['url'].blank?
|
||||
if !bps['bulletin_links_attributes'].nil?
|
||||
bps['bulletin_links_attributes'].each do |idx,link|
|
||||
bps['bulletin_links_attributes'].delete(idx.to_s) if link['url'].blank?
|
||||
end
|
||||
end
|
||||
|
||||
bulletin.update_attributes(bulletin_params)
|
||||
if bps[:is_top] == "1" && !AnnouncementSetting.check_limit_for_user(bulletin.create_user_id, bulletin.id)
|
||||
bps[:is_top] = "0"
|
||||
bps[:top_end_date] = nil
|
||||
end
|
||||
|
||||
bulletin.update_attributes(bps)
|
||||
bulletin.save
|
||||
build_email(bulletin)
|
||||
redirect_to params['referer_url']
|
||||
|
@ -261,4 +294,8 @@ class Admin::AnnouncementsController < OrbitAdminController
|
|||
def feed_params
|
||||
params.require(:bulletin_feed).permit!
|
||||
end
|
||||
|
||||
def settings_params
|
||||
params.require(:announcement_setting).permit!
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
class AnnouncementsController < ApplicationController
|
||||
|
||||
def index
|
||||
Bulletin.remove_expired_status
|
||||
params = OrbitHelper.params
|
||||
feeds_anns = []
|
||||
if !params['tags'].blank?
|
||||
|
@ -109,6 +110,7 @@ class AnnouncementsController < ApplicationController
|
|||
end
|
||||
|
||||
def widget
|
||||
Bulletin.remove_expired_status
|
||||
uid = OrbitHelper.params[:uid] rescue ""
|
||||
tags = OrbitHelper.widget_tags
|
||||
announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil],:uid.ne => uid).and(:title.ne => nil).can_display.is_approved.filter_by_widget_categories.filter_by_tags(tags)
|
||||
|
@ -279,4 +281,5 @@ class AnnouncementsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
class AnnouncementSetting
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
|
||||
field :top_limit, type: Integer, :default => 0
|
||||
|
||||
def self.check_limit_for_user(user_id, b_id = nil)
|
||||
limit = self.first.top_limit
|
||||
return true if limit == 0
|
||||
count = Bulletin.where(:is_top => true, :create_user_id => user_id, :id.ne => b_id).count
|
||||
return count < limit
|
||||
end
|
||||
end
|
|
@ -28,6 +28,7 @@ class Bulletin
|
|||
field :email_member_ids
|
||||
field :other_mailaddress
|
||||
field :image_description, localize: true
|
||||
field :top_end_date, :type => DateTime
|
||||
|
||||
mount_uploader :image, ImageUploader
|
||||
|
||||
|
@ -43,6 +44,7 @@ class Bulletin
|
|||
scope :is_approved, ->{where(:approved => true)}
|
||||
|
||||
before_create :set_expire
|
||||
|
||||
def set_expire
|
||||
self.expirable_created_at = Time.now if self.is_preview
|
||||
return true
|
||||
|
@ -79,4 +81,12 @@ class Bulletin
|
|||
mail.destroy if !mail.nil?
|
||||
end
|
||||
|
||||
def self.remove_expired_status
|
||||
self.where(:is_top => true, :top_end_date.ne => nil, :top_end_date.lt => Time.now).each do |b|
|
||||
b.is_top = false
|
||||
b.top_end_date = nil
|
||||
b.save
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
<div class="control-group">
|
||||
<label class="control-label muted"><%= t(:status) %></label>
|
||||
<div class="controls" data-toggle="buttons-checkbox">
|
||||
<label class="checkbox inline btn <%= 'active' if @bulletin.is_top? %>">
|
||||
<label class="checkbox inline btn <%= 'active' if @bulletin.is_top? || (!@bulletin.top_end_date.nil? && @bulletin.top_end_date > Time.now) %>">
|
||||
<%= f.check_box :is_top %> <%= t(:top) %>
|
||||
</label>
|
||||
<label class="checkbox inline btn <%= 'active' if @bulletin.is_hot? %>">
|
||||
|
@ -71,6 +71,17 @@
|
|||
<%= f.check_box :is_hidden %> <%= t(:hide) %>
|
||||
</label>
|
||||
</div>
|
||||
<div class="controls">
|
||||
<% if !@bulletin.is_top? && !AnnouncementSetting.check_limit_for_user((@bulletin.new_record? ? current_user.id : @bulletin.create_user_id)) %>
|
||||
<span>Top limit has been reached. The bulletin wont be marked as top even if you click on it.</span>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group <%= @bulletin.is_top? || (!@bulletin.top_end_date.nil? && @bulletin.top_end_date > Time.now) ? "" : "hide" %>" data-for="is_top">
|
||||
<label for="" class="control-label muted">Top end time</label>
|
||||
<div class="controls">
|
||||
<%= f.datetime_picker :top_end_date, :no_label => true, :new_record => @bulletin.new_record? %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
@ -409,6 +420,17 @@
|
|||
return false;
|
||||
});
|
||||
|
||||
$("#bulletin_is_top").parent().on("click",function(){
|
||||
setTimeout(function(){
|
||||
if($("#bulletin_is_top").parent().hasClass("active")){
|
||||
$("div[data-for=is_top]").removeClass("hide");
|
||||
}else{
|
||||
$("div[data-for=is_top]").addClass("hide");
|
||||
$("div[data-for=is_top]").find("input[type=text]").val("");
|
||||
}
|
||||
},100)
|
||||
})
|
||||
|
||||
});
|
||||
</script>
|
||||
<% end %>
|
|
@ -0,0 +1,14 @@
|
|||
<%= form_for @setting, url: (@setting.new_record? ? admin_announcement_createsettings_path : admin_announcement_updatesettings_path), html: {class: "form-horizontal main-forms"} do |f| %>
|
||||
<div class="input-area">
|
||||
<div class="control-group">
|
||||
<%= f.label :top_limit, :class => "control-label muted" %>
|
||||
<div class="controls">
|
||||
<%= f.number_field :top_limit, :min => "0" %>
|
||||
<span class="help-block">Put 0 for unlimited.</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
<%= f.submit t('submit'), class: 'btn btn-primary' %>
|
||||
</div>
|
||||
<% end %>
|
|
@ -17,6 +17,7 @@ en:
|
|||
feed_list: Feed List
|
||||
approve: Approve
|
||||
all_articles: All Articles
|
||||
settings: Settings
|
||||
announcement: Announcement
|
||||
approval_setting: Approval Setting
|
||||
approve_bulletin_fail: Approval Fail
|
||||
|
|
|
@ -14,6 +14,7 @@ zh_tw:
|
|||
add_new: 新建
|
||||
approve: 通過
|
||||
feed_name: Feed 標題
|
||||
settings: Settings
|
||||
rssfeed: Rss Feed Link
|
||||
feed_list: 訂閱清單
|
||||
all_articles: 文章列表
|
||||
|
|
|
@ -12,6 +12,9 @@ Rails.application.routes.draw do
|
|||
get 'announcement/approve_bulletin', to: 'announcements#approve_bulletin'
|
||||
get 'announcement/feed', to: 'announcements#feed'
|
||||
get 'announcements/feedform', to: 'announcements#feedform'
|
||||
get 'announcement/settings', to: 'announcements#settings'
|
||||
post 'announcement/createsettings', to: 'announcements#createsettings'
|
||||
patch 'announcement/updatesettings', to: 'announcements#updatesettings'
|
||||
resources :announcements
|
||||
end
|
||||
|
||||
|
|
|
@ -49,6 +49,11 @@ module Announcement
|
|||
:priority=>5,
|
||||
:active_for_action=>{'admin/announcements'=>'feed'},
|
||||
:available_for => 'managers'
|
||||
context_link 'announcement.settings',
|
||||
:link_path=>"admin_announcement_settings_path" ,
|
||||
:priority=>6,
|
||||
:active_for_action=>{'admin/announcements'=>'settings'},
|
||||
:available_for => 'managers'
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue