diff --git a/app/assets/javascripts/shield_activities.js.coffee b/app/assets/javascripts/shield_activities.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/shield_activities.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/shield_activities.css.scss b/app/assets/stylesheets/shield_activities.css.scss new file mode 100644 index 000000000..9ac6bff3e --- /dev/null +++ b/app/assets/stylesheets/shield_activities.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the shield_activities controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/at_controller.rb b/app/controllers/at_controller.rb index 8c551d0df..9e7309646 100644 --- a/app/controllers/at_controller.rb +++ b/app/controllers/at_controller.rb @@ -7,10 +7,14 @@ class AtController < ApplicationController @logger = Logger.new(Rails.root.join('log', 'at.log').to_s) users = find_at_users(params[:type], params[:id]) @users = users - @users = users.uniq { |u| u.id }.delete_if { |u| u.id == User.current.id } if users + @users = users.uniq { |u| u.id }.delete_if { |u| u.id == User.current.id }.sort{|x,y| to_pinyin(x.show_name) <=> to_pinyin(y.show_name)} if users end private + def to_pinyin(s) + Pinyin.t(s).downcase + end + def find_at_users(type, id) @logger.info("#{type}, #{id}") case type diff --git a/app/controllers/blog_comments_controller.rb b/app/controllers/blog_comments_controller.rb index 7c09e2cdf..ae6aff794 100644 --- a/app/controllers/blog_comments_controller.rb +++ b/app/controllers/blog_comments_controller.rb @@ -52,7 +52,11 @@ class BlogCommentsController < ApplicationController render_attachment_warning_if_needed(@article) else end - redirect_to user_blog_blog_comment_path(:user_id=>params[:user_id],:blog_id=>params[:blog_id],:id=>params[:id]) + if params[:is_homepage] + redirect_to user_blogs_path(params[:user_id]) + else + redirect_to user_blog_blog_comment_path(:user_id=>params[:user_id],:blog_id=>params[:blog_id],:id=>params[:id]) + end end def destroy @article = BlogComment.find(params[:id]) diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index 07bf60464..0202224ed 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb @@ -1,5 +1,5 @@ class BlogsController < ApplicationController - before_filter :find_blog,:except => [:index,:create,:new] + before_filter :find_blog,:except => [:index,:create,:new,:set_homepage, :cancel_homepage] before_filter :find_user def index @articls = @user.blog.articles @@ -26,6 +26,18 @@ class BlogsController < ApplicationController def edit end + + def set_homepage + @blog = Blog.find(params[:id]) + @blog.update_attribute(:homepage_id, params[:article_id]) + redirect_to user_blogs_path(params[:user_id]) + end + + def cancel_homepage + @blog = Blog.find(params[:id]) + @blog.update_attribute(:homepage_id, nil) + redirect_to user_blogs_path(params[:user_id]) + end private def find_blog if params[:blog_id] diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 57e365aff..70794fa71 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1,3 +1,4 @@ +#encoding: utf-8 class CoursesController < ApplicationController # layout 'base_courses' include CoursesHelper @@ -38,14 +39,16 @@ class CoursesController < ApplicationController end limit = 15 course_org_ids = OrgCourse.find_by_sql("select distinct organization_id from org_courses where course_id = #{params[:id]}").map(&:organization_id) - if course_org_ids.empty? - @orgs_not_in_course = Organization.where("(is_public or creator_id =?) and name like ?",User.current.id, condition).page((params[:page].to_i || 1)).per(limit) - @org_count = Organization.where("is_public = 1 or creator_id =?", User.current.id).where("name like ?", condition).count - else - course_org_ids = "(" + course_org_ids.join(',') + ")" - @orgs_not_in_course = Organization.where("id not in #{course_org_ids} and (is_public = 1 or creator_id =?) and name like ?", User.current.id, condition).page((params[:page].to_i || 1)).per(limit) - @org_count = Organization.where("id not in #{course_org_ids} and (is_public = 1 or creator_id =?)", User.current.id).where("name like ?", condition).count - end + @orgs_not_in_course = User.current.organizations.where("organizations.id not in (#{course_org_ids.join(',')}) and organizations.name like ?", condition).page(params[:page].to_i || 1).per(limit) + @org_count = User.current.organizations.where("organizations.id not in (#{course_org_ids.join(',')}) and organizations.name like ?", condition).count + # if course_org_ids.empty? + # @orgs_not_in_course = Organization.where("(is_public or creator_id =?) and name like ?",User.current.id, condition).page((params[:page].to_i || 1)).per(limit) + # @org_count = Organization.where("is_public = 1 or creator_id =?", User.current.id).where("name like ?", condition).count + # else + # course_org_ids = "(" + course_org_ids.join(',') + ")" + # @orgs_not_in_course = Organization.where("id not in #{course_org_ids} and (is_public = 1 or creator_id =?) and name like ?", User.current.id, condition).page((params[:page].to_i || 1)).per(limit) + # @org_count = Organization.where("id not in #{course_org_ids} and (is_public = 1 or creator_id =?)", User.current.id).where("name like ?", condition).count + # end # @course_count = Project.course_entities.visible.like(params[:name]).page(params[:page]).count @orgs_page = Paginator.new @org_count, limit,params[:page] @hint_flag = params[:hint_flag] @@ -436,6 +439,73 @@ class CoursesController < ApplicationController def create cs = CoursesService.new @course = cs.create_course(params,User.current)[:course] + if params[:copy_course] + copy_course = Course.find params[:copy_course].to_i + @course.update_attributes(:open_student => copy_course.open_student, :publish_resource => copy_course.publish_resource) + if params[:checkAll] + attachments = copy_course.attachments + attachments.each do |attachment| + attach_copied_obj = attachment.copy + attach_copied_obj.tag_list.add(attachment.tag_list) # tag关联 + attach_copied_obj.container = @course + attach_copied_obj.created_on = Time.now + attach_copied_obj.author_id = User.current.id + attach_copied_obj.copy_from = attachment.copy_from.nil? ? attachment.id : attachment.copy_from + if attach_copied_obj.attachtype == nil + attach_copied_obj.attachtype = 4 + end + attach_copied_obj.save + update_quotes attach_copied_obj + end + elsif params[:course_attachment_type] + copy_attachments = [] + params[:course_attachment_type].each do |type| + case type + when "1" + tag_name = l(:label_courseware) + when "2" + tag_name = l(:label_software) + when "3" + tag_name = l(:label_media) + when "4" + tag_name = l(:label_code) + when "6" + tag_name = "论文" + else + tag_name = "" + end + if tag_name == "" + tag_attachments = copy_course.attachments.select{|attachment| + !attachment.tag_list.include?('课件') && + !attachment.tag_list.include?('软件') && + !attachment.tag_list.include?('媒体') && + !attachment.tag_list.include?('代码') && + !attachment.tag_list.include?('论文') } + else + tag_attachments = copy_course.attachments.select{|attachment| attachment.tag_list.include?(tag_name)} + end + tag_attachments.each do |attach| + next if copy_attachments.include?(attach) + copy_attachments << attach + end + end + unless copy_attachments.blank? + copy_attachments.each do |c_attach| + attach_copied_obj = c_attach.copy + attach_copied_obj.tag_list.add(c_attach.tag_list) # tag关联 + attach_copied_obj.container = @course + attach_copied_obj.created_on = Time.now + attach_copied_obj.author_id = User.current.id + attach_copied_obj.copy_from = c_attach.copy_from.nil? ? c_attach.id : c_attach.copy_from + if attach_copied_obj.attachtype == nil + attach_copied_obj.attachtype = 4 + end + attach_copied_obj.save + update_quotes attach_copied_obj + end + end + end + end if @course respond_to do |format| flash[:notice] = l(:notice_successful_create) @@ -751,6 +821,11 @@ class CoursesController < ApplicationController #param id:已有课程ID def copy_course if @course + @new_course = Course.new + respond_to do |format| + format.js + end +=begin @new_course = Course.new @course.attributes @new_course.tea_id = User.current.id @new_course.created_at = DateTime.now @@ -769,6 +844,7 @@ class CoursesController < ApplicationController @new_course.course_infos << course redirect_to settings_course_url @new_course end +=end else render_404 end @@ -829,6 +905,33 @@ class CoursesController < ApplicationController end private + def update_quotes attachment + if attachment.copy_from + attachments = Attachment.find_by_sql("select * from attachments where copy_from = #{attachment.copy_from} or id = #{attachment.copy_from}") + else + attachments = Attachment.find_by_sql("select * from attachments where copy_from = #{attachment.id} or id = #{attachment.copy_from}") + end + attachment.quotes = get_qute_number attachment + attachment.save + attachments.each do |att| + att.quotes = attachment.quotes + att.save + end + end + + def get_qute_number attachment + if attachment.copy_from + result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.copy_from}") + else + result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.id}") + end + if result.nil? || result.count <= 0 + return 0 + else + return result[0].number + end + end + def allow_join course if course_endTime_timeout? course respond_to do |format| diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 444446ef4..b1e5456c5 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -1,681 +1,709 @@ -class ExerciseController < ApplicationController - layout "base_courses" - - before_filter :find_exercise_and_course, :only => [:create_exercise_question, :edit, :update, :show, :destroy, - :commit_exercise, :commit_answer,:publish_exercise,:republish_exercise, - :show_student_result,:student_exercise_list] - before_filter :find_course, :only => [:index,:new,:create] - include ExerciseHelper - - def index - publish_exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now) - publish_exercises.each do |exercise| - exercise.update_column('exercise_status', 2) - course = exercise.course - course.members.each do |m| - exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 2) - end - end - - if @course.is_public == 0 && !(User.current.member_of_course?(@course)||User.current.admin?) - render_403 - return - end - remove_invalid_exercise(@course) - @is_teacher = User.current.allowed_to?(:as_teacher,@course) - if @is_teacher || User.current.admin? - exercises = @course.exercises.order("created_at asc") - else - exercises = @course.exercises.where("exercise_status <> 1").order("created_at asc") - end - @exercises = paginateHelper exercises,20 #分页 - respond_to do |format| - format.html - end - end - - def show - publish_exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now) - publish_exercises.each do |exercise| - exercise.update_column('exercise_status', 2) - course = exercise.course - course.members.each do |m| - exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 2) - end - end - - unless User.current.member_of_course?(@course) || User.current.admin? - render_403 - return - end - @exercise = Exercise.find params[:id] - @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? - exercise_end = @exercise.end_time > Time.now - if @exercise.time == -1 - @can_edit_excercise = exercise_end - else - @can_edit_excercise = !has_commit_exercise?(@exercise.id,User.current.id)&& exercise_end - end - unless @is_teacher - @exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first - if @exercise_user.nil? - eu = ExerciseUser.create(:user_id => User.current.id, :exercise_id => @exercise.id, :start_at => Time.now, :status => false) - @exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first - end - score = calculate_student_score(@exercise, User.current) - @exercise_user.update_attributes(:score => score) - end - # @percent = get_percent(@exercise,User.current) - @exercise_questions = @exercise.exercise_questions - respond_to do |format| - format.html {render :layout => 'base_courses'} - end - #end - end - - def new - option = { - :exercise_name => "", - :course_id => @course.id, - :exercise_status => 1, - :user_id => User.current.id, - :time => "", - :end_time => "", - :publish_time => "", - :exercise_description => "", - :show_result => 1 - } - @exercise = Exercise.create option - if @exercise - redirect_to edit_exercise_url @exercise.id - end - end - - def create - if params[:exercise] - exercise = Exercise.find(params[:exercise_id]) if params[:exercise_id] - exercise ||= Exercise.new - exercise.exercise_name = params[:exercise][:exercise_name] - exercise.exercise_description = params[:exercise][:exercise_description] - exercise.end_time = Time.at(params[:exercise][:end_time].to_time.to_i + 16*60*60 -1) - exercise.publish_time = params[:exercise][:publish_time] - exercise.user_id = User.current.id - exercise.time = params[:exercise][:time] - exercise.course_id = params[:course_id] - exercise.exercise_status = 1 - if exercise.save - @exercise = exercise - respond_to do |format| - format.js - end - end - end - end - - def edit - respond_to do |format| - format.html{render :layout => 'base_courses'} - end - end - - def update - @exercise.exercise_name = params[:exercise][:exercise_name] - @exercise.exercise_description = params[:exercise][:exercise_description] - @exercise.time = params[:exercise][:time].blank? ? -1 : params[:exercise][:time] - @exercise.end_time = Time.at(params[:exercise][:end_time].to_time.to_i + 16*60*60 -1) - @exercise.publish_time = params[:exercise][:publish_time] - @exercise.show_result = params[:exercise][:show_result].blank? ? 1 : params[:exercise][:show_result] - if @exercise.save - respond_to do |format| - format.js - end - else - render_404 - end - end - - def destroy - @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? - if @exercise && @exercise.destroy - if @is_teacher - exercises = Exercise.where("course_id =?", @course.id) - else - exercises = Exercise.where("course_id =? and exercise_status =?", @course.id, 2) - end - @exercises = paginateHelper exercises,20 #分页 - respond_to do |format| - format.js - end - end - end - - # 统计结果 - def statistics_result - @exercise = Exercise.find(params[:id]) - exercise_questions = @exercise.exercise_questions - @exercise_questions = paginateHelper exercise_questions, 5 - respond_to do |format| - format.html{render :layout => 'base_courses'} - end - end - - # 添加题目 - # question_type 1:单选 2:多选 3:填空题 - def create_exercise_question - question_title = params[:question_title].nil? || params[:question_title].empty? ? l(:label_enter_single_title) : params[:question_title] - option = { - :question_title => question_title, - :question_type => params[:question_type] || 1, - :question_number => params[:question_type] == "1"? @exercise.exercise_questions.where("question_type = 1").count + 1 : - (params[:question_type] == "2" ? (@exercise.exercise_questions.where("question_type = 2").count + 1) : - @exercise.exercise_questions.where("question_type = 3").count + 1), - :question_score => params[:question_score] - } - @exercise_questions = @exercise.exercise_questions.new option - # params[:question_answer] 题目选项 - if params[:question_answer] - for i in 1..params[:question_answer].count - answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1] - question_option = { - :choice_position => i, - :choice_text => answer - } - @exercise_questions.exercise_choices.new question_option - end - end - # 如果是插入的话,那么从插入的这个id以后的question_num都将要+1 - if params[:quest_id] - @is_insert = true - if @exercise_questions.question_type == 1 - ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 1).update_all(" question_number = question_number + 1") - #@exercise.exercise_questions.where("question_number > #{params[:quest_num].to_i} and question_type == 1").update_all(" question_number = question_number + 1") - elsif @exercise_questions.question_type == 2 - ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 2).update_all(" question_number = question_number + 1") - else - ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 3).update_all(" question_number = question_number + 1") - end - # @exercise_question_num = params[:quest_num].to_i - @exercise_questions.question_number = params[:quest_num].to_i + 1 - end - if @exercise_questions.save - # params[:exercise_choice] 标准答案参数 - # 问答题标准答案有三个,单独处理 - if @exercise_questions.question_type == 3 - for i in 1..params[:exercise_choice].count - standart_answer = ExerciseStandardAnswer.new - standart_answer.exercise_question_id = @exercise_questions.id - standart_answer.answer_text = params[:exercise_choice].values[i-1] - standart_answer.save - end - else - standart_answer = ExerciseStandardAnswer.new - standart_answer.exercise_question_id = @exercise_questions.id - if @exercise_questions.question_type == 1 - standart_answer.exercise_choice_id = sigle_selection_standard_answer(params[:exercise_choice]) - else - standart_answer.exercise_choice_id = multiselect_standard_answer(params[:exercise_choice]) - end - standart_answer.save - end - respond_to do |format| - format.js - end - end - - end - - # 修改题目 - # params[:exercise_question] The id of exercise_question - # params[:question_answer] eg:A、B、C选项 - def update_exercise_question - @exercise_question = ExerciseQuestion.find params[:exercise_question] - @exercise_question.question_title = params[:question_title].nil? || params[:question_title].empty? ? l(:label_enter_single_title) : params[:question_title] - @exercise_question.question_score = params[:question_score] - # 处理选项:如果选了某个选项,那么则要删除之前的选项 - if params[:question_answer] - @exercise_question.exercise_choices.each do |answer| - answer.destroy unless params[:question_answer].keys.include? answer.id.to_s - end - for i in 1..params[:question_answer].count - question = @exercise_question.exercise_choices.find_by_id params[:question_answer].keys[i-1] - answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1] - if question - question.choice_position = i - question.choice_text = answer - question.save - else - question_option = { - :choice_position => i, - :choice_text => answer - } - @exercise_question.exercise_choices.new question_option - end - end - end - # 更新标准答案 - if params[:exercise_choice] - if @exercise_question.question_type == 3 - # 删除不合理的选项 - @exercise_question.exercise_standard_answers.each do |answer| - answer.destroy unless params[:exercise_choice].keys.include? answer.id.to_s - end - for i in 1..params[:exercise_choice].count - # 找到对应的标准答案 - question_standart = @exercise_question.exercise_standard_answers.find_by_id params[:exercise_choice].keys[i-1] - # 标准答案值 - answer_standart = (params[:exercise_choice].values[i-1].nil? || params[:exercise_choice].values[i-1].empty?) ? l(:label_new_answer) : params[:exercise_choice].values[i-1] - if question_standart - question_standart.answer_text = answer_standart - question_standart.save - else - standart_answer_option = { - :answer_text => answer_standart - } - @exercise_question.exercise_standard_answers.new standart_answer_option - end - end - else - answer_standart = @exercise_question.exercise_standard_answers.first - answer_standart.exercise_choice_id = @exercise_question.question_type == 1 ? sigle_selection_standard_answer(params[:exercise_choice]) : multiselect_standard_answer(params[:exercise_choice]) - answer_standart.save - end - @exercise_question.save - respond_to do |format| - format.js - end - end - end - - # 删除题目 - def delete_exercise_question - @exercise_question = ExerciseQuestion.find params[:exercise_question] - @exercise = @exercise_question.exercise - - if @exercise_question.question_type == 1 - ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 1).update_all(" question_number = question_number - 1") - #@exercise.exercise_questions.where("question_number > #{params[:quest_num].to_i} and question_type == 1").update_all(" question_number = question_number + 1") - elsif @exercise_question.question_type == 2 - ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 2).update_all(" question_number = question_number - 1") - else - ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 3).update_all(" question_number = question_number - 1") - end - # @exercise_question_num = params[:quest_num].to_i - # @exercise_questions.question_number = params[:quest_num].to_i - 1 - # - # exercise_questions = @exercise.exercise_questions.where("question_number > #{@exercise_question.question_number}") - # exercise_questions.each do |question| - # question.question_number -= 1 - # question.save - # end - if @exercise_question && @exercise_question.destroy - respond_to do |format| - format.js - end - end - end - - # 发布试卷 - def publish_exercise - @is_teacher = User.current.allowed_to?(:as_teacher,@course) - @index = params[:index] - @exercise.exercise_status = 2 - @exercise.publish_time = Time.now - if @exercise.save - @exercise.course.members.each do |m| - @exercise.course_messages << CourseMessage.create(:user_id =>m.user_id, :course_id => @exercise.course.id, :viewed => false,:status=>2) - end - #redirect_to exercise_index_url(:course_id=> @course.id) - respond_to do |format| - format.js - end - end - end - - # 重新发布试卷 - # 重新发布的时候会删除所有的答题 - def republish_exercise - @is_teacher = User.current.allowed_to?(:as_teacher,@course) - @index = params[:index] - @exercise.exercise_questions.each do |exercise_question| - exercise_question.exercise_answers.destroy_all - end - @exercise.course_messages.destroy_all - @exercise.exercise_users.destroy_all - @exercise.exercise_status = 1 - @exercise.publish_time = nil - @exercise.save - respond_to do |format| - format.js - end - end - - def student_exercise_list -=begin - if @exercise.end_time <= Time.now - @course.student.each do |student| - if ExerciseUser.where("user_id = ? && exercise_id = ?",student.student_id,@exercise.id).empty? - ExerciseUser.create(:user_id => student.student_id, :exercise_id => @exercise.id, :start_at => @exercise.end_time, :status => true,:score=>0) - end - - s_score = calculate_student_score(@exercise, student.student) - exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", student.student_id, @exercise.id).first - exercise_user.update_attributes(:score => s_score) - end - end -=end - @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? - @all_exercises = @course.exercises.where("exercise_status > 1").order("created_at desc") - @exercise_count = @exercise.exercise_users.where('score is not NULL').count - if @is_teacher || (!@exercise.exercise_users.where(:user_id => User.current.id).empty? && @exercise.end_time <= Time.now) - @exercise_users_list = @exercise.exercise_users.where('score is not NULL') - @show_all = true; - elsif !@exercise.exercise_users.where(:user_id => User.current.id).empty? && @exercise.end_time > Time.now - @exercise_users_list = @exercise.exercise_users.where("user_id = ? and score is not NULL",User.current.id) - else - @exercise_users_list = [] - end - respond_to do |format| - format.html - end - end - - # 学生提交答卷,选中答案的过程中提交 - def commit_answer - eq = ExerciseQuestion.find(params[:exercise_question_id]) - # 已提交过的且是限时的则不允许答题 - if (has_commit_exercise?(@exercise.id,User.current.id) && (!User.current.admin?) && @exercise.time != -1) || @exercise.end_time < Time.now - render :json => {:text => "failure"} - return - end - if eq.question_type == 1 - # 单选题 - ea = ExerciseAnswer.find_by_exercise_question_id_and_user_id(params[:exercise_question_id],User.current.id) - if ea.nil? - # 尚未答该题,添加答案 - ea = ExerciseAnswer.new - ea.user_id = User.current.id - ea.exercise_question_id = params[:exercise_question_id] - end - #修改该题对应答案 - ea.exercise_choice_id = params[:exercise_choice_id] - if ea.save - # 保存成功返回成功信息及当前以答题百分比 - uncomplete_question = get_uncomplete_question(@exercise, User.current) - if uncomplete_question.count < 1 - complete = 1; - else - complete = 0; - end - @percent = get_percent(@exercise,User.current) - render :json => {:text => "ok" ,:complete => complete,:percent => format("%.2f" ,@percent)} - else - #返回失败信息 - render :json => {:text => "failure"} - end - elsif eq.question_type == 2 - #多选题 - ea = ExerciseAnswer.find_by_exercise_choice_id_and_user_id(params[:exercise_choice_id],User.current.id) - if ea.nil? - #尚未答该题,添加答案 - ea = ExerciseAnswer.new - ea.user_id = User.current.id - ea.exercise_question_id = params[:exercise_question_id] - ea.exercise_choice_id = params[:exercise_choice_id] - if ea.save - uncomplete_question = get_uncomplete_question(@exercise, User.current) - if uncomplete_question.count < 1 - complete = 1; - else - complete = 0; - end - @percent = get_percent(@exercise,User.current) - render :json => {:text => "ok",:complete => complete,:percent => format("%.2f" ,@percent)} - else - render :json => {:text => "failure"} - end - else - #pv不为空,则当前选项之前已被选择,再次点击则是不再选择该项,故删除该答案 - if ea.delete - @percent = get_percent(@exercise, User.current) - render :json => {:text => "false" ,:percent => format("%.2f" , @percent)} - else - render :json => {:text => "failure"} - end - end - elsif eq.question_type == 3 - #单行文本,多行文本题 - ea = ExerciseAnswer.find_by_exercise_question_id_and_user_id(params[:exercise_question_id], User.current.id) - if ea.nil? - # ea为空之前尚未答题,添加答案 - if params[:answer_text].nil? || params[:answer_text].blank? - #用户提交空答案,视作不作答 - @percent = get_percent(@exercise,User.current) - render :json => {:text => "",:percent => format("%.2f", @percent)} - else - #添加答案 - ea = ExerciseAnswer.new - ea.user_id = User.current.id - ea.exercise_question_id = params[:exercise_question_id] - ea.answer_text = params[:answer_text] - if ea.save - uncomplete_question = get_uncomplete_question(@exercise, User.current) - if uncomplete_question.count < 1 - complete = 1; - else - complete = 0; - end - @percent = get_percent(@exercise,User.current) - render :json => {:text => ea.answer_text,:complete => complete,:percent => format("%.2f",@percent)} - else - render :json => {:text => "failure"} - end - end - else - # ea不为空说明用户之前已作答 - if params[:answer_text].nil? || params[:answer_text].blank? - # 用户提交空答案,视为删除答案 - if ea.delete - @percent = get_percent(@exercise,User.current) - render :json => {:text => "",:percent => format("%.2f", @percent)} - else - render :json => {:text => "failure"} - end - else - #用户修改答案 - ea.answer_text = params[:answer_text] - if ea.save - @percent = get_percent(@exercise,User.current) - render :json => {:text => ea.answer_text,:percent => format("%.2f", @percent)} - else - render :json => {:text => "failure"} - end - end - end - - else - render :json => {:text => "failure"} - end - end - - # 提交问卷 - def commit_exercise - # 老师不需要提交 - if User.current.allowed_to?(:as_teacher,@course) - if @exercise.publish_time.nil? - @exercise.update_attributes(:show_result => params[:show_result]) - @exercise.update_attributes(:exercise_status => 2) - @exercise.update_attributes(:publish_time => Time.now) - course = @exercise.course - course.members.each do |m| - @exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 2) - end - redirect_to exercise_url(@exercise) - return - elsif @exercise.publish_time > Time.now - @exercise.update_attributes(:show_result => params[:show_result]) - redirect_to exercise_url(@exercise) - return - end - @exercise.update_attributes(:show_result => params[:show_result]) - redirect_to exercise_url(@exercise) - # REDO: 提示提交成功 - else - # 更新提交状态 - cur_exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", User.current, @exercise.id).first - cur_exercise_user.update_attributes(:status => 1) - # 答题过程中需要统计完成量 - @uncomplete_question = get_uncomplete_question(@exercise, User.current) - # 获取改学生的考试得分 - @score = calculate_student_score(@exercise, User.current) - # @score = 100 - if @uncomplete_question.count < 1 - # 查看是否有已提交记录 - cur_exercise_user.score = @score - if cur_exercise_user.save - #redirect_to poll_index_path(:polls_group_id => @course.id,:polls_type => 'Course') - @status = 0 #提交成功 - else - @status = 2 #未知错误 - end - else - @status = 1 #有未做得必答题 - end - @save = params[:save].to_i if params[:save] - respond_to do |format| - format.js - end - end - end - - #查看学生的答卷情况 - def show_student_result - @user = User.find params[:user_id] - @can_edit_excercise = false - @exercise_questions = @exercise.exercise_questions - score = calculate_student_score(@exercise, @user) - eu = get_exercise_user(@exercise.id, @user.id) - eu.update_attributes(:score => score) - @exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", @user.id, @exercise.id).first - respond_to do |format| - format.html {render :layout => 'base_courses'} - end - end - - # 计算学生得分 - def calculate_student_score(exercise, user) - score = 0 - score1 = 0 - score2 = 0 - score3 = 0 - exercise_qustions = exercise.exercise_questions - exercise_qustions.each do |question| - answer = get_user_answer(question, user) - standard_answer = get_user_standard_answer(question, user) - unless answer.empty? - # 问答题有多个答案 - if question.question_type == 3 && !standard_answer.empty? - if standard_answer.include?(answer.first.answer_text) - score1 = score1+ question.question_score unless question.question_score.nil? - end - elsif question.question_type == 1 && !standard_answer.nil? - if answer.first.exercise_choice.choice_position == standard_answer.exercise_choice_id - score2 = score2 + question.question_score unless question.question_score.nil? - end - elsif question.question_type == 2 && !standard_answer.nil? - arr = get_mulscore(question, user) - if arr.to_i == standard_answer.exercise_choice_id - score3 = score3 + question.question_score unless question.question_score.nil? - end - # ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id) - # arr = [] - # ecs.each do |ec| - # arr << ec.exercise_choice.choice_position - # end - # arr.sort - # arr = arr.join("") - # if arr.to_i == standard_answer.exercise_choice_id - # score3 = score + question.question_score unless question.question_score.nil? - # end - end - end - end - score = score1 + score2 + score3 - end - - private - - # ExerciseUser记录用户是否已提交问卷有对应的记录则已提交,没有则新建一个 - def get_exercise_user exercise_id,user_id - eu = ExerciseUser.find_by_exercise_id_and_user_id(exercise_id,user_id) - if eu.nil? - eu = ExerciseUser.new - end - eu - end - - # 获取当前学生回答问题的答案 - def get_user_answer(question,user) - # user_answer = ExerciseAnswer.where("user_id=? and exercise_question_id=?", user.id, question.id).first - user_answer = question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{user.id}") - user_answer - end - - # 获取问题的标准答案 - def get_user_standard_answer(question,user) - if question.question_type == 3 - standard_answer =[] - question.exercise_standard_answers.each do |answer| - standard_answer << answer.answer_text - end - else - standard_answer = question.exercise_standard_answers.first - end - standard_answer - end - # 是否完成了答题 - def get_complete_question(exercise,user) - questions = exercise.exercise_questions - complete_question = [] - questions.each do |question| - answers = get_user_answer(question,user) - if !(answers.nil? || answers.count < 1) - complete_question << question - end - end - complete_question - end - - # 获取答题百分比 - def get_percent exercise,user - complete_count = get_complete_question(exercise,user).count - if exercise.exercise_questions.count == 0 - return 0 - else - return (complete_count.to_f / exercise.exercise_questions.count.to_f)*100 - end - end - - def remove_invalid_exercise(course) - exercises = course.exercises.where("exercise_name=?","") - unless exercises.empty? - exercises.each do |exercise| - if exercise.exercise_questions.empty? - exercise.destroy - end - end - end - end - - def find_exercise_and_course - @exercise = Exercise.find params[:id] - @course = Course.find @exercise.course_id - rescue Exception => e - render_404 - end - - def find_course - @course = Course.find params[:course_id] - rescue Exception => e - render_404 - end +class ExerciseController < ApplicationController + layout "base_courses" + + before_filter :find_exercise_and_course, :only => [:create_exercise_question, :edit, :update, :show, :destroy, + :commit_exercise, :commit_answer,:publish_exercise,:republish_exercise, + :show_student_result,:student_exercise_list] + before_filter :find_course, :only => [:index,:new,:create] + include ExerciseHelper + + def index + publish_exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now) + publish_exercises.each do |exercise| + exercise.update_column('exercise_status', 2) + course = exercise.course + course.members.each do |m| + exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 2) + end + end + + if @course.is_public == 0 && !(User.current.member_of_course?(@course)||User.current.admin?) + render_403 + return + end + remove_invalid_exercise(@course) + @is_teacher = User.current.allowed_to?(:as_teacher,@course) + if @is_teacher || User.current.admin? + exercises = @course.exercises.order("created_at asc") + else + exercises = @course.exercises.where("exercise_status <> 1").order("created_at asc") + end + @exercises = paginateHelper exercises,20 #分页 + respond_to do |format| + format.html + end + end + + def show + publish_exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now) + publish_exercises.each do |exercise| + exercise.update_column('exercise_status', 2) + course = exercise.course + course.members.each do |m| + exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 2) + end + end + + unless User.current.member_of_course?(@course) || User.current.admin? + render_403 + return + end + @exercise = Exercise.find params[:id] + @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? + exercise_end = @exercise.end_time > Time.now + if @exercise.time == -1 + @can_edit_excercise = exercise_end + else + @can_edit_excercise = !has_commit_exercise?(@exercise.id,User.current.id)&& exercise_end + end + unless @is_teacher + @exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first + if @exercise_user.nil? + eu = ExerciseUser.create(:user_id => User.current.id, :exercise_id => @exercise.id, :start_at => Time.now, :status => false) + @exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first + end + score = calculate_student_score(@exercise, User.current) + @exercise_user.update_attributes(:score => score) + end + # @percent = get_percent(@exercise,User.current) + @exercise_questions = @exercise.exercise_questions + respond_to do |format| + format.html {render :layout => 'base_courses'} + end + #end + end + + def new + option = { + :exercise_name => "", + :course_id => @course.id, + :exercise_status => 1, + :user_id => User.current.id, + :time => "", + :end_time => "", + :publish_time => "", + :exercise_description => "", + :show_result => 1 + } + @exercise = Exercise.create option + if @exercise + redirect_to edit_exercise_url @exercise.id + end + end + + def create + if params[:exercise] + exercise = Exercise.find(params[:exercise_id]) if params[:exercise_id] + exercise ||= Exercise.new + exercise.exercise_name = params[:exercise][:exercise_name] + exercise.exercise_description = params[:exercise][:exercise_description] + exercise.end_time = Time.at(params[:exercise][:end_time].to_time.to_i + 16*60*60 -1) + exercise.publish_time = params[:exercise][:publish_time] + exercise.user_id = User.current.id + exercise.time = params[:exercise][:time] + exercise.course_id = params[:course_id] + exercise.exercise_status = 1 + if exercise.save + @exercise = exercise + respond_to do |format| + format.js + end + end + end + end + + def edit + respond_to do |format| + format.html{render :layout => 'base_courses'} + end + end + + def update + @exercise.exercise_name = params[:exercise][:exercise_name] + @exercise.exercise_description = params[:exercise][:exercise_description] + @exercise.time = params[:exercise][:time].blank? ? -1 : params[:exercise][:time] + @exercise.end_time = Time.at(params[:exercise][:end_time].to_time.to_i + 16*60*60 -1) + @exercise.publish_time = params[:exercise][:publish_time] + @exercise.show_result = params[:exercise][:show_result].blank? ? 1 : params[:exercise][:show_result] + if @exercise.save + respond_to do |format| + format.js + end + else + render_404 + end + end + + def destroy + @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? + if @exercise && @exercise.destroy + if @is_teacher + exercises = Exercise.where("course_id =?", @course.id) + else + exercises = Exercise.where("course_id =? and exercise_status =?", @course.id, 2) + end + @exercises = paginateHelper exercises,20 #分页 + respond_to do |format| + format.js + end + end + end + + # 统计结果 + def statistics_result + @exercise = Exercise.find(params[:id]) + exercise_questions = @exercise.exercise_questions + @exercise_questions = paginateHelper exercise_questions, 5 + respond_to do |format| + format.html{render :layout => 'base_courses'} + end + end + + # 添加题目 + # question_type 1:单选 2:多选 3:填空题 + def create_exercise_question + question_title = params[:question_title].nil? || params[:question_title].empty? ? l(:label_enter_single_title) : params[:question_title] + option = { + :question_title => question_title, + :question_type => params[:question_type] || 1, + :question_number => params[:question_type] == "1"? @exercise.exercise_questions.where("question_type = 1").count + 1 : + (params[:question_type] == "2" ? (@exercise.exercise_questions.where("question_type = 2").count + 1) : + @exercise.exercise_questions.where("question_type = 3").count + 1), + :question_score => params[:question_score] + } + @exercise_questions = @exercise.exercise_questions.new option + # params[:question_answer] 题目选项 + if params[:question_answer] + for i in 1..params[:question_answer].count + answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1] + question_option = { + :choice_position => i, + :choice_text => answer + } + @exercise_questions.exercise_choices.new question_option + end + end + # 如果是插入的话,那么从插入的这个id以后的question_num都将要+1 + if params[:quest_id] + @is_insert = true + if @exercise_questions.question_type == 1 + ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 1).update_all(" question_number = question_number + 1") + #@exercise.exercise_questions.where("question_number > #{params[:quest_num].to_i} and question_type == 1").update_all(" question_number = question_number + 1") + elsif @exercise_questions.question_type == 2 + ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 2).update_all(" question_number = question_number + 1") + else + ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 3).update_all(" question_number = question_number + 1") + end + # @exercise_question_num = params[:quest_num].to_i + @exercise_questions.question_number = params[:quest_num].to_i + 1 + end + if @exercise_questions.save + # params[:exercise_choice] 标准答案参数 + # 问答题标准答案有三个,单独处理 + if @exercise_questions.question_type == 3 + for i in 1..params[:exercise_choice].count + standart_answer = ExerciseStandardAnswer.new + standart_answer.exercise_question_id = @exercise_questions.id + standart_answer.answer_text = params[:exercise_choice].values[i-1] + standart_answer.save + end + else + standart_answer = ExerciseStandardAnswer.new + standart_answer.exercise_question_id = @exercise_questions.id + if @exercise_questions.question_type == 1 + standart_answer.exercise_choice_id = sigle_selection_standard_answer(params[:exercise_choice]) + else + standart_answer.exercise_choice_id = multiselect_standard_answer(params[:exercise_choice]) + end + standart_answer.save + end + respond_to do |format| + format.js + end + end + + end + + # 修改题目 + # params[:exercise_question] The id of exercise_question + # params[:question_answer] eg:A、B、C选项 + def update_exercise_question + @exercise_question = ExerciseQuestion.find params[:exercise_question] + @exercise_question.question_title = params[:question_title].nil? || params[:question_title].empty? ? l(:label_enter_single_title) : params[:question_title] + @exercise_question.question_score = params[:question_score] + # 处理选项:如果选了某个选项,那么则要删除之前的选项 + if params[:question_answer] + @exercise_question.exercise_choices.each do |answer| + answer.destroy unless params[:question_answer].keys.include? answer.id.to_s + end + for i in 1..params[:question_answer].count + question = @exercise_question.exercise_choices.find_by_id params[:question_answer].keys[i-1] + answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1] + if question + question.choice_position = i + question.choice_text = answer + question.save + else + question_option = { + :choice_position => i, + :choice_text => answer + } + @exercise_question.exercise_choices.new question_option + end + end + end + # 更新标准答案 + if params[:exercise_choice] + if @exercise_question.question_type == 3 + # 删除不合理的选项 + @exercise_question.exercise_standard_answers.each do |answer| + answer.destroy unless params[:exercise_choice].keys.include? answer.id.to_s + end + for i in 1..params[:exercise_choice].count + # 找到对应的标准答案 + question_standart = @exercise_question.exercise_standard_answers.find_by_id params[:exercise_choice].keys[i-1] + # 标准答案值 + answer_standart = (params[:exercise_choice].values[i-1].nil? || params[:exercise_choice].values[i-1].empty?) ? l(:label_new_answer) : params[:exercise_choice].values[i-1] + if question_standart + question_standart.answer_text = answer_standart + question_standart.save + else + standart_answer_option = { + :answer_text => answer_standart + } + @exercise_question.exercise_standard_answers.new standart_answer_option + end + end + else + answer_standart = @exercise_question.exercise_standard_answers.first + answer_standart.exercise_choice_id = @exercise_question.question_type == 1 ? sigle_selection_standard_answer(params[:exercise_choice]) : multiselect_standard_answer(params[:exercise_choice]) + answer_standart.save + end + @exercise_question.save + respond_to do |format| + format.js + end + end + end + + # 删除题目 + def delete_exercise_question + @exercise_question = ExerciseQuestion.find params[:exercise_question] + @exercise = @exercise_question.exercise + + if @exercise_question.question_type == 1 + ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 1).update_all(" question_number = question_number - 1") + #@exercise.exercise_questions.where("question_number > #{params[:quest_num].to_i} and question_type == 1").update_all(" question_number = question_number + 1") + elsif @exercise_question.question_type == 2 + ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 2).update_all(" question_number = question_number - 1") + else + ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 3).update_all(" question_number = question_number - 1") + end + # @exercise_question_num = params[:quest_num].to_i + # @exercise_questions.question_number = params[:quest_num].to_i - 1 + # + # exercise_questions = @exercise.exercise_questions.where("question_number > #{@exercise_question.question_number}") + # exercise_questions.each do |question| + # question.question_number -= 1 + # question.save + # end + if @exercise_question && @exercise_question.destroy + respond_to do |format| + format.js + end + end + end + + # 发布试卷 + def publish_exercise + @is_teacher = User.current.allowed_to?(:as_teacher,@course) + @index = params[:index] + @exercise.exercise_status = 2 + @exercise.publish_time = Time.now + if @exercise.save + @exercise.course.members.each do |m| + @exercise.course_messages << CourseMessage.create(:user_id =>m.user_id, :course_id => @exercise.course.id, :viewed => false,:status=>2) + end + #redirect_to exercise_index_url(:course_id=> @course.id) + respond_to do |format| + format.js + end + end + end + + # 重新发布试卷 + # 重新发布的时候会删除所有的答题 + def republish_exercise + @is_teacher = User.current.allowed_to?(:as_teacher,@course) + @index = params[:index] + @exercise.exercise_questions.each do |exercise_question| + exercise_question.exercise_answers.destroy_all + end + @exercise.course_messages.destroy_all + @exercise.exercise_users.destroy_all + @exercise.exercise_status = 1 + @exercise.publish_time = nil + @exercise.save + respond_to do |format| + format.js + end + end + + def student_exercise_list +=begin + if @exercise.end_time <= Time.now + @course.student.each do |student| + if ExerciseUser.where("user_id = ? && exercise_id = ?",student.student_id,@exercise.id).empty? + ExerciseUser.create(:user_id => student.student_id, :exercise_id => @exercise.id, :start_at => @exercise.end_time, :status => true,:score=>0) + end + + s_score = calculate_student_score(@exercise, student.student) + exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", student.student_id, @exercise.id).first + exercise_user.update_attributes(:score => s_score) + end + end +=end + @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? + @all_exercises = @course.exercises.where("exercise_status > 1").order("created_at desc") + @exercise_count = @exercise.exercise_users.where('score is not NULL').count + if @is_teacher || (!@exercise.exercise_users.where(:user_id => User.current.id).empty? && @exercise.end_time <= Time.now) + @exercise_users_list = @exercise.exercise_users.where('score is not NULL') + @show_all = true; + elsif !@exercise.exercise_users.where(:user_id => User.current.id).empty? && @exercise.end_time > Time.now + @exercise_users_list = @exercise.exercise_users.where("user_id = ? and score is not NULL",User.current.id) + else + @exercise_users_list = [] + end + respond_to do |format| + format.html + format.xls { + filename = "#{@course.teacher.lastname.to_s + @course.teacher.firstname}_#{@course.name}_#{@course.time.to_s + @course.term}_#{@exercise.exercise_name}#{l(:excel_exercise_list)}.xls" + send_data(exercise_to_xls(@exercise_users_list), :type => "text/excel;charset=utf-8; header=present", + :filename => filename_for_content_disposition(filename)) + } + end + end + + # 学生提交答卷,选中答案的过程中提交 + def commit_answer + eq = ExerciseQuestion.find(params[:exercise_question_id]) + # 已提交过的且是限时的则不允许答题 + if (has_commit_exercise?(@exercise.id,User.current.id) && (!User.current.admin?) && @exercise.time != -1) || @exercise.end_time < Time.now + render :json => {:text => "failure"} + return + end + if eq.question_type == 1 + # 单选题 + ea = ExerciseAnswer.find_by_exercise_question_id_and_user_id(params[:exercise_question_id],User.current.id) + if ea.nil? + # 尚未答该题,添加答案 + ea = ExerciseAnswer.new + ea.user_id = User.current.id + ea.exercise_question_id = params[:exercise_question_id] + end + #修改该题对应答案 + ea.exercise_choice_id = params[:exercise_choice_id] + if ea.save + # 保存成功返回成功信息及当前以答题百分比 + uncomplete_question = get_uncomplete_question(@exercise, User.current) + if uncomplete_question.count < 1 + complete = 1; + else + complete = 0; + end + @percent = get_percent(@exercise,User.current) + render :json => {:text => "ok" ,:complete => complete,:percent => format("%.2f" ,@percent)} + else + #返回失败信息 + render :json => {:text => "failure"} + end + elsif eq.question_type == 2 + #多选题 + ea = ExerciseAnswer.find_by_exercise_choice_id_and_user_id(params[:exercise_choice_id],User.current.id) + if ea.nil? + #尚未答该题,添加答案 + ea = ExerciseAnswer.new + ea.user_id = User.current.id + ea.exercise_question_id = params[:exercise_question_id] + ea.exercise_choice_id = params[:exercise_choice_id] + if ea.save + uncomplete_question = get_uncomplete_question(@exercise, User.current) + if uncomplete_question.count < 1 + complete = 1; + else + complete = 0; + end + @percent = get_percent(@exercise,User.current) + render :json => {:text => "ok",:complete => complete,:percent => format("%.2f" ,@percent)} + else + render :json => {:text => "failure"} + end + else + #pv不为空,则当前选项之前已被选择,再次点击则是不再选择该项,故删除该答案 + if ea.delete + @percent = get_percent(@exercise, User.current) + render :json => {:text => "false" ,:percent => format("%.2f" , @percent)} + else + render :json => {:text => "failure"} + end + end + elsif eq.question_type == 3 + #单行文本,多行文本题 + ea = ExerciseAnswer.find_by_exercise_question_id_and_user_id(params[:exercise_question_id], User.current.id) + if ea.nil? + # ea为空之前尚未答题,添加答案 + if params[:answer_text].nil? || params[:answer_text].blank? + #用户提交空答案,视作不作答 + @percent = get_percent(@exercise,User.current) + render :json => {:text => "",:percent => format("%.2f", @percent)} + else + #添加答案 + ea = ExerciseAnswer.new + ea.user_id = User.current.id + ea.exercise_question_id = params[:exercise_question_id] + ea.answer_text = params[:answer_text] + if ea.save + uncomplete_question = get_uncomplete_question(@exercise, User.current) + if uncomplete_question.count < 1 + complete = 1; + else + complete = 0; + end + @percent = get_percent(@exercise,User.current) + render :json => {:text => ea.answer_text,:complete => complete,:percent => format("%.2f",@percent)} + else + render :json => {:text => "failure"} + end + end + else + # ea不为空说明用户之前已作答 + if params[:answer_text].nil? || params[:answer_text].blank? + # 用户提交空答案,视为删除答案 + if ea.delete + @percent = get_percent(@exercise,User.current) + render :json => {:text => "",:percent => format("%.2f", @percent)} + else + render :json => {:text => "failure"} + end + else + #用户修改答案 + ea.answer_text = params[:answer_text] + if ea.save + @percent = get_percent(@exercise,User.current) + render :json => {:text => ea.answer_text,:percent => format("%.2f", @percent)} + else + render :json => {:text => "failure"} + end + end + end + + else + render :json => {:text => "failure"} + end + end + + # 提交问卷 + def commit_exercise + # 老师不需要提交 + if User.current.allowed_to?(:as_teacher,@course) + if @exercise.publish_time.nil? + @exercise.update_attributes(:show_result => params[:show_result]) + @exercise.update_attributes(:exercise_status => 2) + @exercise.update_attributes(:publish_time => Time.now) + course = @exercise.course + course.members.each do |m| + @exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 2) + end + redirect_to exercise_url(@exercise) + return + elsif @exercise.publish_time > Time.now + @exercise.update_attributes(:show_result => params[:show_result]) + redirect_to exercise_url(@exercise) + return + end + @exercise.update_attributes(:show_result => params[:show_result]) + redirect_to exercise_url(@exercise) + # REDO: 提示提交成功 + else + # 更新提交状态 + cur_exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", User.current, @exercise.id).first + cur_exercise_user.update_attributes(:status => 1) + # 答题过程中需要统计完成量 + @uncomplete_question = get_uncomplete_question(@exercise, User.current) + # 获取改学生的考试得分 + @score = calculate_student_score(@exercise, User.current) + # @score = 100 + if @uncomplete_question.count < 1 + # 查看是否有已提交记录 + cur_exercise_user.score = @score + if cur_exercise_user.save + #redirect_to poll_index_path(:polls_group_id => @course.id,:polls_type => 'Course') + @status = 0 #提交成功 + else + @status = 2 #未知错误 + end + else + @status = 1 #有未做得必答题 + end + @save = params[:save].to_i if params[:save] + respond_to do |format| + format.js + end + end + end + + #查看学生的答卷情况 + def show_student_result + @user = User.find params[:user_id] + @can_edit_excercise = false + @exercise_questions = @exercise.exercise_questions + score = calculate_student_score(@exercise, @user) + eu = get_exercise_user(@exercise.id, @user.id) + eu.update_attributes(:score => score) + @exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", @user.id, @exercise.id).first + respond_to do |format| + format.html {render :layout => 'base_courses'} + end + end + + # 计算学生得分 + def calculate_student_score(exercise, user) + score = 0 + score1 = 0 + score2 = 0 + score3 = 0 + exercise_qustions = exercise.exercise_questions + exercise_qustions.each do |question| + answer = get_user_answer(question, user) + standard_answer = get_user_standard_answer(question, user) + unless answer.empty? + # 问答题有多个答案 + if question.question_type == 3 && !standard_answer.empty? + if standard_answer.include?(answer.first.answer_text) + score1 = score1+ question.question_score unless question.question_score.nil? + end + elsif question.question_type == 1 && !standard_answer.nil? + if answer.first.exercise_choice.choice_position == standard_answer.exercise_choice_id + score2 = score2 + question.question_score unless question.question_score.nil? + end + elsif question.question_type == 2 && !standard_answer.nil? + arr = get_mulscore(question, user) + if arr.to_i == standard_answer.exercise_choice_id + score3 = score3 + question.question_score unless question.question_score.nil? + end + # ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id) + # arr = [] + # ecs.each do |ec| + # arr << ec.exercise_choice.choice_position + # end + # arr.sort + # arr = arr.join("") + # if arr.to_i == standard_answer.exercise_choice_id + # score3 = score + question.question_score unless question.question_score.nil? + # end + end + end + end + score = score1 + score2 + score3 + end + + private + #测验列表转换为excel + def exercise_to_xls items + xls_report = StringIO.new + book = Spreadsheet::Workbook.new + sheet1 = book.create_worksheet :name => "exercise" + blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10 + sheet1.row(0).default_format = blue + sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_class),l(:excel_f_score),l(:excel_commit_time)]) + count_row = 1 + items.each do |exercise| + sheet1[count_row,0]=exercise.user.id + sheet1[count_row,1] = exercise.user.lastname.to_s + exercise.user.firstname.to_s + sheet1[count_row,2] = exercise.user.login + sheet1[count_row,3] = exercise.user.user_extensions.student_id + sheet1[count_row,4] = exercise.user.mail + sheet1[count_row,5] = "" + sheet1[count_row,6] = exercise.score + sheet1[count_row,7] = format_time(exercise.created_at) + count_row += 1 + end + book.write xls_report + xls_report.string + end + + # ExerciseUser记录用户是否已提交问卷有对应的记录则已提交,没有则新建一个 + def get_exercise_user exercise_id,user_id + eu = ExerciseUser.find_by_exercise_id_and_user_id(exercise_id,user_id) + if eu.nil? + eu = ExerciseUser.new + end + eu + end + + # 获取当前学生回答问题的答案 + def get_user_answer(question,user) + # user_answer = ExerciseAnswer.where("user_id=? and exercise_question_id=?", user.id, question.id).first + user_answer = question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{user.id}") + user_answer + end + + # 获取问题的标准答案 + def get_user_standard_answer(question,user) + if question.question_type == 3 + standard_answer =[] + question.exercise_standard_answers.each do |answer| + standard_answer << answer.answer_text + end + else + standard_answer = question.exercise_standard_answers.first + end + standard_answer + end + # 是否完成了答题 + def get_complete_question(exercise,user) + questions = exercise.exercise_questions + complete_question = [] + questions.each do |question| + answers = get_user_answer(question,user) + if !(answers.nil? || answers.count < 1) + complete_question << question + end + end + complete_question + end + + # 获取答题百分比 + def get_percent exercise,user + complete_count = get_complete_question(exercise,user).count + if exercise.exercise_questions.count == 0 + return 0 + else + return (complete_count.to_f / exercise.exercise_questions.count.to_f)*100 + end + end + + def remove_invalid_exercise(course) + exercises = course.exercises.where("exercise_name=?","") + unless exercises.empty? + exercises.each do |exercise| + if exercise.exercise_questions.empty? + exercise.destroy + end + end + end + end + + def find_exercise_and_course + @exercise = Exercise.find params[:id] + @course = Course.find @exercise.course_id + rescue Exception => e + render_404 + end + + def find_course + @course = Course.find params[:course_id] + rescue Exception => e + render_404 + end end \ No newline at end of file diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 5cbf1ab2f..c6773ef57 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -24,7 +24,10 @@ 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 => [:create,:getattachtype,:quote_resource_show,:search,:searchone4reload,:search_project,:quote_resource_show_project,:search_tag_attachment,:subfield_upload_file,:search_org_subfield_tag_attachment,:search_tag_attachment,:quote_resource_show_org_subfield,:find_org_subfield_attache,:search_files_in_subfield] + before_filter :authorize, :except => [:create,:getattachtype,:quote_resource_show,:search,:searchone4reload,:search_project,:quote_resource_show_project, + :search_tag_attachment,:subfield_upload_file,:search_org_subfield_tag_attachment, + :search_tag_attachment,:quote_resource_show_org_subfield,:find_org_subfield_attache, + :search_files_in_subfield,:upload_files_menu] helper :sort include SortHelper @@ -99,6 +102,7 @@ class FilesController < ApplicationController @sort = "" @order = "" @is_remote = true + @q = params[:name].strip if params[:sort] order_by = params[:sort].split(":") @sort = order_by[0] @@ -107,24 +111,25 @@ class FilesController < ApplicationController end sort = "#{@sort} #{@order}" end + # show_attachments [@course] begin q = "%#{params[:name].strip}%" #(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank? if params[:insite] if q == "%%" - @result = [] - @searched_attach = paginateHelper @result,10 + @project_attachment_result = [] + @searched_attach = paginateHelper @project_attachment_result, 10 else - @result = find_public_attache q,sort - @result = visable_attachemnts_insite @result,@project - @searched_attach = paginateHelper @result,10 + @project_attachment_result = find_public_attache q,sort + @project_attachment_result = visable_attachemnts_insite @project_attachment_result, @project + @searched_attach = paginateHelper @project_attachment_result, 10 end else - @result = find_project_attache q,@project,sort - @result = visable_attachemnts @result - @searched_attach = paginateHelper @result,10 + @project_attachment_result = find_project_attache q, @project,sort + @project_attachment_result = visable_attachemnts @project_attachment_result + @searched_attach = paginateHelper @project_attachment_result,10 + @tag_list = get_project_tag_list @project end - #rescue Exception => e # #render 'stores' # redirect_to search_course_files_url @@ -200,23 +205,10 @@ class FilesController < ApplicationController 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 - if ids.blank? - resultSet = Attachment.where("attachments.container_type = 'Project' And attachments.container_id = '#{project.id}' AND filename LIKE :like ", like: "%#{keywords}%"). - reorder(sort) + if keywords != "%%" + resultSet = Attachment.where("attachments.container_type = 'Project' And attachments.container_id = '#{project.id}' AND filename LIKE :like ", like: "%#{keywords}%").reorder(sort) else - 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.where("attachments.container_type = 'Project' And attachments.container_id = '#{project.id}' "). reorder(sort) end end @@ -239,11 +231,9 @@ class FilesController < ApplicationController @is_remote = false if params[:project_id] @container_type = 0 - if params[:sort] params[:sort].split(",").each do |sort_type| order_by = sort_type.split(":") - case order_by[0] when "filename" attribute = "filename" @@ -281,25 +271,19 @@ class FilesController < ApplicationController else sort = "#{Attachment.table_name}.created_on desc" end + # @containers = [ Project.includes(:attachments).find(@project.id)] + # @containers += @project.versions.includes(:attachments).all - @containers = [ Project.includes(:attachments).find(@project.id)] - @containers += @project.versions.includes(:attachments).all - - ids = [] - @containers.each do |c| - ids += c.attachments.pluck(:id) - end - @containers = [Struct.new(:attachments).new(Attachment.where('id in (?)',ids).reorder(sort))] + @containers = [ Project.includes(:attachments).reorder(sort).find(@project.id)] show_attachments @containers - respond_to do |format| - format.html - format.js - end + @tag_list = attachment_tag_list @all_attachments + + render :layout => 'base_projects' elsif params[:course_id] @container_type = 1 - + @page = params[:page] ? params[:page].to_i + 1 : 2 if params[:sort] params[:sort].split(",").each do |sort_type| order_by = sort_type.split(":") @@ -440,16 +424,35 @@ class FilesController < ApplicationController if @project @addTag=false if params[:in_project_toolbar] - @in_project_toolbar = params[:in_project_toolbar] + @in_project_toolbar = params[:in_project_toolbar] end - container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id])) - attachments = Attachment.attach_filesex(container, params[:attachments], params[:attachment_type]) - render_attachment_warning_if_needed(container) - + # 发送邮件 + attachments = Attachment.attach_filesex(@project, params[:attachments], params[:attachment_type]) if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added') Mailer.run.attachments_added(attachments[:files]) end - + # end + if params[:project_attachment_type] && params[:project_attachment_type].is_a?(Array) + params[:project_attachment_type].each do |type| + tag_name = get_project_tag_name_by_type_nmuber type + if !attachments.empty? && attachments[:files] && tag_name != "" + attachments[:files].each do |attachment| + attachment.tag_list.add(tag_name) + attachment.save + end + end + end + else + if params[:project_attachment_type] && params[:project_attachment_type] != "6" + tag_name = get_project_tag_name_by_type_nmuber params[:project_attachment_type] + if !attachments.empty? && attachments[:files] && tag_name != "" + attachments[:files].each do |attachment| + attachment.tag_list.add(tag_name) + attachment.save + end + end + end + end # TODO: 临时用 nyan sort_init 'created_on', 'desc' sort_update 'created_on' => "#{Attachment.table_name}.created_on", @@ -457,14 +460,11 @@ class FilesController < ApplicationController 'size' => "#{Attachment.table_name}.filesize", 'downloads' => "#{Attachment.table_name}.downloads" - @containers = [Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)] #modify by Long Jun - @containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort - + @containers = [Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)] show_attachments @containers - + @tag_list = attachment_tag_list @all_attachments @attachtype = 0 @contenttype = 0 - respond_to do |format| format.js format.html { @@ -592,6 +592,25 @@ class FilesController < ApplicationController end end + def get_project_tag_name_by_type_nmuber type + case type + when "1" + tag_name = "软件版本" + when "2" + tag_name = "文档" + when "3" + tag_name = "代码" + when "4" + tag_name = "媒体" + when "5" + tag_name = "论文" + when "6" + tag_name = "其它" + else + tag_name = "" + end + end + def get_tag_name_by_type_number type case type when "1" @@ -743,21 +762,33 @@ class FilesController < ApplicationController end q = "%#{@q.strip}%" - @result = find_course_attache q,@course,sort + if @project + @result = find_project_attache q, @project,sort + else + @result = find_course_attache q,@course,sort + end @result = visable_attachemnts @result 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?('论文') } + if @project + @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?('课件') && + !attachment.tag_list.include?('软件') && + !attachment.tag_list.include?('媒体') && + !attachment.tag_list.include?('代码') && + !attachment.tag_list.include?('论文') } + end 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 - + if @project + @tag_list = get_project_tag_list @project + @result_search_project = @result + else + @tag_list = get_course_tag_list @course + end respond_to do |format| format.js # format.html @@ -793,4 +824,8 @@ class FilesController < ApplicationController def subfield_upload_file @org_subfield = OrgSubfield.find(params[:org_subfield_id]) end + + def upload_files_menu + p 1 + end end diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index c3f926867..91a0bc902 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -137,6 +137,7 @@ class IssuesController < ApplicationController end end # end + @jour_reply = Journal.new @journals = @issue.journals.includes(:user, :details).reorder("#{Journal.table_name}.id ASC").all @journals.each_with_index {|j,i| j.indice = i+1} @journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project) @@ -153,6 +154,7 @@ class IssuesController < ApplicationController @project_base_tag = (params[:project_id] || @issue.project) ? 'base_projects':'base'#by young @available_watchers = (@issue.project.users.sort + @issue.watcher_users).uniq + @journal = Journal.new(:journalized => @issue) respond_to do |format| format.html { @@ -401,6 +403,7 @@ class IssuesController < ApplicationController jour.user_id = User.current.id jour.notes = params[:notes] jour.journalized = @issue + jour.save_attachments(params[:attachments]) jour.save user_activity = UserActivity.where("act_type='Issue' and act_id =#{@issue.id}").first user_activity.updated_at = jour.created_on diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 45256bb1b..18eb25675 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -1,303 +1,319 @@ -# 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 +# 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, :apply_subdomain] + 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 + shield_project_ids = ShieldActivity.where("container_type='Organization' and container_id=#{@organization.id} and shield_type='Project'").map(&:shield_id) + shield_course_ids = ShieldActivity.where("container_type='Organization' and container_id=#{@organization.id} and shield_type='Course'").map(&:shield_id) + project_ids = (@organization.projects.map(&:id)-shield_project_ids) << 0 + course_ids = (@organization.courses.map(&:id)-shield_course_ids) << 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] ? params[:page].to_i : 1 + 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 + def apply_subdomain + @organization = Organization.find(params[:id]) + admins = User.where("admin=1") + admins.each do |admin| + OrgMessage.create(:user_id => admin.id, :organization_id => @organization.id, :message_type => 'ApplySubdomain', :message_id => @organization.id, :sender_id => User.current.id, :viewed => 0, :content => params[:domain]) + end + end + + def agree_apply_subdomain + @organization = Organization.find(params[:organization_id]) + @organization.update_attribute(:domain, params[:org_domain]) + if OrgMessage.where("message_type='AgreeApplySubdomain' and organization_id=#{@organization.id} and content=#{params[:org_domain]}").count == 0 + OrgMessage.create(:user_id => params[:user_id], :organization_id => @organization.id, :message_type => 'AgreeApplySubdomain', :message_id => @organization.id, :sender_id => User.current.id, :viewed => 0, :content => params[:org_domain]) + end + end +end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index ccebdccfa..31c70e92a 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -76,16 +76,17 @@ class ProjectsController < ApplicationController condition = "%#{params[:name].strip}%".gsub(" ","") end limit = 15 - project_org_ids = OrgProject.find_by_sql("select distinct organization_id from org_projects where project_id = #{params[:id]}").map(&:organization_id) - if project_org_ids.empty? - @orgs_not_in_project = Organization.where("(is_public or creator_id =?) = 1 and name like ?",User.current.id, condition).page((params[:page].to_i || 1)).per(limit) - @org_count = Organization.where("is_public = 1 or creator_id =?", User.current.id).where("name like ?", condition).count - else - project_org_ids = "(" + project_org_ids.join(',') + ")" - @orgs_not_in_project = Organization.where("id not in #{project_org_ids} and (is_public = 1 or creator_id =?) and name like ?", User.current.id, condition).page((params[:page].to_i || 1)).per(limit) - @org_count = Organization.where("id not in #{project_org_ids} and (is_public = 1 or creator_id =?)", User.current.id).where("name like ?", condition).count - end - # @project_count = Project.project_entities.visible.like(params[:name]).page(params[:page]).count + project_org_ids = OrgProject.find_by_sql("select distinct organization_id from org_projects where project_id = #{params[:id]}").map(&:organization_id) << 0 + @orgs_not_in_project = User.current.organizations.where("organizations.id not in (#{project_org_ids.join(',')}) and organizations.name like ?", condition).page(params[:page].to_i || 1).per(limit) + @org_count = User.current.organizations.where("organizations.id not in (#{project_org_ids.join(',')}) and organizations.name like '#{condition}'").count + # if project_org_ids.empty? + # @orgs_not_in_project = Organization.where("(is_public or creator_id =?) = 1 and name like ?",User.current.id, condition).page((params[:page].to_i || 1)).per(limit) + # @org_count = Organization.where("is_public = 1 or creator_id =?", User.current.id).where("name like ?", condition).count + # else + # project_org_ids = "(" + project_org_ids.join(',') + ")" + # @orgs_not_in_project = Organization.where("id not in #{project_org_ids} and (is_public = 1 or creator_id =?) and name like ?", User.current.id, condition).page((params[:page].to_i || 1)).per(limit) + # @org_count = Organization.where("id not in #{project_org_ids} and (is_public = 1 or creator_id =?)", User.current.id).where("name like ?", condition).count + # end @orgs_page = Paginator.new @org_count, limit,params[:page] @no_roll_hint = params[:hint_flag] #render :json => {:orgs => @orgs_not_in_project, :count => @org_count}.to_json diff --git a/app/controllers/shield_activities_controller.rb b/app/controllers/shield_activities_controller.rb new file mode 100644 index 000000000..b2d5191b3 --- /dev/null +++ b/app/controllers/shield_activities_controller.rb @@ -0,0 +1,43 @@ +class ShieldActivitiesController < ApplicationController + def create + if params[:org_id] + if params[:project_id] + ShieldActivity.create(:container_type => 'Organization', :container_id => params[:org_id].to_i, :shield_type => 'Project', :shield_id => params[:project_id].to_i) + elsif params[:course_id] + ShieldActivity.create(:container_type => 'Organization', :container_id => params[:org_id].to_i, :shield_type => 'Course', :shield_id => params[:course_id].to_i) + end + elsif params[:user_id] + if params[:project_id] + ShieldActivity.create(:container_type => 'User', :container_id => params[:user_id].to_i, :shield_type => 'Project', :shield_id => params[:project_id].to_i) + elsif params[:course_id] + ShieldActivity.create(:container_type => 'User', :container_id => params[:user_id].to_i, :shield_type => 'Course', :shield_id => params[:course_id].to_i) + end + end + end + + def show_acts + if params[:org_id] + if params[:project_id] + ShieldActivity.where("container_type='Organization' and container_id=#{params[:org_id].to_i} and shield_type='Project' and shield_id=#{params[:project_id]}").each do |act| + act.destroy + end + # ShieldActivity.create(:container_type => 'Organization', :container_id => params[:org_id].to_i, :shield_type => 'Project', :shield_id => params[:project_id].to_i) + elsif params[:course_id] + ShieldActivity.where("container_type='Organization' and container_id=#{params[:org_id].to_i} and shield_type='Course' and shield_id=#{params[:course_id]}").each do |act| + act.destroy + end + end + elsif params[:user_id] + if params[:project_id] + ShieldActivity.where("container_type='User' and container_id=#{params[:user_id].to_i} and shield_type='Project' and shield_id=#{params[:project_id]}").each do |act| + act.destroy + end + # ShieldActivity.create(:container_type => 'Organization', :container_id => params[:org_id].to_i, :shield_type => 'Project', :shield_id => params[:project_id].to_i) + elsif params[:course_id] + ShieldActivity.where("container_type='User' and container_id=#{params[:user_id].to_i} and shield_type='Course' and shield_id=#{params[:course_id]}").each do |act| + act.destroy + end + end + end + end +end diff --git a/app/controllers/system_messages_controller.rb b/app/controllers/system_messages_controller.rb index 684378e8a..df17ca3e2 100644 --- a/app/controllers/system_messages_controller.rb +++ b/app/controllers/system_messages_controller.rb @@ -1,4 +1,5 @@ class SystemMessagesController < ApplicationController + # before_filter :message_author, :only => [:show] # # def message_author @@ -41,6 +42,7 @@ class SystemMessagesController < ApplicationController @system_messages.description = params[:system_message][:description] @system_messages.subject = params[:system_message][:subject] @system_messages.user_id = User.current.id + # @system_messages.save_attachments(params[:attachments]) respond_to do |format| if @system_messages.save format.html {redirect_to user_system_messages_path(User.current)} diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index d40bc7c7c..507dada24 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -228,6 +228,12 @@ class TagsController < ApplicationController @select_tag_name = params[:select_tag_name] end + if @obj && @object_flag == '6' && @obj.container.kind_of?(Project) + @project = @obj.container + @tag_list = get_course_tag_list @project + @select_tag_name = params[:select_tag_name] + end + if @obj && @object_flag == '6' && @obj.container.kind_of?(OrgSubfield) @org_subfield = @obj.container @tag_list = get_org_subfield_tag_list @org_subfield @@ -320,6 +326,88 @@ class TagsController < ApplicationController end end + def update_project_tag_name + @tag_name = params[:tagName] + @rename_tag_name = params[:renameName] + @taggable_id = params[:taggableId] + @taggable_type = numbers_to_object_type(params[:taggableType]) + @project_id = params[:projectId] + + @rename_tag = (ActsAsTaggableOn::Tag.find_by_name(@rename_tag_name)) #查找重命名后的tag + @tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id #重命名前的tag_id + @taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) unless @taggable_id.blank? + @obj = get_object(@taggable_id,params[:taggableType]) unless @taggable_id.blank? + if @taggable_id.blank? #如果没有传tag_id,那么直接更新tag_name就好了。但是要防止 重命名后的tag存在。 + if @project_id + project = Project.find @project_id + if project + project.attachments.each do |attachment| + taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,attachment.id,attachment.class) + if taggings + taggings.delete + attachment.tag_list.add(@rename_tag_name.split(",")) + attachment.save + end + end + end + end + else + if(@rename_tag.nil?) #这次命名的是新的tag + + # 是否还有其他记录 引用了 tag_id + @tagging = ActsAsTaggableOn::Tagging.where("tag_id = #{@tag_id}") + # 如果taggings表中记录为 1 ,那么改变@tag_id对应的tag的名字 + if @tagging.count == 1 + @tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id) + @tag.update_attributes({:name=>@rename_tag_name}) + else #如果tagging表中的记录大于1,那么就要新增tag记录 + + unless @obj.nil? + @obj.tag_list.add(@rename_tag_name.split(",")) + @obj.save + end + #删除原来的对应的taggings的记录 + unless @taggings.nil? + @taggings.delete + end + end + else #这是已有的tag + # 更改taggings记录里的tag_id + unless @taggings.nil? + @taggings.update_attributes({:tag_id=>@rename_tag.id}) + end + end + end + + @obj_flag = params[:taggableType] + if @obj && @obj_flag == '6' && @obj.container.kind_of?(Project) + @project = @obj.container + @tag_list = @tag_list = get_course_tag_list @project + elsif @project_id + @project = Project.find(@project_id) + @tag_list = get_project_tag_list @project + + #这里要引用FilesController里的逻辑了。将资源库当前的文件列表刷新一遍。 + @flag = params[:flag] || false + sort = "" + @sort = "" + @order = "" + @is_remote = false + @isproject = false + + sort = "#{Attachment.table_name}.created_on desc" + + @containers = [ Project.includes(:attachments).reorder(sort).find(@project.id)] + + show_attachments @containers + elsif @obj && @obj_flag == '5' + @forum = @obj + end + respond_to do |format| + format.js + end + end + def update_org_subfield_tag_name @tag_name = params[:tagName] @rename_tag_name = params[:renameName] @@ -458,6 +546,10 @@ class TagsController < ApplicationController @course = @obj.container @tag_list = @tag_list = get_course_tag_list @course end + if @obj && @obj_flag == '6' && @obj.container.kind_of?(Project) + @project = @obj.container + @tag_list = @tag_list = get_project_tag_list @project + end if @obj && @obj_flag == '6' && @obj.container.kind_of?(OrgSubfield) @org_subfield = @obj.container @tag_list = @tag_list = get_org_subfield_tag_list @org_subfield diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index d28837858..449d8b9de 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -55,6 +55,7 @@ class UsersController < ApplicationController before_filter :recorded_visitor, :only => [:show,:user_fanslist,:user_watchlist,:user_visitorlist] helper :sort + helper :attachments include SortHelper helper :custom_fields include CustomFieldsHelper @@ -63,6 +64,7 @@ class UsersController < ApplicationController include GitlabHelper include UserScoreHelper + include PollHelper helper :user_score helper :journals @@ -965,9 +967,11 @@ class UsersController < ApplicationController params[:course_id], 'JoinCourseRequest', User.current.id, @user.id, false) join_course_messages.update_all(:viewed => true) end + shield_project_ids = ShieldActivity.where("container_type='User' and container_id=#{@user.id} and shield_type='Project'").map(&:shield_id) + shield_course_ids = ShieldActivity.where("container_type='User' and container_id=#{@user.id} and shield_type='Course'").map(&:shield_id) @page = params[:page] ? params[:page].to_i + 1 : 0 - user_project_ids = @user.projects.visible.empty? ? "(-1)" : "(" + @user.projects.visible.map{|project| project.id}.join(",") + ")" - user_course_ids = @user.courses.visible.empty? ? "(-1)" : "(" + @user.courses.visible.map{|course| course.id}.join(",") + ")" + user_project_ids = (@user.projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (@user.projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")" + user_course_ids = (@user.courses.visible.map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.courses.visible.map{|course| course.id}-shield_course_ids).join(",") + ")" course_types = "('Message','News','HomeworkCommon','Poll','Course')" project_types = "('Message','Issue','ProjectCreateInfo')" principal_types = "JournalsForMessage" diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index df9fd30f2..79981ec4d 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -236,7 +236,11 @@ class WordsController < ApplicationController if User.current.logged? @user = User.find(params[:id]) if params[:new_form][:user_message].size>0 && User.current.logged? && @user - @user.add_jour(User.current, params[:new_form][:user_message]) + if params[:private] && params[:private] == '1' + @user.journals_for_messages << JournalsForMessage.new(:user_id => User.current.id, :notes => params[:new_form][:user_message], :reply_id => 0, :status => true, :is_readed => false, :private => 1) + else + @user.add_jour(User.current, params[:new_form][:user_message]) + end end redirect_to feedback_path(@user) else diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 55a017019..56ef460a0 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -48,6 +48,7 @@ module ApplicationHelper end end end + # 获取组织成员中文名字 def get_org_member_role_name member case member.roles[0].name @@ -2432,6 +2433,16 @@ module ApplicationHelper tag_list end + # 获取项目资源的Tag云 + def get_project_tag_list project + all_attachments = project.attachments.select{|attachment| attachment.is_public? || + (attachment.container_type == "Project" && User.current.member_of?(project))|| + attachment.author_id == User.current.id + } + tag_list = attachment_tag_list all_attachments + tag_list + end + def get_org_subfield_tag_list org_subfield all_attachments = org_subfield.attachments.select{|attachment| attachment.is_public? || (attachment.container_type == "OrgSubfield" && User.current.member_of_org?(org_subfield.organization))|| @@ -2757,4 +2768,11 @@ int main(int argc, char** argv){ ss.html_safe end + #代码提交数量 + def changesets_num project + g = Gitlab.client + project.gpid.nil? ? 0 : g.commits_total_count(project.gpid).count + # # commits_total_count(project.gpid) + # project.changesets.count + end end diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb index be24629af..3dc2c66af 100644 --- a/app/helpers/attachments_helper.rb +++ b/app/helpers/attachments_helper.rb @@ -96,6 +96,7 @@ module AttachmentsHelper end false end + #判断项目project中是否包含课件attachment,project中引用了attachment也算作包含 def project_contains_attachment? project,attachment project.attachments.each do |att| diff --git a/app/helpers/project_score_helper.rb b/app/helpers/project_score_helper.rb index d73e1592e..133212718 100644 --- a/app/helpers/project_score_helper.rb +++ b/app/helpers/project_score_helper.rb @@ -20,14 +20,6 @@ module ProjectScoreHelper project.documents.count end - #代码提交数量 - def changesets_num project - g = Gitlab.client - project.gpid.nil? ? 0 : g.commits_total_count(project.gpid).count - # # commits_total_count(project.gpid) - # project.changesets.count - end - #讨论区帖子数量 def board_message_num project board_message_count = 0 diff --git a/app/helpers/shield_activities_helper.rb b/app/helpers/shield_activities_helper.rb new file mode 100644 index 000000000..5dcbcca33 --- /dev/null +++ b/app/helpers/shield_activities_helper.rb @@ -0,0 +1,2 @@ +module ShieldActivitiesHelper +end diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb index 2e8b98a2d..8847f4163 100644 --- a/app/helpers/tags_helper.rb +++ b/app/helpers/tags_helper.rb @@ -73,6 +73,16 @@ def course_contains_attachment? course,attachment false end +#判断项目project中是否包含课件attachment,project中引用了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 has_course? user,file result = false diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index d1ab6661a..bfc01a102 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -591,7 +591,7 @@ module UsersHelper option << "请选择发布作业的课程" option << -1 type << option - user.courses.visible.select("courses.*,(SELECT MAX(created_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").select{|c| user.allowed_to?(:as_teacher,c)}.each do |course| + user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(created_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").select{|c| user.allowed_to?(:as_teacher,c)}.each do |course| option = [] option << course.name+"("+course.time.to_s+course.term+")" option << course.id diff --git a/app/models/attachment.rb b/app/models/attachment.rb index c8fe0811e..d90b0368e 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -618,7 +618,7 @@ class Attachment < ActiveRecord::Base end end def update_attachment_ealasticsearch_index - if self.is_public == 1 && ( (self.container_type == 'Project' && Project.find(self.container_id).is_public == 1) || + if self.is_public == 1 && ( ((self.container_type == 'Project' or self.container_type == 'Version') && Project.find(self.container_id).is_public == 1) || ( self.container_type == 'Course' && Course.find(self.container_id).is_public == 1) || self.container_type == 'Principal') begin diff --git a/app/models/journal.rb b/app/models/journal.rb index a66c4327a..e1464a703 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -31,9 +31,8 @@ class Journal < ActiveRecord::Base #has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy 评论不应该算入 # 被ForgeMessage虚拟关联 has_many :forge_messages, :class_name => 'ForgeMessage',:as =>:forge_message ,:dependent => :destroy - has_many :at_messages, as: :at_message, dependent: :destroy - + acts_as_attachable attr_accessor :indice acts_as_event :title =>Proc.new {|o| status = ((s = o.new_status) ? " (#{s})" : nil); "#{o.issue.tracker} ##{o.issue.project_index}#{status}: #{o.issue.subject}" }, @@ -46,8 +45,8 @@ class Journal < ActiveRecord::Base acts_as_activity_provider :type => 'issues', :author_key => :user_id, :find_options => {:include => [{:issue => :project}, :details, :user], - :conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" + - " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"} + :conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" + + "(#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"} before_create :split_private_notes diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 59da817f4..d3e76addc 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -15,8 +15,9 @@ class JournalsForMessage < ActiveRecord::Base "m_parent_id", # 留言信息的父留言id "is_readed", # 留言是否已读 "m_reply_count", # 留言的回复数量 - "m_reply_id" # 回复某留言的留言id(a留言回复了b留言,这是b留言的id) - "is_comprehensive_evaluation" # 1 教师评论、2 匿评、3 留言 + "m_reply_id" , # 回复某留言的留言id(a留言回复了b留言,这是b留言的id) + "is_comprehensive_evaluation", # 1 教师评论、2 匿评、3 留言 + "private" 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, diff --git a/app/models/org_message.rb b/app/models/org_message.rb new file mode 100644 index 000000000..baedc77f4 --- /dev/null +++ b/app/models/org_message.rb @@ -0,0 +1,15 @@ +class OrgMessage < ActiveRecord::Base + belongs_to :user + belongs_to :organization + has_many :message_alls, :as => :message, :dependent => :destroy + validates :message_type, :presence => true + validates :message_id, :presence => true + validates :organization_id, :presence => true + after_create :add_user_message + + def add_user_message + if MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first.nil? + self.message_alls << MessageAll.new(:user_id => self.user_id) + end + end +end \ No newline at end of file diff --git a/app/models/shield_activity.rb b/app/models/shield_activity.rb new file mode 100644 index 000000000..8f8447dcf --- /dev/null +++ b/app/models/shield_activity.rb @@ -0,0 +1,3 @@ +class ShieldActivity < ActiveRecord::Base + +end \ No newline at end of file diff --git a/app/models/system_message.rb b/app/models/system_message.rb index a05610da7..65623c104 100644 --- a/app/models/system_message.rb +++ b/app/models/system_message.rb @@ -7,6 +7,7 @@ class SystemMessage < ActiveRecord::Base validates_length_of :description, maximum: 10000 has_many :message_alls, :class_name => 'MessageAll',:as =>:message, :dependent => :destroy + acts_as_attachable # 系统消息放置总消息列表 after_create :add_system_message diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index aabe1a921..6f2819f53 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -193,6 +193,7 @@ class CoursesService @course.extra = 'course' + DateTime.parse(Time.now.to_s).strftime('%Y-%m-%d_%H-%M-%S').to_s @course.send(:safe_attributes=, params[:course], current_user) #@course.safe_attributes(current_user,params[:course]) + @course.password = params[:course][:password] @course.tea_id = current_user.id @course.term = params[:term] @course.time = params[:time] diff --git a/app/views/admin/messages.html.erb b/app/views/admin/messages.html.erb index e4d053d49..040dd0fe8 100644 --- a/app/views/admin/messages.html.erb +++ b/app/views/admin/messages.html.erb @@ -19,6 +19,7 @@

+
<%= link_to l(:label_submit), "javascript:void(0)", :class => "btn_message_free", :onclick => "system_message_editor.sync();submit_message();" %>
diff --git a/app/views/attachments/_activity_attach.html.erb b/app/views/attachments/_activity_attach.html.erb new file mode 100644 index 000000000..9bd7d9d2f --- /dev/null +++ b/app/views/attachments/_activity_attach.html.erb @@ -0,0 +1,19 @@ +<% if activity.attachments.any? %> + <% activity.attachments.each do |attachment| %> +
+ + + <%= link_to_short_attachment attachment,:length=> 58, :class => 'mw400 hidden link_file_a fl newsBlue', :download => true -%> + + + ( + <%= number_to_human_size attachment.filesize %>) + + + <%= link_to h(truncate(attachment.author.name, length: 10, omission: '...')),user_path(attachment.author),:class => "c_orange" %>, + <%= format_time(attachment.created_on) %> + +
+
+ <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/attachments/_issue_reply.html.erb b/app/views/attachments/_issue_reply.html.erb new file mode 100644 index 000000000..5526b0d17 --- /dev/null +++ b/app/views/attachments/_issue_reply.html.erb @@ -0,0 +1,38 @@ + + <% if defined?(container) && container && container.saved_attachments %> + <% container.attachments.each_with_index do |attachment, i| %> + + <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %> + + <% end %> +<% end %> + + + <% id ="file#{container.id}"%> + 上传附件 + <%= file_field_tag 'attachments[dummy][file]', + :id => "file#{container.id}", + :class => 'file_selector', + :multiple => true, + :onchange => "addInputFiles_board(this, '#{container.id}');", + :style => 'display:none', + :data => { + :max_file_size => Setting.attachment_max_size.to_i.kilobytes, + :max_file_size_message => l(:error_attachment_too_big, :max_size => number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)), + :max_concurrent_uploads => Redmine::Configuration['max_concurrent_ajax_uploads'].to_i, + :upload_path => uploads_path(:format => 'js'), + :description_placeholder => l(:label_optional_description), + :field_is_public => l(:field_is_public), + :are_you_sure => l(:text_are_you_sure), + :file_count => l(:label_file_count), + :delete_all_files => l(:text_are_you_sure_all), + :lebel_file_uploding => l(:lebel_file_uploding)} %> + <% if container.nil? %> + <%= l(:label_no_file_uploaded)%> + <% end %> + +<% content_for :header_tags do %> + <%= javascript_include_tag 'attachments' %> +<% end %> + + diff --git a/app/views/attachments/update_file_dense.js.erb b/app/views/attachments/update_file_dense.js.erb index 747024dec..0a3124e83 100644 --- a/app/views/attachments/update_file_dense.js.erb +++ b/app/views/attachments/update_file_dense.js.erb @@ -1,12 +1,16 @@ <% if @attachment.container_type == 'Course' %> $("#is_public_<%= @attachment.id %>").html("<%= escape_javascript(link_to (@attachment.is_public? ? "设为私有":"设为公开"), update_file_dense_attachments_path(:attachmentid=>@attachment.id,:newtype=>(@attachment.is_public? ? 0:1)), :remote=>true,:class=>"postOptionLink",:method => :post) %>"); -<%else%> +<% elsif @attachment.container_type == 'Project' %> + $("#is_public_<%= @attachment.id %>").html("<%= escape_javascript(link_to (@attachment.is_public? ? "设为私有":"设为公开"), update_file_dense_attachments_path(:attachmentid => @attachment.id, :newtype => (@attachment.is_public? ? 0:1)), + :remote => true, :class => "postOptionLink", :method => :post) %>"); + +<% else %> $("#is_public_<%= @attachment.id %>").html("<%= escape_javascript(link_to (@attachment.is_public? ? "公开":"私有"), update_file_dense_attachments_path(:attachmentid=>@attachment.id,:newtype=>(@attachment.is_public? ? 0:1)), :remote=>true,:class=>"f_l re_open",:method => :post) %>"); -<%end %> -<%if @attachment.is_public? %> +<% end %> +<% if @attachment.is_public? %> $("#image_private_<%= @attachment.id%>").html('') <%else%> $("#image_private_<%= @attachment.id%>").html('私有') -<%end%> \ No newline at end of file +<% end %> \ No newline at end of file diff --git a/app/views/blog_comments/edit.html.erb b/app/views/blog_comments/edit.html.erb index a878063db..43a8aae92 100644 --- a/app/views/blog_comments/edit.html.erb +++ b/app/views/blog_comments/edit.html.erb @@ -1,5 +1,5 @@ <% if User.current.logged? && User.current.id == @user.id %> - <%= form_for @article, :url =>{:controller=>'blog_comments',:action => 'update',:user_id=>@user.id , :blog_id => @article.id},:method=>'PUT', + <%= form_for @article, :url =>{:controller=>'blog_comments',:action => 'update',:user_id=>@user.id , :blog_id => @article.id, :is_homepage => params[:is_homepage]},:method=>'PUT', :html => {:nhname=>'form',:multipart => true, :id => 'message-form'} do |f| %> <%= render :partial => 'blog_comments/edit', :locals => {:f => f, :article => @article, :edit_mode => true, :user => @user} %> <% end %> diff --git a/app/views/blog_comments/reply.js.erb b/app/views/blog_comments/reply.js.erb index fe46d870c..2a4e71f1c 100644 --- a/app/views/blog_comments/reply.js.erb +++ b/app/views/blog_comments/reply.js.erb @@ -5,20 +5,4 @@ $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'blogs/article', :locals => {:activity => @article,:user_activity_id =>@user_activity_id}) %>"); //init_activity_KindEditor_data(<%#= @user_activity_id%>,"","87%", 'UserActivity'); <% end %> -init_activity_KindEditor_data(<%= @user_activity_id%>,"","87%", 'UserActivity'); -showNormalImage('activity_description_<%= @user_activity_id %>'); -if($("#intro_content_<%= @user_activity_id %>").height() > 810) { - $("#intro_content_show_<%= @user_activity_id %>").show(); -} -$("#intro_content_show_<%= @user_activity_id %>").click(function(){ - $("#activity_description_<%= @user_activity_id %>").toggleClass("maxh360"); - $("#activity_description_<%= @user_activity_id%>").toggleClass("lh18"); - $("#intro_content_show_<%= @user_activity_id %>").hide(); - $("#intro_content_hide_<%= @user_activity_id %>").show(); -}); -$("#intro_content_hide_<%= @user_activity_id %>").click(function(){ - $("#activity_description_<%= @user_activity_id %>").toggleClass("maxh360"); - $("#activity_description_<%= @user_activity_id%>").toggleClass("lh18"); - $("#intro_content_hide_<%= @user_activity_id %>").hide(); - $("#intro_content_show_<%= @user_activity_id %>").show(); -}); \ No newline at end of file +init_activity_KindEditor_data(<%= @user_activity_id%>,"","87%", 'UserActivity'); \ No newline at end of file diff --git a/app/views/blog_comments/show.html.erb b/app/views/blog_comments/show.html.erb index aa984c621..02f1ad1ad 100644 --- a/app/views/blog_comments/show.html.erb +++ b/app/views/blog_comments/show.html.erb @@ -58,6 +58,23 @@ :class => 'postOptionLink' ) if User.current && User.current.id == @article.author.id %> +
  • + <% if @article.id == @article.blog.homepage_id %> + <%= link_to( + l(:button_cancel_homepage), + {:controller => 'blogs',:action => 'cancel_homepage',:user_id=>@article.author_id,:id=>@article.blog_id, :article_id => @article.id}, + :method => :post, + :class => 'postOptionLink' + ) if User.current && User.current.id == @article.blog.author_id %> + <% else %> + <%= link_to( + l(:button_set_homepage), + {:controller => 'blogs',:action => 'set_homepage',:user_id=>@article.author_id,:id=>@article.blog_id, :article_id => @article.id}, + :method => :post, + :class => 'postOptionLink' + ) if User.current && User.current.id == @article.blog.author_id %> + <% end %> +
  • diff --git a/app/views/blogs/_article.html.erb b/app/views/blogs/_article.html.erb index 99c743a96..0b813c4a7 100644 --- a/app/views/blogs/_article.html.erb +++ b/app/views/blogs/_article.html.erb @@ -25,6 +25,14 @@ :class => 'postOptionLink' ) if User.current && User.current.id == activity.author.id %> +
  • + <%= link_to( + l(:button_set_homepage), + {:controller => 'blogs',:action => 'set_homepage',:user_id=>activity.author_id,:id=>activity.blog_id, :article_id => activity.id}, + :method => :post, + :class => 'postOptionLink' + ) if User.current && User.current.id == activity.blog.author_id %> +
  • @@ -38,6 +46,9 @@ <% end %> TO <%= link_to activity.blog.name+" | 博客", user_blogs_path(:user_id=>activity.author_id,:host=>Setting.host_user), :class => "newsBlue ml15 mr5"%> + <% if activity.blog.homepage_id and activity.id == activity.blog.homepage_id %> + 已设为首页 + <% end %>
    + + <% if blog.homepage_id and BlogComment.where("id=?", blog.homepage_id).count > 0 %> + <% homepage = BlogComment.find(blog.homepage_id) %> + <%= render :partial => 'blogs/homepage', :locals => {:activity => homepage, :user_activity_id => homepage.id} %> + <% end %> + <% if User.current.logged? && User.current.id == @user.id %> <%= labelled_form_for @article, :url =>{:controller=>'blog_comments',:action => 'create',:user_id=>user.id , :blog_id => blog.id}, :html => {:nhname=>'form',:multipart => true, :id => 'message-form'} do |f| %> @@ -75,22 +81,6 @@ $(function () { init_activity_KindEditor_data(<%= topic.id%>, null, "87%", "<%=topic.class.to_s%>"); - showNormalImage('activity_description_<%= topic.id %>'); - if($("#intro_content_<%= topic.id %>").height() > 810) { - $("#intro_content_show_<%= topic.id %>").show(); - } - $("#intro_content_show_<%= topic.id %>").click(function(){ - $("#activity_description_<%= topic.id %>").toggleClass("maxh360"); - $("#activity_description_<%= topic.id%>").toggleClass("lh18"); - $("#intro_content_show_<%= topic.id %>").hide(); - $("#intro_content_hide_<%= topic.id %>").show(); - }); - $("#intro_content_hide_<%= topic.id %>").click(function(){ - $("#activity_description_<%= topic.id %>").toggleClass("maxh360"); - $("#activity_description_<%= topic.id%>").toggleClass("lh18"); - $("#intro_content_hide_<%= topic.id %>").hide(); - $("#intro_content_show_<%= topic.id %>").show(); - }); }); <% if topic %> diff --git a/app/views/blogs/_homepage.html.erb b/app/views/blogs/_homepage.html.erb new file mode 100644 index 000000000..30e1b69a5 --- /dev/null +++ b/app/views/blogs/_homepage.html.erb @@ -0,0 +1,50 @@ +
    +
    +
    + <% if activity.author.id == User.current.id%> + + <%end%> +
    + +
    + <%= activity.content.to_s.html_safe %> +
    +
    +
    +
    +
    +
    diff --git a/app/views/boards/_course_show_detail.html.erb b/app/views/boards/_course_show_detail.html.erb index 8f50905c6..804f6543e 100644 --- a/app/views/boards/_course_show_detail.html.erb +++ b/app/views/boards/_course_show_detail.html.erb @@ -41,22 +41,6 @@ $(function () { init_activity_KindEditor_data(<%= topic.id%>, null, "87%"); - showNormalImage('activity_description_<%= topic.id %>'); - if($("#intro_content_<%= topic.id %>").height() > 810) { - $("#intro_content_show_<%= topic.id %>").show(); - } - $("#intro_content_show_<%= topic.id %>").click(function(){ - $("#activity_description_<%= topic.id %>").toggleClass("maxh360"); - $("#activity_description_<%= topic.id%>").toggleClass("lh18"); - $("#intro_content_show_<%= topic.id %>").hide(); - $("#intro_content_hide_<%= topic.id %>").show(); - }); - $("#intro_content_hide_<%= topic.id %>").click(function(){ - $("#activity_description_<%= topic.id %>").toggleClass("maxh360"); - $("#activity_description_<%= topic.id%>").toggleClass("lh18"); - $("#intro_content_hide_<%= topic.id %>").hide(); - $("#intro_content_show_<%= topic.id %>").show(); - }); }); <% if topic %> diff --git a/app/views/boards/_project_show_detail.html.erb b/app/views/boards/_project_show_detail.html.erb index 5b266b90c..367f0552c 100644 --- a/app/views/boards/_project_show_detail.html.erb +++ b/app/views/boards/_project_show_detail.html.erb @@ -40,22 +40,6 @@ $(function () { init_activity_KindEditor_data(<%= topic.id%>, null, "87%"); - showNormalImage('activity_description_<%= topic.id %>'); - if($("#intro_content_<%= topic.id %>").height() > 810) { - $("#intro_content_show_<%= topic.id %>").show(); - } - $("#intro_content_show_<%= topic.id %>").click(function(){ - $("#activity_description_<%= topic.id %>").toggleClass("maxh360"); - $("#activity_description_<%= topic.id%>").toggleClass("lh18"); - $("#intro_content_show_<%= topic.id %>").hide(); - $("#intro_content_hide_<%= topic.id %>").show(); - }); - $("#intro_content_hide_<%= topic.id %>").click(function(){ - $("#activity_description_<%= topic.id %>").toggleClass("maxh360"); - $("#activity_description_<%= topic.id%>").toggleClass("lh18"); - $("#intro_content_hide_<%= topic.id %>").hide(); - $("#intro_content_show_<%= topic.id %>").show(); - }); }); <% if topic %> diff --git a/app/views/boards/show.html.erb b/app/views/boards/show.html.erb index 89f43e0d6..9dd5c78ca 100644 --- a/app/views/boards/show.html.erb +++ b/app/views/boards/show.html.erb @@ -1,3 +1,4 @@ +