Browse Source

add: setting of system notification

tags/v4.0.0
yystopf 4 years ago
parent
commit
490ce7a234
4 changed files with 29 additions and 7 deletions
  1. +6
    -6
      app/controllers/admins/system_notifications_controller.rb
  2. +5
    -1
      app/controllers/settings_controller.rb
  3. +9
    -0
      app/models/system_notification.rb
  4. +9
    -0
      app/views/settings/show.json.jbuilder

+ 6
- 6
app/controllers/admins/system_notifications_controller.rb View File

@@ -6,7 +6,7 @@ class Admins::SystemNotificationsController < Admins::BaseController
sort_by = SystemNotification.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at'
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
q = SystemNotification.ransack(subject_cont: params[:search])
notifications = q.result(distinct: true).order("#{sort_by} #{sort_direction},created_at desc")
notifications = q.result(distinct: true).reorder("#{sort_by} #{sort_direction},created_at desc")
@notifications = paginate(notifications)
end

@@ -25,7 +25,7 @@ class Admins::SystemNotificationsController < Admins::BaseController
@notification = SystemNotification.new(notification_params)
if @notification.save
redirect_to admins_system_notifications_path
flash[:success] = '系统保留关键词创建成功'
flash[:success] = '系统消息创建成功'
else
redirect_to admins_system_notifications_path
flash[:danger] = @notification.errors.full_messages.join(",")
@@ -38,7 +38,7 @@ class Admins::SystemNotificationsController < Admins::BaseController
if @notification.update_attributes(notification_params)
format.html do
redirect_to admins_system_notifications_path
flash[:success] = '系统保留关键词更新成功'
flash[:success] = '系统消息更新成功'
end
format.js {render_ok}
else
@@ -54,10 +54,10 @@ class Admins::SystemNotificationsController < Admins::BaseController
def destroy
if @notification.destroy
redirect_to admins_system_notifications_path
flash[:success] = "系统保留关键词删除成功"
flash[:success] = "系统消息删除成功"
else
redirect_to admins_system_notifications_path
flash[:danger] = "系统保留关键词删除失败"
flash[:danger] = "系统消息删除失败"
end
end

@@ -70,7 +70,7 @@ class Admins::SystemNotificationsController < Admins::BaseController
@notification = SystemNotification.find_by(id: params[:id])
unless @notification.present?
redirect_to admins_system_notifications_path
flash[:danger] = "系统保留关键词不存在"
flash[:danger] = "系统消息不存在"
end
end
end

+ 5
- 1
app/controllers/settings_controller.rb View File

@@ -4,7 +4,7 @@ class SettingsController < ApplicationController
get_add_menu
get_common_menu
get_personal_menu
get_top_system_notification
end

private
@@ -40,6 +40,10 @@ class SettingsController < ApplicationController
end
end

def get_top_system_notification
@top_system_notification = SystemNotification.is_top.first
end

def get_site_url(key, value)
key.to_s === "url" ? append_http(reset_site_url(value)) : reset_site_url(value)
end


+ 9
- 0
app/models/system_notification.rb View File

@@ -12,6 +12,15 @@

class SystemNotification < ApplicationRecord

default_scope { order(created_at: :desc)}

has_many :system_notification_histories
has_many :users, through: :system_notification_histories

scope :is_top, lambda { where(is_top: true) }


def read_member?(user_id)
self.system_notification_histories.where(user_id: user_id).present? ? true : false
end
end

+ 9
- 0
app/views/settings/show.json.jbuilder View File

@@ -56,4 +56,13 @@ json.setting do
end

json.common @common

if @top_system_notification.present?
json.system_notification do
json.(@top_system_notification, :subject, :sub_subject, :content)
json.is_read @top_system_notification.read_member?(current_user.id)
end
else
json.system_notification nil
end
end

Loading…
Cancel
Save