From 83b46fcb501d8a63347c1ed61f3bb42082ed5f57 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 9 Nov 2022 11:37:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=8F=8D=E9=A6=88=E6=84=8F=E8=A7=81=E5=90=8E=E5=8F=B0=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admins/feedbacks_controller.rb | 49 +++++++++++++++++++ app/models/feedback.rb | 1 + app/models/feedback_message_history.rb | 24 +++++++++ .../feedbacks/_history_form_modal.html.erb | 39 +++++++++++++++ app/views/admins/feedbacks/_list.html.erb | 33 +++++++++++++ app/views/admins/feedbacks/index.html.erb | 9 ++++ app/views/admins/feedbacks/index.js.erb | 1 + app/views/admins/feedbacks/new_history.js.erb | 3 ++ app/views/admins/shared/_sidebar.html.erb | 1 + config/routes.rb | 4 ++ ...00538_create_feedback_message_histories.rb | 12 +++++ 11 files changed, 176 insertions(+) create mode 100644 app/controllers/admins/feedbacks_controller.rb create mode 100644 app/models/feedback_message_history.rb create mode 100644 app/views/admins/feedbacks/_history_form_modal.html.erb create mode 100644 app/views/admins/feedbacks/_list.html.erb create mode 100644 app/views/admins/feedbacks/index.html.erb create mode 100644 app/views/admins/feedbacks/index.js.erb create mode 100644 app/views/admins/feedbacks/new_history.js.erb create mode 100644 db/migrate/20221108100538_create_feedback_message_histories.rb diff --git a/app/controllers/admins/feedbacks_controller.rb b/app/controllers/admins/feedbacks_controller.rb new file mode 100644 index 000000000..caff0a9f8 --- /dev/null +++ b/app/controllers/admins/feedbacks_controller.rb @@ -0,0 +1,49 @@ +class Admins::FeedbacksController < Admins::BaseController + before_action :get_feedback, only: [:new_history, :create_history, :destroy] + + def index + sort_by = Feedback.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at' + sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc' + feedbacks = Feedback.order("#{sort_by} #{sort_direction}") + @feedbacks = paginate(feedbacks) + end + + def destroy + if @feedback.destroy + redirect_to admins_feedbacks_path + flash[:success] = "反馈意见删除成功" + else + redirect_to admins_feedbacks_path + flash[:danger] = "反馈意见删除失败" + end + end + + def new_history + @feedback_message_history = FeedbackMessageHistory.new + end + + def create_history + @feedback_message_history = @feedback.feedback_message_histories.new(feedback_message_history_params) + @feedback_message_history.user = current_user + if @feedback_message_history.save + redirect_to admins_feedbacks_path + flash[:success] = "发送通知成功" + else + redirect_to admins_feedbacks_path + flash[:danger] = "发送通知失败" + end + end + + private + def feedback_params + params.require(:feedback).permit! + end + + def feedback_message_history_params + params.require(:feedback_message_history).permit(:title, :content) + end + + def get_feedback + @feedback = Feedback.find_by_id(params[:id]) + end +end \ No newline at end of file diff --git a/app/models/feedback.rb b/app/models/feedback.rb index 3cb7e5ea3..2528d4022 100644 --- a/app/models/feedback.rb +++ b/app/models/feedback.rb @@ -16,5 +16,6 @@ class Feedback < ApplicationRecord belongs_to :user + has_many :feedback_message_histories, dependent: :destroy end diff --git a/app/models/feedback_message_history.rb b/app/models/feedback_message_history.rb new file mode 100644 index 000000000..d04a005f1 --- /dev/null +++ b/app/models/feedback_message_history.rb @@ -0,0 +1,24 @@ +# == Schema Information +# +# Table name: feedback_message_histories +# +# id :integer not null, primary key +# feedback_id :integer +# user_id :integer +# title :string(255) +# content :text(65535) +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_feedback_message_histories_on_feedback_id (feedback_id) +# index_feedback_message_histories_on_user_id (user_id) +# + +class FeedbackMessageHistory < ApplicationRecord + + belongs_to :feedback + belongs_to :user + +end diff --git a/app/views/admins/feedbacks/_history_form_modal.html.erb b/app/views/admins/feedbacks/_history_form_modal.html.erb new file mode 100644 index 000000000..df12a73d3 --- /dev/null +++ b/app/views/admins/feedbacks/_history_form_modal.html.erb @@ -0,0 +1,39 @@ + \ No newline at end of file diff --git a/app/views/admins/feedbacks/_list.html.erb b/app/views/admins/feedbacks/_list.html.erb new file mode 100644 index 000000000..9ac47cdc4 --- /dev/null +++ b/app/views/admins/feedbacks/_list.html.erb @@ -0,0 +1,33 @@ + + + + + + + + + + + + + <% if feedbacks.present? %> + <% feedbacks.each_with_index do |feedback, index| %> + + + + + + + + + <% end %> + <% else %> + <%= render 'admins/shared/no_data_for_table' %> + <% end %> + +
序号用户名用户邮箱<%= sort_tag('创建时间', name: 'created_at', path: admins_feedbacks_path) %>反馈意见操作
+ +<%= render partial: 'admins/shared/paginate', locals: { objects: feedbacks } %> \ No newline at end of file diff --git a/app/views/admins/feedbacks/index.html.erb b/app/views/admins/feedbacks/index.html.erb new file mode 100644 index 000000000..06a25e8c3 --- /dev/null +++ b/app/views/admins/feedbacks/index.html.erb @@ -0,0 +1,9 @@ +<% define_admin_breadcrumbs do %> + <% add_admin_breadcrumb('反馈意见') %> +<% end %> + +
+ <%= render partial: 'admins/feedbacks/list', locals: { feedbacks: @feedbacks } %> +
+
+
diff --git a/app/views/admins/feedbacks/index.js.erb b/app/views/admins/feedbacks/index.js.erb new file mode 100644 index 000000000..daaa24cc7 --- /dev/null +++ b/app/views/admins/feedbacks/index.js.erb @@ -0,0 +1 @@ +$('.feedback-list-container').html("<%= j( render partial: 'admins/feedbacks/list', locals: { feedbacks: @feedbacks } ) %>"); \ No newline at end of file diff --git a/app/views/admins/feedbacks/new_history.js.erb b/app/views/admins/feedbacks/new_history.js.erb new file mode 100644 index 000000000..2b96cf488 --- /dev/null +++ b/app/views/admins/feedbacks/new_history.js.erb @@ -0,0 +1,3 @@ +$("#feedback-modals").html("<%= j render(partial: 'admins/feedbacks/history_form_modal', locals: {type: 'new_history'}) %>") +$(".feedback-history-change-modal").modal('show'); +createMDEditor('feedback-history-email-editor', {width: 750, height: 300, placeholder: '请输入邮件正文',watch: false }); diff --git a/app/views/admins/shared/_sidebar.html.erb b/app/views/admins/shared/_sidebar.html.erb index b78f0e86c..d3a752909 100644 --- a/app/views/admins/shared/_sidebar.html.erb +++ b/app/views/admins/shared/_sidebar.html.erb @@ -36,6 +36,7 @@ <%= sidebar_item_group('#setting-submenu', '网站建设', icon: 'cogs') do %>
  • <%= sidebar_item(admins_faqs_path, 'FAQ', icon: 'question-circle', controller: 'admins-faqs') %>
  • <%= sidebar_item(admins_nps_path, 'NPS用户调研', icon: 'question-circle', controller: 'admins-nps') %>
  • +
  • <%= sidebar_item(admins_feedbacks_path, '用户反馈', icon: 'question-circle', controller: 'admins-feedbacks') %>
  • <% end %>
  • diff --git a/config/routes.rb b/config/routes.rb index e78d9654a..cf3bfd1eb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -898,6 +898,10 @@ Rails.application.routes.draw do resources :nps do post :switch_change, on: :collection end + resources :feedbacks, only: [:index, :destroy] do + get :new_history, on: :member + post :create_history, on: :member + end resources :laboratories, only: [:index, :create, :destroy, :update] do member do get :shixuns_for_select diff --git a/db/migrate/20221108100538_create_feedback_message_histories.rb b/db/migrate/20221108100538_create_feedback_message_histories.rb new file mode 100644 index 000000000..cd5f236df --- /dev/null +++ b/db/migrate/20221108100538_create_feedback_message_histories.rb @@ -0,0 +1,12 @@ +class CreateFeedbackMessageHistories < ActiveRecord::Migration[5.2] + def change + create_table :feedback_message_histories do |t| + t.references :feedback + t.references :user + t.string :title + t.text :content + + t.timestamps + end + end +end