From 4477223637d069416877206165247aa5696e1410 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 9 Feb 2018 10:55:26 +0800 Subject: [PATCH] =?UTF-8?q?editorMD=E4=B8=8A=E4=BC=A0=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 21 +++++++++++++++++++++ app/views/statistics/_form.html.erb | 2 +- config/routes.rb | 3 ++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 4939d1798..7733aabb0 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -328,6 +328,25 @@ class AttachmentsController < ApplicationController end end + def upload_with_markdown + logger.debug "upload_with_markdown" + @attachment = Attachment.new(:file => params["editormd-image-file"]) + @attachment.author = User.current + # 如果其它类型的条用md,必须传类型,elsif判断 + if params[:container_type] == "Statistic" + @attachment.container_type = "Statistic" + @attachment.container_id = params[:container_id] + end + @attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16) + saved = @attachment.save + saved + render json: { + success: saved ? 1 : 0, # | 1, // 0 表示上传失败,1 表示上传成功 + message: "上传失败:#{ @attachment.errors.full_messages.join(',') }", + url: download_attachment_path(@attachment.id) # 上传成功时才返回 + } + end + def upload_attachment_version @flag = false Attachment.transaction do @@ -750,6 +769,8 @@ class AttachmentsController < ApplicationController elsif !@attachment.container.nil? && ((@attachment.container.has_attribute?(:board) || @attachment.container.has_attribute?(:board_id)) && @attachment.container.board && @attachment.container.board.contest) @contest = @attachment.container.board.contest + elsif @attachment.container_type == 'Statistic' + @statistic = @attachment.container else unless @attachment.container_type == 'Syllabus' || @attachment.container_type == 'Bid' || @attachment.container_type == 'Organization' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication' || @attachment.container_type == 'PhoneAppVersion' || @attachment.container_type == 'StudentWorksScore'|| @attachment.container_type == 'StudentWork' || @attachment.container_type == 'Work'|| @attachment.container_type == 'ContestantWork'|| @attachment.container_type == 'Contest' || @attachment.container_type == 'HomeworkBank' @project = @attachment.project diff --git a/app/views/statistics/_form.html.erb b/app/views/statistics/_form.html.erb index 77e00a4cf..b907c1931 100644 --- a/app/views/statistics/_form.html.erb +++ b/app/views/statistics/_form.html.erb @@ -82,7 +82,7 @@ placeholder: "<%= @st == 0 ? "请输入完成当前任务依赖的知识点或者其它相关信息" : "请输入选择题的题干内容" %>", imageUpload : true, imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp", "JPG", "JPEG", "GIF", "PNG", "BMP", "WEBP"], - imageUploadURL : "<%#= upload_with_markdown_path(:container_id => @shixun.id, :container_type => @shixun.class) %>",//url + imageUploadURL : "<%= upload_with_markdown_path(:container_id => @statistic.id, :container_type => @statistic.class) %>",//url onload: function(){ $("#statistics_description [type=\"latex\"]").bind("click", function(){ taskpass_editormd.cm.replaceSelection("```latex"); diff --git a/config/routes.rb b/config/routes.rb index 6afb84f0c..2451a958d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1237,7 +1237,7 @@ RedmineApp::Application.routes.draw do post 'attachments/upload_attachment_version',:to=>'attachments#upload_attachment_version',:as=>'upload_attachment_version' get 'attachments/download/:id/:filename', :to => 'attachments#download', :id => /\d+/, :filename => /.*/, :as => 'download_named_attachment' get 'attachments/download_history/:id/:filename', :to => 'attachments#download_history', :id => /\d+/, :filename => /.*/, :as => 'download_history_attachment' - get 'attachments/download/:id', :to => 'attachments#download', :id => /\d+/ + get 'attachments/download/:id', :to => 'attachments#download', :id => /\d+/, :as => 'download_attachment' get 'attachments/thumbnail/:id(/:size)', :to => 'attachments#thumbnail', :id => /\d+/, :size => /\d+/, :as => 'thumbnail' get 'attachments/autocomplete' get 'attachments/update_attachment_publish_time/:id',:to=>'attachments#update_attachment_publish_time',:as=>'update_attachment_publish_time' @@ -1501,6 +1501,7 @@ RedmineApp::Application.routes.draw do match 'sys/fetch_changesets', :via => :get match 'uploads', :to => 'attachments#upload', :via => :post + match 'upload_with_markdown', :to => 'attachments#upload_with_markdown', :via => :post # Added by Tao match 'upload_avatar', :to => 'avatar#upload', :via => :post match 'delete_avatar', :to => 'avatar#delete_image',:via => :post