add: system notification management
This commit is contained in:
parent
37e5e6d547
commit
d176508010
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* @Description: Do not edit
|
||||
* @Date: 2021-08-31 11:16:45
|
||||
* @LastEditors: viletyy
|
||||
* @Author: viletyy
|
||||
* @LastEditTime: 2021-08-31 14:19:46
|
||||
* @FilePath: /forgeplus/app/assets/javascripts/admins/system_notifications/index.js
|
||||
*/
|
||||
$(document).on('turbolinks:load', function(){
|
||||
|
||||
var showSuccessNotify = function() {
|
||||
$.notify({
|
||||
message: '操作成功'
|
||||
},{
|
||||
type: 'success'
|
||||
});
|
||||
}
|
||||
|
||||
// close user
|
||||
$('.system-notification-list-container').on('click', '.close-action', function(){
|
||||
var $closeAction = $(this);
|
||||
var $uncloseAction = $closeAction.siblings('.unclose-action');
|
||||
|
||||
var keywordID = $closeAction.data('id');
|
||||
customConfirm({
|
||||
content: '确认取消置顶吗?',
|
||||
ok: function(){
|
||||
$.ajax({
|
||||
url: '/admins/system_notifications/' + keywordID,
|
||||
method: 'PUT',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
system_notification: {
|
||||
is_top: false
|
||||
}
|
||||
},
|
||||
success: function() {
|
||||
showSuccessNotify();
|
||||
$closeAction.hide();
|
||||
$uncloseAction.show();
|
||||
$(".system-notification-item-"+keywordID).children('td').eq(3).text("")
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// unclose user
|
||||
$('.system-notification-list-container').on('click', '.unclose-action', function(){
|
||||
var $uncloseAction = $(this);
|
||||
var $closeAction = $uncloseAction.siblings('.close-action');
|
||||
|
||||
var keywordID = $uncloseAction.data('id');
|
||||
customConfirm({
|
||||
content: '确认置顶吗?',
|
||||
ok: function () {
|
||||
$.ajax({
|
||||
url: '/admins/system_notifications/' + keywordID,
|
||||
method: 'PUT',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
system_notification: {
|
||||
is_top: true
|
||||
}
|
||||
},
|
||||
success: function() {
|
||||
showSuccessNotify();
|
||||
$closeAction.show();
|
||||
$uncloseAction.hide();
|
||||
$(".system-notification-item-"+keywordID).children('td').eq(3).text("√")
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
})
|
|
@ -0,0 +1,76 @@
|
|||
class Admins::SystemNotificationsController < Admins::BaseController
|
||||
before_action :get_notification, only: [:history, :edit,:update, :destroy]
|
||||
# before_action :validate_identifer, only: [:create, :update]
|
||||
|
||||
def index
|
||||
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 = paginate(notifications)
|
||||
end
|
||||
|
||||
def history
|
||||
@users = @notification.users
|
||||
end
|
||||
|
||||
def new
|
||||
@notification = SystemNotification.new
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def create
|
||||
@notification = SystemNotification.new(notification_params)
|
||||
if @notification.save
|
||||
redirect_to admins_system_notifications_path
|
||||
flash[:success] = '系统保留关键词创建成功'
|
||||
else
|
||||
redirect_to admins_system_notifications_path
|
||||
flash[:danger] = @notification.errors.full_messages.join(",")
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
|
||||
respond_to do |format|
|
||||
if @notification.update_attributes(notification_params)
|
||||
format.html do
|
||||
redirect_to admins_system_notifications_path
|
||||
flash[:success] = '系统保留关键词更新成功'
|
||||
end
|
||||
format.js {render_ok}
|
||||
else
|
||||
format.html do
|
||||
redirect_to admins_system_notifications_path
|
||||
flash[:danger] = @notification.errors.full_messages.join(",")
|
||||
end
|
||||
format.js {render_js_error}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @notification.destroy
|
||||
redirect_to admins_system_notifications_path
|
||||
flash[:success] = "系统保留关键词删除成功"
|
||||
else
|
||||
redirect_to admins_system_notifications_path
|
||||
flash[:danger] = "系统保留关键词删除失败"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def notification_params
|
||||
params.require(:system_notification).permit!
|
||||
end
|
||||
|
||||
def get_notification
|
||||
@notification = SystemNotification.find_by(id: params[:id])
|
||||
unless @notification.present?
|
||||
redirect_to admins_system_notifications_path
|
||||
flash[:danger] = "系统保留关键词不存在"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,17 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: system_notifications
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# subject :string(255)
|
||||
# sub_subject :string(255)
|
||||
# content :string(255)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
class SystemNotification < ApplicationRecord
|
||||
|
||||
has_many :system_notification_histories
|
||||
has_many :users, through: :system_notification_histories
|
||||
end
|
|
@ -0,0 +1,21 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: system_notification_histories
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# system_message_id :integer
|
||||
# user_id :integer
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_system_notification_histories_on_system_message_id (system_message_id)
|
||||
# index_system_notification_histories_on_user_id (user_id)
|
||||
#
|
||||
|
||||
class SystemNotificationHistory < ApplicationRecord
|
||||
|
||||
belongs_to :system_notification
|
||||
belongs_to :user
|
||||
end
|
|
@ -170,7 +170,9 @@ class User < Owner
|
|||
has_many :issues, dependent: :destroy, foreign_key: :author_id
|
||||
has_many :pull_requests, dependent: :destroy
|
||||
has_many :public_keys, class_name: "Gitea::PublicKey",primary_key: :gitea_uid, foreign_key: :owner_id, dependent: :destroy
|
||||
|
||||
has_many :system_notification_histories
|
||||
has_many :system_notifications, through: :system_notification_histories
|
||||
|
||||
# Groups and active users
|
||||
scope :active, lambda { where(status: STATUS_ACTIVE) }
|
||||
scope :like, lambda { |keywords|
|
||||
|
|
|
@ -30,8 +30,6 @@
|
|||
</li>
|
||||
|
||||
<li><%= sidebar_item(admins_reversed_keywords_path, '系统保留关键词', icon: 'key', controller: 'admins-reversed_keywords') %></li>
|
||||
<li><%= sidebar_item(admins_message_templates_path, '消息模版', icon: 'folder', controller: 'admins-message_templates') %></li>
|
||||
|
||||
<li><%= sidebar_item(admins_laboratories_path, '云上实验室', icon: 'cloud', controller: 'admins-laboratories') %></li>
|
||||
|
||||
<li>
|
||||
|
@ -48,6 +46,8 @@
|
|||
<%= sidebar_item_group('#setting-system', '系统配置', icon: 'wrench') do %>
|
||||
<li><%= sidebar_item(admins_sites_path, 'setting接口配置', icon: 'deaf', controller: 'admins-sites') %></li>
|
||||
<li><%= sidebar_item(admins_edu_settings_path, '全局变量配置', icon: 'pencil-square', controller: 'admins-edu_settings') %></li>
|
||||
<li><%= sidebar_item(admins_system_notifications_path, '系统通知配置', icon: 'bell', controller: 'admins-system_notifications') %></li>
|
||||
<li><%= sidebar_item(admins_message_templates_path, '消息模版配置', icon: 'folder', controller: 'admins-message_templates') %></li>
|
||||
<% end %>
|
||||
</li>
|
||||
<li>
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
<div class="box search-form-container project-list-form">
|
||||
<div style="line-height: 38px;" class="flex-1"><%= type == "create" ? "新建" : "编辑" %>忽略文件</div>
|
||||
<%= link_to "返回", admins_project_ignores_path, class: "btn btn-default pull-right" %>
|
||||
</div>
|
||||
|
||||
<div class="box">
|
||||
<%= form_for @notification, url: {controller: "system_notifications", action: "#{type}"} do |p| %>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
<span class="color-grey-6 pt10">
|
||||
系统通知标题
|
||||
<span class="ml10 color-orange mr20">*</span>
|
||||
</span>
|
||||
</label>
|
||||
<div class="mt-10">
|
||||
<%= p.text_field :subject, class: "form-control input-lg", placeholder: "请输入系统通知标题" %>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
<span class="color-grey-6 pt10">
|
||||
系统通知副标题
|
||||
<span class="ml10 color-orange mr20">*</span>
|
||||
</span>
|
||||
</label>
|
||||
<div class="mt-10">
|
||||
<%= p.text_field :sub_subject, class: "form-control input-lg", placeholder: "请输入系统通知副标题" %>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
<span class="color-grey-6 pt10">
|
||||
系统通知正文
|
||||
<span class="ml10 color-orange mr20">*</span>
|
||||
</span>
|
||||
</label>
|
||||
<div class="pl-0 my-3 setting-item-body" id="system-notification-content-editor">
|
||||
<%= p.text_area :content, class:"form-control", style: 'display: none;', rows: "10", cols: "20", placeholer: "请输入系统通知正文" %>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="form-check">
|
||||
<%= p.check_box :is_top, class: "form-check-input", value:"true"%>
|
||||
<label class="form-check-label" for="is_top">
|
||||
是否置顶
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<%= p.submit "确认", class: "btn btn-primary submit-btn" %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
|
@ -0,0 +1,40 @@
|
|||
<div class="modal fade system-notification-change-modal" tabindex="-1" role="dialog" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"><%= type == "create" ? "新增" : "编辑" %></h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<%= form_for @notification, url: {controller: "system_notifications", action: "#{type}"} do |p| %>
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label>
|
||||
系统通知标题 <span class="ml10 color-orange mr20">*</span>
|
||||
</label>
|
||||
<%= p.text_field :subject, class: "form-control input-lg",required: true%>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
系统通知副标题 <span class="ml10 color-orange mr20">*</span>
|
||||
</label>
|
||||
<%= p.text_field :sub_subject, class: "form-control input-lg",required: true%>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
系统通知正文
|
||||
</label>
|
||||
<div class="pl-0 my-3 setting-item-body" id="system-notification-content-editor">
|
||||
<%= p.text_area :content, class:"form-control", style: 'display: none;', rows: "10", cols: "20", placeholer: "请输入系统通知正文" %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
|
||||
<%= p.submit "确认", class: "btn btn-primary submit-btn" %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,35 @@
|
|||
<table class="table table-hover text-center subject-list-table">
|
||||
<thead class="thead-light">
|
||||
<tr>
|
||||
<th width="5%">序号</th>
|
||||
<th width="30%">标题</th>
|
||||
<th width="20%">副标题</th>
|
||||
<th width="20%"><%= sort_tag('是否置顶', name: 'is_top', path: admins_system_notifications_path) %></th>
|
||||
<th width="20%"><%= sort_tag('创建时间', name: 'created_at', path: admins_system_notifications_path) %></th>
|
||||
<th width="25%">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% if notifications.present? %>
|
||||
<% notifications.each_with_index do |notification, index| %>
|
||||
<tr class="system-notification-item-<%= notification.id %>">
|
||||
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
|
||||
<td><%= notification.subject %></td>
|
||||
<td><%= notification.sub_subject %></td>
|
||||
<td class="notification_is_top"><%= notification.is_top ? '√' : '' %></td>
|
||||
<td><%= notification.created_at&.strftime('%Y-%m-%d %H:%M') %></td>
|
||||
<td class="action-container">
|
||||
<%= javascript_void_link '置顶', class: 'action unclose-action', data: { id: notification.id }, style: notification.is_top ? 'display: none;' : '' %>
|
||||
<%= javascript_void_link '取消置顶', class: 'action close-action', data: { id: notification.id }, style: notification.is_top ? '' : 'display: none;' %>
|
||||
<%= link_to "编辑", edit_admins_system_notification_path(notification), remote: true, class: "action" %>
|
||||
<%= link_to "删除", admins_system_notification_path(notification), method: :delete, data:{confirm: "确认删除的吗?"}, class: "action" %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= render 'admins/shared/no_data_for_table' %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= render partial: 'admins/shared/paginate', locals: { objects: notifications } %>
|
|
@ -0,0 +1,2 @@
|
|||
$("#admins-system-notification-content").html("<%= j render(partial: 'admins/system_notifications/form', locals: {type: 'create'}) %>")
|
||||
createMDEditor('system-notification-content-editor', { height: 500, placeholder: '请输入邮件模版' });
|
|
@ -0,0 +1,21 @@
|
|||
<% define_admin_breadcrumbs do %>
|
||||
<% add_admin_breadcrumb('系统通知模版') %>
|
||||
<% end %>
|
||||
|
||||
<div id="admins-system-notification-content">
|
||||
<div class="box search-form-container project-list-form">
|
||||
<%= form_tag(admins_system_notifications_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
|
||||
<%= text_field_tag(:search, params[:search], class: 'form-control col-12 col-md-2 mr-3', placeholder: '系统通知标题检索') %>
|
||||
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
|
||||
<input type="reset" class="btn btn-secondary clear-btn" value="清空"/>
|
||||
<% end %>
|
||||
<%= link_to "新增", new_admins_system_notification_path, remote: true, class: "btn btn-primary pull-right", "data-disabled-with":"...新增" %>
|
||||
</div>
|
||||
|
||||
<div class="box py-0 pt-4 pl-4 daily-school-statistic-title">
|
||||
</div>
|
||||
|
||||
<div class="box admin-list-container system-notification-list-container">
|
||||
<%= render partial: 'admins/system_notifications/list', locals: { notifications: @notifications } %>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1 @@
|
|||
$('.system-notification-list-container').html("<%= j( render partial: 'admins/system_notifications/list', locals: { notifications: @notifications } ) %>");
|
|
@ -0,0 +1,2 @@
|
|||
$("#admins-system-notification-content").html("<%= j render(partial: 'admins/system_notifications/form', locals: {type: 'create'}) %>")
|
||||
createMDEditor('system-notification-content-editor', { height: 500, placeholder: '请输入邮件模版' });
|
|
@ -670,6 +670,11 @@ Rails.application.routes.draw do
|
|||
resources :project_licenses
|
||||
resources :project_ignores
|
||||
resources :reversed_keywords
|
||||
resources :system_notifications do
|
||||
member do
|
||||
get :history
|
||||
end
|
||||
end
|
||||
resources :message_templates, only: [:index, :edit, :update] do
|
||||
collection do
|
||||
get :init_data
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
class CreateSystemNotifications < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
# 系统消息
|
||||
create_table :system_notifications do |t|
|
||||
t.string :subject, comment: "标题"
|
||||
t.string :sub_subject, comment: "副标题"
|
||||
t.string :content, comment: "正文"
|
||||
t.boolean :is_top, comment: "是否置顶"
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,10 @@
|
|||
class CreateSystemNotificationHistories < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :system_notification_histories do |t|
|
||||
t.references :system_notification
|
||||
t.references :user
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue