diff --git a/app/controllers/admin/announcements_controller.rb b/app/controllers/admin/announcements_controller.rb index 46f5623..a18802d 100644 --- a/app/controllers/admin/announcements_controller.rb +++ b/app/controllers/admin/announcements_controller.rb @@ -3,18 +3,31 @@ require 'rubyXL' class Admin::AnnouncementsController < OrbitAdminController include Admin::AnnouncementsHelper before_action ->(module_app = @app_title) { set_variables module_app } - before_action :set_bulletin, only: [:edit, :destroy] + before_action :set_bulletin, only: [:edit, :destroy, :comment] before_action :load_access_level, :load_settings def initialize super @app_title = "announcement" end - + def comment_hidden + b = BulletinComment.find(params[:id]) rescue nil + if !b.nil? + b.is_hidden = !b.is_hidden + b.save + @table_feed_fields = ["announcement.time", "announcement.comment", "announcement.account","ip","is_hidden"] + @comments = b.bulletin.bulletin_comments.reverse rescue [] + render partial: 'comment' + end + end + def comment + @table_feed_fields = ["announcement.time", "announcement.comment", "announcement.account","ip","is_hidden"] + @comments = @bulletin.bulletin_comments.reverse rescue [] + end def index Bulletin.remove_expired_status @tags = @module_app.tags - @table_fields = [:status, :category, :title, :start_date, :end_date, :last_modified] + @table_fields = [:status, :category, :title, :start_date, :end_date, "announcement.comment", :last_modified] @current_user = current_user if AnnouncementSetting.first.is_display_edit_only && !current_user.is_admin? && !current_user.is_manager?(@module_app) current_user_is_sub_manager = !current_user.is_manager?(@module_app) && (current_user.is_sub_manager?(@module_app) || current_user.is_sub_manager_with_role?(@module_app)) rescue false diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index d7f5850..e1a5f14 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -1,5 +1,17 @@ class AnnouncementsController < ApplicationController include AnnouncementsHelper + helper_method :complementaryColor,:lighten_color + def comment + @bulletin = Bulletin.where(:uid=>params[:uid]).first + comment_val = params['comment'] + if !@bulletin.nil? && @bulletin.open_comment_for_user(OrbitHelper.current_user) && !comment_val.blank? + account_id = OrbitHelper.current_user.member_profile.id.to_s rescue 'visitor' + b = BulletinComment.new(ip: request.remote_ip,comment: comment_val,account_id: account_id) + b.bulletin_id = @bulletin.id + b.save + render :json => {} + end + end def index Bulletin.remove_expired_status sorted,total_pages = get_sorted_annc @@ -198,6 +210,7 @@ class AnnouncementsController < ApplicationController else announcement = Bulletin.can_display_and_sorted.where(:uid => uid).first end + @bulletin = announcement announcement = Bulletin.where(:uid => uid).first if announcement.nil? url_to_edit = OrbitHelper.user_can_edit?(announcement) ? "/admin/announcements/#{announcement.id.to_s}/edit" : "" @@ -241,7 +254,7 @@ class AnnouncementsController < ApplicationController subtitle_ann = announcement.subtitle if announcement.display_subtitle? img_src = (announcement.image.thumb.url || "/assets/announcement-default.jpg") if announcement.display_img? img_description = announcement.image_description if (announcement.image_description.present?) && (announcement.display_img?) - + show_comment_flag = announcement.open_comment_for_user(OrbitHelper.current_user) { "tags" => tags, "bulletin_files" => files, @@ -258,6 +271,8 @@ class AnnouncementsController < ApplicationController "hide_class" => announcement.display_img? ? '' : ' hide', "alt_title" => desc }, + "comments" => announcement.comments, + "show_comment_flag" => show_comment_flag, "impressionist" => (announcement.is_preview ? nil : announcement), "url_to_edit"=>url_to_edit } @@ -327,6 +342,8 @@ class AnnouncementsController < ApplicationController "hide_class" => announcement["display_img"] ? '' : ' hide', "alt_title" => desc }, + "comments" => [], + "show_comment_flag" => false, "impressionist" => nil, "url_to_edit" => url_to_edit } diff --git a/app/controllers/bulletins_controller.rb b/app/controllers/bulletins_controller.rb index da0b705..8db553c 100644 --- a/app/controllers/bulletins_controller.rb +++ b/app/controllers/bulletins_controller.rb @@ -1,7 +1,6 @@ # encoding: utf-8 class BulletinsController < ApplicationController before_filter :set_I18n - def get_bulletins page = Page.where(:module => "announcement").first rescue nil diff --git a/app/helpers/announcements_helper.rb b/app/helpers/announcements_helper.rb index bde1e22..38b0252 100644 --- a/app/helpers/announcements_helper.rb +++ b/app/helpers/announcements_helper.rb @@ -1,4 +1,25 @@ module AnnouncementsHelper + def complementaryColor(my_hex) + if my_hex[0] == '#' + my_hex = my_hex[1..-1] + end + rgb = my_hex.split(//).each_slice(my_hex.length/3).map{|v| v.join} + comp = rgb.map{|a| (255 - a.to_i(16)).to_s(16).rjust(2,'0')} + '#'+comp.join + end + def lighten_color(my_hex,percent) + if my_hex[0] == '#' + my_hex = my_hex[1..-1] + end + rgb = my_hex.split(//).each_slice(my_hex.length/3).map{|v| v.join} + comp = rgb.collect do |a| + tmp = a.to_i(16)*(1+percent/100.0) + tmp = 255 if tmp>255 + tmp = 0 if tmp < 0 + tmp.to_i.to_s(16).rjust(2,'0') + end + '#'+comp.join + end def set_image_version_for_widget subpart = OrbitHelper.get_current_widget @image_version = 'thumb' diff --git a/app/models/bulletin.rb b/app/models/bulletin.rb index 57853ab..d79c294 100644 --- a/app/models/bulletin.rb +++ b/app/models/bulletin.rb @@ -49,12 +49,15 @@ class Bulletin field :other_mailaddress field :image_description, localize: true field :top_end_date, :type => DateTime - + field :open_comment, :type => Boolean, :default => false + field :comment_end_time, :type => DateTime + field :comment_role, :type => Array, :default => [] + mount_uploader :image, ImageUploader has_many :bulletin_links, :autosave => true, :dependent => :destroy has_many :bulletin_files, :autosave => true, :dependent => :destroy - + has_many :bulletin_comments, :autosave => true, :dependent => :destroy accepts_nested_attributes_for :bulletin_files, :allow_destroy => true accepts_nested_attributes_for :bulletin_links, :allow_destroy => true @@ -166,4 +169,11 @@ class Bulletin def display_img? self.display_img rescue false end + def comments + self.bulletin_comments.select{|v| !v.is_hidden} + end + def open_comment_for_user(user) + role_ids = user.member_profile.roles.collect{|v| v.id.to_s} rescue ['visitor'] + !self.comment_end_time.blank? && self.open_comment && self.comment_end_time > Time.now && (self.comment_role.any?{|v| role_ids.include?(v)} || self.comment_role.include?('visitor') || (self.comment_role.include?('all_member') && role_ids[0] != 'visitor')) + end end diff --git a/app/models/bulletin_comment.rb b/app/models/bulletin_comment.rb new file mode 100644 index 0000000..9ca0570 --- /dev/null +++ b/app/models/bulletin_comment.rb @@ -0,0 +1,21 @@ +# encoding: utf-8 +class BulletinComment + include Mongoid::Document + include Mongoid::Timestamps + + field :ip + field :comment + field :account_id + field :is_hidden,type: Boolean,default: false + def time + self.created_at.strftime('%Y/%m/%d %H:%M') + end + def account + tmp = MemberProfile.where(:id => self.account_id).collect{|v| v.name}.join + tmp.blank? ? I18n.t('announcement_visitor') : tmp + end + def roles + MemberProfile.where(:id => self.account_id).collect{|v| v.roles}.flatten + end + belongs_to :bulletin +end \ No newline at end of file diff --git a/app/views/admin/announcements/_comment.html.erb b/app/views/admin/announcements/_comment.html.erb new file mode 100644 index 0000000..008fd92 --- /dev/null +++ b/app/views/admin/announcements/_comment.html.erb @@ -0,0 +1,25 @@ +
<%= comment.time %> | +<%= comment.comment.html_safe %> | ++ <%= comment.account %> + <% comment.roles.each do |role| %> + <%= role.title rescue '' %> + <% end %> + | +<%= comment.ip %> | +<%= button_tag (comment.is_hidden ? t('show') : t('is_hidden')), type: 'button',"data-href" => "/#{I18n.locale}/admin/annc-comment-hidden/#{comment.id}",:onclick => "update_status(this)" ,class: (comment.is_hidden ? 'btn btn-primary' : 'btn btn-info') %> | +