diff --git a/app/assets/stylesheets/admins/forum_moderators.scss b/app/assets/stylesheets/admins/forum_moderators.scss new file mode 100644 index 00000000..47f1f2ce --- /dev/null +++ b/app/assets/stylesheets/admins/forum_moderators.scss @@ -0,0 +1,11 @@ +.admins-forum-moderators-index-page { + .df{ + display: flex; + } + .flex1 { + flex: 1; +} +.text-center { + text-align: center; +} +} \ No newline at end of file diff --git a/app/assets/stylesheets/admins/forum_sections.scss b/app/assets/stylesheets/admins/forum_sections.scss index 61ec5cce..c5d66216 100644 --- a/app/assets/stylesheets/admins/forum_sections.scss +++ b/app/assets/stylesheets/admins/forum_sections.scss @@ -21,4 +21,108 @@ .pointer { cursor: pointer; } + .avatar100{ + height: 100px; + width: 100px; + border-radius: 8px; +} +.upload-image-100:hover .admin-show-again-upload{display: block;} +.admin-show-again-upload { + bottom: 0; + width: 100px; + height: 100%; + line-height: 100px; + /* top: 0; */ + background: rgba(0,0,0,0.6); + color: #fff; + position: absolute; + border-radius: 8px; +} +.menu_operate { + position: relative; + cursor: pointer; + .operateList { + position: absolute; + right: -110px; + top: 9px; + background: #fff; + width: 100px; + color: #999; + box-shadow: 0px 0px 9px rgba(0,0,0,0.2); + z-index: 100; + display: none; + a { + display: block; + height: 30px; + line-height: 30px; + padding: 0px 10px; + } + +} +.operateList.active { + display: block !important; +} +} +.color-grey-6 { + color: #666!important; +} +.set_l_submenu { + padding-left: 50px; + display: none; + width: 180px; + list-style-type: none; + li{ + padding: 4px 0; + } +} +.set_l_submenu.active { + display: block; +} +.set_l_premenu { + position: relative; + display: flex; + height: 30px; + line-height: 30px; + cursor: pointer; +} +.df{ + display: flex; +} +.flex1 { + flex: 1; +} +.text-center { +text-align: center; +} +.grid-item-left { + display: grid; + grid-template-columns:1fr max-content; + align-self: start; +} +.ml20{margin-left: 20px;} + +.forum-moderators-items { + padding: 10px 30px; + max-height: 175px; + overflow-y: auto; + background: #F4FAFF; + margin-top: 20px; +} +.mr4 {margin-right: 4px;} +.blue-user-btn { + margin: 0 5px; + padding: 2px 8px; + background: #F4F8FA!important; + color: #fff!important; + border: 1px solid #4CACFF; + border-radius: 4px; + white-space: nowrap; +} +.mr5 { + margin-right: 5px; +} +.moderator-list-content{ + display: inline-block; + margin: 5px 0; +} } \ No newline at end of file diff --git a/app/controllers/admins/base_controller.rb b/app/controllers/admins/base_controller.rb index fbfc3fc4..56ce082b 100644 --- a/app/controllers/admins/base_controller.rb +++ b/app/controllers/admins/base_controller.rb @@ -43,4 +43,30 @@ class Admins::BaseController < ApplicationController def setup_laboratory Laboratory.current = Laboratory.find_by_subdomain(request.subdomain) || Laboratory.find(1) end + + def up_and_down(opr,current_target,position,model_name) + modal_target = model_name.capitalize.classify.constantize + if model_name == "forum_section" #只有root才能移动 + modal_target = modal_target.roots + end + if opr.to_s == "up" + last_target = modal_target.where("position > ?",position)&.first + if last_target.present? + current_target.update_attribute(:position, last_target.position) + last_target.update_attribute(:position, position) # 重新获取当前问题的位置 + return 0 + else + return -1 + end + elsif opr.to_s == "down" + next_target = modal_target.where("position < ?",position)&.last + if next_target.present? + current_target.update_attribute(:position, next_target.position) + next_target.update_attribute(:position, position) + return 0 + else + return -1 + end + end + end end diff --git a/app/controllers/admins/forum_moderators_controller.rb b/app/controllers/admins/forum_moderators_controller.rb index 0356952b..969ea477 100644 --- a/app/controllers/admins/forum_moderators_controller.rb +++ b/app/controllers/admins/forum_moderators_controller.rb @@ -43,7 +43,7 @@ class Admins::ForumModeratorsController < Admins::BaseController users = User.where("( LOWER(login) LIKE ? or LOWER(concat(lastname, firstname)) LIKE ? or LOWER(mail) LIKE ? )", "%#{user_name}%","%#{user_name}%","%#{user_name}%") users.each do |u| - check_html = "" + check_html = "
" return_html << check_html end end diff --git a/app/controllers/admins/forum_sections_controller.rb b/app/controllers/admins/forum_sections_controller.rb index 2531cb0d..e2dc0193 100644 --- a/app/controllers/admins/forum_sections_controller.rb +++ b/app/controllers/admins/forum_sections_controller.rb @@ -33,26 +33,26 @@ class Admins::ForumSectionsController < Admins::BaseController attachment_id = params[:attachments]&.first positions = ForumSection.pluck(:position).select { |a| a.is_a? Integer } positions = positions.max.to_i - if params[:parent_id].present? - @parent_forum = ForumSection.find_by_id(params[:parent_id]) + if params[:forum_section][:parent_id].present? + @parent_forum = ForumSection.find_by_id(params[:forum_section][:parent_id]) end - if params[:title].blank? + if params[:forum_section][:title].blank? forum_status = 0 - forum_msg = "不能为空" - elsif params[:title].strip.length > 20 + forum_msg = "标题不能为空" + elsif params[:forum_section][:title].strip.length > 20 forum_status = 0 forum_msg = "不能超过最大限制:20个字符" - elsif ForumSection.exists?(title: params[:title].strip) + elsif ForumSection.exists?(title: params[:forum_section][:title].strip) forum_status = 0 forum_msg = "不能重名" else forum_section_params = { user_id: current_user.id, - title: params[:title].strip, + title: params[:forum_section][:title].strip, position: positions + 1, - parent_id: params[:parent_id], + parent_id: params[:forum_section][:parent_id], is_recommend: false, - description: params[:description].to_s.truncate(200) + description: params[:forum_section][:description].to_s.truncate(200) } @forum_section = ForumSection.new(forum_section_params) if @forum_section.save @@ -80,18 +80,18 @@ class Admins::ForumSectionsController < Admins::BaseController def update attachment_id = params[:attachments]&.first - if params[:title].blank? + if params[:forum_section][:title].blank? forum_status = 0 - forum_msg = "不能为空" - elsif params[:title].strip.length > 20 + forum_msg = "名称不能为空" + elsif params[:forum_section][:title].strip.length > 20 forum_status = 0 forum_msg = "不能超过最大限制:20个字符" - elsif params[:title].strip != @forum_section.title && ForumSection.exists?(title: params[:title].strip) + elsif params[:forum_section][:title].strip != @forum_section.title && ForumSection.exists?(title: params[:forum_section][:title].strip) forum_status = 0 forum_msg = "不能重名" else - if @forum_section.update_attributes(title: params[:title].strip, description: params[:description].to_s.truncate(200)) + if @forum_section.update_attributes(title: params[:forum_section][:title].strip, description: params[:forum_section][:description].to_s.truncate(200)) unless attachment_id.blank? || @forum_section.attachment_id.to_i == attachment_id.to_i Attachment.where(id: @forum_section.attachment_id.to_i).destroy_all if @forum_section.attachment_id.present? @@ -101,18 +101,6 @@ class Admins::ForumSectionsController < Admins::BaseController @forum_section.attachment_id = attachment_id @forum_section.save end - # if attachment_id.present? - # unless @forum_section.attachment_id.to_i == attachment_id.to_i - # if @forum_section.attachment_id.to_i != attachment_id.to_i - # Attachment.where(id: @forum_section.attachment_id.to_i).destroy_all - # end - # attachment = Attachment.find(attachment_id) - # attachment.container = @forum_section - # attachment.save - # @forum_section.attachment_id = attachment_id - # @forum_section.save - # end - # end forum_status = 1 forum_msg = "更新成功" else @@ -151,6 +139,7 @@ class Admins::ForumSectionsController < Admins::BaseController else @c_msg = "移动失败" end + redirect_to admins_forum_sections_path end private @@ -159,4 +148,6 @@ class Admins::ForumSectionsController < Admins::BaseController @forum_section = ForumSection.find_by_id(params[:id]) end + + end diff --git a/app/controllers/admins/upload_images_controller.rb b/app/controllers/admins/upload_images_controller.rb deleted file mode 100644 index 802ea306..00000000 --- a/app/controllers/admins/upload_images_controller.rb +++ /dev/null @@ -1,15 +0,0 @@ -class Admins::UploadImagesController < Admins::BaseController - def create - @attachment = Attachment.new(:file => request.raw_post) - @attachment.author = User.current - @attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16) - if @attachment.save - @status = 1 - else - @status = -1 - end - respond_to do |format| - format.js - end - end -end \ No newline at end of file diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 16842fb5..f052a873 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -92,6 +92,44 @@ class AttachmentsController < ApplicationController end end + #后台上传图片 + def upload_images + upload_file = params["file"] || params["#{params[:file_param_name]}"]# 这里的file_param_name是为了方便其他插件名称 + raise "未上传文件" unless upload_file + + folder = edu_setting('attachment_folder') + raise "存储目录未定义" unless folder.present? + month_folder = current_month_folder + save_path = File.join(folder, month_folder) + + ext = SecureRandom.urlsafe_base64 + + local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext) + + content_type = upload_file.content_type.presence || 'application/octet-stream' + + disk_filename = local_path[save_path.size + 1, local_path.size] + + @attachment = Attachment.where(disk_filename: disk_filename,author_id: current_user.id).first + if @attachment.blank? + @attachment = Attachment.new + @attachment.filename = upload_file.original_filename + @attachment.disk_filename = disk_filename + @attachment.filesize = upload_file.tempfile.size + @attachment.content_type = content_type + @attachment.digest = digest + @attachment.author_id = current_user.id + @attachment.disk_directory = month_folder + @attachment.save! + @status = 1 + else + @status = -1 + end + respond_to do |format| + format.js + end + end + def destroy begin @file_path = absolute_path(local_path(@file)) diff --git a/app/views/admins/forum_moderators/_forum_moderator_item.html.erb b/app/views/admins/forum_moderators/_forum_moderator_item.html.erb index 79764db7..8bffb62f 100644 --- a/app/views/admins/forum_moderators/_forum_moderator_item.html.erb +++ b/app/views/admins/forum_moderators/_forum_moderator_item.html.erb @@ -1,9 +1,12 @@ <% if users.present? && users.size > 0 %> <% users.each do |u| %> <% user = u.user %> + <%= link_to user.try(:show_real_name), user_path(user) %> - <%= link_to "".html_safe,admin_forum_section_forum_moderator_path(forum, u), method: :delete, data:{confirm: "确认删除吗?"}, remote: true, class: "color-grey-9" %> + <%= link_to "".html_safe,admins_forum_section_forum_moderator_path(forum, u), method: :delete, data:{confirm: "确认删除吗?"}, remote: true, class: "color-grey-9" %> + + <% end %> <% end %> \ No newline at end of file diff --git a/app/views/admins/forum_moderators/create.js.erb b/app/views/admins/forum_moderators/create.js.erb index 5a4630df..8d82b337 100644 --- a/app/views/admins/forum_moderators/create.js.erb +++ b/app/views/admins/forum_moderators/create.js.erb @@ -1,6 +1,4 @@ <% if @forum_status > 0 %> $("#forum_sections_moderators_<%= @forum_section.id %>").html("<%= j render partial: "admins/forum_moderators/forum_moderator_item", locals: {users: @forum_moderators, forum: @forum_section} %>") -op_know("添加成功") -<% else %> -op_know("没有选择版主") +$('#admin-managers-modal').modal("hide") <% end %> \ No newline at end of file diff --git a/app/views/admins/forum_moderators/new.js.erb b/app/views/admins/forum_moderators/new.js.erb index 9ca23dcc..ba6b10ab 100644 --- a/app/views/admins/forum_moderators/new.js.erb +++ b/app/views/admins/forum_moderators/new.js.erb @@ -1,11 +1,13 @@ -var htmlvalue = "<%= j render :partial => 'admins/forum_moderators/new_forum_moderators' %>"; -pop_box_new(htmlvalue, 520, 400); + +var htmlvalue = "<%= j render :partial => 'admins/forum_moderators/shared/form'%>"; +$("#admin-forum-managers-content").html(htmlvalue) +$('#admin-managers-modal').modal('show') function search_forum_users(target) { var t_value = $("#"+ target).val() $.ajax({ type: "POST", - url:'/admin/forum_sections/<%= @forum_section.id %>/forum_moderators/search_user?user_name='+t_value, + url:'/admins/forum_sections/<%= @forum_section.id %>/forum_moderators/search_user?user_name='+t_value, dataType:'JSON', success: function (data) { if(data.html.length > 0){ diff --git a/app/views/admins/forum_moderators/shared/_form.html.erb b/app/views/admins/forum_moderators/shared/_form.html.erb new file mode 100644 index 00000000..16825ec6 --- /dev/null +++ b/app/views/admins/forum_moderators/shared/_form.html.erb @@ -0,0 +1,26 @@ +