diff --git a/app/controllers/admin/announcements_controller.rb b/app/controllers/admin/announcements_controller.rb index 14006c0..36de13d 100644 --- a/app/controllers/admin/announcements_controller.rb +++ b/app/controllers/admin/announcements_controller.rb @@ -182,7 +182,7 @@ class Admin::AnnouncementsController < OrbitAdminController else bulletin = Bulletin.new(bulletin_params) end - + bulletin.is_preview = true bulletin.save render :text=>page_for_bulletin(bulletin) diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index a0dc270..c964700 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -19,13 +19,13 @@ class AnnouncementsController < ApplicationController elsif params[:tag] !params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"} - announcements = Bulletin.where(:title.ne => "" ,:is_preview.in=>[false,nil]).is_approved.order_by(sort).filter_by_categories(["all"]).filter_by_tags([params[:tag]]) + announcements = Bulletin.where(:title.ne => "" ,:is_preview.in=>[false,nil]).can_display.is_approved.order_by(sort).filter_by_categories(["all"]).filter_by_tags([params[:tag]]) keyword = "搜尋有關 ' " + Tag.where(:id => params[:tag]).first.name + " '" elsif params[:category] !params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"} category = Category.find_by(:uid => params["category"].split("-").last) rescue nil - announcements = Bulletin.all.where(:title.ne => "").is_approved.order_by(sort).filter_by_categories([category.id.to_s]) if !category.nil? + announcements = Bulletin.all.where(:title.ne => "").can_display.is_approved.order_by(sort).filter_by_categories([category.id.to_s]) if !category.nil? announcements_count = ",共有" + announcements.count.to_s + "筆資料" keywords = params[:category].split("-") @@ -43,7 +43,7 @@ class AnnouncementsController < ApplicationController if OrbitHelper.page_categories.first == "all" announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).can_display.is_approved.order_by(sort).filter_by_tags.page(params[:page_no]).per(OrbitHelper.page_data_count) else - announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).is_approved.filter_by_categories.filter_by_tags.order_by(sort).page(params[:page_no]).per(OrbitHelper.page_data_count) + announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).can_display.is_approved.filter_by_categories.filter_by_tags.order_by(sort).page(params[:page_no]).per(OrbitHelper.page_data_count) end end page = Page.where(:module => "announcement").first rescue nil @@ -161,7 +161,6 @@ class AnnouncementsController < ApplicationController def show params = OrbitHelper.params - # announcement = Bulletin.where(:title.ne => "").find_by(:uid=>params[:uid]) rescue nil announcement = Bulletin.find_by(:uid=>params[:uid]) if !announcement.nil? url_to_edit = OrbitHelper.user_can_edit?(announcement) ? "/admin/announcements/#{announcement.id.to_s}/edit" : "" @@ -227,7 +226,9 @@ class AnnouncementsController < ApplicationController "image" => announcement.image.url, "dept_link" => "/#{I18n.locale.to_s + page.url}/?unit=#{announcement.cache_dept}", "cache_dept" => announcement.cache_dept, - "view_count" =>announcement.view_count + "view_count" =>announcement.view_count, + "view-count-title" => t("news.view_count"), + "dept-title" => t("announcement.dept_title") }, "impressionist" => (announcement.is_preview ? nil : announcement), "url_to_edit"=>url_to_edit diff --git a/app/helpers/admin/announcements_helper.rb b/app/helpers/admin/announcements_helper.rb index 47e32f2..5521577 100644 --- a/app/helpers/admin/announcements_helper.rb +++ b/app/helpers/admin/announcements_helper.rb @@ -28,7 +28,7 @@ module Admin::AnnouncementsHelper ann_page = pages.first.url if ann_page.nil? end - request.protocol+(request.host_with_port+ann_page+'/'+bulletin.to_param).gsub('//','/') rescue "/" + request.protocol+(request.host_with_port+'/'+ann_page+'/'+'/'+bulletin.to_param).gsub('//','/') rescue "/" end def load_access_level diff --git a/app/models/bulletin.rb b/app/models/bulletin.rb index 241e3b0..81745cb 100644 --- a/app/models/bulletin.rb +++ b/app/models/bulletin.rb @@ -22,6 +22,7 @@ class Bulletin field :rejected, :type => Boolean, :default => false field :rejection_reason field :is_preview, :type => Boolean, :default => false + field :expirable_created_at, type: DateTime field :email_id field :email_sent, :type => Boolean, :default => false @@ -42,6 +43,12 @@ class Bulletin before_destroy :destroy_email + before_create :set_expire + def set_expire + self.expirable_created_at = Time.now if self.is_preview + return true + end + # before_save :fetch_dept scope :can_display, ->{where(:is_hidden=>false).any_of({:postdate.lt=>Time.now, :deadline.gt=>Time.now},{:postdate.lt=>Time.now, :deadline=>nil}).order_by([:is_top, :desc])} diff --git a/app/views/admin/announcements/_form.html.erb b/app/views/admin/announcements/_form.html.erb index 0574ba3..21b91a3 100644 --- a/app/views/admin/announcements/_form.html.erb +++ b/app/views/admin/announcements/_form.html.erb @@ -46,14 +46,14 @@
- <%= f.datetime_picker :postdate, :no_label => true %> + <%= f.datetime_picker :postdate, :no_label => true, :new_record => @bulletin.new_record? %>
- <%= f.datetime_picker :deadline, :no_label => true %> + <%= f.datetime_picker :deadline, :no_label => true, :new_record => @bulletin.new_record? %>
@@ -227,6 +227,10 @@ <% content_for :page_specific_javascript do %>