forked from Gitlink/forgeplus
新增: 通用消息模板后台创建
This commit is contained in:
parent
9427db3e5a
commit
877948b0cd
|
@ -2,8 +2,24 @@ 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)
|
||||
message_templates = MessageTemplate.ransack(sys_notice_or_email_or_email_title_cont: params[:search]).result
|
||||
@message_templates = kaminari_paginate(message_templates)
|
||||
end
|
||||
|
||||
def new
|
||||
@message_template = MessageTemplate::CustomTip.new
|
||||
end
|
||||
|
||||
def create
|
||||
@message_template = MessageTemplate::CustomTip.new(ignore_params)
|
||||
|
||||
if @message_template.save!
|
||||
redirect_to admins_message_templates_path
|
||||
flash[:success] = "创建消息模板成功"
|
||||
else
|
||||
render :new
|
||||
flash[:danger] = "创建消息模板失败"
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
|
|
|
@ -16,8 +16,7 @@ class MessageTemplate < ApplicationRecord
|
|||
PLATFORM = 'GitLink'
|
||||
|
||||
def self.build_init_data
|
||||
MessageTemplate::IssueAssignerExpire.destroy_all
|
||||
MessageTemplate::IssueCreatorExpire.destroy_all
|
||||
MessageTemplate.where.not(type: 'MessageTemplate::CustomTip').destroy_all
|
||||
self.create(type: 'MessageTemplate::FollowedTip', sys_notice: '<b>{nickname}</b> 关注了你', notification_url: '{baseurl}/{login}')
|
||||
email_html = File.read("#{email_template_html_dir}/issue_assigned.html")
|
||||
self.create(type: 'MessageTemplate::IssueAssigned', sys_notice: '{nickname1}在 <b>{nickname2}/{repository}</b> 指派给你一个疑修:<b>{title}</b>', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}', email: email_html, email_title: "#{PLATFORM}: {nickname1} 在 {nickname2}/{repository} 指派给你一个疑修")
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
</thead>
|
||||
<tbody>
|
||||
<% if message_templates.present? %>
|
||||
<% message_templates.each_with_index do |message_template_type, index| %>
|
||||
<% message_template = message_template_type.constantize.last%>
|
||||
<% message_templates.each_with_index do |message_template, 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.simple_type %></td>
|
||||
|
|
|
@ -3,7 +3,13 @@
|
|||
<% end %>
|
||||
<div id="admins-message-templates-content">
|
||||
<div class="box search-form-container project-list-form">
|
||||
<%= link_to "初始化数据", init_data_admins_message_templates_path, class: "btn btn-primary pull-right", "data-disabled-with":"...初始化数据" %>
|
||||
<%= form_tag(admins_message_templates_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 "初始化数据", init_data_admins_message_templates_path, class: "btn btn-primary mr-3 pull-right", "data-disabled-with":"...初始化数据" %>
|
||||
<%= link_to "新增", new_admins_message_template_path, remote: true, class: "btn btn-primary pull-right", "data-disabled-with":"...新增" %>
|
||||
</div>
|
||||
<div class="box admin-list-container message-templates-list-container">
|
||||
<%= render partial: 'admins/message_templates/list', locals: { message_templates: @message_templates } %>
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
$("#admins-message-templates-content").html("<%= j render partial: 'admins/message_templates/form', locals:{type: 'create'} %>")
|
||||
createMDEditor('message-template-email-editor', { height: 500, placeholder: '请输入邮件模版' });
|
|
@ -694,7 +694,7 @@ Rails.application.routes.draw do
|
|||
get :history
|
||||
end
|
||||
end
|
||||
resources :message_templates, only: [:index, :edit, :update] do
|
||||
resources :message_templates, only: [:index, :new, :create, :edit, :update] do
|
||||
collection do
|
||||
get :init_data
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue