diff --git a/Gemfile b/Gemfile index 0125e9d60..38364b556 100644 --- a/Gemfile +++ b/Gemfile @@ -44,7 +44,9 @@ group :development do gem 'grape-swagger' gem 'better_errors', '~> 1.1.0' gem 'rack-mini-profiler', '~> 0.9.3' - gem 'win32console' + if RUBY_PLATFORM =~ /w32/ + gem 'win32console' + end end group :development, :test do diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 2a75d0580..75751e4f7 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -27,7 +27,7 @@ class ExerciseController < ApplicationController if @is_teacher || User.current.admin? exercises = @course.exercises.order("created_at asc") else - exercises = @course.exercises.where(:exercise_status => 2).order("created_at asc") + exercises = @course.exercises.where("exercise_status <> 1").order("created_at asc") end @exercises = paginateHelper exercises,20 #分页 respond_to do |format| @@ -54,41 +54,26 @@ class ExerciseController < ApplicationController end @exercise = Exercise.find params[:id] @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? - if @exercise.exercise_status != 2 && (!(User.current.allowed_to?(:as_teacher,@course) || User.current.admin?)) - render_403 - return - end 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) || User.current.admin? + @can_edit_excercise = !has_commit_exercise?(@exercise.id,User.current.id)&& exercise_end end - @exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first - # 学生点击的时候即创建关联,自动保存 - #eu = ExerciseUser.create(:user_id => User.current, :exercise_id => @exercise.id, :start_at => Time.now, :status => false) - - # 已提交问卷的用户不能再访问该界面 -=begin - if has_commit_exercise?(@exercise.id, User.current.id) && (!User.current.admin?) - respond_to do |format| - format.html {render :layout => 'base_courses'} - end - else -=end - if !@is_teacher && !has_click_exercise?(@exercise.id, User.current.id) + 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 - # @percent = get_percent(@exercise,User.current) - exercise_questions = @exercise.exercise_questions - @exercise_questions = paginateHelper exercise_questions,5 #分页 score = calculate_student_score(@exercise, User.current) - eu = get_exercise_user(@exercise.id, User.current.id) - eu.update_attributes(:score => score) - respond_to do |format| - format.html {render :layout => 'base_courses'} - end + @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 @@ -537,12 +522,9 @@ class ExerciseController < ApplicationController # @score = 100 if @uncomplete_question.count < 1 # 查看是否有已提交记录 - eu = get_exercise_user(@exercise.id, User.current.id) - eu.user_id = User.current.id - eu.exercise_id = @exercise.id - eu.score = @score - if eu.save - #redirect_to poll_index_path(:polls_group_id => @course.id,:polls_type => 'Course') + 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 #未知错误 @@ -550,6 +532,7 @@ class ExerciseController < ApplicationController else @status = 1 #有未做得必答题 end + @save = params[:save].to_i if params[:save] respond_to do |format| format.js end diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index edf055370..7cdc838e2 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -142,6 +142,13 @@ 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 + #id name email + #1. issues list persons + #2. project persons + @at_persons = @journals.map(&:user) + @issue.project.users + @at_persons = @at_persons.uniq{|u| u.id}.delete_if{|u| u.id == User.current.id} + @at_persons = nil + respond_to do |format|`` format.html { retrieve_previous_and_next_issue_ids diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index 794347591..0883b3799 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -85,7 +85,7 @@ class MyController < ApplicationController flash[:notice] = l(:notice_mail_notification_updated) redirect_to my_account_url else - redirect_to signin_url + redirect_to signin_url end end @@ -223,7 +223,7 @@ class MyController < ApplicationController end flash.now[:error] = l(:notice_account_old_wrong_password) end - render :template => 'my/account',:layout=>'base_users_new' + render :template => 'my/account',:layout=>'new_base_user' end # Create a new feeds key diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 7384e2c98..ccebdccfa 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -30,7 +30,7 @@ class ProjectsController < ApplicationController before_filter :find_project, :except => [ :index, :search,:list, :new, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,:view_homework_attaches,:join_project] before_filter :authorize, :only => [:show, :settings, :edit, :sort_project_members, :update, :modules, :close, :reopen,:view_homework_attaches,:course] before_filter :authorize_global, :only => [:new, :create,:view_homework_attaches] - before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy, :calendar] + before_filter :require_admin, :only => [ :copy, :unarchive, :destroy, :calendar] before_filter :file, :statistics #:watcherlist # 除非项目内人员,不可查看成员, TODO: 完了写报表里去 # before_filter :memberAccess, only: :member diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index f79646ade..b79adda2d 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -270,6 +270,9 @@ class StudentWorkController < ApplicationController user_activity.updated_at = Time.now user_activity.save end + course_message = CourseMessage.new(:user_id =>User.current.id,:content=>"new",:course_message_id=>student_work.id,:course_id => @course.id,:course_message_type=>"StudentWork", :status => 9) #作品提交记录 + course_message.save + @student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id).first respond_to do |format| format.js @@ -299,10 +302,11 @@ class StudentWorkController < ApplicationController @submit_result = true @work.name = params[:student_work][:name] @work.description = params[:student_work][:description] - @work.project_id = params[:student_work][:project] @work.save_attachments(params[:attachments]) render_attachment_warning_if_needed(@work) if @work.save + course_message = CourseMessage.new(:user_id =>User.current.id,:content=>"edit",:course_message_id=>@work.id,:course_id => @course.id,:course_message_type=>"StudentWork", :status => 9) #作品提交记录 + course_message.save =begin respond_to do |format| format.html { @@ -687,6 +691,7 @@ class StudentWorkController < ApplicationController end all_student_ids = "(" + @homework.course.student.map{|student| student.student_id}.join(",") + ")" all_students = User.where("id in #{all_student_ids}") + @commit_student_ids = @homework.student_work_projects.map{|student| student.user_id} @users = searchstudent_by_name all_students,name respond_to do |format| format.js @@ -918,7 +923,7 @@ class StudentWorkController < ApplicationController #成绩计算 def set_final_score homework,student_work if homework && homework.homework_detail_manual - if homework.homework_type == 1 #匿评作业 + if homework.homework_type != 2 #匿评作业 if homework.teacher_priority == 1 #教师优先 if student_work.teacher_score student_work.final_score = student_work.teacher_score diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ccbf7099a..68a6aa48b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1936,6 +1936,8 @@ module ApplicationHelper candown = true elsif attachment.container.class.to_s=="StudentWork" candown = true + elsif attachment.container.class.to_s=="BlogComment" + candown = true elsif attachment.container.class.to_s == "User" candown = (attachment.is_public == 1 || attachment.is_public == true || attachment.author_id == User.current.id) elsif attachment.container_type == "Bid" && attachment.container && attachment.container.courses @@ -2466,7 +2468,7 @@ module ApplicationHelper link_to "查看作品(#{homework.student_works.count})", student_work_index_path(:homework => homework.id), :class => 'c_blue', :title => "匿评已结束" elsif homework.homework_type == 2 && Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d")#编程作业不能修改作品 link_to "修改作品(#{homework.student_works.count})", new_student_work_path(:homework => homework.id),:class => 'c_blue' - elsif Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") + elsif Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") && work.user_id == User.current.id link_to "修改作品(#{homework.student_works.count})", edit_student_work_path(work.id),:class => 'c_blue' else link_to "查看作品(#{homework.student_works.count})", student_work_index_path(:homework => homework.id), :class => 'c_blue', :title => "作业截止后不可修改作品" @@ -2670,4 +2672,38 @@ int main(int argc, char** argv){ true end end + + def import_ke(default_opt={}) + opt = {enable_at: true, prettify: false, init_activity: false}.merge default_opt + ss = '' + if opt[:enable_at] + ss = '" + end + + ss += javascript_include_tag("/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg') + if opt[:enable_at] + ss += javascript_include_tag('/assets/kindeditor/at/jquery.caret.min.js', '/assets/kindeditor/at/jquery.atwho.js', '/assets/kindeditor/at/config.js') + ss += stylesheet_link_tag("/assets/kindeditor/at/jquery.atwho.css") + end + + if opt[:prettify] + ss += javascript_include_tag 'prettify' + ss += stylesheet_link_tag 'prettify' + end + + if opt[:init_activity] + ss += javascript_include_tag "init_activity_KindEditor" + end + + ss.html_safe + end + end diff --git a/app/models/course_message.rb b/app/models/course_message.rb index 11b0165c5..79d27f3c5 100644 --- a/app/models/course_message.rb +++ b/app/models/course_message.rb @@ -1,5 +1,5 @@ class CourseMessage < ActiveRecord::Base - # status说明: status在课程不同的类型,区分不同的功能 + # status说明: status在课程不同的类型,区分不同的功能 status = 9 作品的提交记录 # HomeworkCommon:status: # nil:发布了作业; 1:作业截止时间到了提醒!;2:开启匿评; 3:关闭匿评; 4:匿评开始失败 attr_accessible :course_id, :course_message_id, :course_message_type, :user_id, :viewed, :content, :status @@ -19,7 +19,7 @@ class CourseMessage < ActiveRecord::Base def add_user_message #unless self.course_message_type == 'JoinCourseRequest' - if MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first.nil? + if MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first.nil? && self.status != 9 self.message_alls << MessageAll.new(:user_id => self.user_id) end #end diff --git a/app/models/memo.rb b/app/models/memo.rb index 2ead1cbb6..ee9f4c8db 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -18,10 +18,28 @@ class Memo < ActiveRecord::Base #elasticsearch kaminari init Kaminari::Hooks.init Elasticsearch::Model::Response::Response.__send__ :include, Elasticsearch::Model::Response::Pagination::Kaminari - settings index: { number_of_shards: 5 } do + settings index: { + number_of_shards: 5 , + analysis: { + char_filter: { + and_filter: { + type: "mapping", + mappings: [ "&=> and "] + } + }, + analyzer: { + my_analyzer: { + type: 'custom', + tokenizer: 'standard', + filter: ['classic'], + char_filter: ['html_strip'] + } + } + } + } do mappings dynamic: 'false' do - indexes :subject, analyzer: 'smartcn',index_options: 'offsets' - indexes :content, analyzer: 'smartcn',index_options: 'offsets' + indexes :subject, analyzer: 'smartcn',index_options: 'offsets'#, char_filter: 'html_strip' + indexes :content, analyzer:'my_analyzer',index_options: 'offsets',search_analyzer: 'smartcn' indexes :updated_at,index:"not_analyzed" ,type:'date' end end diff --git a/app/models/student_work.rb b/app/models/student_work.rb index c6e2a6584..144f3859f 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -46,7 +46,7 @@ class StudentWork < ActiveRecord::Base #成绩计算 def set_final_score homework,student_work if homework && homework.homework_detail_manual - if homework.homework_type == 1 #匿评作业 + if homework.homework_type != 2 #匿评作业 if homework.teacher_priority == 1 #教师优先 if student_work.teacher_score student_work.final_score = student_work.teacher_score diff --git a/app/models/user.rb b/app/models/user.rb index 6e6d58f86..0c8d65481 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -410,10 +410,14 @@ class User < Principal else name = lastname+firstname end - name = name.empty? || name.nil? ? login : name - name + name.empty? || name.nil? ? login : name end ## end + + def get_at_show_name + name = show_name + name = "#{name} #{self.login}" if name != self.login + end #added by nie def count_new_journal_reply diff --git a/app/services/users_service.rb b/app/services/users_service.rb index 8b39c39ab..8df42fb41 100644 --- a/app/services/users_service.rb +++ b/app/services/users_service.rb @@ -228,7 +228,7 @@ class UsersService end course_list end - + #修改密码 def change_password params @current_user = User.find(params[:current_user_id]) diff --git a/app/views/admin/messages.html.erb b/app/views/admin/messages.html.erb index f87741dd9..e4d053d49 100644 --- a/app/views/admin/messages.html.erb +++ b/app/views/admin/messages.html.erb @@ -1,4 +1,6 @@ -<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %> +<%= content_for(:header_tags) do %> + <%= import_ke(enable_at: false) %> +<% end %>