diff --git a/.access_token b/.access_token index 610b08d2e..2e228963c 100644 --- a/.access_token +++ b/.access_token @@ -1 +1 @@ -{"access_token":"oEEf8ZKAB8Y2G0o_xnTPkPJHKKk8iHkLC-f5ptvQ2nCMj9IpC86ivLD2-p38GfOkuG-HuQp3pWZqhs3NJXUMdPLWsr5k67hPZYuqg4ozLccx0xdLswapj0mn8ovZhK1tKIKiAFAOMO","expires_in":7200,"got_token_at":1467012449} \ No newline at end of file +{"access_token":"b_Pc60Dd5eyg_ut3cHbsjQO9EJJdj2Qj5F99o9LH9ltKSme7_FZ3Of22lWLL-K2V0siWzv-bd9PO0Dn-L1PBvIy9LhXa0qPVaFl6vTtZHR2kA8qjo1ps2ancya0t7KmzURGbAFAAXM","expires_in":7200,"got_token_at":1467976842} \ No newline at end of file diff --git a/.gitignore b/.gitignore index dbc349c80..1ef7e63ce 100644 --- a/.gitignore +++ b/.gitignore @@ -6,8 +6,7 @@ /config/database.yml /config/configuration.yml /config/additional_environment.rb -/config/menu.yml -/config/wechat.yml + /files/* /log/* @@ -35,3 +34,5 @@ vendor/cache 1234567 public/javascripts/wechat/node_modules/ .ruby-version +.access_token +tmux*.log diff --git a/Gemfile b/Gemfile index bb94100a5..3bea83669 100644 --- a/Gemfile +++ b/Gemfile @@ -5,8 +5,8 @@ unless RUBY_PLATFORM =~ /w32/ gem 'iconv' if RUBY_PLATFORM =~ /darwin/ gem "rmagick", "= 2.15.4" ## osx must be this version - else - gem "rmagick", "= 2.13.1" ## centos yum install ImageMagick-devel + elsif RUBY_PLATFORM =~ /linux/ + #gem "rmagick", "= 2.13.1" ## centos yum install ImageMagick-devel end gem 'certified' gem 'net-ssh', '2.9.1' @@ -57,7 +57,7 @@ group :development do gem 'grape-swagger' gem 'better_errors', '~> 1.1.0' # gem "query_reviewer" - # gem 'rack-mini-profiler', '~> 0.9.3' + gem 'rack-mini-profiler', '~> 0.9.3' if RUBY_PLATFORM =~ /w32/ gem 'win32console' end diff --git a/Gemfile~ b/Gemfile~ new file mode 100644 index 000000000..334f15853 --- /dev/null +++ b/Gemfile~ @@ -0,0 +1,114 @@ +source 'https://ruby.taobao.org/' + +unless RUBY_PLATFORM =~ /w32/ + # unix-like only + gem 'iconv' + gem "rmagick", ">= 2.0.0" + gem 'certified' +end + +gem 'net-ssh', '2.9.1' +gem 'jenkins_api_client' +gem 'nokogiri' + +gem 'wechat',path: 'lib/wechat' +gem 'grack', path:'lib/grack' +gem 'gitlab', path: 'lib/gitlab-cli' +gem 'rest-client' +gem "mysql2", "= 0.3.18" +gem 'redis-rails' +gem 'rubyzip' +gem 'delayed_job_active_record'#, :group => :production +gem 'daemons' +gem 'grape', '~> 0.9.0' +gem 'grape-entity' +gem 'rack-cors', :require => 'rack/cors' +gem 'seems_rateable', '~> 1.0.13' +gem 'rails', '~> 3.2' +gem "jquery-rails", "~> 2.0.2" +gem "i18n", "~> 0.6.0" +gem 'coderay', '~> 1.1.0' +gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby] +gem "builder", "3.0.0" +gem 'acts-as-taggable-on', '2.4.1' +gem 'spreadsheet' +gem 'ruby-ole' +gem 'rails_kindeditor',path:'lib/rails_kindeditor' +gem 'binding_of_caller' +gem 'chinese_pinyin' +# gem 'sunspot_rails', '~> 1.3.3' +# gem 'sunspot_solr' +# gem 'sunspot' +# gem 'progress_bar' +gem 'ansi' + +gem 'kaminari' +gem 'elasticsearch-model' +gem 'elasticsearch-rails' + + +### profile +#gem 'oneapm_rpm' + +group :development do + gem 'grape-swagger' + gem 'better_errors', '~> 1.1.0' + # gem "query_reviewer" + # gem 'rack-mini-profiler', '~> 0.9.3' + if RUBY_PLATFORM =~ /w32/ + gem 'win32console' + end +end + +group :development, :test do + unless RUBY_PLATFORM =~ /w32/ + gem 'pry-rails' + if RUBY_VERSION >= '2.0.0' + gem 'pry-byebug' + end + gem 'pry-stack_explorer' + if RUBY_PLATFORM =~ /darwin/ + gem 'puma' + end + end + + gem 'rspec-rails', '~> 3.0' + gem 'factory_girl_rails' +end + +# Gems used only for assets and not required +# in production environments by default. +group :assets do + gem 'sass-rails', '~> 3.2.3' + gem 'coffee-rails', '~> 3.2.1' + + # See https://github.com/sstephenson/execjs#readme for more supported runtimes + # gem 'therubyracer', :platforms => :ruby + + gem 'uglifier', '>= 1.0.3' +end + +# Optional gem for LDAP authentication +group :ldap do + gem "net-ldap", "~> 0.3.1" +end + + +# Optional gem for OpenID authentication +group :openid do + gem "ruby-openid", "~> 2.1.4", :require => "openid" + gem "rack-openid" +end + + +database_file = File.join(File.dirname(__FILE__), "config/database.yml") +if File.exist?(database_file) +else + warn("Please configure your config/database.yml first") +end + +# Load plugins' Gemfiles +Dir.glob File.expand_path("../plugins/*/Gemfile", __FILE__) do |file| + puts "Loading #{file} ..." if $DEBUG # `ruby -d` or `bundle -v` + instance_eval File.read(file) +end diff --git a/app/api/mobile/api.rb b/app/api/mobile/api.rb index c555eb633..9b4bdb5d6 100644 --- a/app/api/mobile/api.rb +++ b/app/api/mobile/api.rb @@ -19,6 +19,7 @@ module Mobile require_relative 'apis/new_comment' require_relative 'apis/praise' require_relative 'apis/resources' + require_relative 'apis/syllabuses' class API < Grape::API version 'v1', using: :path @@ -73,6 +74,7 @@ module Mobile mount Apis::NewComment mount Apis::Praise mount Apis::Resources + mount Apis::Syllabuses add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development? diff --git a/app/api/mobile/apis/activities.rb b/app/api/mobile/apis/activities.rb index 661925012..b4fb90ea7 100644 --- a/app/api/mobile/apis/activities.rb +++ b/app/api/mobile/apis/activities.rb @@ -10,30 +10,44 @@ module Mobile params do requires :page, type: Integer requires :token, type: String + requires :container_type, type: String end post do authenticate! user = current_user - shield_project_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Project'").map(&:shield_id) - shield_course_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Course'").map(&:shield_id) + container_type = params[:container_type] ? params[:container_type] : "All" + + if container_type == "All" || container_type == "Project" + shield_project_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Project'").map(&:shield_id) + user_project_ids = (user.projects.where("status = 1").map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (user.projects.where("status = 1").map{|project| project.id}-shield_project_ids).join(",") + ")" + project_types = "('Message','Issue','Project')" + end + + if container_type == "All" || container_type == "Course" + shield_course_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Course'").map(&:shield_id) + user_course_ids = (user.courses.where("is_delete = 0").map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (user.courses.where("is_delete = 0").map{|course| course.id}-shield_course_ids).join(",") + ")" + course_types = "('Message','News','HomeworkCommon','Poll','Course')" + end + page = params[:page] ? params[:page] : 0 - user_project_ids = (user.projects.where("status = 1").map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (user.projects.where("status = 1").map{|project| project.id}-shield_project_ids).join(",") + ")" - user_course_ids = (user.courses.where("is_delete = 0").map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (user.courses.where("is_delete = 0").map{|course| course.id}-shield_course_ids).join(",") + ")" - course_types = "('Message','News','HomeworkCommon','Poll','Course')" - project_types = "('Message','Issue','Project')" principal_types = "JournalsForMessage" watched_user_ids = User.watched_by(user.id).count == 0 ? " " : ("," + User.watched_by(user.id).map{|u| u.id.to_s }.join(',')) user_ids = "(" + user.id.to_s + watched_user_ids + ")" watched_user_blog_ids = Blog.select("id").where("author_id in #{user_ids}").count == 0 ? " " :Blog.select("id").where("author_id in #{user_ids}").map { |blog| blog.id}.join(",") blog_ids = "(" + watched_user_blog_ids + ")" - activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + - "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ - "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{user.id}) " + - "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc') - + if container_type == "Course" + activities = UserActivity.where("(container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})").order('updated_at desc') + elsif container_type == "Project" + activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})").order('updated_at desc') + else + activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + + "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ + "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{user.id}) " + + "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc') + end all_count = activities.count activities = activities.limit(10).offset(page * 10) count = activities.count @@ -42,6 +56,7 @@ module Mobile present :count, count present :page, page present :status, 0 + present :container_type, container_type end end end diff --git a/app/api/mobile/apis/blog_comments.rb b/app/api/mobile/apis/blog_comments.rb index 5a064245a..bb5758e71 100644 --- a/app/api/mobile/apis/blog_comments.rb +++ b/app/api/mobile/apis/blog_comments.rb @@ -7,7 +7,7 @@ module Mobile desc "get special topic" get ':id' do - user = UserWechat.find_by_openid(params[:openid]).user + user = current_user blog = BlogComment.find params[:id] present :data, blog, with: Mobile::Entities::BlogComment,user: user present :status, 0 diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index 42303b63d..301417781 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -107,7 +107,7 @@ module Mobile status = cs.join_course({role: "10", openid: params[:openid], invite_code: params[:invite_code]}, current_user) { status: status[:state], - messsge:CoursesService::JoinCourseError.message(status[:state]) + message:CoursesService::JoinCourseError.message(status[:state]) } end @@ -396,6 +396,23 @@ module Mobile present :status,0 end + desc '删除课程' + params do + requires :token, type: String + end + post ':course_id/del' do + authenticate! + c = Course.find(params[:course_id]) + # if c.members.count > 1 + # {status: -1, message: '已经有成员加入,不能删除'} + # else + c.delete! + present :status,0 + # end + + + end + end end end diff --git a/app/api/mobile/apis/resources.rb b/app/api/mobile/apis/resources.rb index fca94a642..6dfe8e599 100644 --- a/app/api/mobile/apis/resources.rb +++ b/app/api/mobile/apis/resources.rb @@ -46,10 +46,26 @@ module Mobile end + desc '发送资源' + params do + requires :token, type: String + requires :course_ids, type: Array[Integer] + requires :send_id, type: Integer + end + post 'send' do + authenticate! + + rs = ResourcesService.new + ori, flag, save_message = rs.send_resource_to_course(current_user,params) + if flag + present :status, 0 + else + {status: -1, message: save_message.first} + end + end + end - - end end end \ No newline at end of file diff --git a/app/api/mobile/apis/syllabuses.rb b/app/api/mobile/apis/syllabuses.rb new file mode 100644 index 000000000..57db4cb9e --- /dev/null +++ b/app/api/mobile/apis/syllabuses.rb @@ -0,0 +1,103 @@ +#coding=utf-8 + +module Mobile + module Apis + class Syllabuses < Grape::API + + resources :syllabuses do + desc "获取大纲列表" + params do + requires :token, type: String + end + get do + authenticate! + + cs = SyllabusesService.new + courses = cs.user_syllabus(current_user) + present :data, courses, with: Mobile::Entities::Syllabus + present :status, 0 + end + + desc "获取某个大纲" + params do + requires :token, type: String + end + get ':id' do + authenticate! + + ss = SyllabusesService.new + + sy = ::Syllabus.find(params[:id]) + sy.courses = sy.courses.not_deleted + sy = ss.judge_can_setting(sy,current_user) + + present :data, sy, with: Mobile::Entities::Syllabus + present :status, 0 + end + + desc "获取新建大纲的权限" + params do + requires :token, type: String + end + post 'auth' do + authenticate! + + auth = 0 + + if (current_user.user_extensions && current_user.user_extensions.identity == 0 && current_user.allowed_to?(:add_course, nil, :global => true)) + auth = 1 + end + + present :auth, auth + end + + desc "新建大纲" + params do + requires :token, type: String + requires :title, type: String, desc: '大纲标题' + requires :courses, type: Array[String], desc: '课程名' + end + post do + authenticate! + + ss = SyllabusesService.new + + sy = ss.create(current_user, params[:title], + params[:courses].map{|c| {name: c} }) + + if sy.new_record? + {status:-1, message: '创建大纲失败' } + else + present :data, sy, with: Mobile::Entities::Syllabus + present :status, 0 + end + + end + + desc '编辑大纲' + params do + requires :token, type: String + requires :title, type: String, desc: '大纲标题' + # requires :add_courses, type: Array[String], desc: '课程名' + # requires :modify_courses, type: Array[Integer,String], desc: '课程名' + end + post ':id/edit' do + + authenticate! + + ss = SyllabusesService.new + + #修改课程大纲 + status = ss.edit(current_user, params) + + if status == -1 + {status:status, message: '修改课程信息失败' } + else + present :status, status + end + end + end + + end + end +end \ No newline at end of file diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb index b5ee14d19..a6536e73e 100644 --- a/app/api/mobile/apis/users.rb +++ b/app/api/mobile/apis/users.rb @@ -53,10 +53,20 @@ module Mobile requires :password, type: String, desc: 'password' end post do + + openid = session[:wechat_openid] + logger.debug "openid ============== #{openid}" + raise "无法获取到openid,请在微信中打开本页面" unless openid + + us = UsersService.new user = us.register params.merge(:password_confirmation => params[:password], :should_confirmation_password => true) - raise "该邮箱已经被注册过了" if user.new_record? + raise user.errors.full_messages.first if user.new_record? + UserWechat.create!( + openid: openid, + user: user + ) present :data, user, with: Mobile::Entities::User present :status, 0 diff --git a/app/api/mobile/entities/course.rb b/app/api/mobile/entities/course.rb index 487a75c4d..d44869a60 100644 --- a/app/api/mobile/entities/course.rb +++ b/app/api/mobile/entities/course.rb @@ -15,6 +15,8 @@ module Mobile #f.img_url if f.respond_to?(:img_url) elsif field == :created_at || field == :updated_at (format_time(c[field]) if (c.is_a?(Hash) && c.key?(field))) || (format_time(c.send(field)) if c.respond_to?(field)) + elsif field == :member_count + ::Course===c ? c.members.count : 0 else (c[field] if (c.is_a?(Hash) && c.key?(field))) || (c.send(field) if c.respond_to?(field)) end @@ -49,6 +51,8 @@ module Mobile course_expose :qrcode course_expose :updated_at course_expose :course_student_num + course_expose :member_count + course_expose :can_setting expose :teacher, using: Mobile::Entities::User do |c, opt| if c.is_a? ::Course c.teacher diff --git a/app/api/mobile/entities/syllabus.rb b/app/api/mobile/entities/syllabus.rb new file mode 100644 index 000000000..4f97dd868 --- /dev/null +++ b/app/api/mobile/entities/syllabus.rb @@ -0,0 +1,13 @@ +module Mobile + module Entities + class Syllabus < Grape::Entity + include ApplicationHelper + + expose :title + expose :id + expose :can_setting + + expose :courses, using: Mobile::Entities::Course + end + end +end diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 2e3612b94..bc764d034 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -45,9 +45,62 @@ class AdminController < ApplicationController render :action => "projects", :layout => false if request.xhr? end - def courses + def syllabuses @name = params[:name] - @courses = Course.like(@name).order('created_at desc') + @syllabuses = Syllabus.like(@name).order('created_at desc') + @syllabuses = paginateHelper @syllabuses,30 + @page = (params['page'] || 1).to_i - 1 + respond_to do |format| + format.html + end + end + + #为班级选择课程 + def select_course_syllabus + @flag = false + if params[:syllabus_id] && params[:course_id] + course = Course.where("id = #{params[:course_id].to_i}").first + unless course.nil? + course.update_attribute('syllabus_id', params[:syllabus_id].to_i) + @flag = true + end + end + if @flag + render :text=> "succ" + else + render :text=>'fail' + end + end + + #新建课程 + def create_syllabus + if params[:course_id] + course = Course.where("id = #{params[:course_id]}").first + if course + @user = course.teacher + syllabus = Syllabus.new + syllabus.update_attributes(:title => params[:title], :eng_name => params[:eng_name], :user_id => @user.id) + syllabus.description = Message.where("id = 19412").first.nil? ? nil : Message.where("id = 19412").first.content + if syllabus.save + course.update_attribute('syllabus_id', syllabus.id) + @flag = params[:flag].to_i + @course = course + respond_to do |format| + format.js + end + end + end + end + end + + def courses + @name = params[:name].to_s.strip.downcase + if @name && @name != "" + @courses = Course.select{ |course| (course.teacher[:lastname].to_s.downcase + course.teacher[:firstname].to_s.downcase).include?(@name) || course.name.include?(@name)} + @courses = @courses.sort{|x, y| y.created_at <=> x.created_at} + else + @courses = Course.order('created_at desc') + end @courses = paginateHelper @courses,30 @page = (params['page'] || 1).to_i - 1 respond_to do |format| @@ -55,6 +108,33 @@ class AdminController < ApplicationController end end + #未配置班级列表 + def non_syllabus_courses + @name = params[:name].to_s.strip.downcase + if @name && @name != "" + @courses = Course.where("syllabus_id is null").select{ |course| (course.teacher[:lastname].to_s.downcase + course.teacher[:firstname].to_s.downcase).include?(@name) || course.name.include?(@name)} + @courses = @courses.sort{|x, y| y.created_at <=> x.created_at} + else + @courses = Course.where("syllabus_id is null").order('created_at desc') + end + @courses = paginateHelper @courses,30 + @page = (params['page'] || 1).to_i - 1 + respond_to do |format| + format.html + end + end + + #修改课程名称 + def update_course_name + @course = Course.where("id = #{params[:course_id].to_i}").first + unless @course.nil? + @course.update_attribute("name", params[:name]) + respond_to do |format| + format.js + end + end + end + #管理员界面精品课程列表 def excellent_courses @courses = Course.where("is_excellent =? or excellent_option =?", 1, 1 ) diff --git a/app/controllers/blog_comments_controller.rb b/app/controllers/blog_comments_controller.rb index 0224a587d..4a8de5814 100644 --- a/app/controllers/blog_comments_controller.rb +++ b/app/controllers/blog_comments_controller.rb @@ -116,6 +116,9 @@ class BlogCommentsController < ApplicationController #回复 def reply + if params[:homepage] + @in_user_homepage = true + end if params[:in_user_center] @in_user_center = true end diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index e81251f63..a9d84c2d9 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1090,7 +1090,7 @@ class CoursesController < ApplicationController #删除课程 #删除课程只是将课程的is_deleted状态改为false,is_deleted为false状态的课程只有管理员可以看到 def destroy - @course.update_attributes(:is_delete => true) + @course.delete! @course = nil redirect_to user_url(User.current) end diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 376f8d5c2..6724f42bb 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -27,6 +27,7 @@ class HomeworkCommonController < ApplicationController #@homeworks = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("created_at desc").limit(10).offset(@page * 10) @homework_commons = @course.homework_commons.where("name like '%#{search}%' and publish_time <= '#{Date.today}'").order("created_at desc") end + #update_homework_time @homework_commons @is_student = User.current.logged? && (User.current.admin? || (User.current.member_of_course?(@course) && !@is_teacher)) @is_new = params[:is_new] @@ -178,7 +179,7 @@ class HomeworkCommonController < ApplicationController @statue = 4 and return unless User.current.admin? || User.current.allowed_to?(:as_teacher,@course) @statue = 5 and return if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") if @homework_detail_manual.comment_status == 1 - student_works = @homework.student_works + student_works = @homework.student_works.has_committed if student_works && student_works.size >= 2 if @homework.homework_type == 3 student_work_projects = @homework.student_work_projects.where("student_work_id is not null") @@ -232,8 +233,8 @@ class HomeworkCommonController < ApplicationController @homework_detail_manual.update_column('comment_status', 3) @homework_detail_manual.update_column('evaluation_end', Date.today) #计算缺评扣分 - work_ids = "(" + @homework.student_works.map(&:id).join(",") + ")" - @homework.student_works.each do |student_work| + work_ids = "(" + @homework.student_works.has_committed.map(&:id).join(",") + ")" + @homework.student_works.has_committed.each do |student_work| absence_penalty_count = student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - student_work.user.student_works_scores.where("student_work_id IN #{work_ids}").count student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * @homework_detail_manual.absence_penalty : 0 student_work.save @@ -263,11 +264,11 @@ class HomeworkCommonController < ApplicationController @totle_size = 0 if @homework_detail_manual.comment_status == 1 @totle_size = @course.student.count - @cur_size = @homework.student_works.size + @cur_size = @homework.student_works.has_committed.size elsif @homework_detail_manual.comment_status == 2 - @homework.student_works.map { |work| @totle_size += work.student_works_evaluation_distributions.count} + @homework.student_works.has_committed.map { |work| @totle_size += work.student_works_evaluation_distributions.count} @cur_size = 0 - @homework.student_works.map { |work| @cur_size += work.student_works_scores.where(:reviewer_role => 3).count} + @homework.student_works.has_committed.map { |work| @cur_size += work.student_works_scores.select("distinct user_id").where(:reviewer_role => 3).count} end @percent = format("%.2f",(@cur_size.to_f / ( @totle_size == 0 ? 1 : @totle_size)) * 100) @user_activity_id = params[:user_activity_id].to_i @@ -409,8 +410,8 @@ class HomeworkCommonController < ApplicationController def update_homework_time homeworks unless homeworks.nil? homeworks.each do |h| - if h.homework_type == 3 - student_works = h.student_work_projects.where("is_leader = 1") + if h.homework_type == 3 && h.homework_detail_group.base_on_project == 1 + student_works = h.student_work_projects.where("is_leader = 1 && project_id != -1") time = h.updated_at unless student_works.nil? student_works.each do |s| @@ -418,7 +419,7 @@ class HomeworkCommonController < ApplicationController unless project.nil? && project.gpid.nil? project_time=project.updated_on project_time=ForgeActivity.where("project_id=?",project.id).last.updated_at if ForgeActivity.where("project_id=?",project.id).last - if format_time(time) < format_time(project_time) + if time.strftime('%Y-%m-%d %H:%M:%S') < project_time.strftime('%Y-%m-%d %H:%M:%S') time = project_time end begin @@ -428,21 +429,30 @@ class HomeworkCommonController < ApplicationController changesets = g.commits(project.gpid, :ref_name => default_branch) changesets_latest_coimmit = changesets[0] unless changesets[0].blank? - if format_time(time) < format_time(changesets_latest_coimmit.created_at) + if time.strftime('%Y-%m-%d %H:%M:%S') update homework project time") end end end end - puts h.updated_at - puts time s_time = time - if format_time(time) > format_time(h.updated_at) + if time.strftime('%Y-%m-%d %H:%M:%S') > h.updated_at.strftime('%Y-%m-%d %H:%M:%S') h.update_column('updated_at', s_time) + course_activity = CourseActivity.where("course_act_type=? and course_act_id =?", 'HomeworkCommon', h.id).first + if course_activity && (time.strftime('%Y-%m-%d %H:%M:%S') > course_activity.updated_at.strftime('%Y-%m-%d %H:%M:%S')) + course_activity.update_column('updated_at', s_time) + end + user_activity = UserActivity.where("act_type=? and act_id =?", 'HomeworkCommon', h.id).first + if user_activity && (time.strftime('%Y-%m-%d %H:%M:%S') > user_activity.updated_at.strftime('%Y-%m-%d %H:%M:%S')) + user_activity.update_column('updated_at', s_time) + end + org_activity = OrgActivity.where("org_act_type=? and org_act_id =?", 'HomeworkCommon', h.id).first + if org_activity && (time.strftime('%Y-%m-%d %H:%M:%S') > org_activity.updated_at.strftime('%Y-%m-%d %H:%M:%S')) + org_activity.update_column('updated_at', s_time) + end end end end diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb index bec66aeff..73672d11a 100644 --- a/app/controllers/quality_analysis_controller.rb +++ b/app/controllers/quality_analysis_controller.rb @@ -26,14 +26,25 @@ class QualityAnalysisController < ApplicationController job_name = "#{user_name}-#{rep_id}" sonar_name = "#{user_name}:#{rep_id}" + # 考虑到历史数据:有些用户创建类job但是build失败,即sonar没有结果,这个时候需要把job删除,并且删掉quality_analyses表数据 + # 如果不要这句则需要迁移数据 + @sonar_address = Redmine::Configuration['sonar_address'] + projects_date = open(@sonar_address + "/api/projects/index").read + arr = JSON.parse(projects_date).map {|m| m["nm"]} # eg: ["Hjqreturn:cc_rep", "Hjqreturn:putong", "Hjqreturn:sonar_rep2", "shitou:sonar_rep"] + quality_an = QualityAnalysis.where(:sonar_name => sonar_name).first + if @client.job.exists?(job_name) && QualityAnalysis.where(:sonar_name => sonar_name).select{|qa| arr.include?(qa.sonar_name)}.blank? + logger.info("88888888888888888888") + aa = @client.job.delete("#{job_name}") + quality_an.delete unless quality_an.blank? + end # Checks if the given job exists in Jenkins. unless @client.job.exists?(job_name) @g = Gitlab.client branch = params[:branch] language = swith_language_type(params[:language]) path = params[:path].blank? ? "./" : params[:path] - qa = QualityAnalysis.where(:project_id => @project.id, :author_login => user_name).first - version = qa.nil? ? 1 : qa.sonar_version + 1 + # qa = QualityAnalysis.where(:project_id => @project.id, :author_login => user_name).first + version = quality_an.nil? ? 1 : quality_an.sonar_version + 1 properties = "sonar.projectKey=#{sonar_name} sonar.projectName=#{sonar_name} sonar.projectVersion=#{version} @@ -60,37 +71,64 @@ class QualityAnalysisController < ApplicationController # 判断调用sonar分析是否成功 # 等待启动时间处理, 最长时间为30分钟 - for i in 0..60 do - sleep(60) + for i in 0..360 do + sleep(5) @current_build_status = @client.job.get_current_build_status("#{job_name}") - if (@current_build_status != "not_run" || @current_build_status != "running") + if (@current_build_status == "success" || @current_build_status == "failure") break - if i == 60 + if i == 360 @build_console_result = false break end end end - @console_build = @client.job.get_console_output("#{job_name}", build_num = 0, start = 0, mode = 'text') - logger.info("@current_build_status is ==> #{@current_build_status}") - logger.info("@console_build is ==> #{@console_build}") + # sonar 缓冲,取数据 + sleep(5) - d = @client.job.delete("#{job_name}") if jenkins_job == '200' && code != '201' - logger.error("delete result ==> #{code}") - if qa.blank? && @current_build_status == "success" - QualityAnalysis.create(:project_id => @project.id, :author_login => user_name, :rep_identifier => identifier, - :sonar_version => version, :path => path, :branch => branch, :language => language, :sonar_name => "#{user_name}:#{rep_id}") + # 获取sonar output结果 + console_build = @client.job.get_console_output("#{job_name}", build_num = 0, start = 0, mode = 'text')["output"] + logger.info("@current_build_status is ==> #{@current_build_status}") + + # 两种情况需要删除job: + # 1/创建成功但是build失败则删除job + # 2/creat和build成功,调用sonar启动失败则删除job + # 错误信息存储需存到Trustie数据库,否则一旦job删除则无法获取这些信息 + if jenkins_job == '200' && code != '201' + @client.job.delete("#{job_name}") else - qa.update_attribute(:sonar_version, version) + if @current_build_status == "failure" + reg_console = /Exception:.*?\r/.match(console_build) + output = reg_console[0].gsub("\r", "") unless reg_console.nil? + se = SonarError.where(:jenkins_job_name => job_name).first + se.nil? ? SonarError.create(:project_id => @project.id, :jenkins_job_name => job_name, :output => output) : se.update_column(:output, output) + @client.job.delete("#{job_name}") + elsif @current_build_status == "success" + if quality_an.blank? + QualityAnalysis.create(:project_id => @project.id, :author_login => user_name, :rep_identifier => identifier, + :sonar_version => version, :path => path, :branch => branch, :language => language, :sonar_name => "#{user_name}:#{rep_id}") + else + qa.update_attribute(:sonar_version, version) + end + end end end rescue => e puts e end respond_to do |format| - format.html{redirect_to project_quality_analysis_path(:project_id => @project.id, :resource_id => sonar_name, :branch => branch, :current_build_status => @current_build_status, :job_name => job_name)} - # format.js{redirect_to project_quality_analysis_path(:project_id => @project.id, :resource_id => sonar_name, :branch => branch)} + if @current_build_status == "success" + format.html{redirect_to project_quality_analysis_path(:project_id => @project.id, :resource_id => sonar_name, :branch => branch, :current_build_status => @current_build_status, :job_name => job_name)} + elsif @current_build_status == "failure" + format.html{redirect_to error_list_project_quality_analysi_path(:project_id => @project.id, :job_name => job_name)} + end + end + end + + def error_list + @error_list = SonarError.where(:jenkins_job_name => params[:job_name]).first + respond_to do |format| + format.html end end @@ -145,7 +183,7 @@ class QualityAnalysisController < ApplicationController get_current_build_status = @client.job.get_current_build_status("Hjqreturn-1280") logger.error("Failed to update job: ==> #{jenkins_job}") unless jenkins_job == '200' - # 数据更新到Trustie数据库 + # 数据更新到Trustie数据 if jenkins_job == '200' logger.info("quality_ananlysis will be updated: ==> #{jenkins_job}") @quality_analysis.path = path @@ -168,27 +206,34 @@ class QualityAnalysisController < ApplicationController @branch = params[:branch] @resource_id = params[:resource_id] @sonar_address = Redmine::Configuration['sonar_address'] - @jenkins_address = Redmine::Configuration['jenkins_address'] if params[:resource_id].nil? @name_flag = true projects_date = open(@sonar_address + "/api/projects/index").read arr = JSON.parse(projects_date).map {|m| m["nm"]} # eg: ["Hjqreturn:cc_rep", "Hjqreturn:putong", "Hjqreturn:sonar_rep2", "shitou:sonar_rep"] @quality_analyses = QualityAnalysis.where(:project_id => @project.id).select{|qa| arr.include?(qa.sonar_name)} - else - if params[:current_build_status] == "failure" - job_name = params[:job_name] - @console_build = @client.job.get_console_output("#{job_name}", build_num = 0, start = 0, mode = 'text')["output"] - end - complexity_date = open(@sonar_address + "/api/resources/index?resource=#{@resource_id}&depth=0&metrics=sqale_rating,function_complexity,duplicated_lines_density,comment_lines_density,sqale_index,lines,file_line,files,functions,classes,directories").read + filter = "sqale_rating,function_complexity,duplicated_lines_density,comment_lines_density,sqale_index,lines,files,functions,classes,directories,blocker_violations,critical_violations,major_violations,minor_violations,info_violations,violations" + complexity_date = open(@sonar_address + "/api/resources/index?resource=#{@resource_id}&depth=0&metrics=#{filter}").read @complexity =JSON.parse(complexity_date).first + + # 按名称转换成hash键值对 + @ha = {} + @complexity["msr"].each do |com| + key = com["key"] + if key == "sqale_index" + value = com["frmt_val"] + else + value = com["val"].to_i + end + @ha.store(key,value) + end + issue_date = open(@sonar_address + "/api/resources/index?resource=#{@resource_id}&depth=0&metrics=blocker_violations,critical_violations,major_violations,minor_violations,info_violations,violations").read @sonar_issues = JSON.parse(issue_date).first end rescue => e puts e end - end # Find project of id params[:project_id] diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index d0904ddf5..4764d1cd7 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -38,7 +38,9 @@ class RepositoriesController < ApplicationController before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue] before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :commit_diff, :project_archive, :quality_analysis] # 链接gitlab - before_filter :connect_gitlab, :only => [:quality_analysis] + before_filter :connect_gitlab, :only => [:quality_analysis, :show] + # 版本库新增权限 + before_filter :show_rep, :only => [:show] accept_rss_auth :revisions # hidden repositories filter // 隐藏代码过滤器 before_filter :check_hidden_repo, :only => [:show, :stats, :revisions, :revision, :diff ] @@ -361,44 +363,42 @@ update def show ## TODO: the below will move to filter, done. - if !User.current.member_of?(@project) && @project.hidden_repo - render_403 - return - end + + # 获取版本库目录结构 @entries = @repository.entries(@path, @rev) - @changeset = @repository.find_changeset_by_name(@rev) if request.xhr? @entries ? render(:partial => 'dir_list_content') : render(:nothing => true) else - g = Gitlab.client - @changesets = g.commits(@project.gpid, :ref_name => @rev) - g_project = g.project(@project.gpid) - # 总的提交数 - @changesets_all_count = @project.gpid.nil? ? 0 : commit_count(@project, @rev) - @g_default_branch = g_project.default_branch.nil? ? "master" : g_project.default_branch - # 访问该页面的是会后则刷新 - if @project.project_score.nil? - ProjectScore.create(:project_id => @project.id, :score => false) - end - # 刷新改页面的时候,更新统计数 - if @changesets_all_count != @project.project_score.changeset_num && @changesets_all_count != 0 - update_commits_count(@project, @changesets_all_count) - end + @changesets = @g.commits(@project.gpid, :ref_name => @rev) # 最近一次提交 @changesets_latest_coimmit = @changesets[0] - unless @changesets[0].blank? - update_commits_date(@project, @changesets_latest_coimmit) + g_project = @g.project(@project.gpid) + # 总的提交数 + @changesets_all_count = @g.user_static(@project.gpid, :rev => @rev).count + + # 获取默认分支 + @g_default_branch = g_project.default_branch.nil? ? "master" : g_project.default_branch + + # 访问版本庫后更新project_score表数据;changeset_num为提交总数 + project_score = @project.project_score + if project_score.nil? + ProjectScore.create(:project_id => @project.id, :score => false) + else + project_score.update_column(:changeset_num, @changesets_all_count) end - @creator = User.where("id =?", @project.user_id).first.try(:login) - # @properties = @repository.properties(@path, @rev) - # @repositories = @project.repositories - # project_path_cut = RepositoriesHelper::PROJECT_PATH_CUT - # ip = RepositoriesHelper::REPO_IP_ADDRESS + + # unless @changesets_latest_coimmit.blank? + # update_commits_date(@project, @changesets_latest_coimmit) + # end + @creator = @project.owner.to_s gitlab_address = Redmine::Configuration['gitlab_address'] + # REDO:需优化,仅测试用 @zip_path = Gitlab.endpoint.to_s + "/projects/" + @project.gpid.to_s + "/repository/archive?&private_token=" + Gitlab.private_token + + # 获取版本库路径,主要分为两种,一种随Gitlab类型,另一种为Git类型,Git类型为无用数据,最终需要删掉这种类型。 if @repository.type.to_s == "Repository::Gitlab" - @repos_url = gitlab_address.to_s+"/"+@project.owner.to_s+"/"+@repository.identifier+"."+"git" + @repos_url = gitlab_address.to_s+"/" + @creator + "/" + @repository.identifier+"."+"git" else @repos_url = "http://"+@repository.login.to_s+"_"+@repository.identifier.to_s+"@"+ip.to_s + @repository.url.slice(project_path_cut, @repository.url.length).to_s end @@ -653,9 +653,20 @@ update # 链接gitlab def connect_gitlab - @g = Gitlab.client - unless @project.gpid.nil? - @g_project = @g.project(@project.gpid) + begin + @g = Gitlab.client + unless @project.gpid.nil? + @g_project = @g.project(@project.gpid) + end + rescue => e + logger.error("failed to connect gitlab ==> #{e}") + end + end + + def show_rep + if !User.current.member_of?(@project) && @project.hidden_repo + render_403 + return end end diff --git a/app/controllers/school_controller.rb b/app/controllers/school_controller.rb index 44f4378fe..dab752afb 100644 --- a/app/controllers/school_controller.rb +++ b/app/controllers/school_controller.rb @@ -155,47 +155,51 @@ class SchoolController < ApplicationController def apply_add_school data = {result:0,name:params[:name],school_id:0} - #0 成功 1参数错误 2名称已存在 + #0 成功 1参数错误 2名称已存在 3.失败 data[:result] = 0 #检验参数 if params[:name] == "" || params[:province] == "" || params[:city] == "" || params[:address] == "" data[:result] = 1 else - school_id = School.find_by_sql("select id from schools where name='#{params[:name]}'").first - if school_id + school = School.where("name = '#{params[:name]}'").first + if school data[:result] = 2 else school = School.new school.name = params[:name].strip school.pinyin = Pinyin.t(params[:name].strip, splitter: '') - school.save #status 0未处理 1通过 2拒绝 applyschool = ApplyAddSchools.new - applyschool.school_id = school.id + + #用belongs_to 可以一起存数据库 + applyschool.school = school applyschool.name = school.name applyschool.province = params[:province] applyschool.city = params[:city] applyschool.address = params[:address] applyschool.remarks = params[:remarks] - applyschool.save - data[:school_id] = school.id + if applyschool.save + data[:school_id] = school.id + else + data[:result] = 3 + end end end render :json =>data end def search_repeat_schoolname - status = 0 + status = 0 #没有重复的 name = params[:name] if name - school_id = School.find_by_sql("select id from schools where name='#{name}'").first + school = School.where("name = '#{name}'").first - if school_id - status = 1 + if school + status = 1 #有重复的 end end diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 661770206..4c3a608de 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -390,7 +390,7 @@ class StudentWorkController < ApplicationController student_in_group = '(' + group_students.map{|user| user.id}.join(',') + ')' end #开放作品 || 老师 || 超级管理员 || 禁用匿评&&作业截止&&已提交作品 显示所有列表 - if (@homework.is_open == 1 && @course.is_public == 1) || (@homework.is_open == 1 && @course.is_public == 0 && User.current.member_of_course?(@course)) || @is_teacher || User.current.admin? || (User.current.member_of_course?(@course) && @homework.anonymous_comment == 1 && Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && !@homework.student_works.where(:user_id => User.current.id).empty?) + if (@homework.is_open == 1 && @course.is_public == 1) || (@homework.is_open == 1 && @course.is_public == 0 && User.current.member_of_course?(@course)) || @is_teacher || User.current.admin? || (User.current.member_of_course?(@course) && @homework.anonymous_comment == 1 && Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && !@homework.student_works.has_committed.where(:user_id => User.current.id).empty?) if @order == 'lastname' @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name elsif @order == 'student_id' @@ -409,7 +409,7 @@ class StudentWorkController < ApplicationController @stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:id => pro.student_work_id) end else - @stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id) + @stundet_works = @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id) end elsif @homework.homework_detail_manual.comment_status == 2 #学生 && 开启匿评 看到匿评列表 if @homework.homework_type == 3 @@ -420,7 +420,7 @@ class StudentWorkController < ApplicationController my_work = @homework.student_works.where(:id => pro.student_work_id) end else - my_work = @homework.student_works.where(:user_id => User.current.id) + my_work = @homework.student_works.has_committed.where(:user_id => User.current.id) end @stundet_works = my_work + User.current.student_works_evaluation_distributions.map(&:student_work).select { |work| work.homework_common_id == @homework.id} elsif @homework.homework_detail_manual.comment_status == 3 #学生 && 关闭匿评 未提交作品之前列表为空,提交了作品看到所有的 @@ -432,17 +432,17 @@ class StudentWorkController < ApplicationController my_work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:id => pro.student_work_id) end else - my_work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id) + my_work = @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id) end if my_work.empty? @stundet_works = [] else if @order == 'lastname' - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name + @stundet_works = search_homework_member @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name elsif @order == 'student_id' - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name + @stundet_works = search_homework_member @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name else - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name + @stundet_works = search_homework_member @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name end @show_all = true end @@ -454,9 +454,9 @@ class StudentWorkController < ApplicationController return end - @student_work_count = (search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name).count + @student_work_count = (search_homework_member @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name).count else - if (@homework.is_open == 1 &&@course.is_public == 1) || (@homework.is_open == 1 && @course.is_public == 0 && User.current.member_of_course?(@course)) || @is_teacher || User.current.admin? || (User.current.member_of_course?(@course) && @homework.anonymous_comment == 1 && Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && !@homework.student_works.where(:user_id => User.current.id).empty?) + if (@homework.is_open == 1 &&@course.is_public == 1) || (@homework.is_open == 1 && @course.is_public == 0 && User.current.member_of_course?(@course)) || @is_teacher || User.current.admin? || (User.current.member_of_course?(@course) && @homework.anonymous_comment == 1 && Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && !@homework.student_works.has_committed.where(:user_id => User.current.id).empty?) if @order == 'lastname' @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name elsif @order == 'student_id' @@ -475,7 +475,7 @@ class StudentWorkController < ApplicationController @stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:id => pro.student_work_id) end else - @stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id) + @stundet_works = @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id) end elsif @homework.homework_detail_manual.comment_status == 2 #学生 && 开启匿评 看到匿评列表 if @homework.homework_type == 3 @@ -486,7 +486,7 @@ class StudentWorkController < ApplicationController my_work = @homework.student_works.where(:id => pro.student_work_id) end else - my_work = @homework.student_works.where(:user_id => User.current.id) + my_work = @homework.student_works.has_committed.where(:user_id => User.current.id) end @stundet_works = my_work + User.current.student_works_evaluation_distributions.map(&:student_work).select { |work| work.homework_common_id == @homework.id} elsif @homework.homework_detail_manual.comment_status == 3 #学生 && 关闭匿评 未提交作品之前列表为空,提交了作品看到所有的 @@ -498,17 +498,17 @@ class StudentWorkController < ApplicationController my_work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:id => pro.student_work_id) end else - my_work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id) + my_work = @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id) end if my_work.empty? @stundet_works = [] else if @order == 'lastname' - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name + @stundet_works = search_homework_member @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").joins(:user).order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name elsif @order == 'student_id' - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name + @stundet_works = search_homework_member @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name else - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").order("#{@order} #{@b_sort}"),@name + @stundet_works = search_homework_member @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").order("#{@order} #{@b_sort}"),@name end @show_all = true end @@ -519,7 +519,7 @@ class StudentWorkController < ApplicationController render_403 return end - @student_work_count = (search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").order("#{@order} #{@b_sort}"),@name).count + @student_work_count = (search_homework_member @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").order("#{@order} #{@b_sort}"),@name).count end @score = @b_sort == "desc" ? "asc" : "desc" @@ -547,10 +547,10 @@ class StudentWorkController < ApplicationController return end @user = User.current - @student_work = @homework.student_works.where("user_id = ?",User.current.id).first - if @student_work.nil? + #@student_work = @homework.student_works.where("user_id = ?",User.current.id).first + #if @student_work.nil? @student_work = StudentWork.new - end + #end respond_to do |format| format.html{ render :layout => "new_base_user"} end @@ -560,7 +560,7 @@ class StudentWorkController < ApplicationController # 提交作品前先判断是否已经提交 @has_commit = false; if hsd_committed_work?(User.current.id, @homework.id) - @work = StudentWork.where("user_id =? and homework_common_id =?", User.current.id, @homework.id).first + @work = StudentWork.where("user_id =? and homework_common_id =? and work_status != 0", User.current.id, @homework.id).first @has_commit = true; #flash[:notice] = l(:notice_successful_create) #redirect_to edit_student_work_url(params[:student_work]) @@ -572,6 +572,7 @@ class StudentWorkController < ApplicationController if params[:student_work] @submit_result = true student_work = StudentWork.find(params[:student_work_id]) if params[:student_work_id] + student_work = StudentWork.where("user_id =? and homework_common_id =? and work_status = 0", User.current.id, @homework.id).first student_work ||= StudentWork.new student_work.name = params[:student_work][:name] == "#{@homework.name}的作品提交(可修改)" ? "#{@homework.name}的作品提交" : params[:student_work][:name] student_work.description = params[:student_work][:description] @@ -586,8 +587,10 @@ class StudentWorkController < ApplicationController #提交作品时,计算是否迟交 if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d") student_work.late_penalty = @homework.late_penalty + student_work.work_status = 2 else student_work.late_penalty = 0 + student_work.work_status = 1 end if student_work.save if @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 1 @@ -800,6 +803,9 @@ class StudentWorkController < ApplicationController @new_score.comment = params[:new_form][:user_message] if params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != "" @new_score.user_id = User.current.id @new_score.student_work_id = @work.id + if @is_teacher && @work.work_status == 0 + @work.update_column('work_status', 1) + end if User.current.admin? @new_score.reviewer_role = 1 else @@ -1148,7 +1154,7 @@ class StudentWorkController < ApplicationController end def hsd_committed_work?(user, homework) - sw = StudentWork.where("user_id =? and homework_common_id =?", user, homework).first + sw = StudentWork.where("user_id =? and homework_common_id =? and work_status != 0", user, homework).first sw.nil? ? result = false : result = true result end @@ -1225,7 +1231,7 @@ class StudentWorkController < ApplicationController sheet1[count_row,3] = homework.user.user_extensions.student_id sheet1[count_row,4] = homework.user.mail sheet1[count_row,5] = homework.name - sheet1[count_row,6] = strip_html homework.description + sheet1[count_row,6] = strip_html homework.description if !homework.description.nil? sheet1[count_row,7] = homework.teacher_score.nil? ? l(:label_without_score) : homework.teacher_score.round(2) sheet1[count_row,8] = homework.teaching_asistant_score.nil? ? l(:label_without_score) : homework.teaching_asistant_score.round(2) if @homework.anonymous_comment ==0 diff --git a/app/controllers/syllabuses_controller.rb b/app/controllers/syllabuses_controller.rb index 8ff88823d..8d7195f38 100644 --- a/app/controllers/syllabuses_controller.rb +++ b/app/controllers/syllabuses_controller.rb @@ -6,7 +6,7 @@ class SyllabusesController < ApplicationController include CoursesHelper before_filter :is_logged, :only => [:index, :show, :edit, :new, :update, :destroy, :delete_syllabus] - before_filter :find_syllabus, :only => [:show, :edit, :update, :destroy, :syllabus_courselist, :edit_syllabus_eng_name, :update_base_info, :delete_syllabus, :delete_des] + before_filter :find_syllabus, :only => [:show, :edit, :update, :destroy, :syllabus_courselist, :edit_syllabus_eng_name, :edit_syllabus_title, :update_base_info, :delete_syllabus, :delete_des] def index user = User.current @syllabuses = user.syllabuses @@ -140,6 +140,16 @@ class SyllabusesController < ApplicationController end end + #修改课程名称 + def edit_syllabus_title + if @syllabus && params[:title] != "" + @syllabus.update_column("title",params[:title]) + end + respond_to do |format| + format.js + end + end + #修改英文名称 def edit_syllabus_eng_name if @syllabus diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index fe42e6919..3f23d94dc 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -950,8 +950,10 @@ class UsersController < ApplicationController #提交作品时,计算是否迟交 if Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d") student_work.late_penalty = homework.late_penalty + student_work.work_status = 2 else student_work.late_penalty = 0 + student_work.work_status = 1 end student_work.save @@ -1042,6 +1044,26 @@ class UsersController < ApplicationController homework_detail_manual.save if homework_detail_manual homework_detail_programing.save if homework_detail_programing homework_detail_group.save if homework_detail_group + + if homework.homework_type != 3 + students = homework.course.student + if !homework.course.nil? && !students.empty? + name = homework.name + name_str = name + "的作品提交" + str = "" + students.each do |student| + if str != "" + str += "," + end + str += "('#{name_str}',#{homework.id},#{student.student_id}, '#{format_time(Time.now)}', '#{format_time(Time.now)}')" + end + #('#{name}的作品提交',#{homework.id},#{student.student_id}, '#{format_time(Time.now)}', '#{format_time(Time.now)}') + sql = "insert into student_works (name, homework_common_id,user_id, created_at, updated_at) values" + str + #StudentWork.create(:name => "#{name}的作品提交", :homework_common_id => homework.id, :user_id => student.student_id) + ActiveRecord::Base.connection.execute sql + end + end + if params[:quotes] && !params[:quotes].blank? quotes_homework = HomeworkCommon.find params[:quotes].to_i quotes_homework.update_column(:quotes, quotes_homework.quotes+1) @@ -2000,44 +2022,8 @@ class UsersController < ApplicationController def add_exist_file_to_course @flag = true if params[:send_id].present? - send_id = params[:send_id] - @ori = Attachment.find_by_id(send_id) - course_ids = params[:course_ids] - if course_ids.nil? - @flag = false - end - unless course_ids.nil? - course_ids.each do |id| - next if @ori.blank? - @exist = false - Course.find(id).attachments.each do |att| #如果课程中包含该资源 - if att.id == @ori.id || (!att.copy_from.nil? && !@ori.copy_from.nil? && att.copy_from == @ori.copy_from) || att.copy_from == @ori.id || att.id == @ori.copy_from - att.created_on = Time.now - att.save - @exist = true - break - end - end - next if @exist - attach_copied_obj = @ori.copy - attach_copied_obj.tag_list.add(@ori.tag_list) # tag关联 - attach_copied_obj.container = Course.find(id) - attach_copied_obj.created_on = Time.now - attach_copied_obj.author_id = User.current.id - attach_copied_obj.is_public = 0 - attach_copied_obj.copy_from = @ori.copy_from.nil? ? @ori.id : @ori.copy_from #发送要添加copy_from - if attach_copied_obj.attachtype == nil - attach_copied_obj.attachtype = 4 - end - if attach_copied_obj.save - # 更新引用次数 - quotes = @ori.quotes.to_i + 1 - @ori.update_attribute(:quotes, quotes) unless @ori.nil? - @ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) - end - @save_message = attach_copied_obj.errors.full_messages - end - end + rs = ResourcesService.new + @ori, @flag, @save_message = rs.send_resource_to_course(params) elsif params[:send_ids].present? send_ids = params[:send_ids].split(",") course_ids = params[:course_ids] @@ -2782,8 +2768,8 @@ class UsersController < ApplicationController # 获取我的课程资源 def get_course_resources author_id, user_course_ids, order, score - attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Course')"+ - "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) + attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and container_type = 'Course')"+ + "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" ).order("#{order.nil? ? 'created_on' : order} #{score}") end diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb index 4a79d6d93..f49398ff7 100644 --- a/app/controllers/wechats_controller.rb +++ b/app/controllers/wechats_controller.rb @@ -8,7 +8,11 @@ class WechatsController < ActionController::Base # default text responder when no other match on :text do |request, content| #邀请码 - sendBindClass(request, {invite_code: content}) + if join_request(request) + sendBindClass(request, {invite_code: content}) + else + request.reply.text '您的意见已收到,感谢您的反馈!' + end end # When receive 'help', will trigger this responder @@ -142,6 +146,11 @@ class WechatsController < ActionController::Base end end + def join_request(request) + openid = request[:FromUserName] + wl = WechatLog.where("openid = '#{openid}' and request_raw like '%\"Event\":\"click\"%'").order('id desc').first + wl && JSON(wl.request_raw)["EventKey"] == 'JOIN_CLASS' + end def sendBindClass(request, params) begin diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f29981999..23fd401fd 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2631,7 +2631,7 @@ module ApplicationHelper def homework_anonymous_comment (homework, is_in_course, user_activity_id = -1, course_activity = -1) if homework.homework_detail_manual.comment_status == 0 ||Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") link = link_to "启动匿评","javascript:void(0)", :class => "postOptionLink", :title => "作业截止日期之前不可以启动匿评" - elsif homework.student_works.count >= 2 && homework.homework_detail_manual#作业份数大于2 + elsif homework.student_works.has_committed.count >= 2 && homework.homework_detail_manual#作业份数大于2 case homework.homework_detail_manual.comment_status when 1 link = link_to '启动匿评', Setting.protocol + "://" + Setting.host_name + "/homework_common/" + homework.id.to_s + "/alert_anonymous_comment?is_in_course=" + is_in_course.to_s + "&user_activity_id=" + user_activity_id.to_s + "&course_activity=" + course_activity.to_s, id: "#{homework.id}_start_anonymous_comment", remote: true, disable_with: '加载中...',:class => 'postOptionLink' @@ -2681,40 +2681,41 @@ module ApplicationHelper #根据传入作业确定显示为编辑作品还是新建作品,或者显示作品数量 def user_for_homework_common homework,is_teacher + count = homework.student_works.has_committed.count if User.current.member_of_course?(homework.course) if is_teacher #老师显示作品数量 - link_to "作品(#{homework.student_works.count})", student_work_index_url_in_org(homework.id), :class => "c_blue" + link_to "作品(#{count})", student_work_index_url_in_org(homework.id), :class => "c_blue" else #学生显示提交作品、修改作品等按钮 work = cur_user_works_for_homework homework project = cur_user_projects_for_homework homework if work.nil? && Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") if homework.homework_type ==3 && project.nil? && homework.homework_detail_group.base_on_project == 1 - link_to "提交作品(#{homework.student_works.count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再提交作品' + link_to "提交作品(#{count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再提交作品' else - link_to "提交作品(#{homework.student_works.count})", new_student_work_url_without_domain(homework.id),:class => 'c_blue' + link_to "提交作品(#{count})", new_student_work_url_without_domain(homework.id),:class => 'c_blue' end elsif work.nil? && Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") if homework.homework_type ==3 && project.nil? && homework.homework_detail_group.base_on_project == 1 - link_to "补交作品(#{homework.student_works.count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再补交作品' + link_to "补交作品(#{count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再补交作品' else - link_to "补交作品(#{homework.student_works.count})", new_student_work_url_without_domain(homework.id),:class => 'c_red' + link_to "补交作品(#{count})", new_student_work_url_without_domain(homework.id),:class => 'c_red' end else if homework.homework_detail_manual && homework.homework_detail_manual.comment_status == 2 #匿评作业,且作业状态不是在开启匿评之前 link_to "作品匿评", student_work_index_url_in_org(homework.id), :class => 'c_blue', :title => "开启匿评后不可修改作品" elsif homework.homework_detail_manual && homework.homework_detail_manual.comment_status == 3 - link_to "查看作品(#{homework.student_works.count})",student_work_index_url_in_org(homework.id), :class => 'c_blue', :title => "匿评已结束" + link_to "查看作品(#{count})",student_work_index_url_in_org(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_url_without_domain(homework.id),:class => 'c_blue' + link_to "修改作品(#{count})", new_student_work_url_without_domain(homework.id),:class => 'c_blue' 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_url_without_domain(work.id),:class => 'c_blue' + link_to "修改作品(#{count})", edit_student_work_url_without_domain(work.id),:class => 'c_blue' else - link_to "查看作品(#{homework.student_works.count})", student_work_index_url_in_org(homework.id), :class => 'c_blue', :title => "作业截止后不可修改作品" + link_to "查看作品(#{count})", student_work_index_url_in_org(homework.id), :class => 'c_blue', :title => "作业截止后不可修改作品" end end end else - link_to "作品(#{homework.student_works.count})",student_work_index_url_in_org(homework.id),:class => "c_blue" + link_to "作品(#{count})",student_work_index_url_in_org(homework.id),:class => "c_blue" end end @@ -2752,7 +2753,7 @@ module ApplicationHelper #获取当前用户在指定作业下提交的作业的集合 def cur_user_works_for_homework homework - work = homework.student_works.where("user_id = ?",User.current).first + work = homework.student_works.where("user_id = ? && work_status != 0",User.current).first if homework.homework_type == 3 pro = homework.student_work_projects.where("user_id = #{User.current.id}").first if pro.nil? || pro.student_work_id == "" || pro.student_work_id.nil? @@ -3281,7 +3282,7 @@ end def strip_html(text,len=0,endss="...") ss = "" - if text.length>0 + if !text.nil? && text.length>0 ss=text.gsub(/<\/?.*?>/, '').strip ss = ss.gsub(/ /, ' ') @@ -3322,3 +3323,21 @@ def get_group_member_names work end result end + +def course_syllabus_option user = User.current + syllabuses = user.syllabuses + type = [] + option1 = [] + option1 << "请选择课程" + option1 << 0 + type << option1 + unless syllabuses.empty? + syllabuses.each do |syllabus| + option = [] + option << syllabus.title + option << syllabus.id + type << option + end + end + type +end diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 55a4da73a..d1f4bfe97 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -772,12 +772,12 @@ module CoursesHelper url = joined ? join_path(:object_id => course.id) : try_join_path(:object_id => course.id) method = joined ? 'delete' : 'post' if joined - link = link_to(text, url, :remote => true, :method => method, :class => "pr_join_a", :id => "#{course.id}", :confirm => l(:text_are_you_sure_out)) + link = link_to(text, url, :remote => true, :method => method, :class => "Blue-btn", :style => "margin_left: 0px;", :id => "#{course.id}", :confirm => l(:text_are_you_sure_out)) else - link = link_to(text, url, :remote => true, :method => method, :id => "#{course.id}", :class => "pr_join_a") + link = link_to(text, url, :remote => true, :method => method, :id => "#{course.id}", :class => "Blue-btn", :style => "margin_left: 0px;") end else - link = "#{l(:label_course_join_student)}" + link = "#{l(:label_course_join_student)}" end link.html_safe end diff --git a/app/helpers/student_work_helper.rb b/app/helpers/student_work_helper.rb index 74788751b..42a3a6538 100644 --- a/app/helpers/student_work_helper.rb +++ b/app/helpers/student_work_helper.rb @@ -52,6 +52,19 @@ module StudentWorkHelper result end + def get_status status + str = "" + case status + when 0 + str = "未提交" + when 1 + str = "已提交" + when 2 + str = "迟交" + end + str + end + #获取赞的总数 def praise_homework_count obj_id PraiseTread.where("praise_tread_object_id = #{obj_id} AND praise_tread_object_type = 'StudentWork'").count diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index f312d2275..98b993183 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -388,6 +388,21 @@ module UsersHelper return result end + + #获取指定用户的课程大纲 + def user_syllabus(user) + results = [] + courses = user_courses_list(user) + + other = Syllabus.new(title: '未命名课程') + + courses.each do |c| + other << c unless c.syllabus + end + + user.syllabuses.to_a << other + end + #获取用户参与的公开的课程列表 def user_public_course_list user membership = user.coursememberships.all#@user.coursememberships.all(:conditions => Course.visible_condition(User.current)) diff --git a/app/models/apply_add_schools.rb b/app/models/apply_add_schools.rb index 2082c0012..efa56e808 100644 --- a/app/models/apply_add_schools.rb +++ b/app/models/apply_add_schools.rb @@ -1,3 +1,4 @@ class ApplyAddSchools < ActiveRecord::Base attr_accessible :address, :city, :name, :province, :remarks, :school_id, :status + belongs_to :school end diff --git a/app/models/course.rb b/app/models/course.rb index e4b08697b..561a031ae 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -4,6 +4,8 @@ require 'elasticsearch/model' class Course < ActiveRecord::Base include Redmine::SafeAttributes + include CoursesHelper + STATUS_ACTIVE = 1 STATUS_CLOSED = 5 STATUS_ARCHIVED = 9 @@ -22,7 +24,7 @@ class Course < ActiveRecord::Base end end - attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password,:is_public,:description,:class_period, :open_student, :enterprise_name, :is_delete + attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password,:is_public,:description,:class_period, :open_student, :enterprise_name, :is_delete, :syllabus_id #belongs_to :project, :class_name => 'Course', :foreign_key => :extra, primary_key: :identifier belongs_to :teacher, :class_name => 'User', :foreign_key => :tea_id # 定义一个方法teacher,该方法通过tea_id来调用User表 belongs_to :school, :class_name => 'School', :foreign_key => :school_id #定义一个方法school,该方法通过school_id来调用School表 @@ -69,8 +71,10 @@ class Course < ActiveRecord::Base validates_presence_of :term,:name validates_format_of :class_period, :with =>/^[1-9]\d*$/ - validates_format_of :name,:with =>/^[^ ]+[a-zA-Z0-9_\u4e00-\u9fa5\s\S]+$/ + validates_format_of :time, :with => /^\d{4}$/ + validates_format_of :name,:with =>/^[^ ]+[a-zA-Z0-9_\u4e00-\u9fa5\s\S]*$/ validates_length_of :description, :maximum => 10000 + before_save :self_validate # 公开课程变成私有课程,所有资源都变成私有 after_update :update_files_public,:update_course_ealasticsearch_index @@ -169,6 +173,10 @@ class Course < ActiveRecord::Base ) end + def delete! + update_attribute(:is_delete, true) + end + def visible?(user=User.current) user.allowed_to?(:view_course, self) end @@ -296,6 +304,13 @@ class Course < ActiveRecord::Base end end + + def update_default_value + self.time = Time.now.year unless time + self.term = cur_course_term unless term + self.class_period = 10 unless class_period + end + # 创建课程讨论区 def create_board_sync @board = self.boards.build @@ -480,7 +495,7 @@ class Course < ActiveRecord::Base def generate_qrcode ticket = self.qrcode if !ticket || ticket.size < 10 - response = Wechat.api.qrcode_create_scene(invite_code) + response = Wechat.api.qrcode_create_scene(invite_code, 2592000) logger.debug "response = #{response}" self.qrcode = response['ticket'] save! && reload diff --git a/app/models/sonar_error.rb b/app/models/sonar_error.rb new file mode 100644 index 000000000..05fcfc5b9 --- /dev/null +++ b/app/models/sonar_error.rb @@ -0,0 +1,3 @@ +class SonarError < ActiveRecord::Base + attr_accessible :jenkins_job_name, :output, :project_id +end diff --git a/app/models/student_work.rb b/app/models/student_work.rb index ddd91df38..3fcc9fb8a 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -13,6 +13,8 @@ class StudentWork < ActiveRecord::Base has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy has_many :attachments, :dependent => :destroy + scope :has_committed, lambda{where("work_status != 0")} + before_destroy :delete_praise before_save :set_program_score, :set_src @@ -172,7 +174,7 @@ class StudentWork < ActiveRecord::Base # status == 0 : delay def act_as_message - if self.created_at > self.homework_common.end_time + 1 + if self.work_status != 0 && self.created_at > self.homework_common.end_time + 1 self.course_messages << CourseMessage.new(:user_id => self.user_id, :course_id => self.homework_common.course_id, :viewed => false, :status => false) end end diff --git a/app/models/syllabus.rb b/app/models/syllabus.rb index 5e368f341..29b675d25 100644 --- a/app/models/syllabus.rb +++ b/app/models/syllabus.rb @@ -9,8 +9,19 @@ class Syllabus < ActiveRecord::Base belongs_to :user has_many :courses has_many :journals_for_messages, :as => :jour, :dependent => :destroy - attr_accessible :description, :title, :eng_name, :syllabus_type, :credit, :hours, :theory_hours, :practice_hours, :applicable_major, :pre_course - safe_attributes 'title', 'description', 'eng_name', 'syllabus_type', 'credit', 'hours', 'theory_hours', 'practice_hours', 'credit', 'applicable_major', 'pre_course' + attr_accessible :description, :user_id, :title, :eng_name, :syllabus_type, :credit, :hours, :theory_hours, :practice_hours, :applicable_major, :pre_course + safe_attributes 'title','user', 'description', 'eng_name', 'syllabus_type', 'credit', 'hours', 'theory_hours', 'practice_hours', 'credit', 'applicable_major', 'pre_course' + + validates :title, :user_id, presence: true + + scope :like, lambda {|arg| + if arg.blank? + where(nil) + else + pattern = "%#{arg.to_s.strip.downcase}%" + where(" LOWER(title) LIKE :p ", :p => pattern) + end + } def delete_kindeditor_assets delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::SYLLABUS diff --git a/app/models/wechat_log.rb b/app/models/wechat_log.rb new file mode 100644 index 000000000..118a9fade --- /dev/null +++ b/app/models/wechat_log.rb @@ -0,0 +1,4 @@ +#coding=utf-8 +# +class WechatLog < ActiveRecord::Base +end diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index f59beb7e5..a55a81e89 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -44,6 +44,8 @@ class CoursesService } end + + #搜索课程 def search_course params,current_user courses_all = Course.all_course @@ -324,9 +326,9 @@ class CoursesService define_error [ 0, '加入成功', 1, '密码错误', - 2, '班级已过期 请联系班级管理员重启班级。', - 3, '您已经加入了班级', - 4, '您加入的班级不存在', + 2, '课程已过期 请联系课程管理员重启课程。', + 3, '您已经加入了课程', + 4, '您的邀请码不正确', 5, '您还未登录', 6, '申请成功,请等待审核完毕', 7, '您已经发送过申请了,请耐心等待', diff --git a/app/services/resources_service.rb b/app/services/resources_service.rb new file mode 100644 index 000000000..a0fec585a --- /dev/null +++ b/app/services/resources_service.rb @@ -0,0 +1,53 @@ +#coding=utf-8 + +class ResourcesService + + #发送资源到课程 + def send_resource_to_course user,params + send_id = params[:send_id] + @ori = Attachment.find_by_id(send_id) + course_ids = params[:course_ids] + @flag = false + unless course_ids.nil? + course_ids.each do |id| + next if @ori.blank? + @exist = false + Course.find(id).attachments.each do |att| #如果课程中包含该资源 + if att.id == @ori.id || (!att.copy_from.nil? && !@ori.copy_from.nil? && att.copy_from == @ori.copy_from) || att.copy_from == @ori.id || att.id == @ori.copy_from + att.created_on = Time.now + att.save + @exist = true + @flag = true + break + end + end + next if @exist + attach_copied_obj = @ori.copy + attach_copied_obj.tag_list.add(@ori.tag_list) # tag关联 + attach_copied_obj.container = Course.find(id) + attach_copied_obj.created_on = Time.now + attach_copied_obj.author_id = user.id + attach_copied_obj.is_public = 0 + attach_copied_obj.copy_from = @ori.copy_from.nil? ? @ori.id : @ori.copy_from #发送要添加copy_from + if attach_copied_obj.attachtype == nil + attach_copied_obj.attachtype = 4 + end + if attach_copied_obj.save + # 更新引用次数 + quotes = @ori.quotes.to_i + 1 + @ori.update_attribute(:quotes, quotes) unless @ori.nil? + @ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) + @flag = true + else + @flag = false + @save_message = attach_copied_obj.errors.full_messages + break + end + + end + end + + [@ori, @flag, @save_message] + end + +end \ No newline at end of file diff --git a/app/services/syllabuses_service.rb b/app/services/syllabuses_service.rb new file mode 100644 index 000000000..b3190182c --- /dev/null +++ b/app/services/syllabuses_service.rb @@ -0,0 +1,143 @@ +#coding=utf-8 + +class SyllabusesService + + include ApplicationHelper + include CoursesHelper + + def judge_can_setting(sy,user) + sy[:can_setting] = sy[:user_id] == user.id ? true : false + + sy[:can_setting] = false if sy[:id].nil? + + sy.courses.each do |c| + c[:can_setting] = false + + member = c.members.where("user_id=#{user.id} and course_id=#{c.id}")[0] + roleName = member.roles[0].name if member + + if roleName && (roleName == "TeachingAsistant" || roleName == "Teacher" ) + c[:can_setting] = true + end + + if c.tea_id == user.id + c[:can_setting] = true + end + end + + sy + end + #获取指定用户的课程大纲 + def user_syllabus(user) + courses = CoursesService.new.user_courses_list(user) + + other = Syllabus.new(title: '未命名课程',user_id: user.id) + + courses.each do |c| + other.courses << c[:course] unless c[:course].syllabus + end + + # user.syllabuses.each do |syllabus| + # syllabus.courses = syllabus.courses.not_deleted + # end + # + # user.syllabuses.to_a << other + + courses = user.courses.not_deleted + syllabus_ids = courses.empty? ? '(-1)' : "(" + courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")" + syllabuses = Syllabus.where("id in #{syllabus_ids} or user_id = #{user.id}").order("updated_at desc") + + syllabuses.each do |syllabus| + syllabus.courses = courses.where("syllabus_id = #{syllabus.id}").select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("time desc") + end + + syllabuses.to_a << other + + #管理权限 can_setting + syllabuses.each do |s| + s = judge_can_setting(s,user) + end + + syllabuses + end + + def after_create_course(course, user) + #unless User.current.admin? + r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first + m = Member.new(:user => user, :roles => [r]) + m.project_id = -1 + course_info = CourseInfos.new(:user_id => user.id, :course_id => course.id) + #user_grades = UserGrade.create(:user_id => User.current.id, :course_id => @course.id) + course.members << m + course.course_infos << course_info + end + + #创建大纲 + # params {title: '大纲名称', [{course}, {course}]} + def create(user, title, courses = []) + sy = Syllabus.new(title: title, user_id: user.id) + ActiveRecord::Base.transaction() do + sy.save! + + courses.each do |course| + if ::Course === course + course.syllabus_id = sy.id + course.save! + elsif Hash === course + c = ::Course.new(course) + c.tea_id = user.id + c.syllabus_id = sy.id + c.update_default_value + c.is_public = 0 + c.save! + after_create_course(c, user) + end + end + + end + sy[:can_setting] = true + sy + end + + #修改课程大纲的名称、班级名称、新增班级 + def edit(user, option) + courses = [] + status = -1 + syllabus_id = option[:id] + + sy = Syllabus.where("id=?",option[:id]).first + + if sy && sy.user_id == user.id + syllabus_title = option[:title] + + sy.title = syllabus_title + sy.save! + #修改班级名称 + modify_courses = option[:modify_courses] + modify_courses.each do |c| + course = Course.where("id=?",c.id).first + + if course && course.tea_id == user.id + course.name = c.name + !course.save + end + end + + #新增班级 + add_courses = option[:add_courses] + add_courses.each do |c| + course = Course.new() + course.name = c + course.tea_id = user.id + course.syllabus_id = sy.id + course.update_default_value + course.is_public = 0 + course.save! + after_create_course(course, user) + end + status = 0 + end + status + end + +end diff --git a/app/services/users_service.rb b/app/services/users_service.rb index 8df42fb41..ab1bb2ec4 100644 --- a/app/services/users_service.rb +++ b/app/services/users_service.rb @@ -319,4 +319,8 @@ class UsersService my_jours_arr end + + + + end diff --git a/app/views/admin/_courselist_detail_tr.html.erb b/app/views/admin/_courselist_detail_tr.html.erb new file mode 100644 index 000000000..07486faa3 --- /dev/null +++ b/app/views/admin/_courselist_detail_tr.html.erb @@ -0,0 +1,30 @@ + + <%= course.id %> + + + + <%= link_to(course.name, course_path(course.id)) %> + + + + <%= link_to(course.try(:teacher).try(:realname).truncate(6, omission: '...'), user_path(course.teacher)) %> + + + <%= course.class_period %> + + + <%= checked_image course.is_public? %> + + + <%= format_date(course.created_at) %> + + + <%= course.updated_at.strftime('%Y-%m-%d %H:%M:%S') %> + + + <%= select_tag :syllabus_id,options_for_select(course_syllabus_option(course.teacher),course.syllabus_id), {:id=>"new_syllabus_id_#{course.id}", :class=>"course_syllabus_input", :onchange=>"select_syllabus(#{course.id});"}%> + + + 新建课程 + <%#= link_to "新建课程", admin_create_syllabus_path%> + \ No newline at end of file diff --git a/app/views/admin/_rename_course_name.html.erb b/app/views/admin/_rename_course_name.html.erb new file mode 100644 index 000000000..8cc061c76 --- /dev/null +++ b/app/views/admin/_rename_course_name.html.erb @@ -0,0 +1,3 @@ + + <%= course.name %> + \ No newline at end of file diff --git a/app/views/admin/_tab_syllabuses_courses.erb b/app/views/admin/_tab_syllabuses_courses.erb new file mode 100644 index 000000000..7530b3af7 --- /dev/null +++ b/app/views/admin/_tab_syllabuses_courses.erb @@ -0,0 +1,7 @@ +
+ +
\ No newline at end of file diff --git a/app/views/admin/courses.html.erb b/app/views/admin/courses.html.erb index 7e5b816c4..11fb1973f 100644 --- a/app/views/admin/courses.html.erb +++ b/app/views/admin/courses.html.erb @@ -5,15 +5,20 @@

<%=l(:label_course_all)%>

+<%= render 'tab_syllabuses_courses' %> + +

+ 班级列表 +

<%= form_tag({}, :method => :get) do %>
- <%= text_field_tag 'name', params[:name], :size => 30, :placeholder => '课程名称' %> + <%= text_field_tag 'name', params[:name], :size => 30, :placeholder => '班级、老师名称' %> <%= submit_tag l(:button_apply), :class => "small", :name => nil %> - <%= link_to l(:button_clear), {:controller => 'admin', :action => 'courses'},:remote => true, :class => 'icon icon-reload' %> + <%= link_to l(:button_clear), {:controller => 'admin', :action => 'courses'}, :class => 'icon icon-reload' %>
<% end %>   @@ -26,51 +31,35 @@ 序号 - 课程 + 班级 主讲老师 - + 学时 - + <%=l(:field_is_public)%> - + <%=l(:field_created_on)%> - + 动态时间 + + 课程 + + + + <% @courses.each do |course| %> - "> - - <%= course.id %> - - - - <%= link_to(course.name, course_path(course.id)) %> - - - - <%= link_to(course.try(:teacher).try(:realname).truncate(6, omission: '...'), user_path(course.teacher)) %> - - - <%= course.class_period %> - - - <%= checked_image course.is_public? %> - - - <%= format_date(course.created_at) %> - - - <%= course.course_activities.order('updated_at DESC').first.updated_at.strftime('%Y-%m-%d %H:%M:%S') %> - + " id="course_<%=course.id %>"> + <%=render :partial => 'courselist_detail_tr', :locals => {:course => course} %> <% end %> @@ -81,4 +70,19 @@ <%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false %> + <% html_title(l(:label_course_all)) -%> diff --git a/app/views/admin/create_syllabus.js.erb b/app/views/admin/create_syllabus.js.erb new file mode 100644 index 000000000..ac37abd78 --- /dev/null +++ b/app/views/admin/create_syllabus.js.erb @@ -0,0 +1,10 @@ +hideModal(); +<%courses = Course.where("tea_id = #{@user.id}") %> +<% unless courses.empty? %> + <% courses.each do |course|%> + $("#course_<%=course.id %>").html("<%=escape_javascript(render :partial => 'courselist_detail_tr', :locals => {:course => course}) %>"); + <% end %> +<% end %> +<% if @flag == 1 %> + $("#course_<%=@course.id %>").html(""); +<% end %> \ No newline at end of file diff --git a/app/views/admin/excellent_courses.html.erb b/app/views/admin/excellent_courses.html.erb index c107713a0..0418ebf30 100644 --- a/app/views/admin/excellent_courses.html.erb +++ b/app/views/admin/excellent_courses.html.erb @@ -16,7 +16,7 @@ 序号 - 课程名 + 班级名 主讲老师 diff --git a/app/views/admin/non_syllabus_courses.html.erb b/app/views/admin/non_syllabus_courses.html.erb new file mode 100644 index 000000000..6c3cbec10 --- /dev/null +++ b/app/views/admin/non_syllabus_courses.html.erb @@ -0,0 +1,164 @@ +
+ <%= link_to l(:label_course_new), {:controller => 'courses', :action => 'new'}, :class => 'icon icon-add' %> +
+ +

+ 未配置班级列表 +

+<%= render 'tab_syllabuses_courses' %> + +

+ 未配置班级列表 +

+ +<%= form_tag({}, :method => :get) do %> +
+ + <%= text_field_tag 'name', params[:name], :size => 30, :placeholder => '班级、老师名称' %> + <%= submit_tag l(:button_apply), :class => "small", :name => nil %> + <%= link_to l(:button_clear), {:controller => 'admin', :action => 'non_syllabus_courses'}, :class => 'icon icon-reload' %> +
+<% end %> +  + +
+ + + + + + + + + + + + + + + + <% @courses.each do |course| %> + " id="course_<%=course.id %>"> + + + + + + + + + + + <% end %> + +
+ 序号 + + 班级 + + 主讲老师 + + 学时 + + <%=l(:field_is_public)%> + + <%=l(:field_created_on)%> + + 动态时间 + + 课程 + + +
+ <%= course.id %> + + + <%= course.name%> + + + <%= link_to(course.try(:teacher).try(:realname).truncate(6, omission: '...'), user_path(course.teacher)) %> + + <%= course.class_period %> + + <%= checked_image course.is_public? %> + + <%= format_date(course.created_at) %> + + <%= course.updated_at.strftime('%Y-%m-%d %H:%M:%S') %> + + <%= select_tag :syllabus_id,options_for_select(course_syllabus_option(course.teacher),course.syllabus_id), {:id=>"new_syllabus_id_#{course.id}", :class=>"course_syllabus_input", :onchange=>"select_syllabus(#{course.id});"}%> + + 新建课程 +
+
+ + + + +<% html_title(l(:label_course_all)) -%> diff --git a/app/views/admin/syllabuses.html.erb b/app/views/admin/syllabuses.html.erb new file mode 100644 index 000000000..782f6b01c --- /dev/null +++ b/app/views/admin/syllabuses.html.erb @@ -0,0 +1,140 @@ +

+ 课程列表 +

+<%= render 'tab_syllabuses_courses' %> + +

+ 课程列表 +

+ +<%= form_tag({}, :method => :get) do %> +
+ + <%= text_field_tag 'name', params[:name], :size => 30, :placeholder => '课程名称' %> + <%= submit_tag l(:button_apply), :class => "small", :name => nil %> + <%= link_to l(:button_clear), {:controller => 'admin', :action => 'syllabuses'}, :class => 'icon icon-reload' %> +
+<% end %> +  + +
+ + + + + + + + + + + + <% @syllabuses.each do |syllabus| %> + + + + + + + + <% courses = syllabus.courses %> + <% courses.each do |course| %> + + + + + + + + <% end %> + <% end %> + +
+ 序号 + + 课程名称 + + 班级名称 + + 创建老师 + + <%=l(:field_created_on)%> +
+ <%= syllabus.id %> + + + <%= link_to(syllabus.title, syllabus_path(syllabus.id)) %> + + + + <%= link_to(syllabus.try(:user).try(:realname).truncate(6, omission: '...'), user_path(syllabus.user)) %> + + <%= format_date(syllabus.created_at) %> +
+ <%= course.id %> + + + <%= render :partial => 'admin/rename_course_name', :locals => {:course => course} %> + + <%= link_to(course.try(:teacher).try(:realname).truncate(6, omission: '...'), user_path(course.teacher)) %> + + <%= format_date(course.created_at) %> +
+
+ + + + \ No newline at end of file diff --git a/app/views/admin/update_course_name.js.erb b/app/views/admin/update_course_name.js.erb new file mode 100644 index 000000000..45c0cb99d --- /dev/null +++ b/app/views/admin/update_course_name.js.erb @@ -0,0 +1 @@ +$("#syllabus_course_name_<%=@course.id %>").html("<%=escape_javascript(render :partial => 'admin/rename_course_name', :locals => {:course => @course}) %>"); diff --git a/app/views/blog_comments/reply.js.erb b/app/views/blog_comments/reply.js.erb index 915ab892d..baf4418e9 100644 --- a/app/views/blog_comments/reply.js.erb +++ b/app/views/blog_comments/reply.js.erb @@ -1,4 +1,7 @@ -<% if @in_user_center%> +<% if @in_user_homepage %> + <% homepage = BlogComment.find(@user.blog.homepage_id) %> + $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'blogs/homepage', :locals => {:activity => homepage, :user_activity_id => homepage.id}) %>"); +<% elsif @in_user_center%> $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'users/user_blog', :locals => {:activity => @article,:user_activity_id =>@user_activity_id}) %>"); // init_activity_KindEditor_data(<%#= @user_activity_id%>,"","87%", 'UserActivity'); <% else%> diff --git a/app/views/blogs/_homepage.html.erb b/app/views/blogs/_homepage.html.erb index 5dbee59d6..140f547cb 100644 --- a/app/views/blogs/_homepage.html.erb +++ b/app/views/blogs/_homepage.html.erb @@ -48,4 +48,53 @@
+ <% count=activity.children.count %> +
+ <%= render :partial => 'users/reply_banner', :locals => {:count => count, :activity => activity, :user_activity_id => user_activity_id} %> + + <% comments = activity.children.reorder("created_on desc").limit(3) %> + <% if count > 0 %> +
+ <%= render :partial => 'users/all_replies', :locals => {:comments => comments}%> +
+ <% end %> + + <% if activity.locked == false && User.current.logged?%> +
+
<%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(activity.author_id), :alt => "用户头像" %>
+
+ <% if User.current.logged? %> +
+ <%= form_for('new_form',:url => {:controller => 'blog_comments', :action => 'reply', :user_id=>activity.author_id,:blog_id=>activity.blog_id,:id=>activity.id,:homepage=>1},:method => "post", :remote => true) do |f|%> + + + + + + +
+ + +
+

+ <% end%> +
+ <% else %> + <%= render :partial => "users/show_unlogged" %> + <% end %> +
+
+
+
+ <% end %> +
+ \ No newline at end of file diff --git a/app/views/courses/new.html.erb b/app/views/courses/new.html.erb index f8db461a6..78b3d8293 100644 --- a/app/views/courses/new.html.erb +++ b/app/views/courses/new.html.erb @@ -7,7 +7,7 @@
  • <% if @syllabus.nil? %> - <%= select_tag :syllabus_id,options_for_select(syllabus_option,@course.syllabus_id), {:id=>"new_syllabus_id", :class=>"syllabus_input"} %> + <%= select_tag :syllabus_id,options_for_select(course_syllabus_option,@course.syllabus_id), {:id=>"new_syllabus_id", :class=>"syllabus_input"} %> <% else %> <%=@syllabus.title %> diff --git a/app/views/courses/settings.html.erb b/app/views/courses/settings.html.erb index 903d01f8a..ee0f6c98a 100644 --- a/app/views/courses/settings.html.erb +++ b/app/views/courses/settings.html.erb @@ -31,14 +31,13 @@
  • - <%= select_tag :syllabus_id,options_for_select(syllabus_option,@course.syllabus_id), {:id=>"edit_syllabus_id", :class=>"syllabus_input", :style=>'width:280px'} %> + <%= select_tag :syllabus_id,options_for_select(course_syllabus_option,@course.syllabus_id), {:id=>"edit_syllabus_id", :class=>"syllabus_input", :style=>'width:280px'} %>
  • - + -
  • diff --git a/app/views/files/_course_file.html.erb b/app/views/files/_course_file.html.erb index 2cf43f896..946449680 100644 --- a/app/views/files/_course_file.html.erb +++ b/app/views/files/_course_file.html.erb @@ -86,6 +86,14 @@
  • +
    + <% unless User.current.logged? %> +
    +

    您尚未登录,登录 + 后可浏览更多信息 +

    +
    + <% end %>
    <%= form_tag( search_course_files_path(@course), method: 'get',:class => "re_search",:remote=>true) do %> diff --git a/app/views/files/_project_file.html.erb b/app/views/files/_project_file.html.erb index 98b9ad514..40e5163a8 100644 --- a/app/views/files/_project_file.html.erb +++ b/app/views/files/_project_file.html.erb @@ -57,6 +57,14 @@
    +
    + <% unless User.current.logged? %> +
    +

    您尚未登录,登录 + 后可浏览更多信息 +

    +
    + <% end %>
    <%= form_tag( search_project_project_files_path(@project), method: 'get',:class => "re_search",:remote=>true) do %> diff --git a/app/views/files/_subfield_files.html.erb b/app/views/files/_subfield_files.html.erb index 516e42c68..6a60442b8 100644 --- a/app/views/files/_subfield_files.html.erb +++ b/app/views/files/_subfield_files.html.erb @@ -35,6 +35,14 @@
    +
    + <% unless User.current.logged? %> +
    +

    您尚未登录,登录 + 后可浏览更多信息 +

    +
    + <% end %>
    <%= form_tag( search_files_in_subfield_org_subfield_files_path(@org_subfield), method: 'get',:class => "re_search",:remote=>true) do %> diff --git a/app/views/layouts/_project_info.html.erb b/app/views/layouts/_project_info.html.erb index 85f02310d..abfebd828 100644 --- a/app/views/layouts/_project_info.html.erb +++ b/app/views/layouts/_project_info.html.erb @@ -8,31 +8,29 @@ <% end %> <%= image_tag(url_to_avatar(@course), :width => "60", :height => "60") %>
    -
    +
    + <% if @course.syllabus%> - + <%= @course.syllabus.title + " •" %> <% end %> -
    - - <%=@course.is_public == 0 ? '(私有)' : '(公开)' %> -
    -
    +  <%= @course.name %><%=@course.is_public == 0 ? '(私有)' : '(公开)' %> <% if is_excellent_course(@course) %> - 精品课程 - <% end %> -
    -
    - <% unless is_teacher %> -
    <%= join_in_course_header(@course, User.current) %>
    + 精品课程 <% end %> +
    +
    - 邀请码: - <%=@course.generate_invite_code %> + 邀请码: + <%=@course.generate_invite_code %> + <% unless is_teacher %> +
    <%= join_in_course_header(@course, User.current) %>
    + <% end %>
    +
    <%= l(:label_account_identity_teacher)%>(<%= course_teacher_link teacher_num %>) @@ -46,6 +44,9 @@