editorMD上传图片

This commit is contained in:
daiao 2018-02-09 10:55:26 +08:00
parent 691b59d856
commit 4477223637
3 changed files with 24 additions and 2 deletions

View File

@ -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

View File

@ -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");

View File

@ -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