memcached_alan
whimlex 10 years ago
commit 2ef224556e

@ -41,7 +41,7 @@ module Mobile
mount Apis::Comments
#add_swagger_documentation ({api_version: 'v1', base_path: 'http://u06.shellinfo.cn/trustie/api'})
#add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development?
add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development?
end
end

@ -27,7 +27,7 @@ class AttachmentsController < ApplicationController
accept_api_auth :show, :download, :upload
require 'iconv'
include AttachmentsHelper
include ApplicationHelper
def show
respond_to do |format|
@ -65,36 +65,7 @@ class AttachmentsController < ApplicationController
def download
# modify by nwb
# 下载添加权限设置
candown = false
if @attachment.container.class.to_s != "HomeworkAttach" && (@attachment.container.has_attribute?(:project) || @attachment.container.has_attribute?(:project_id)) && @attachment.container.project
project = @attachment.container.project
candown= User.current.member_of?(project) || (project.is_public && @attachment.is_public == 1)
elsif @attachment.container.is_a?(Project)
project = @attachment.container
candown= User.current.member_of?(project) || (project.is_public && @attachment.is_public == 1)
elsif (@attachment.container.has_attribute?(:board) || @attachment.container.has_attribute?(:board_id)) && @attachment.container.board &&
@attachment.container.board.project
project = @attachment.container.board.project
candown = User.current.member_of?(project) || (project.is_public && @attachment.is_public == 1)
elsif (@attachment.container.has_attribute?(:course) ||@attachment.container.has_attribute?(:course_id) ) && @attachment.container.course
course = @attachment.container.course
candown = User.current.member_of_course?(course) || (course.is_public==1 && @attachment.is_public == 1)
elsif @attachment.container.is_a?(Course)
course = @attachment.container
candown= User.current.member_of_course?(course) || (course.is_public==1 && @attachment.is_public == 1)
elsif (@attachment.container.has_attribute?(:board) || @attachment.container.has_attribute?(:board_id)) && @attachment.container.board &&
@attachment.container.board.course
course = @attachment.container.board.course
candown= User.current.member_of_course?(course) || (course.is_public==1 && @attachment.is_public == 1)
elsif @attachment.container.class.to_s=="HomeworkAttach" && @attachment.container.bid.reward_type == 3
candown = true
elsif @attachment.container_type == "Bid" && @attachment.container && @attachment.container.courses.first
course = @attachment.container.courses.first
candown = User.current.member_of_course?(course) || (course.is_public == 1 && @attachment.is_public == 1)
else
candown = @attachment.is_public == 1
end
candown = attachment_candown @attachment
if candown || User.current.admin? || User.current.id == @attachment.author_id
@attachment.increment_download
if stale?(:etag => @attachment.digest)
@ -349,6 +320,46 @@ class AttachmentsController < ApplicationController
end
end
def add_exist_file_to_projects
file = Attachment.find(params[:file_id])
projects = params[:projects][:project]
@message = ""
projects.each do |project|
c = Project.find(project);
if project_contains_attachment?(c,file)
if @message && @message == ""
@message += l(:label_project_prompt) + c.name + l(:label_contain_resource) + file.filename + l(:label_quote_resource_failed)
next
else
@message += "<br/>" + l(:label_project_prompt) + c.name + l(:label_contain_resource) + file.filename + l(:label_quote_resource_failed)
next
end
end
attach_copied_obj = file.copy
attach_copied_obj.tag_list.add(file.tag_list) # tag关联
attach_copied_obj.container = c
attach_copied_obj.created_on = Time.now
attach_copied_obj.author_id = User.current.id
attach_copied_obj.copy_from = file.copy_from.nil? ? file.id : file.copy_from
if attach_copied_obj.attachtype == nil
attach_copied_obj.attachtype = 4
end
@obj = c
@save_flag = attach_copied_obj.save
@save_message = attach_copied_obj.errors.full_messages
update_quotes attach_copied_obj
end
respond_to do |format|
format.js
end
rescue NoMethodError
@save_flag = false
@save_message = [] << l(:label_course_empty_select)
respond_to do |format|
format.js
end
end
def add_exist_file_to_courses
file = Attachment.find(params[:file_id])
courses = params[:courses][:course]

@ -17,6 +17,7 @@
class CommentsController < ApplicationController
default_search_scope :news
include ApplicationHelper
model_object News
before_filter :find_model_object
before_filter :find_project_from_association
@ -26,9 +27,11 @@ class CommentsController < ApplicationController
raise Unauthorized unless @news.commentable?
@comment = Comment.new
@comment.safe_attributes = params[:comment]
@comment.comments = params[:comment]
@comment.author = User.current
if @news.comments << @comment
ids = params[:asset_id].split(',')
update_kindeditor_assets_owner ids,@comment.id,OwnerTypeHelper::COMMENT
flash[:notice] = l(:label_comment_added)
end

@ -23,13 +23,14 @@ class FilesController < ApplicationController
before_filter :auth_login1, :only => [:index]
before_filter :logged_user_by_apptoken,:only => [:index]
before_filter :find_project_by_project_id#, :except => [:getattachtype]
before_filter :authorize, :except => [:getattachtype,:quote_resource_show,:search]
before_filter :authorize, :except => [:getattachtype,:quote_resource_show,:search,:search_project,:quote_resource_show_project]
helper :sort
include SortHelper
include FilesHelper
helper :project_score
include CoursesHelper
include ApplicationHelper
def show_attachments obj
@attachments = []
@ -41,8 +42,8 @@ class FilesController < ApplicationController
@feedback_count = @all_attachments.count
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
@offset ||= @feedback_pages.offset
@curse_attachments_all = @all_attachments[@offset, @limit]
@curse_attachments = paginateHelper @all_attachments,10
#@curse_attachments_all = @all_attachments[@offset, @limit]
@obj_attachments = paginateHelper @all_attachments,10
end
def search
@ -78,6 +79,39 @@ class FilesController < ApplicationController
end
end
def search_project
sort = ""
@sort = ""
@order = ""
@is_remote = true
if params[:sort]
order_by = params[:sort].split(":")
@sort = order_by[0]
if order_by.count > 1
@order = order_by[1]
end
sort = "#{@sort} #{@order}"
end
begin
q = "%#{params[:name].strip}%"
#(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank?
if params[:insite]
@result = find_public_attache q,sort
@result = visable_attachemnts_insite @result,@project
@searched_attach = paginateHelper @result,10
else
@result = find_project_attache q,@project,sort
@result = visable_attachemnts @result
@searched_attach = paginateHelper @result,10
end
#rescue Exception => e
# #render 'stores'
# redirect_to search_course_files_url
end
end
def find_course_attache keywords,course,sort = ""
if sort == ""
sort = "created_on DESC"
@ -87,6 +121,26 @@ class FilesController < ApplicationController
#resultSet = Attachment.find_by_sql("SELECT `attachments`.* FROM `attachments` LEFT OUTER JOIN `homework_attaches` ON `attachments`.container_type = 'HomeworkAttach' AND `attachments`.container_id = `homework_attaches`.id LEFT OUTER JOIN `homework_for_courses` ON `homework_attaches`.bid_id = `homework_for_courses`.bid_id LEFT OUTER JOIN `homework_for_courses` AS H_C ON `attachments`.container_type = 'Bid' AND `attachments`.container_id = H_C.bid_id WHERE (`homework_for_courses`.course_id = 117 OR H_C.course_id = 117 OR (`attachments`.container_type = 'Course' AND `attachments`.container_id = 117)) AND `attachments`.filename LIKE '%#{keywords}%'").reorder("created_on DESC")
end
def find_project_attache keywords,project,sort = ""
if sort == ""
sort = "created_on DESC"
end
ids = ""
len = 0
count = project.versions.count
project.versions.each do |version|
len = len + 1
if len != count
ids += version.id.to_s + ','
else
ids += version.id.to_s
end
end
resultSet = Attachment.where("((attachments.container_type = 'Project' And attachments.container_id = '#{project.id}') OR (container_type = 'Version' AND container_id IN (#{ids}))) AND filename LIKE :like ", like: "%#{keywords}%").
reorder(sort)
#resultSet = Attachment.find_by_sql("SELECT `attachments`.* FROM `attachments` LEFT OUTER JOIN `homework_attaches` ON `attachments`.container_type = 'HomeworkAttach' AND `attachments`.container_id = `homework_attaches`.id LEFT OUTER JOIN `homework_for_courses` ON `homework_attaches`.bid_id = `homework_for_courses`.bid_id LEFT OUTER JOIN `homework_for_courses` AS H_C ON `attachments`.container_type = 'Bid' AND `attachments`.container_id = H_C.bid_id WHERE (`homework_for_courses`.course_id = 117 OR H_C.course_id = 117 OR (`attachments`.container_type = 'Course' AND `attachments`.container_id = 117)) AND `attachments`.filename LIKE '%#{keywords}%'").reorder("created_on DESC")
end
def find_public_attache keywords,sort = ""
# StoresController#search 将每条文件都查出来,再次进行判断过滤。---> resultSet.to_a.map
# 此时内容不多速度还可但文件增长每条判断多则进行3-4次表连接。
@ -132,17 +186,27 @@ class FilesController < ApplicationController
attribute = "downloads"
when "created_on"
attribute = "created_on"
when "quotes"
attribute = "quotes"
else
attribute = "created_on"
end
if order_by.count == 1
sort += "#{Attachment.table_name}.#{attribute} asc " if attribute
elsif order_by.count == 2
sort += "#{Attachment.table_name}.#{attribute} #{order_by[1]} " if attribute && order_by[1]
end
if sort_type != params[:sort].split(",").last
sort += ","
@sort = order_by[0]
@order = order_by[1]
if order_by.count == 1 && attribute
sort += "#{Attachment.table_name}.#{attribute} asc "
if sort_type != params[:sort].split(",").last
sort += ","
end
elsif order_by.count == 2 && order_by[1]
sort += "#{Attachment.table_name}.#{attribute} #{order_by[1]} "
if sort_type != params[:sort].split(",").last
sort += ","
end
end
end
else
sort = "#{Attachment.table_name}.created_on desc"
end
@containers = [ Project.includes(:attachments).find(@project.id)]
@ -184,6 +248,8 @@ class FilesController < ApplicationController
attribute = "created_on"
when "quotes"
attribute = "quotes"
else
attribute = "created_on"
end
@sort = order_by[0]
@order = order_by[1]
@ -199,6 +265,8 @@ class FilesController < ApplicationController
end
end
end
else
sort = "#{Attachment.table_name}.created_on desc"
end
@containers = [ Course.includes(:attachments).reorder(sort).find(@course.id)]
@ -215,6 +283,11 @@ class FilesController < ApplicationController
@can_quote = attachment_candown @file
end
def quote_resource_show_project
@file = Attachment.find(params[:id])
@can_quote = attachment_candown @file
end
def new
@versions = @project.versions.sort
@course_tag = @project.project_type

@ -64,7 +64,7 @@ class ForumsController < ApplicationController
respond_to do |format|
if @memo.save
ids = params[:asset_id].split(',')
update_kindeditor_assets_owner ids ,@memo.id,1
update_kindeditor_assets_owner ids ,@memo.id,OwnerTypeHelper::MEMO
#end
format.html { redirect_to (forum_memo_url(@forum, (@memo.parent_id.nil? ? @memo : @memo.parent_id))), notice: "#{l :label_memo_create_succ}" }
format.json { render json: @memo, status: :created, location: @memo }
@ -171,7 +171,7 @@ class ForumsController < ApplicationController
# Description after save后需要进行资源记录的更新
# owner_type = 2 对应的是 forum
ids = params[:asset_id].split(',')
update_kindeditor_assets_owner ids ,@forum.id,2
update_kindeditor_assets_owner ids ,@forum.id,OwnerTypeHelper::FORUM
#end
respond_to do |format|

@ -86,6 +86,10 @@ class MessagesController < ApplicationController
if request.post?
@message.save_attachments(params[:attachments])
if @message.save
# 更新kindeditor上传的图片资源所有者
ids = params[:asset_id].split(',')
update_kindeditor_assets_owner ids,@message.id,OwnerTypeHelper::MESSAGE
call_hook(:controller_messages_new_after_save, { :params => params, :message => @message})
render_attachment_warning_if_needed(@message)
redirect_to board_message_url(@board, @message)
@ -117,6 +121,8 @@ class MessagesController < ApplicationController
@topic.children << @reply
#@topic.update_attribute(:updated_on, Time.now)
if !@reply.new_record?
ids = params[:asset_id].split(',')
update_kindeditor_assets_owner ids,@reply.id,OwnerTypeHelper::MESSAGE
call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply})
attachments = Attachment.attach_files(@reply, params[:attachments])
render_attachment_warning_if_needed(@reply)

@ -17,6 +17,7 @@
class NewsController < ApplicationController
layout 'base_projects'# by young
include ApplicationHelper
before_filter :authorize1, :only => [:show]
default_search_scope :news
model_object News
@ -136,6 +137,8 @@ class NewsController < ApplicationController
@news.safe_attributes = params[:news]
@news.save_attachments(params[:attachments])
if @news.save
ids = params[:asset_id].split(',')
update_kindeditor_assets_owner ids,@news.id,OwnerTypeHelper::NEWS
render_attachment_warning_if_needed(@news)
flash[:notice] = l(:notice_successful_create)
redirect_to course_news_index_url(@course)

@ -1,7 +1,7 @@
# encoding: utf-8
#####leave message fq
class WordsController < ApplicationController
include ApplicationHelper
before_filter :find_user, :only => [:new, :create, :destroy, :more, :back]
def create
if params[:new_form][:user_message].size>0
@ -209,6 +209,8 @@ class WordsController < ApplicationController
message = params[:new_form][:course_message]
feedback = Course.add_new_jour(user, message, params[:id])
if(feedback.errors.empty?)
ids = params[:asset_id].split(',')
update_kindeditor_assets_owner ids,feedback[:id],OwnerTypeHelper::JOURNALSFORMESSAGE
redirect_to course_feedback_url(params[:id]), notice: l(:label_feedback_success)
else
flash[:error] = feedback.errors.full_messages[0]

@ -53,6 +53,10 @@ module ApplicationHelper
# Author lizanle
# Description after save后需要进行资源记录的更新
# owner_type = 1 对应的是 memo
# owner_type = 2 对应的是forum
# owner_type = 3 对应的是message
# owner_type = 4 对应的是news
# owner_type = 5 对应的是comment
def update_kindeditor_assets_owner ids,owner_id,owner_type
ids.each do |id|
asset = Kindeditor::Asset.find(id.to_i)
@ -1676,6 +1680,42 @@ module ApplicationHelper
courses_doing
end
def attachment_candown attachment
candown = false
if attachment.container
if attachment.container.class.to_s != "HomeworkAttach" && (attachment.container.has_attribute?(:project) || attachment.container.has_attribute?(:project_id)) && attachment.container.project
project = attachment.container.project
candown= User.current.member_of?(project) || (project.is_public && attachment.is_public == 1)
elsif attachment.container.is_a?(Project)
project = attachment.container
candown= User.current.member_of?(project) || (project.is_public && attachment.is_public == 1)
elsif (attachment.container.has_attribute?(:board) || attachment.container.has_attribute?(:board_id)) && attachment.container.board &&
attachment.container.board.project
project = attachment.container.board.project
candown = User.current.member_of?(project) || (project.is_public && attachment.is_public == 1)
elsif (attachment.container.has_attribute?(:course) ||attachment.container.has_attribute?(:course_id) ) && attachment.container.course
course = attachment.container.course
candown = User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1)
elsif attachment.container.is_a?(Course)
course = attachment.container
candown= User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1)
elsif (attachment.container.has_attribute?(:board) || attachment.container.has_attribute?(:board_id)) && attachment.container.board &&
attachment.container.board.course
course = attachment.container.board.course
candown= User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1)
elsif attachment.container.class.to_s=="HomeworkAttach" && attachment.container.bid.reward_type == 3
candown = true
elsif attachment.container_type == "Bid" && attachment.container && attachment.container.courses
course = attachment.container.courses.first
candown = User.current.member_of_course?(attachment.container.courses.first) || (course.is_public == 1 && attachment.is_public == 1)
else
candown = (attachment.is_public == 1 || attachment.is_public == true)
end
end
candown
end
private
def wiki_helper

@ -77,6 +77,7 @@ module AttachmentsHelper
end
end
#判断课程course中是否包含课件attachmentcourse中引用了attachment也算作包含
def course_contains_attachment? course,attachment
course.attachments.each do |att|
if att.id == attachment.id || (!att.copy_from.nil? && !attachment.copy_from.nil? && att.copy_from == attachment.copy_from) || att.copy_from == attachment.id || att.id == attachment.copy_from
@ -85,6 +86,15 @@ module AttachmentsHelper
end
false
end
#判断项目project中是否包含课件attachmentproject中引用了attachment也算作包含
def project_contains_attachment? project,attachment
project.attachments.each do |att|
if att.id == attachment.id || (!att.copy_from.nil? && !attachment.copy_from.nil? && att.copy_from == attachment.copy_from) || att.copy_from == attachment.id || att.id == attachment.copy_from
return true
end
end
false
end
def get_qute_number attachment
if attachment.copy_from

@ -45,6 +45,7 @@ module FilesHelper
File.new(zipfile_name,'w+')
end
#带勾选框的课程列表
def courses_check_box_tags(name,courses,current_course,attachment)
s = ''
courses.each do |course|
@ -55,6 +56,17 @@ module FilesHelper
s.html_safe
end
#带勾选框的项目列表
def projects_check_box_tags(name,projects,current_project,attachment)
s = ''
projects.each do |project|
if !project_contains_attachment?(project,attachment) && User.current.allowed_to?(:manage_files, project)
s << "<label>#{ check_box_tag name, project.id, false, :id => nil } #{h project.name}</label>"
end
end
s.html_safe
end
#判断用户是否拥有不包含当前资源的课程,需用户在该课程中角色为教师且该课程属于当前学期或下一学期
def has_course? user,file
result = false
@ -66,6 +78,17 @@ module FilesHelper
result
end
#判断用户是否拥有不包含当前资源的项目,需用户在该项目中有资源管理相关资源
def has_project? user,file
result = false
user.projects.each do |project|
if !project_contains_attachment?(project,file) && User.current.allowed_to?(:manage_files, project)
return true
end
end
result
end
# 判断指定的资源时候符合类型
def isTypeOk(attachment, type, contentType)
result = false
@ -97,49 +120,23 @@ module FilesHelper
result
end
def visable_attachemnts_insite attachments,course
def visable_attachemnts_insite attachments,obj
result = []
attachments.each do |attachment|
if attachment.is_public? || (attachment.container_type == "Course" && attachment.container_id == course.id && User.current.member_of_course?(Course.find(attachment.container_id)))|| attachment.author_id == User.current.id
result << attachment
if obj.is_a?(Course)
attachments.each do |attachment|
if attachment.is_public? || (attachment.container_type == "Course" && attachment.container_id == obj.id && User.current.member_of_course?(Course.find(attachment.container_id)))|| attachment.author_id == User.current.id
result << attachment
end
end
else if obj.is_a?(Project)
attachments.each do |attachment|
if attachment.is_public? || (attachment.container_type == "Project" && attachment.container_id == obj.id && User.current.member_of_course?(Project.find(attachment.container_id)))|| attachment.author_id == User.current.id
result << attachment
end
end
end
result
end
def attachment_candown attachment
candown = false
if attachment.container
if attachment.container.class.to_s != "HomeworkAttach" && (attachment.container.has_attribute?(:project) || attachment.container.has_attribute?(:project_id)) && attachment.container.project
project = attachment.container.project
candown= User.current.member_of?(project) || (project.is_public && attachment.is_public == 1)
elsif attachment.container.is_a?(Project)
project = attachment.container
candown= User.current.member_of?(project) || (project.is_public && attachment.is_public == 1)
elsif (attachment.container.has_attribute?(:board) || attachment.container.has_attribute?(:board_id)) && attachment.container.board &&
attachment.container.board.project
project = attachment.container.board.project
candown = User.current.member_of?(project) || (project.is_public && attachment.is_public == 1)
elsif (attachment.container.has_attribute?(:course) ||attachment.container.has_attribute?(:course_id) ) && attachment.container.course
course = attachment.container.course
candown = User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1)
elsif attachment.container.is_a?(Course)
course = attachment.container
candown= User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1)
elsif (attachment.container.has_attribute?(:board) || attachment.container.has_attribute?(:board_id)) && attachment.container.board &&
attachment.container.board.course
course = attachment.container.board.course
candown= User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1)
elsif attachment.container.class.to_s=="HomeworkAttach" && attachment.container.bid.reward_type == 3
candown = true
elsif attachment.container_type == "Bid" && attachment.container && attachment.container.courses
course = attachment.container.courses.first
candown = User.current.member_of_course?(attachment.container.courses.first) || (course.is_public == 1 && attachment.is_public == 1)
else
candown = (attachment.is_public == 1 || attachment.is_public == true)
end
end
candown
result
end

@ -17,7 +17,8 @@ class Bid < ActiveRecord::Base
HomeworkProject = 2
attr_accessible :author_id, :budget, :deadline, :name, :description, :homework_type, :password
include Redmine::SafeAttributes
include ApplicationHelper
has_many_kindeditor_assets :assets, :dependent => :destroy
belongs_to :author, :class_name => 'User', :foreign_key => :author_id
belongs_to :course
has_many :biding_projects, :dependent => :destroy
@ -47,7 +48,7 @@ class Bid < ActiveRecord::Base
validate :validate_user
validate :validate_reward_type
after_create :act_as_activity
after_destroy :delete_kindeditor_assets
scope :visible, lambda {|*args|
nil
}
@ -157,5 +158,10 @@ class Bid < ActiveRecord::Base
end
end
# Time 2015-04-01 14:19:06
# Author lizanle
# Description 删除对应课程通知的图片资源
def delete_kindeditor_assets
delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::BID
end
end

@ -17,8 +17,18 @@
class Comment < ActiveRecord::Base
include Redmine::SafeAttributes
include ApplicationHelper
has_many_kindeditor_assets :assets, :dependent => :destroy
belongs_to :commented, :polymorphic => true, :counter_cache => true
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
validates_presence_of :commented, :author, :comments
safe_attributes 'comments'
after_destroy :delete_kindeditor_assets
# Time 2015-03-31 09:15:06
# Author lizanle
# Description 删除对应评论的图片资源
def delete_kindeditor_assets
delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::COMMENT
end
end

@ -53,7 +53,7 @@ class Forum < ActiveRecord::Base
# Author lizanle
# Description 删除论坛后删除对应的资源
def delete_kindeditor_assets
delete_kindeditor_assets_from_disk self.id,2
delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::FORUM
end
end

@ -4,6 +4,8 @@
class JournalsForMessage < ActiveRecord::Base
include Redmine::SafeAttributes
include UserScoreHelper
include ApplicationHelper
has_many_kindeditor_assets :assets, :dependent => :destroy
safe_attributes "jour_type", # 留言所属类型
"jour_id", # 留言所属类型的id
"notes", # 留言内容
@ -16,7 +18,7 @@ class JournalsForMessage < ActiveRecord::Base
"m_reply_id" # 回复某留言的留言id(a留言回复了b留言这是b留言的id)
"is_comprehensive_evaluation" # 1 教师评论、2 匿评、3 留言
acts_as_tree :foreign_key => 'm_parent_id', :counter_cache => :m_reply_count, :order => "#{JournalsForMessage.table_name}.created_on ASC"
after_destroy :delete_kindeditor_assets
belongs_to :project,
:foreign_key => 'jour_id',
:conditions => "#{self.table_name}.jour_type = 'Project' "
@ -163,5 +165,10 @@ class JournalsForMessage < ActiveRecord::Base
end
end
# Time 2015-04-01 14:15:06
# Author lizanle
# Description 删除对应课程留言的图片资源
def delete_kindeditor_assets
delete_kindeditor_assets_from_disk self.id,7
end
end

@ -176,6 +176,6 @@ class Memo < ActiveRecord::Base
# Author lizanle
# Description 从硬盘上删除资源
def delete_kindeditor_assets
delete_kindeditor_assets_from_disk self.id,1
delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::MEMO
end
end

@ -18,6 +18,8 @@
class Message < ActiveRecord::Base
include Redmine::SafeAttributes
include UserScoreHelper
include ApplicationHelper
has_many_kindeditor_assets :assets, :dependent => :destroy
belongs_to :board
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
has_many :praise_tread, as: :praise_tread_object, dependent: :destroy
@ -62,7 +64,7 @@ class Message < ActiveRecord::Base
after_create :add_author_as_watcher, :reset_counters!
after_update :update_messages_board
after_destroy :reset_counters!,:down_user_score
after_destroy :reset_counters!,:down_user_score,:delete_kindeditor_assets
# fq
after_create :act_as_activity,:be_user_score,:act_as_forge_activity
@ -208,5 +210,10 @@ class Message < ActiveRecord::Base
end
end
# Time 2015-03-31 09:15:06
# Author lizanle
# Description 删除对应消息的图片资源
def delete_kindeditor_assets
delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::MESSAGE
end
end

@ -18,6 +18,8 @@
class News < ActiveRecord::Base
include Redmine::SafeAttributes
belongs_to :project
include ApplicationHelper
has_many_kindeditor_assets :assets, :dependent => :destroy
#added by nwb
belongs_to :course
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
@ -49,6 +51,7 @@ class News < ActiveRecord::Base
# fq
after_create :act_as_activity,:act_as_forge_activity
# end
after_destroy :delete_kindeditor_assets
scope :visible, lambda {|*args|
includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_news, *args))
@ -105,4 +108,11 @@ class News < ActiveRecord::Base
end
end
# Time 2015-03-31 13:50:54
# Author lizanle
# Description 删除news后删除对应的资源
def delete_kindeditor_assets
delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::NEWS
end
end

@ -20,7 +20,7 @@ class HomeworkService
many_times = course.homeworks.index(@bid) + 1
name = @bid.name
homework_count = @bid.homeworks.count #已提交的作业数量
student_questions_count = @bid.commit.nil? ? 0 : @bid.commit
student_questions_count = @bid.journals_for_messages.where('m_parent_id IS NULL').count
description = @bid.description
#if is_course_teacher(User.current, course) && @bid.open_anonymous_evaluation == 1 && @bid.homeworks.count >= 2
state = @bid.comment_status
@ -282,7 +282,7 @@ class HomeworkService
many_times = course.homeworks.index(@bid) + 1
name = @bid.name
homework_count = @bid.homeworks.count #已提交的作业数量
student_questions_count = @bid.commit.nil? ? 0 : @bid.commit
student_questions_count = @bid.journals_for_messages.where('m_parent_id IS NULL').count
description = @bid.description
#if is_course_teacher(User.current, course) && @bid.open_anonymous_evaluation == 1 && @bid.homeworks.count >= 2
state = @bid.comment_status

@ -0,0 +1,7 @@
<% if !@save_flag && @save_message %>
$("#error_show").html("<%= @save_message.join(', ') %>");
<% elsif @message && @message != "" %>
$("#error_show").html("<%= @message.html_safe %>");
<% else %>
closeModal();
<% end %>

@ -13,7 +13,13 @@
</li>
<li class="ml45">
<label class="fl" >&nbsp;&nbsp;<%= l(:field_quote)%>&nbsp;&nbsp;</label>
<textarea name="bid[description]" placeholder="最多3000个汉字(或6000个英文字符)" class="hwork_text fl"><%= bid.description%></textarea>
<!--<textarea name="bid[description]" placeholder="最多3000个汉字(或6000个英文字符)" class="hwork_text fl"></textarea>-->
<% if edit_mode %>
<%= f.kindeditor :description,:width=>'91%',:editor_id => 'bid_description_editor',:owner_id => bid.id,:owner_type =>OwnerTypeHelper::BID %>
<% else %>
<%= hidden_field_tag :asset_id,params[:asset_id],:required => false,:style => 'display:none' %>
<%= f.kindeditor :description,:width=>'91%',:editor_id => 'bid_description_editor' %>
<% end %>
</li>
<div class="cl"></div>
<li class="ml21">

@ -1,3 +1,4 @@
<%= javascript_include_tag "/assets/kindeditor/kindeditor" %>
<%= labelled_form_for @bid do |f| %>
<%= render :partial => 'new_homework_form', :locals => { :bid => @bid, :bid_id => "edit_bid_#{@bid.id}"} %>
<%= render :partial => 'new_homework_form', :locals => { :bid => @bid, :bid_id => "edit_bid_#{@bid.id}",:f=>f,:edit_mode => true} %>
<% end %>

@ -1,3 +1,4 @@
<% if @project %>
<%= render :partial => 'project_show', locals: {project: @project} %>
<% elsif @course %>

@ -1,4 +1,4 @@
<%= javascript_include_tag "/assets/kindeditor/kindeditor" %>
<div class="msg_box" id='leave-message'>
<%# reply_allow = JournalsForMessage.create_by_user? User.current %>
<h4><%= l(:label_leave_message) %></h4>
@ -11,11 +11,12 @@
</div>
<% else %>
<%= form_for('new_form', :method => :post,
:url => {:controller => 'words', :action => 'leave_course_message'}) do |f|%>
<%= f.text_area 'course_message',:id => "leave_meassge",:style => "resize: none;",
:placeholder => "#{l(:label_welcome_my_respond)}",:maxlength => 250%>
:url => {:controller => 'words', :action => 'leave_course_message'},:html => {:id=>'leave_message_form'}) do |f|%>
<%= hidden_field_tag :asset_id,params[:asset_id],:required => false,:style => 'display:none' %>
<%= f.kindeditor 'course_message',:editor_id => 'leave_message_editor',:input_html=>{:id => "leave_meassge",:style => "resize: none;",
:placeholder => "#{l(:label_welcome_my_respond)}",:maxlength => 250}%>
<a href="#" class="grey_btn fr ml10">取&nbsp;&nbsp;消</a>
<a href="#" onclick='$("#leave_meassge").parent().submit();' class="blue_btn fr"> <%= l(:button_leave_meassge)%></a>
<a href="#" onclick='leave_message_editor.sync();$("#leave_message_form").submit();' class="blue_btn fr"> <%= l(:button_leave_meassge)%></a>
<% end %>
<% end %>
</div>

@ -32,7 +32,7 @@
</script>
<div id="bid_description_<%= bid.id%>" class="news_description mt5">
<div id="bid_description_<%= bid.id%>_content">
<%= textilizable bid, :description %>
<%= textAreailizable bid, :description %>
</div>
</div>
<div class="news_foot c_red" id="bid_show_more_des_button<%= bid.id%>" onclick="bid_show_more_des(<%= bid.id%>);" style="cursor:pointer;display: none;">

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save