diff --git a/app/assets/stylesheets/admins/diff.scss b/app/assets/stylesheets/admins/diff.scss new file mode 100644 index 000000000..13957570c --- /dev/null +++ b/app/assets/stylesheets/admins/diff.scss @@ -0,0 +1,14 @@ +.diff{overflow:auto;} +.diff ul{background:#fff;overflow:auto;font-size:13px;list-style:none;margin:0;padding:0;display:table;width:100%;} +.diff del, .diff ins{display:block;text-decoration:none;} +.diff li{padding:0; display:table-row;margin: 0;height:1em;} +.diff li.ins{background:#dfd; color:#080} +.diff li.del{background:#fee; color:#b00} +.diff li:hover{background:#ffc} + +/* try 'whitespace:pre;' if you don't want lines to wrap */ +.diff del, .diff ins, .diff span{white-space:pre-wrap;font-family:courier;} +.diff del strong{font-weight:normal;background:#fcc;} +.diff ins strong{font-weight:normal;background:#9f9;} +.diff li.diff-comment { display: none; } +.diff li.diff-block-info { background: none repeat scroll 0 0 gray; } \ No newline at end of file diff --git a/app/controllers/admins/shixun_modify_records_controller.rb b/app/controllers/admins/shixun_modify_records_controller.rb new file mode 100644 index 000000000..43d9a4a16 --- /dev/null +++ b/app/controllers/admins/shixun_modify_records_controller.rb @@ -0,0 +1,9 @@ +class Admins::ShixunModifyRecordsController < Admins::BaseController + + def index + records = Admins::ShixunModifyRecordQuery.call(params) + + @records = paginate records.includes(:diff_record_content) + end + +end diff --git a/app/queries/admins/shixun_modify_record_query.rb b/app/queries/admins/shixun_modify_record_query.rb new file mode 100644 index 000000000..227e2f4c2 --- /dev/null +++ b/app/queries/admins/shixun_modify_record_query.rb @@ -0,0 +1,33 @@ +class Admins::ShixunModifyRecordQuery < ApplicationQuery + attr_reader :params + + def initialize(params) + @params = params + end + + def call + if params[:user_name].blank? || params[:date].blank? + records = DiffRecord.none + else + records = DiffRecord.joins(:user).where("concat(users.lastname, users.firstname) like ?", "%#{params[:user_name].strip}%") + if time_range.present? + records = records.where(created_at: time_range) + end + end + records.order("diff_records.created_at desc") + end + + private + + def time_range + @_time_range ||= begin + case params[:date] + when 'weekly' then 1.weeks.ago..Time.now + when 'monthly' then 1.months.ago..Time.now + when 'quarterly' then 3.months.ago..Time.now + when 'yearly' then 1.years.ago..Time.now + else '' + end + end + end +end diff --git a/app/views/admins/shared/_sidebar.html.erb b/app/views/admins/shared/_sidebar.html.erb index df344fd1a..4b84068e7 100644 --- a/app/views/admins/shared/_sidebar.html.erb +++ b/app/views/admins/shared/_sidebar.html.erb @@ -27,8 +27,9 @@
  • <%= sidebar_item(admins_shixun_settings_path, '实训配置', icon: 'cog', controller: 'admins-shixun_settings') %>
  • <%= sidebar_item(admins_mirror_repositories_path, '镜像管理', icon: 'cubes', controller: 'admins-mirror_repositories') %>
  • <%= sidebar_item(admins_myshixuns_path, '学员实训列表', icon: 'server', controller: 'admins-myshixuns') %>
  • -
  • <%= sidebar_item(admins_shixun_recycles_path, '实训回收站', icon: 'recycle', controller: 'admins-myshixuns') %>
  • - <% end %> +
  • <%= sidebar_item(admins_shixun_modify_records_path, '实训修改记录', icon: 'eraser', controller: 'admins-shixun_modify_records') %>
  • +
  • <%= sidebar_item(admins_shixun_recycles_path, '实训回收站', icon: 'recycle', controller: 'admins-shixun_recycles') %>
  • + <% end %>
  • diff --git a/app/views/admins/shixun_modify_records/index.html.erb b/app/views/admins/shixun_modify_records/index.html.erb new file mode 100644 index 000000000..cecba30cb --- /dev/null +++ b/app/views/admins/shixun_modify_records/index.html.erb @@ -0,0 +1,25 @@ +<% define_admin_breadcrumbs do %> + <% add_admin_breadcrumb('实训修改记录') %> +<% end %> + +
    + <%= form_tag(admins_shixun_modify_records_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %> +
    + + <%= text_field_tag :user_name, params[:user_name], class: 'form-control flex-1', placeholder: '真实姓名搜索' %> +
    + +
    + + <% data_arrs = [['最近一周', 'weekly'], ['最近一个月', 'monthly']] %> + <%= select_tag(:date, options_for_select(data_arrs, params[:date]), class: 'form-control') %> +
    + + <%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %> + + <% end %> +
    + +
    + <%= render partial: 'admins/shixun_modify_records/shared/list', locals: { records: @records } %> +
    \ No newline at end of file diff --git a/app/views/admins/shixun_modify_records/index.js.erb b/app/views/admins/shixun_modify_records/index.js.erb new file mode 100644 index 000000000..fc9dc033b --- /dev/null +++ b/app/views/admins/shixun_modify_records/index.js.erb @@ -0,0 +1 @@ +$('.shixun-modify-record-list-container').html("<%= j( render partial: 'admins/shixun_modify_records/shared/list', locals: { records: @records } ) %>"); \ No newline at end of file diff --git a/app/views/admins/shixun_modify_records/shared/_list.html.erb b/app/views/admins/shixun_modify_records/shared/_list.html.erb new file mode 100644 index 000000000..1f5ec53b9 --- /dev/null +++ b/app/views/admins/shixun_modify_records/shared/_list.html.erb @@ -0,0 +1,38 @@ +<% if records.present? %> + <% records.each do |record| %> +
    +
    + <%= record.user.real_name %> + <%= format_time record.created_at %> +
    + + +
    + 实训名称:<%= record.container&.shixun&.name %> + <% if record.container_type == "Challenge" %> + / + 关卡名:<%= record.container&.subject %> + <% end %> +
    + +
    +
      + <% record.diff_record_content&.content&.split("\n").each do |line| %> + <% if line =~ /^[\+]/ %> +
    • <%= line %>
    • + <% elsif line =~ /^[\-]/ %> +
    • <%= line %>
    • + <% else %> +
    • <%= line %>
    • + <% end %> + <% end %> +
    +
    +
    + + <% end %> +<% else %> + <%= render 'admins/shared/no_data_for_table' %> +<% end %> + +<%= render partial: 'admins/shared/paginate', locals: { objects: records } %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 283ee0d24..958ac9e92 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1056,6 +1056,7 @@ Rails.application.routes.draw do resources :shixun_recycles, only: [:index, :destroy] do post :resume, on: :member end + resources :shixun_modify_records, only: [:index] resources :department_applies,only: [:index,:destroy] do collection do post :merge