From 877948b0cd515eb414891801e63f8cd934e77368 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 1 Jun 2022 10:00:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E:=20=E9=80=9A=E7=94=A8?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=A8=A1=E6=9D=BF=E5=90=8E=E5=8F=B0=E5=88=9B?= =?UTF-8?q?=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admins/message_templates_controller.rb | 20 +++++++++++++++++-- app/models/message_template.rb | 3 +-- .../admins/message_templates/_list.html.erb | 4 ++-- .../admins/message_templates/index.html.erb | 8 +++++++- app/views/admins/message_templates/new.js.erb | 2 ++ config/routes.rb | 2 +- 6 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 app/views/admins/message_templates/new.js.erb diff --git a/app/controllers/admins/message_templates_controller.rb b/app/controllers/admins/message_templates_controller.rb index 23c94e784..af77858e1 100644 --- a/app/controllers/admins/message_templates_controller.rb +++ b/app/controllers/admins/message_templates_controller.rb @@ -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 diff --git a/app/models/message_template.rb b/app/models/message_template.rb index f34200132..50de7d8ef 100644 --- a/app/models/message_template.rb +++ b/app/models/message_template.rb @@ -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: '{nickname} 关注了你', notification_url: '{baseurl}/{login}') email_html = File.read("#{email_template_html_dir}/issue_assigned.html") self.create(type: 'MessageTemplate::IssueAssigned', sys_notice: '{nickname1}在 {nickname2}/{repository} 指派给你一个疑修:{title}', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}', email: email_html, email_title: "#{PLATFORM}: {nickname1} 在 {nickname2}/{repository} 指派给你一个疑修") diff --git a/app/views/admins/message_templates/_list.html.erb b/app/views/admins/message_templates/_list.html.erb index 4082735f5..dae87d576 100644 --- a/app/views/admins/message_templates/_list.html.erb +++ b/app/views/admins/message_templates/_list.html.erb @@ -11,8 +11,8 @@ <% 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%> <%= list_index_no((params[:page] || 1).to_i, index) %> <%= message_template.simple_type %> diff --git a/app/views/admins/message_templates/index.html.erb b/app/views/admins/message_templates/index.html.erb index 54d273332..e14de841b 100644 --- a/app/views/admins/message_templates/index.html.erb +++ b/app/views/admins/message_templates/index.html.erb @@ -3,7 +3,13 @@ <% end %>
- <%= 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': '搜索中...') %> + + <% 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":"...新增" %>
<%= render partial: 'admins/message_templates/list', locals: { message_templates: @message_templates } %> diff --git a/app/views/admins/message_templates/new.js.erb b/app/views/admins/message_templates/new.js.erb new file mode 100644 index 000000000..e75d923d1 --- /dev/null +++ b/app/views/admins/message_templates/new.js.erb @@ -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: '请输入邮件模版' }); diff --git a/config/routes.rb b/config/routes.rb index 4d1e3adeb..b585f0775 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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