add: message template management

This commit is contained in:
yystopf 2021-09-18 18:41:03 +08:00
parent 74a4b499a9
commit d957e0544f
9 changed files with 145 additions and 2 deletions

View File

@ -0,0 +1,34 @@
class Admins::MessageTemplatesController < Admins::BaseController
before_action :get_template, only: [:edit,:update, :destroy]
def index
message_templates = MessageTemplate.group(:type).count.keys
@message_templates = kaminari_array_paginate(message_templates)
end
def edit
end
def update
if @message_template.update_attributes(message_template_params)
redirect_to admins_message_templates_path
flash[:success] = '消息模版更新成功'
else
redirect_to admins_message_templates_path
flash[:danger] = @message_template.errors.full_messages.join(",")
end
end
private
def message_template_params
params.require(:message_template).permit!
end
def get_template
@message_template = MessageTemplate.find_by(id: params[:id])
unless @message_template.present?
redirect_to admins_message_templates_path
flash[:danger] = "消息模版不存在"
end
end
end

View File

@ -110,8 +110,12 @@ class MessageTemplate::ProjectSettingChanged < MessageTemplate
end
# 项目导航更改
if change_params[:navbar].present?
navbar = project.project_units.order(unit_type: :asc).pluck(:unit_type).join('')
navbar.gsub!('code', '')
unit_types = project.project_units.order(unit_type: :asc).pluck(:unit_type)
unit_types.delete('code')
unit_types.unshift('代码库')
unit_types.unshift('主页')
unit_types.append('动态')
navbar = unit_types.join('')
navbar.gsub!('issues', '易修')
navbar.gsub!('pulls', '合并请求')
navbar.gsub!('wiki', 'Wiki')

View File

@ -0,0 +1,53 @@
<div class="box search-form-container project-list-form">
<div style="line-height: 38px;" class="flex-1"><%= type == "create" ? "新建" : "编辑" %>消息模版</div>
<%= link_to "返回", admins_message_templates_path, class: "btn btn-default pull-right" %>
</div>
<div class="box">
<%= form_for @message_template, url: {controller: "message_templates", action: "#{type}"} do |f| %>
<div class="form-group">
<label>
<span class="color-grey-6 pt10">
站内信模版
<span class="ml10 color-orange mr20">*</span>
</span>
</label>
<div class="mt-10">
<%= f.text_area :sys_notice, class:"form-control", rows: "10", cols: "20",placeholer: "站内信模版" %>
</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">
<%= f.text_area :email, class:"form-control", rows: "10", cols: "20",placeholer: "邮件模版" %>
</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">
<%= f.text_field :notification_url, class: "form-control input-lg", maxlength: "60", placeholder: "跳转地址" %>
</div>
</div>
<div class="form-group">
<%= f.submit "确认", class: "btn btn-primary submit-btn" %>
</div>
<% end %>
</div>

View File

@ -0,0 +1,39 @@
<table class="table table-hover text-center subject-list-table">
<thead class="thead-light">
<tr>
<th width="5%">序号</th>
<th width="15%">类型</th>
<th width="35%">系统消息模版</th>
<th width="35%">邮件模版</th>
<th width="25%">通知地址</th>
<th width="20%">操作</th>
</tr>
</thead>
<tbody>
<% if message_templates.present? %>
<% message_templates.each_with_index do |message_template_type, index| %>
<% message_template = message_template_type.constantize.last%>
<tr class="project-language-item-<%= message_template.id %>">
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
<td><%= message_template.type.split("::")[1] %></td>
<td>
<%= message_template.sys_notice.to_s.truncate(200) %>
</td>
<td>
<%= message_template.email.to_s.truncate(200) %>
</td>
<td>
<%= message_template.notification_url.to_s.truncate(200) %>
</td>
<td class="action-container">
<%= link_to "编辑", edit_admins_message_template_path(message_template),remote: true, class: "action" %>
</td>
</tr>
<% end %>
<% else %>
<%= render 'admins/shared/no_data_for_table' %>
<% end %>
</tbody>
</table>
<%= render partial: 'admins/shared/paginate', locals: { objects: message_templates } %>

View File

@ -0,0 +1 @@
$("#admins-message-templates-content").html("<%= j render partial: 'admins/message_templates/form', locals:{type: 'update'} %>")

View File

@ -0,0 +1,9 @@
<% define_admin_breadcrumbs do %>
<% add_admin_breadcrumb('消息模版') %>
<% end %>
<div id="admins-message-templates-content">
<div class="box admin-list-container message-templates-list-container">
<%= render partial: 'admins/message_templates/list', locals: { message_templates: @message_templates } %>
</div>
</div>

View File

@ -0,0 +1 @@
$('.message-templates-list-container').html("<%= j( render partial: 'admins/message_templates/list', locals: { message_templates: @message_templates } ) %>");

View File

@ -30,6 +30,7 @@
</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>

View File

@ -668,6 +668,7 @@ Rails.application.routes.draw do
resources :project_licenses
resources :project_ignores
resources :reversed_keywords
resources :message_templates, only: [:index, :edit, :update]
resources :major_informations, only: [:index]
resources :ec_templates, only: [:index, :destroy] do
collection do