diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb
index 9ce76dca8..fd43977ee 100644
--- a/app/controllers/attachments_controller.rb
+++ b/app/controllers/attachments_controller.rb
@@ -185,7 +185,6 @@ class AttachmentsController < ApplicationController
end
@attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16)
saved = @attachment.save
-
respond_to do |format|
format.js
format.api {
@@ -198,12 +197,43 @@ class AttachmentsController < ApplicationController
end
end
+ def upload_attachment_version
+ @flag = false
+ Attachment.transaction do
+ @old_attachment = Attachment.find params[:old_attachment_id]
+ #取出当前上传的文件
+ @attachment = Attachment.find(params[:attachments ].first[1][:attachment_id])
+ #将需要修改的记录保存到历史记录
+ @history = AttachmentHistory.new
+ @history.attributes = @old_attachment.attributes.dup.except("id")
+ @history.attachment_id = params[:old_attachment_id]
+ #需要更新版本号,需要拿到原来该文件最大的历史版本号
+ @old_history = @old_attachment.attachment_histories.reorder('version desc').first
+ @history.version = @old_history.nil? ? 1 : @old_history.version + 1
+ @history.save #历史记录保存完毕
+ #将最新保存的记录 数据替换到 需要修改的文件记录
+ @old_attachment.attributes = @attachment.attributes.dup.except("id","container_id","container_type","is_public")
+ @old_attachment.save
+ #删除当前记录
+ @attachment.delete
+ @flag = true
+ end
+
+ respond_to do |format|
+ format.js
+ end
+ end
+
def destroy
if @attachment.container.respond_to?(:init_journal)
@attachment.container.init_journal(User.current)
end
if @attachment.container
- @attachment.container.attachments.delete(@attachment)
+ if @attachment.container_type == "Issue"
+ @attachment.destroy
+ else
+ @attachment.container.attachments.delete(@attachment)
+ end
else
@attachment.destroy
end
@@ -255,7 +285,7 @@ class AttachmentsController < ApplicationController
format.js
end
end
-
+
def delete_homework
@bid = @attachment.container.bid
# Make sure association callbacks are called
@@ -318,13 +348,13 @@ class AttachmentsController < ApplicationController
end
respond_to do |format|
- format.js
+ format.js
end
rescue NoMethodError
@save_flag = false
@save_message = [] << l(:error_attachment_empty)
respond_to do |format|
- format.js
+ format.js
end
end
@@ -494,6 +524,15 @@ class AttachmentsController < ApplicationController
end
end
+ #找到文件的所有的历史版本
+ def attachment_versions
+ @attachment = Attachment.find(params[:id])
+ @attachment_histories = @attachment.attachment_histories
+ respond_to do |format|
+ format.js
+ end
+ end
+
private
def find_project
@attachment = Attachment.find(params[:id])
diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb
index 9c073afa8..444446ef4 100644
--- a/app/controllers/exercise_controller.rb
+++ b/app/controllers/exercise_controller.rb
@@ -450,7 +450,7 @@ class ExerciseController < ApplicationController
if params[:answer_text].nil? || params[:answer_text].blank?
#用户提交空答案,视作不作答
@percent = get_percent(@exercise,User.current)
- render :json => {:text => ea.answer_text,:percent => format("%.2f", @percent)}
+ render :json => {:text => "",:percent => format("%.2f", @percent)}
else
#添加答案
ea = ExerciseAnswer.new
@@ -476,7 +476,7 @@ class ExerciseController < ApplicationController
# 用户提交空答案,视为删除答案
if ea.delete
@percent = get_percent(@exercise,User.current)
- render :json => {:text => ea.answer_text,:percent => format("%.2f", @percent)}
+ render :json => {:text => "",:percent => format("%.2f", @percent)}
else
render :json => {:text => "failure"}
end
diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb
index 121cd3a42..5cbf1ab2f 100644
--- a/app/controllers/files_controller.rb
+++ b/app/controllers/files_controller.rb
@@ -745,7 +745,16 @@ class FilesController < ApplicationController
q = "%#{@q.strip}%"
@result = find_course_attache q,@course,sort
@result = visable_attachemnts @result
- @result = @result.select{|attachment| attachment.tag_list.include?(@tag_name)} unless @tag_name.blank?
+ if params[:other]
+ @result = @result.select{|attachment|
+ !attachment.tag_list.include?('课件') &&
+ !attachment.tag_list.include?('软件') &&
+ !attachment.tag_list.include?('媒体') &&
+ !attachment.tag_list.include?('代码') &&
+ !attachment.tag_list.include?('论文') }
+ else
+ @result = @result.select{|attachment| attachment.tag_list.include?(@tag_name)} unless @tag_name.blank?
+ end
@searched_attach = paginateHelper @result,10
@tag_list = get_course_tag_list @course
diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb
index 46362c2d3..d345fba5f 100644
--- a/app/controllers/homework_common_controller.rb
+++ b/app/controllers/homework_common_controller.rb
@@ -63,7 +63,7 @@ class HomeworkCommonController < ApplicationController
end
@homework.end_time = params[:homework_common][:end_time] || Time.now
@homework.course_id = params[:course_id]
- @homework.anonymous_comment = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment] : 1
+ @homework.anonymous_comment = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment] : 0
homework_detail_manual = @homework.homework_detail_manual || HomeworkDetailManual.new
if @homework.publish_time <= Date.today && homework_detail_manual.comment_status == 0
diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb
index 5e21251b8..91a0bc902 100644
--- a/app/controllers/issues_controller.rb
+++ b/app/controllers/issues_controller.rb
@@ -85,7 +85,7 @@ class IssuesController < ApplicationController
params[:page] = (params[:page] || 1).to_i + 1 #页码需要加1
@offset ||= @issue_pages.offset
@issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
- :order => sort_clause,
+ :order => 'issues.updated_on desc',
:offset => @offset,
:limit => @limit)
if params[:set_filter]
diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb
index 7b70dffe5..72bffa06c 100644
--- a/app/controllers/messages_controller.rb
+++ b/app/controllers/messages_controller.rb
@@ -75,7 +75,7 @@ class MessagesController < ApplicationController
@replies = paginateHelper messages_replies,10
@reply = Message.new(:subject => "RE: #{@message.subject}")
render :action => "show", :layout => "base_courses"#by young
- else
+ elsif @project
@reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page
@replies = @topic.children.
includes(:author, :attachments, {:board => :project}).
@@ -86,6 +86,18 @@ class MessagesController < ApplicationController
@reply = Message.new(:subject => "RE: #{@message.subject}")
render :action => "show", :layout => "base_projects"#by young
+ else
+ @reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page
+ @replies = @topic.children.
+ includes(:author, :attachments, {:board => :project}).
+ reorder("#{Message.table_name}.created_on DESC").
+ limit(@reply_pages.per_page).
+ offset(@reply_pages.offset).
+ all
+
+ @reply = Message.new(:subject => "RE: #{@message.subject}")
+ @organization = @org_subfield.organization
+ render :action => "show", :layout => "base_org"#by young
end
end
@@ -199,6 +211,8 @@ class MessagesController < ApplicationController
end
if params[:user_activity_id]
@user_activity_id = params[:user_activity_id]
+ @is_course = params[:is_course]
+ @is_board = params[:is_board]
respond_to do |format|
format.js
end
@@ -219,17 +233,27 @@ class MessagesController < ApplicationController
@isReply = false
if @project
(render_403; return false) unless @message.editable_by?(User.current)
- else
+ elsif @course
(render_403; return false) unless @message.course_editable_by?(User.current)
+ else
+ (render_403; return false) unless @message.org_subfield_editable_by?(User.current)
end
@message.safe_attributes = params[:message]
if request.post? && @message.save
attachments = Attachment.attach_files(@message, params[:attachments])
render_attachment_warning_if_needed(@message)
- flash[:notice] = l(:notice_successful_update)
+ #flash[:notice] = l(:notice_successful_update)
@message.reload
- if params[:is_board]
+ if params[:is_course] && params[:is_course].to_i == 0
+ redirect_to user_activities_path(User.current.id)
+ elsif params[:is_course] && params[:is_course].to_i == 1 && params[:is_board] && params[:is_board].to_i == 0
+ if @project
+ redirect_to project_path(@project)
+ elsif @course
+ redirect_to course_activity_path(@course)
+ end
+ elsif params[:is_course] && params[:is_course].to_i == 1 && params[:is_board] && params[:is_board].to_i == 1
if @project
redirect_to project_boards_path(@project)
elsif @course
@@ -239,19 +263,22 @@ class MessagesController < ApplicationController
redirect_to board_message_url(@message.board, @message.root, :r => (@message.parent_id && @message.id))
end
elsif request.get? || request.post?
- if params[:is_board]
- if @project
- redirect_to project_boards_path(@project)
- elsif @course
- redirect_to course_boards_path(@course)
- end
- else
- respond_to do |format|
- format.html {
- layout_file = @project ? 'base_projects' : 'base_courses'
- render :layout => layout_file
- }
- end
+ if params[:is_course] && params[:is_board]
+ @is_course = params[:is_course]
+ @is_board = params[:is_board]
+ end
+ respond_to do |format|
+ format.html {
+ if @project
+ layout_file = 'base_projects'
+ elsif @course
+ layout_file = 'base_courses'
+ elsif @org_subfield
+ @organization = @org_subfield.organization
+ layout_file = 'base_org'
+ end
+ render :layout => layout_file
+ }
end
end
end
@@ -260,31 +287,46 @@ class MessagesController < ApplicationController
def destroy
if @project
(render_403; return false) unless @message.destroyable_by?(User.current)
- else
+ elsif @course
(render_403; return false) unless @message.course_destroyable_by?(User.current)
+ else
+ (render_403; return false) unless @message.org_subfield_editable_by?(User.current)
end
r = @message.to_param
@message.destroy
# modify by nwb
if @project
- if params[:is_board]
- redirect_to project_boards_url(@project)
+ if params[:is_course] && params[:is_course].to_i == 0
+ redirect_to user_activities_path(User.current.id)
+ elsif params[:is_course] && params[:is_course].to_i == 1 && params[:is_board] && params[:is_board].to_i == 0
+ redirect_to project_path(@project)
+ elsif params[:is_course] && params[:is_course].to_i == 1 && params[:is_board] && params[:is_board].to_i == 1
+ redirect_to project_boards_path(@project)
+ elsif @message.parent
+ redirect_to board_message_url(@board, @message.parent, :r => r)
else
- if @message.parent
- redirect_to board_message_url(@board, @message.parent, :r => r)
- else
- redirect_to project_board_url(@project, @board)
- end
- # redirect_to board_message_url(@board, @topic, :r => @reply)
+ redirect_to project_board_url(@project, @board)
end
elsif @course
+ if params[:is_course] && params[:is_course].to_i == 0
+ redirect_to user_activities_path(User.current.id)
+ elsif params[:is_course] && params[:is_course].to_i == 1 && params[:is_board] && params[:is_board].to_i == 0
+ redirect_to course_activity_path(@course)
+ elsif params[:is_course] && params[:is_course].to_i == 1 && params[:is_board] && params[:is_board].to_i == 1
+ redirect_to course_boards_path(@course)
+ elsif @message.parent
+ redirect_to board_message_url(@board, @message.parent, :r => r)
+ else
+ redirect_to course_boards_path(@course)
+ end
+ elsif @org_subfield
if params[:is_board]
- redirect_to course_boards_url(@course)
+ redirect_to organization_path(:id => @org_subfield.organization_id, :org_subfield_id => @org_subfield.id)
else
if @message.parent
redirect_to board_message_url(@board, @message.parent, :r => r)
else
- redirect_to course_board_url(@course, @board)
+ redirect_to organization_path(:id => @org_subfield.organization_id, :org_subfield_id => @org_subfield.id)
end
end
end
@@ -319,15 +361,25 @@ class MessagesController < ApplicationController
org_subfield_ids = params[:org_subfields]
@message = Message.find(params[:id])
# @message.update_attribute(:updated_on, Time.now)
- type = @message.board.course_id.nil? ? "Project":"Course"
+ # type = @message.board.course_id.nil? ? "Project":"Course"
org_subfield_ids.each do |field_id|
- OrgSubfieldMessage.create(:org_subfield_id => field_id.to_i, :message_id => @message.id, :message_type => type)
- org_acts = OrgActivity.where("container_type='OrgSubfield' and container_id=? and org_act_type='Message' and org_act_id=?", field_id.to_i, @message.id)
- if org_acts.all.size() > 0
- org_acts.first.update_attribute(:updated_at, Time.now)
- else
- OrgActivity.create(:container_type => 'OrgSubfield', :container_id => field_id.to_i, :org_act_type=>'Message', :org_act_id => @message.id, :user_id => User.current.id)
+ @message.quotes = @message.quotes.nil? ? 1 : (@message.quotes + 1)
+ @message.save
+ board = OrgSubfield.find(field_id).boards.first
+ mes = Message.create(:board_id => board.id, :subject => @message.subject, :content => @message.content, :author_id => User.current.id,
+ :created_on => Time.now, :updated_on => Time.now, :locked => @message.locked, :sticky => @message.sticky)
+ @message.attachments.each do |attach|
+ mes.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest,
+ :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype,
+ :is_public => attach.is_public, :quotes => 0)
end
+ # OrgSubfieldMessage.create(:org_subfield_id => field_id.to_i, :message_id => mes.id, :message_type => type)
+ # org_acts = OrgActivity.where("container_type='OrgSubfield' and container_id=? and org_act_type='Message' and org_act_id=?", field_id.to_i, @message.id)
+ # if org_acts.all.size() > 0
+ # org_acts.first.update_attribute(:updated_at, Time.now)
+ # else
+ OrgActivity.create(:container_type => 'OrgSubfield', :container_id => field_id.to_i, :org_act_type=>'Message', :org_act_id => mes.id, :user_id => User.current.id)
+ # end
end
end
@@ -347,6 +399,9 @@ class MessagesController < ApplicationController
@project = @board.project
elsif @board.course_id
@course = @board.course
+ else
+ @org_subfield = @board.org_subfield
+ @organization = @org_subfield
end
rescue ActiveRecord::RecordNotFound
diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb
index aba656750..45256bb1b 100644
--- a/app/controllers/organizations_controller.rb
+++ b/app/controllers/organizations_controller.rb
@@ -1,284 +1,303 @@
-# encoding: utf-8
-class OrganizationsController < ApplicationController
-
-
- helper :sort
- include SortHelper
- helper :custom_fields
- include CustomFieldsHelper
- include AvatarHelper
- include WordsHelper
- include GitlabHelper
- include UserScoreHelper
-
- include PollHelper
- helper :user_score
- helper :journals
-
- # added by liuping 关注
-
- helper :watchers
- helper :activities
-
- ### added by william
- include ActsAsTaggableOn::TagsHelper
-
- # fq
- helper :words
- helper :project_score
- helper :issues
- include UsersHelper
- before_filter :find_organization, :only => [:show, :members]
- layout 'base_org'
- def index
-
- end
- def new
- @organization = Organization.new
- render :layout => 'new_base'
- end
-
- def edit
- @organization = Organization.find(params[:id])
- end
-
- def destroy
- @organization = Organization.find(params[:id])
- @organization.destroy
- respond_to do |format|
- format.html{ redirect_to admin_organization_path }
- end
- end
-
- def create
- @organization = Organization.new
- @organization.name = params[:organization][:name]
- @organization.description = params[:organization][:description]
- @organization.is_public = params[:organization][:is_public]
- @organization.creator_id = User.current.id
- member = OrgMember.new(:user_id => User.current.id)
-
- @organization.org_members << member
- if @organization.save
- OrgMemberRole.create(:org_member_id => member.id, :role_id => 11)
- redirect_to organization_path(@organization)
- end
- end
-
- def show
- if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization)
- @organization = Organization.find(params[:id])
- if params[:org_subfield_id]
- @org_subfield = OrgSubfield.find(params[:org_subfield_id])
- @org_subfield_ids = @org_subfield.org_document_comments.map(&:id) << 0
- @org_activities = OrgActivity.where("(org_act_type='OrgDocumentComment'and org_act_id in (#{@org_subfield_ids.join(",")})) || (container_type='OrgSubfield' and container_id=#{@org_subfield.id})").order('updated_at desc').page(params[:page] || 1).per(10)
- else
- project_ids = @organization.projects.map(&:id) << 0
- course_ids = @organization.courses.map(&:id) << 0
- course_types = "('Message','News','HomeworkCommon','Poll','Course')"
- case params[:type]
- when nil
- @org_activities = OrgActivity.where("(container_id =? and container_type =?) " +
- "or (container_type ='Project' and org_act_type in ('Issue','Message','ProjectCreateInfo') and container_id in (#{project_ids.join(',')})) "+
- "or (container_type ='Course' and org_act_type in #{course_types} and container_id in (#{course_ids.join(',')}))",
- @organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10)
- when 'project_issue'
- @org_activities = OrgActivity.where("container_type = 'Project' and org_act_type = 'Issue' and container_id in (#{project_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
- when 'project_message'
- @org_activities = OrgActivity.where("container_type = 'Project' and org_act_type = 'Message' and container_id in (#{project_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
- when 'org'
- @org_activities = OrgActivity.where("container_id =? and container_type =?",@organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10)
- when 'course_homework'
- @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'HomeworkCommon' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
- when 'course_news'
- @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'News' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
- when 'course_message'
- @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'Message' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
- when 'course_poll'
- @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'Poll' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
- end
- end
- @page = params[:page]
- respond_to do |format|
- format.html
- format.js
- end
- else
- render_403
- end
- end
-
- def update
- @organization = Organization.find(params[:id])
- @organization.name = params[:organization][:name]
- @organization.description = params[:organization][:description]
- @organization.domain = params[:organization][:domain]
- @organization.is_public = params[:organization][:is_public] == 'on' ? 1 : 0
- #@organization.name = params[:organization][:name]
- @organization.save
- respond_to do |format|
- format.html { redirect_to setting_organization_path(@organization)}
- end
- end
-
- def check_uniq
- @check = false;
- @org_name = params[:org_name].strip
- @config_page = params[:config_page]
- sameName = @config_page ? Organization.where('name = ? and id != ?',params[:org_name],params[:org_id].to_i).count == 0 : Organization.where('name = ?',params[:org_name]).count == 0
- if sameName == true
- @check = true
- end
- respond_to do |format|
- format.js
- end
- end
-
- def find_organization
- @organization = Organization.find(params[:id])
- end
-
- def setting
- @organization = Organization.find(params[:id])
-
- if User.current.admin? || User.current.admin_of_org?(@organization)
- else
- render_403
- end
- end
-
-
- def clear_org_avatar_temp
-
- end
-
- def set_homepage
- @org = Organization.find(params[:id])
- @org.home_id = params[:home_id]
- @org.save
- # respond_to do |format|
- # format.html {redirect_to organization_path(org)}
- # end
- end
-
- def cancel_homepage
- @org = Organization.find(params[:id])
- @org.home_id = nil
- @org.save
- end
-
- def autocomplete_search
- @project = Project.find(params[:project_id])
- #@flag = params[:flag] || false
- respond_to do |format|
- format.js
- end
- end
-
- def members
- if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization)
- @members = OrgMember.where("organization_id =?", @organization.id)
- else
- render_403
- end
- end
-
- def more_org_projects
- @organization = Organization.find params[:id]
- @page = params[:page]
- @org_projects = @organization.projects.reorder('created_at').uniq.page((params[:page].to_i || 1) +1).per(5)
- respond_to do |format|
- format.js
- end
- end
-
- def more_org_courses
- @organization = Organization.find(params[:id])
- @page = params[:page]
- @org_courses = @organization.courses.reorder('created_at').uniq.page((params[:page].to_i || 1) + 1 ).per(5)
- respond_to do |format|
- format.js
- end
- end
-
- def join_course_menu
- @organization = Organization.find(params[:id])
- respond_to do |format|
- format.js
- end
- end
-
- def search_courses
- @organization = Organization.find(params[:id])
- condition = '%%'
- if !params[:name].nil?
- condition = "%#{params[:name].strip}%".gsub(" ","")
- end
- sql = "select courses.* from courses inner join members on courses.id = members.course_id where members.user_id = #{User.current.id} and courses.name like '#{condition}'"+
- "and courses.id not in (select distinct org_courses.course_id from org_courses where org_courses.organization_id = #{@organization.id})"
- #user_courses = Course.find_by_sql(sql)
- @courses = Course.find_by_sql(sql)
- # @added_course_ids = @organization.courses.map(&:id)
- # @courses = []
- # user_courses.each do |course|
- # if !@added_course_ids.include?(course.id)
- # @courses << course
- # end
- # end
- end
-
- def join_courses
- @organization = Organization.find(params[:id])
- course_ids = params[:courseNames]
- course_ids.each do |id|
- OrgCourse.create(:organization_id => @organization.id, :course_id => id.to_i, :created_at => Time.now)
- end
- respond_to do |format|
- format.js
- end
- end
-
- def join_project_menu
- @organization = Organization.find(params[:id])
- respond_to do |format|
- format.js
- end
- end
-
- def logout
- logout_user
- respond_to do |format|
- format.html {redirect_to organization_path(params[:id])}
- end
- end
-
- def search_projects
- @organization = Organization.find(params[:id])
- condition = '%%'
- if !params[:name].nil?
- condition = "%#{params[:name].strip}%".gsub(" ","")
- end
- sql = "select projects.* from projects inner join members on projects.id = members.project_id where members.user_id = #{User.current.id} and projects.status != 9 and projects.name like '#{condition}'" +
- " and projects.id not in (select org_projects.project_id from org_projects where organization_id = #{@organization.id})"
- #user_projects = Course.find_by_sql(sql)
- @projects = Course.find_by_sql(sql)
- # @added_course_ids = @organization.projects.map(&:id)
- # @projects = []
- # user_projects.each do |project|
- # if !@added_course_ids.include?(project.id)
- # @projects << project
- # end
- # end
- end
-
- def join_projects
- @organization = Organization.find(params[:id])
- project_ids = params[:projectNames]
- project_ids.each do |id|
- OrgProject.create(:organization_id => @organization.id, :project_id => id.to_i, :created_at => Time.now)
- end
- respond_to do |format|
- format.js
- end
- end
-end
+# encoding: utf-8
+class OrganizationsController < ApplicationController
+
+
+ helper :sort
+ include SortHelper
+ helper :custom_fields
+ include CustomFieldsHelper
+ include AvatarHelper
+ include WordsHelper
+ include GitlabHelper
+ include UserScoreHelper
+
+ include PollHelper
+ helper :user_score
+ helper :journals
+ helper :attachments
+ # added by liuping 关注
+
+ helper :watchers
+ helper :activities
+
+ ### added by william
+ include ActsAsTaggableOn::TagsHelper
+
+ # fq
+ helper :words
+ helper :project_score
+ helper :issues
+ include UsersHelper
+ before_filter :find_organization, :only => [:show, :members]
+ layout 'base_org'
+ def index
+
+ end
+ def new
+ @organization = Organization.new
+ render :layout => 'new_base'
+ end
+
+ def edit
+ @organization = Organization.find(params[:id])
+ end
+
+ def destroy
+ @organization = Organization.find(params[:id])
+ @organization.destroy
+ respond_to do |format|
+ format.html{ redirect_to admin_organization_path }
+ end
+ end
+
+ def create
+ @organization = Organization.new
+ @organization.name = params[:organization][:name]
+ @organization.description = params[:organization][:description]
+ @organization.is_public = params[:organization][:is_public]
+ @organization.creator_id = User.current.id
+ member = OrgMember.new(:user_id => User.current.id)
+
+ @organization.org_members << member
+ if @organization.save
+ OrgMemberRole.create(:org_member_id => member.id, :role_id => 11)
+ redirect_to organization_path(@organization)
+ end
+ end
+
+ def show
+ if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization)
+ @organization = Organization.find(params[:id])
+ if params[:org_subfield_id]
+ @org_subfield = OrgSubfield.find(params[:org_subfield_id])
+ @org_subfield_ids = @org_subfield.org_document_comments.map(&:id) << 0
+ @org_activities = OrgActivity.where("(org_act_type='OrgDocumentComment'and org_act_id in (#{@org_subfield_ids.join(",")})) || (container_type='OrgSubfield' and container_id=#{@org_subfield.id})").order('updated_at desc').page(params[:page] || 1).per(10)
+ else
+ project_ids = @organization.projects.map(&:id) << 0
+ course_ids = @organization.courses.map(&:id) << 0
+ course_types = "('Message','News','HomeworkCommon','Poll','Course')"
+ case params[:type]
+ when nil
+ @org_activities = OrgActivity.where("(container_id =? and container_type =?) " +
+ "or (container_type ='Project' and org_act_type in ('Issue','Message','ProjectCreateInfo') and container_id in (#{project_ids.join(',')})) "+
+ "or (container_type ='Course' and org_act_type in #{course_types} and container_id in (#{course_ids.join(',')}))",
+ @organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10)
+ when 'project_issue'
+ @org_activities = OrgActivity.where("container_type = 'Project' and org_act_type = 'Issue' and container_id in (#{project_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
+ when 'project_message'
+ @org_activities = OrgActivity.where("container_type = 'Project' and org_act_type = 'Message' and container_id in (#{project_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
+ when 'org'
+ @org_activities = OrgActivity.where("container_id =? and container_type =?",@organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10)
+ when 'course_homework'
+ @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'HomeworkCommon' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
+ when 'course_news'
+ @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'News' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
+ when 'course_message'
+ @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'Message' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
+ when 'course_poll'
+ @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'Poll' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
+ end
+ end
+ @page = params[:page]
+ respond_to do |format|
+ format.html
+ format.js
+ end
+ else
+ render_403
+ end
+ end
+
+ def update
+ @organization = Organization.find(params[:id])
+ @organization.name = params[:organization][:name]
+ @organization.description = params[:organization][:description]
+ @organization.domain = params[:organization][:domain]
+ @organization.is_public = params[:organization][:is_public] == 'on' ? 1 : 0
+ #@organization.name = params[:organization][:name]
+ @organization.save
+ respond_to do |format|
+ format.html { redirect_to setting_organization_path(@organization)}
+ end
+ end
+
+ def check_uniq
+ @check = false;
+ @org_name = params[:org_name].strip
+ @config_page = params[:config_page]
+ sameName = @config_page ? Organization.where('name = ? and id != ?',params[:org_name],params[:org_id].to_i).count == 0 : Organization.where('name = ?',params[:org_name]).count == 0
+ if sameName == true
+ @check = true
+ end
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ def find_organization
+ @organization = Organization.find(params[:id])
+ end
+
+ def setting
+ @organization = Organization.find(params[:id])
+
+ if User.current.admin? || User.current.admin_of_org?(@organization)
+ else
+ render_403
+ end
+ end
+
+
+ def clear_org_avatar_temp
+
+ end
+
+ def set_homepage
+ @org = Organization.find(params[:id])
+ @org.home_id = params[:home_id]
+ @org.save
+ # respond_to do |format|
+ # format.html {redirect_to organization_path(org)}
+ # end
+ end
+
+ def cancel_homepage
+ @org = Organization.find(params[:id])
+ @org.home_id = nil
+ @org.save
+ end
+
+ def autocomplete_search
+ @project = Project.find(params[:project_id])
+ #@flag = params[:flag] || false
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ def members
+ if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization)
+ @members = OrgMember.where("organization_id =?", @organization.id)
+ else
+ render_403
+ end
+ end
+
+ def more_org_projects
+ @organization = Organization.find params[:id]
+ @page = params[:page]
+ @org_projects = @organization.projects.reorder('created_at').uniq.page((params[:page].to_i || 1) +1).per(5)
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ def more_org_courses
+ @organization = Organization.find(params[:id])
+ @page = params[:page]
+ @org_courses = @organization.courses.reorder('created_at').uniq.page((params[:page].to_i || 1) + 1 ).per(5)
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ def join_course_menu
+ @organization = Organization.find(params[:id])
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ def search_courses
+ @organization = Organization.find(params[:id])
+ condition = '%%'
+ if !params[:name].nil?
+ condition = "%#{params[:name].strip}%".gsub(" ","")
+ end
+ sql = "select courses.* from courses inner join members on courses.id = members.course_id where members.user_id = #{User.current.id} and courses.name like '#{condition}'"+
+ "and courses.id not in (select distinct org_courses.course_id from org_courses where org_courses.organization_id = #{@organization.id})"
+ #user_courses = Course.find_by_sql(sql)
+ @courses = Course.find_by_sql(sql)
+ # @added_course_ids = @organization.courses.map(&:id)
+ # @courses = []
+ # user_courses.each do |course|
+ # if !@added_course_ids.include?(course.id)
+ # @courses << course
+ # end
+ # end
+ end
+
+ def join_courses
+ @organization = Organization.find(params[:id])
+ course_ids = params[:courseNames]
+ course_ids.each do |id|
+ OrgCourse.create(:organization_id => @organization.id, :course_id => id.to_i, :created_at => Time.now)
+ end
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ def join_project_menu
+ @organization = Organization.find(params[:id])
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ def logout
+ logout_user
+ respond_to do |format|
+ format.html {redirect_to organization_path(params[:id])}
+ end
+ end
+
+ def search_projects
+ @organization = Organization.find(params[:id])
+ condition = '%%'
+ if !params[:name].nil?
+ condition = "%#{params[:name].strip}%".gsub(" ","")
+ end
+ sql = "select projects.* from projects inner join members on projects.id = members.project_id where members.user_id = #{User.current.id} and projects.status != 9 and projects.name like '#{condition}'" +
+ " and projects.id not in (select org_projects.project_id from org_projects where organization_id = #{@organization.id})"
+ #user_projects = Course.find_by_sql(sql)
+ @projects = Course.find_by_sql(sql)
+ # @added_course_ids = @organization.projects.map(&:id)
+ # @projects = []
+ # user_projects.each do |project|
+ # if !@added_course_ids.include?(project.id)
+ # @projects << project
+ # end
+ # end
+ end
+
+ def join_projects
+ @organization = Organization.find(params[:id])
+ project_ids = params[:projectNames]
+ project_ids.each do |id|
+ OrgProject.create(:organization_id => @organization.id, :project_id => id.to_i, :created_at => Time.now)
+ end
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ def hide_org_subfield
+ @org_subfield = OrgSubfield.find(params[:org_subfield_id])
+ @org_subfield.update_attribute(:hide, 1)
+ end
+
+ def show_org_subfield
+ @org_subfield = OrgSubfield.find(params[:org_subfield_id])
+ @org_subfield.update_attribute(:hide, 0)
+ end
+
+ def org_resources_subfield
+ @org = Organization.find(params[:id])
+ @subfield = @org.org_subfields.where('field_type = "Resource" ')
+ respond_to do | format|
+ format.js
+ end
+ end
+
+end
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index c57478c4a..016b4ccbb 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -499,7 +499,7 @@ class UsersController < ApplicationController
#提交作品时,计算是否迟交
if Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d")
- student_work.late_penalty = 1
+ student_work.late_penalty = homework.late_penalty
else
student_work.late_penalty = 0
end
@@ -524,7 +524,7 @@ class UsersController < ApplicationController
else
homework.publish_time = params[:homework_common][:publish_time]
end
- homework.anonymous_comment = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment] : 1
+ homework.anonymous_comment = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment] : 0
homework.homework_type = params[:homework_type].to_i || 1
homework.late_penalty = 10
homework.teacher_priority = 1
@@ -621,7 +621,7 @@ class UsersController < ApplicationController
end
if(params[:type].blank? || params[:type] == "1") #全部
user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
- @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
+ @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
"or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc")
elsif params[:type] == "2" #课程资源
user_course_ids = User.current.courses.map { |c| c.id}
@@ -1329,12 +1329,12 @@ class UsersController < ApplicationController
if(params[:type].blank?|| params[:type] == "1") #全部
if User.current.id.to_i == params[:id].to_i
user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
- @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
+ @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
"or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc")
else
user_course_ids = User.find(params[:id]).courses.visible.map { |c| c.id} #Ta的资源库的话,应该是他上传的公开资源 加上 他加入的所有我可见课程里的公开资源
@attachments = Attachment.where("(author_id = #{params[:id]} and is_public = 1 " +
- "and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
+ "and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
"or (container_type = 'Course' and is_public = 1 and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc")
end
elsif params[:type] == "2" #课程资源
@@ -1391,12 +1391,12 @@ class UsersController < ApplicationController
if(params[:type].nil? || params[:type].blank? || params[:type] == "1" || params[:type] == 'all') #全部
if User.current.id.to_i == params[:id].to_i
user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
- @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
+ @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
"or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc")
else
user_course_ids = User.find(params[:id]).courses.visible.map { |c| c.id} #Ta的资源库的话,应该是他上传的公开资源 加上 他加入的所有我可见课程里的公开资源
@attachments = Attachment.where("(author_id = #{params[:id]} and is_public = 1 " +
- "and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
+ "and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
"or (container_type = 'Course' and is_public = 1 and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc")
end
elsif params[:type] == "2" #课程资源
@@ -1491,11 +1491,23 @@ class UsersController < ApplicationController
unless course_ids.nil?
course_ids.each do |id|
next if ori.blank?
+ @exist = false
+ Course.find(id).attachments.each do |att| #如果课程中包含该资源
+ if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from
+ att.created_on = Time.now
+ att.save
+ @exist = true
+ break
+ end
+ end
+ next if @exist
attach_copied_obj = ori.copy
attach_copied_obj.tag_list.add(ori.tag_list) # tag关联
attach_copied_obj.container = Course.find(id)
attach_copied_obj.created_on = Time.now
attach_copied_obj.author_id = User.current.id
+ attach_copied_obj.is_public = 0
+ attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from
if attach_copied_obj.attachtype == nil
attach_copied_obj.attachtype = 4
end
@@ -1515,11 +1527,23 @@ class UsersController < ApplicationController
unless course_ids.nil?
course_ids.each do |id|
next if ori.blank?
+ @exist = false
+ Course.find(id).attachments.each do |att| #如果课程中包含该资源
+ if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from
+ att.created_on = Time.now
+ att.save
+ @exist = true
+ break
+ end
+ end
+ next if @exist
attach_copied_obj = ori.copy
attach_copied_obj.tag_list.add(ori.tag_list) # tag关联
attach_copied_obj.container = Course.find(id)
attach_copied_obj.created_on = Time.now
attach_copied_obj.author_id = User.current.id
+ attach_copied_obj.is_public = 0
+ attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from
if attach_copied_obj.attachtype == nil
attach_copied_obj.attachtype = 4
end
@@ -1532,7 +1556,7 @@ class UsersController < ApplicationController
@flag = false
end
user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
- @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
+ @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
"or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc")
@type = params[:type]
@limit = 25
@@ -1561,11 +1585,23 @@ class UsersController < ApplicationController
unless project_ids.nil?
project_ids.each do |project_id|
next if ori.blank?
+ @exist = false
+ Project.find(project_id).attachments.each do |att| #如果课程中包含该资源
+ if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from
+ att.created_on = Time.now
+ att.save
+ @exist = true
+ break
+ end
+ end
+ next if @exist
attach_copied_obj = ori.copy
attach_copied_obj.tag_list.add(ori.tag_list) # tag关联
attach_copied_obj.container = Project.find(project_id)
attach_copied_obj.created_on = Time.now
attach_copied_obj.author_id = User.current.id
+ attach_copied_obj.is_public = 0
+ attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from
if attach_copied_obj.attachtype == nil
attach_copied_obj.attachtype = 1
end
@@ -1584,11 +1620,23 @@ class UsersController < ApplicationController
unless project_ids.nil?
project_ids.each do |project_id|
next if ori.blank?
+ @exist = false
+ Project.find(project_id).attachments.each do |att| #如果课程中包含该资源
+ if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from
+ att.created_on = Time.now
+ att.save
+ @exist = true
+ break
+ end
+ end
+ next if @exist
attach_copied_obj = ori.copy
attach_copied_obj.tag_list.add(ori.tag_list) # tag关联
attach_copied_obj.container = Project.find(project_id)
attach_copied_obj.created_on = Time.now
attach_copied_obj.author_id = User.current.id
+ attach_copied_obj.is_public = 0
+ attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from
if attach_copied_obj.attachtype == nil
attach_copied_obj.attachtype = 1
end
@@ -1600,7 +1648,7 @@ class UsersController < ApplicationController
@flag=true
end
user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
- @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
+ @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
"or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc")
@type = params[:type]
@limit = 25
@@ -1616,6 +1664,97 @@ class UsersController < ApplicationController
end
end
+ def add_exist_file_to_org
+ @flag = true
+ if params[:send_id].present?
+ send_id = params[:send_id]
+ subfield_id = params[:subfield]
+ if subfield_id.nil?
+ @flag = false
+ end
+ ori = Attachment.find_by_id(send_id)
+ unless subfield_id.nil?
+ attach_copied_obj = ori.copy
+ @exist = false
+ OrgSubfield.find(subfield_id).attachments.each do |att| #如果课程中包含该资源
+ if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from
+ att.created_on = Time.now
+ att.save
+ @exist = true
+ break
+ end
+ end
+ if @exist == false #如果不存在该资源
+ attach_copied_obj.tag_list.add(ori.tag_list) # tag关联
+ attach_copied_obj.container = OrgSubfield.find(subfield_id)
+ attach_copied_obj.created_on = Time.now
+ attach_copied_obj.author_id = User.current.id
+ attach_copied_obj.is_public = 0
+ attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from
+ if attach_copied_obj.attachtype == nil
+ attach_copied_obj.attachtype = 1
+ end
+ attach_copied_obj.save
+ end
+ end
+ elsif params[:send_ids].present?
+ send_ids = params[:send_ids].split(" ")
+ subfield_id = params[:subfield]
+ if subfield_id.nil?
+ @flag = false
+ end
+ send_ids.each do |send_id|
+
+ ori = Attachment.find_by_id(send_id)
+ unless subfield_id.nil?
+ next if ori.blank?
+ @exist = false
+ OrgSubfield.find(subfield_id).attachments.each do |att| #如果课程中包含该资源
+ if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from
+ att.created_on = Time.now
+ att.save
+ @exist = true
+ break
+ end
+ end
+ next if @exist
+ attach_copied_obj = ori.copy
+ attach_copied_obj.tag_list.add(ori.tag_list) # tag关联
+ attach_copied_obj.container = OrgSubfield.find(subfield_id)
+ attach_copied_obj.created_on = Time.now
+ attach_copied_obj.author_id = User.current.id
+ attach_copied_obj.is_public = 0
+ attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from
+ if attach_copied_obj.attachtype == nil
+ attach_copied_obj.attachtype = 1
+ end
+ attach_copied_obj.save
+ end
+ end
+ else
+ @flag=true
+ end
+ user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
+ @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
+ "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc")
+ @type = params[:type]
+ @limit = 25
+ @user = User.current
+ @is_remote = true
+ @atta_count = @attachments.count
+ @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
+ @offset ||= @atta_pages.offset
+ #@curse_attachments_all = @all_attachments[@offset, @limit]
+ @attachments = paginateHelper @attachments,25
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ def change_org_subfield
+
+ end
+
# 资源预览
def resource_preview
preview_id = params[:resource_id]
@@ -1828,12 +1967,12 @@ class UsersController < ApplicationController
if(params[:type].blank? || params[:type] == "1") #全部
if User.current.id.to_i == params[:id].to_i
user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
- @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
+ @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
"or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc")
else
user_course_ids = User.find(params[:id]).courses.visible.map { |c| c.id} #Ta的资源库的话,应该是他上传的公开资源 加上 他加入的所有我可见课程里的公开资源
@attachments = Attachment.where("(author_id = #{params[:id]} and is_public = 1 " +
- "and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
+ "and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
"or (container_type = 'Course' and is_public = 1 and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc")
end
elsif params[:type] == "2" #课程资源
@@ -1884,7 +2023,7 @@ class UsersController < ApplicationController
if(params[:type].nil? || params[:type].blank? || params[:type] == "1" || params[:type] == 'all') #全部
if User.current.id.to_i == params[:id].to_i
user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 取交集并查询
- @attachments = Attachment.where("((author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
+ @attachments = Attachment.where("((author_id = #{params[:id]} and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
" or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))) and (filename like :p) ",:p=>search).order("created_on desc")
else
user_course_ids = User.find(params[:id]).courses.visible.map { |c| c.id} #如果课程私有资源,那么要看这个资源的课程是不是在 这个user的所有我可见的课程中
@@ -1957,6 +2096,23 @@ class UsersController < ApplicationController
end
end
+ def search_user_org
+ @user = User.current
+ if !params[:search].nil? #发送到有栏目类型为资源的组织中
+ search = "%#{params[:search].to_s.strip.downcase}%"
+ @orgs = @user.organizations.where("name like ?", search).select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Resource'").count > 0}
+ else
+ @orgs = @user.organizations.select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Resource'").count > 0}
+ end
+ @search = params[:search]
+ #这里仅仅是传递需要发送的资源id
+ @send_id = params[:send_id]
+ @send_ids = params[:checkbox1] || params[:send_ids]
+ respond_to do |format|
+ format.js
+ end
+ end
+
private
def find_user
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 4bdffb9dc..55a017019 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -2588,6 +2588,12 @@ module ApplicationHelper
end
end
+ def file_preview_eye(file, html_options={})
+ if %w(pdf pptx doc docx xls xlsx).any?{|x| file.filename.downcase.end_with?(x)}
+ link_to '', download_named_attachment_path(file.id, file.filename, preview: true),html_options
+ end
+ end
+
#将文本内的/n转换为
def text_format text
text.gsub("&","&").gsub("<","<").gsub(">",">").gsub("\n","
").html_safe
diff --git a/app/helpers/org_subfields_helper.rb b/app/helpers/org_subfields_helper.rb
index a9f8a396f..8dad7096f 100644
--- a/app/helpers/org_subfields_helper.rb
+++ b/app/helpers/org_subfields_helper.rb
@@ -1,2 +1,3 @@
module OrgSubfieldsHelper
+ include OrganizationsHelper
end
diff --git a/app/helpers/organizations_helper.rb b/app/helpers/organizations_helper.rb
index 607d2af5c..69c355313 100644
--- a/app/helpers/organizations_helper.rb
+++ b/app/helpers/organizations_helper.rb
@@ -17,6 +17,15 @@ module OrganizationsHelper
s + content_tag('ul', links,:class => 'wlist',:style=>'float:left !important', :id => "org_member_pagination_links" )
end
-
+ def get_default_name field
+ case field.name
+ when 'activity' then
+ return '动态'
+ when 'course' then
+ return '课程'
+ when 'project' then
+ return '项目'
+ end
+ end
end
diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb
index 963284f7f..d1ab6661a 100644
--- a/app/helpers/users_helper.rb
+++ b/app/helpers/users_helper.rb
@@ -49,6 +49,8 @@ module UsersHelper
'批改附件'
when 'Principal'
'用户资源'
+ when 'OrgSubfield'
+ '组织资源'
end
end
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index ad5655b02..c8fe0811e 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -32,6 +32,7 @@ class Attachment < ActiveRecord::Base
has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy
# end
include UserScoreHelper
+ has_many :attachment_histories
validates :filename, presence: true, length: {maximum: 254}
validates :author, presence: true
@@ -348,11 +349,18 @@ class Attachment < ActiveRecord::Base
# Deletes the file from the file system if it's not referenced by other attachments
def delete_from_disk
- if Attachment.where("disk_filename = ? AND id <> ?", disk_filename, id).empty?
+ #资源存在,且历史记录为0 且 该资源没有存在任何拷贝才能删除资源
+ if Attachment.where("disk_filename = ? AND id <> ?", disk_filename, id).empty? && self.attachment_histories.count == 0 && Attachment.where('copy_from = ?',self.id) .count == 0
delete_from_disk!
end
end
+ #有了历史记录的数据记录是不能被删除的。
+ #true 能被删除 false 不能被删除
+ def destroyable
+ self.attachment_histories.count == 0
+ end
+
# Returns file's location on disk
def diskfile
File.join(self.class.storage_path, disk_directory.to_s, disk_filename.to_s)
diff --git a/app/models/attachment_history.rb b/app/models/attachment_history.rb
new file mode 100644
index 000000000..2160d242d
--- /dev/null
+++ b/app/models/attachment_history.rb
@@ -0,0 +1,3 @@
+class AttachmentHistory < ActiveRecord::Base
+ belongs_to :attachment,foreign_key: 'attachment_id'
+end
diff --git a/app/models/board.rb b/app/models/board.rb
index 67d59e599..b66719edf 100644
--- a/app/models/board.rb
+++ b/app/models/board.rb
@@ -19,6 +19,7 @@ class Board < ActiveRecord::Base
include Redmine::SafeAttributes
belongs_to :project,:touch => true
belongs_to :course,:touch=>true
+ belongs_to :org_subfield, :touch => true
has_many :topics, :class_name => 'Message', :conditions => "#{Message.table_name}.parent_id IS NULL", :order => "#{Message.table_name}.created_on DESC"
has_many :messages, :dependent => :destroy, :order => "#{Message.table_name}.created_on DESC"
belongs_to :last_message, :class_name => 'Message', :foreign_key => :last_message_id
diff --git a/app/models/journal.rb b/app/models/journal.rb
index 4ab55c158..e1464a703 100644
--- a/app/models/journal.rb
+++ b/app/models/journal.rb
@@ -17,10 +17,10 @@
class Journal < ActiveRecord::Base
include UserScoreHelper
- belongs_to :journalized, :polymorphic => true
+ belongs_to :journalized, :polymorphic => true,:touch => true
# added as a quick fix to allow eager loading of the polymorphic association
# since always associated to an issue, for now
- belongs_to :issue, :foreign_key => :journalized_id
+ belongs_to :issue, :foreign_key => :journalized_id,:touch => true
belongs_to :user
has_many :details, :class_name => "JournalDetail", :dependent => :delete_all
diff --git a/app/models/mailer.rb b/app/models/mailer.rb
index 737a1ea69..318de2942 100644
--- a/app/models/mailer.rb
+++ b/app/models/mailer.rb
@@ -155,7 +155,6 @@ class Mailer < ActionMailer::Base
# 发送内容: 项目【缺陷,讨论区,新闻】,课程【通知,留言,新闻】, 贴吧, 个人留言
def send_for_user_activities(user, date_to, days)
date_from = date_to - days.days
- subject = "[ #{user.show_name}#{l(:label_day_mail)}]"
date_from = "#{date_from} 17:59:59"
date_to = "#{date_to} 17:59:59"
# 生成token用于直接点击登录
@@ -270,10 +269,11 @@ class Mailer < ActionMailer::Base
total_count = @issues.count + @issues_journals.count + @course_messages.count + @project_messages.count + @course_news.count + @course_news_comments.count + @project_news.count + @project_news_comments.count +
@project_attachments.count + @course_journal_messages.count + @user_journal_messages.count + @project_journal_messages.count + @forums.count + @memos.count + @attachments.count +
@bids.count + @wiki_contents.count
+ subject = "[ #{user.show_name}#{l(:label_day_mail_first)}#{total_count}#{l(:label_day_mail_last)}]"
@subject = " #{user.show_name}#{l(:label_day_mail_first)}#{total_count}#{l(:label_day_mail_last)}"
mylogger.debug "Sent activity mail : #{user.mail} - #{has_content}"
#有内容才发,没有不发
- mail :to => user.mail,:subject => subject if has_content
+ mail :to => user.mail,:subject => @subject if has_content
end
# 作业截止时间邮件提醒
diff --git a/app/models/message.rb b/app/models/message.rb
index 19531e270..6d108e607 100644
--- a/app/models/message.rb
+++ b/app/models/message.rb
@@ -23,8 +23,8 @@ class Message < ActiveRecord::Base
belongs_to :board,:touch => true
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
has_many :praise_tread, as: :praise_tread_object, dependent: :destroy
- has_many :org_subfield_messages, :dependent => :destroy
- has_many :org_subfields, :through => :org_subfield_messages
+ # has_many :org_subfield_messages, :dependent => :destroy
+ # has_many :org_subfields, :through => :org_subfield_messages
acts_as_tree :counter_cache => :replies_count, :order => "#{Message.table_name}.created_on ASC"
acts_as_attachable
@@ -44,6 +44,8 @@ class Message < ActiveRecord::Base
has_many :ActivityNotifies,:as => :activity, :dependent => :destroy
+ after_destroy :delete_org_activities
+
acts_as_searchable :columns => ['subject', 'content'],
:include => {:board => :project},
:project_key => "#{Board.table_name}.project_id",
@@ -150,6 +152,10 @@ class Message < ActiveRecord::Base
usr && usr.logged? && (usr.allowed_to?(:edit_messages, course) || (self.author == usr && usr.allowed_to?(:edit_own_messages, course)))
end
+ def org_subfield_editable_by?(usr)
+ usr && usr.logged? && (usr.admin? || self.author == usr ||usr.admin_of_org?(self.board.org_subfield.organization))
+ end
+
def course_destroyable_by?(usr)
usr && usr.logged? && (usr.allowed_to?(:delete_messages, course) || (self.author == usr && usr.allowed_to?(:delete_own_messages, course)))
end
@@ -192,7 +198,7 @@ class Message < ActiveRecord::Base
# Description
def act_as_forge_activity
# 如果project为空,那么就是课程相关的消息
- if !self.board.project.nil? && self.parent_id.nil?
+ if self.board.project_id != -1 && self.parent_id.nil?
self.forge_acts << ForgeActivity.new(:user_id => self.author_id,
:project_id => self.board.project.id)
end
@@ -227,7 +233,7 @@ class Message < ActiveRecord::Base
end
end
end
- else # 项目相关
+ elsif self.project # 项目相关
if self.parent_id.nil? # 主贴
self.project.members.each do |m|
if m.user_id != self.author_id
@@ -312,4 +318,8 @@ class Message < ActiveRecord::Base
end
end
end
+
+ def delete_org_activities
+ OrgActivity.where("org_act_type='Message' and org_act_id =#{self.id} and container_type='OrgSubfield'").destroy_all
+ end
end
diff --git a/app/models/org_subfield.rb b/app/models/org_subfield.rb
index 6a31203b0..0747114ca 100644
--- a/app/models/org_subfield.rb
+++ b/app/models/org_subfield.rb
@@ -4,7 +4,22 @@ class OrgSubfield < ActiveRecord::Base
has_many :files
has_many :org_subfield_messages, :dependent => :destroy
has_many :messages, :through => :org_subfield_messages
+ has_many :boards, :dependent => :destroy
acts_as_attachable
+ after_create :create_board_sync
+ # 创建资源栏目讨论区
+ def create_board_sync
+ @board = self.boards.build
+ #self.name=" #{l(:label_borad_course) }"
+ @board.name = " #{l(:label_borad_org_subfield) }"#self.name
+ @board.description = self.name.to_s
+ @board.project_id = -1
+ if @board.save
+ logger.debug "[OrgSubfield Model] ===> #{@board.to_json}"
+ else
+ logger.error "[OrgSubfield Model] ===> Auto create board when org_subfield saved, because #{@board.full_messages}"
+ end
+ end
def project
end
diff --git a/app/models/organization.rb b/app/models/organization.rb
index 350dc3080..fcb777fb6 100644
--- a/app/models/organization.rb
+++ b/app/models/organization.rb
@@ -9,9 +9,15 @@ class Organization < ActiveRecord::Base
has_many :org_subfields, :dependent => :destroy
has_many :users, :through => :org_members
validates_uniqueness_of :name
- after_create :save_as_org_activity
+ after_create :save_as_org_activity, :add_default_subfields
def save_as_org_activity
OrgActivity.create(:user_id => User.current.id, :org_act_id => self.id, :org_act_type => 'CreateOrganization', :container_id => self.id, :container_type => 'Organization')
end
+
+ def add_default_subfields
+ OrgSubfield.create(:organization_id => self.id, :name => 'activity', :field_type => 'default')
+ OrgSubfield.create(:organization_id => self.id, :name => 'course', :field_type => 'default')
+ OrgSubfield.create(:organization_id => self.id, :name => 'project', :field_type => 'default')
+ end
end
diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb
index 5d60238bf..aabe1a921 100644
--- a/app/services/courses_service.rb
+++ b/app/services/courses_service.rb
@@ -196,6 +196,8 @@ class CoursesService
@course.tea_id = current_user.id
@course.term = params[:term]
@course.time = params[:time]
+ @course.end_term = params[:end_term]
+ @course.end_time = params[:end_time]
#@course.school_id = params[:occupation]
@course.school_id = current_user.user_extensions.school_id
@course.setup_time = params[:setup_time]
diff --git a/app/views/attachments/_show_attachment_history.html.erb b/app/views/attachments/_show_attachment_history.html.erb
new file mode 100644
index 000000000..c1a6464e8
--- /dev/null
+++ b/app/views/attachments/_show_attachment_history.html.erb
@@ -0,0 +1,54 @@
+
+更新资源版本
+
+
共有 <%= @all_attachments.count%> 个资源
++ <% if @order == "asc" %> + 按 <%= link_to "时间",params.merge(:sort=>"created_on:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: @sort,order:@order,current:"created_on"} %> / + <%= link_to "下载次数",params.merge(:sort=>"downloads:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: @sort,order:@order,current:"downloads"} %> / + <%= link_to "引用次数",params.merge(:sort=>"quotes:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: @sort,order:@order,current:"quotes"} %> 排序 + <% else %> + 按 <%= link_to "时间",params.merge(:sort=>"created_on:asc"),:class => "f_b c_grey" ,:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: @sort,order:@order,current:"created_on"} %> / + <%= link_to "下载次数",params.merge(:sort=>"downloads:asc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: @sort,order:@order,current:"downloads"} %> / + <%= link_to "引用次数",params.merge(:sort=>"quotes:asc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: @sort,order:@order,current:"quotes"} %> 排序 + <% end %>
- <% end %> -共有 <%= all_attachments.count%> 个资源
-- <% if order == "asc" %> - 按 <%= link_to "时间",params.merge(:sort=>"created_on:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: sort,order:order,current:"created_on"} %> / - <%= link_to "下载次数",params.merge(:sort=>"downloads:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: sort,order:order,current:"downloads"} %> / - <%= link_to "引用次数",params.merge(:sort=>"quotes:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: sort,order:order,current:"quotes"} %> 排序 - <% else %> - 按 <%= link_to "时间",params.merge(:sort=>"created_on:asc"),:class => "f_b c_grey" ,:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: sort,order:order,current:"created_on"} %> / - <%= link_to "下载次数",params.merge(:sort=>"downloads:asc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: sort,order:order,current:"downloads"} %> / - <%= link_to "引用次数",params.merge(:sort=>"quotes:asc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: sort,order:order,current:"quotes"} %> 排序 - <% end %> -
-文件大小:<%= number_to_human_size(file.filesize) %>
+下载<%= file.downloads%> | 引用<%= file.quotes.nil? ? 0:file.quotes %>
+文件大小:<%= number_to_human_size(file.filesize) %>
- <%= link_to( l(:button_delete), attachment_path(file), - :data => {:confirm => l(:text_are_you_sure)}, :method => :delete,:class => "f_r re_de") if (delete_allowed || User.current.id == file.author_id) && file.container_id == @course.id && file.container_type == "Course"%> -<%= time_tag(file.created_on).html_safe %><%= l(:label_bids_published_ago) %> | 下载<%= file.downloads %> | 引用<%= file.quotes.nil? ? 0:file.quotes %>
-