diff --git a/app/controllers/admins/message_templates_controller.rb b/app/controllers/admins/message_templates_controller.rb new file mode 100644 index 000000000..7724dde59 --- /dev/null +++ b/app/controllers/admins/message_templates_controller.rb @@ -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 \ No newline at end of file diff --git a/app/models/message_template/project_setting_changed.rb b/app/models/message_template/project_setting_changed.rb index 9510fa581..8d4947db6 100644 --- a/app/models/message_template/project_setting_changed.rb +++ b/app/models/message_template/project_setting_changed.rb @@ -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') diff --git a/app/views/admins/message_templates/_form.html.erb b/app/views/admins/message_templates/_form.html.erb new file mode 100644 index 000000000..d8b7158c9 --- /dev/null +++ b/app/views/admins/message_templates/_form.html.erb @@ -0,0 +1,53 @@ +
+
<%= type == "create" ? "新建" : "编辑" %>消息模版
+ <%= link_to "返回", admins_message_templates_path, class: "btn btn-default pull-right" %> +
+ +
+ <%= form_for @message_template, url: {controller: "message_templates", action: "#{type}"} do |f| %> + +
+ +
+ <%= f.text_area :sys_notice, class:"form-control", rows: "10", cols: "20",placeholer: "站内信模版" %> +
+ + + +
+
+ +
+ <%= f.text_area :email, class:"form-control", rows: "10", cols: "20",placeholer: "邮件模版" %> +
+ + + +
+
+ +
+ <%= f.text_field :notification_url, class: "form-control input-lg", maxlength: "60", placeholder: "跳转地址" %> +
+ +
+
+ <%= f.submit "确认", class: "btn btn-primary submit-btn" %> +
+ <% end %> +
\ No newline at end of file diff --git a/app/views/admins/message_templates/_list.html.erb b/app/views/admins/message_templates/_list.html.erb new file mode 100644 index 000000000..0f495eff6 --- /dev/null +++ b/app/views/admins/message_templates/_list.html.erb @@ -0,0 +1,39 @@ + + + + + + + + + + + + + <% if message_templates.present? %> + <% message_templates.each_with_index do |message_template_type, index| %> + <% message_template = message_template_type.constantize.last%> + + + + + + + + + <% end %> + <% else %> + <%= render 'admins/shared/no_data_for_table' %> + <% end %> + +
序号类型系统消息模版邮件模版通知地址操作
<%= list_index_no((params[:page] || 1).to_i, index) %><%= message_template.type.split("::")[1] %> + <%= message_template.sys_notice.to_s.truncate(200) %> + + <%= message_template.email.to_s.truncate(200) %> + + <%= message_template.notification_url.to_s.truncate(200) %> + + <%= link_to "编辑", edit_admins_message_template_path(message_template),remote: true, class: "action" %> +
+ +<%= render partial: 'admins/shared/paginate', locals: { objects: message_templates } %> \ No newline at end of file diff --git a/app/views/admins/message_templates/edit.js.erb b/app/views/admins/message_templates/edit.js.erb new file mode 100644 index 000000000..789dd286d --- /dev/null +++ b/app/views/admins/message_templates/edit.js.erb @@ -0,0 +1 @@ +$("#admins-message-templates-content").html("<%= j render partial: 'admins/message_templates/form', locals:{type: 'update'} %>") \ No newline at end of file diff --git a/app/views/admins/message_templates/index.html.erb b/app/views/admins/message_templates/index.html.erb new file mode 100644 index 000000000..ab2af2f9d --- /dev/null +++ b/app/views/admins/message_templates/index.html.erb @@ -0,0 +1,9 @@ +<% define_admin_breadcrumbs do %> + <% add_admin_breadcrumb('消息模版') %> +<% end %> +
+
+ <%= render partial: 'admins/message_templates/list', locals: { message_templates: @message_templates } %> +
+
+ diff --git a/app/views/admins/message_templates/index.js.erb b/app/views/admins/message_templates/index.js.erb new file mode 100644 index 000000000..d8e0fdd26 --- /dev/null +++ b/app/views/admins/message_templates/index.js.erb @@ -0,0 +1 @@ +$('.message-templates-list-container').html("<%= j( render partial: 'admins/message_templates/list', locals: { message_templates: @message_templates } ) %>"); \ No newline at end of file diff --git a/app/views/admins/shared/_sidebar.html.erb b/app/views/admins/shared/_sidebar.html.erb index e58337c18..402449b3b 100644 --- a/app/views/admins/shared/_sidebar.html.erb +++ b/app/views/admins/shared/_sidebar.html.erb @@ -30,6 +30,7 @@
  • <%= sidebar_item(admins_reversed_keywords_path, '系统保留关键词', icon: 'key', controller: 'admins-reversed_keywords') %>
  • +
  • <%= sidebar_item(admins_message_templates_path, '消息模版', icon: 'folder', controller: 'admins-message_templates') %>
  • <%= sidebar_item(admins_laboratories_path, '云上实验室', icon: 'cloud', controller: 'admins-laboratories') %>
  • diff --git a/config/routes.rb b/config/routes.rb index 06b634fc0..e0ea42073 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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