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/models/project.rb b/app/models/project.rb index 0489c8c82..39fd55906 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -37,6 +37,8 @@ # rep_identifier :string(255) # project_category_id :integer # project_language_id :integer +# license_id :integer +# ignore_id :integer # praises_count :integer default("0") # watchers_count :integer default("0") # issues_count :integer default("0") @@ -50,8 +52,6 @@ # open_devops_count :integer default("0") # recommend :boolean default("0") # platform :integer default("0") -# license_id :integer -# ignore_id :integer # default_branch :string(255) default("master") # website :string(255) # lesson_url :string(255) @@ -373,6 +373,7 @@ class Project < ApplicationRecord logger.info "########namespace_path: #{namespace_path} ########identifier: #{identifier} " user = Owner.find_by_login namespace_path + user = Owner.new(login: namespace_path) if user.nil? project = user&.projects&.find_by(identifier: identifier) || Project.find_by(identifier: "#{namespace_path}/#{identifier}") return nil if project.blank? 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 ed81d6c88..1f68de4b8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -729,7 +729,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