diff --git a/.access_token b/.access_token new file mode 100644 index 000000000..610b08d2e --- /dev/null +++ b/.access_token @@ -0,0 +1 @@ +{"access_token":"oEEf8ZKAB8Y2G0o_xnTPkPJHKKk8iHkLC-f5ptvQ2nCMj9IpC86ivLD2-p38GfOkuG-HuQp3pWZqhs3NJXUMdPLWsr5k67hPZYuqg4ozLccx0xdLswapj0mn8ovZhK1tKIKiAFAOMO","expires_in":7200,"got_token_at":1467012449} \ No newline at end of file diff --git a/.gitignore b/.gitignore index ba7890841..dbc349c80 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,4 @@ vendor/cache /config/initializers/gitlab_config.rb 1234567 public/javascripts/wechat/node_modules/ +.ruby-version diff --git a/Gemfile b/Gemfile index d392c6561..b482cb6fd 100644 --- a/Gemfile +++ b/Gemfile @@ -1,12 +1,15 @@ source 'https://ruby.taobao.org/' -### ����ִ��bundle config mirror.https://rubygems.org https://gems.ruby-china.org �л���ruby-chinaԴ unless RUBY_PLATFORM =~ /w32/ # unix-like only gem 'iconv' + gem "rmagick", "= 2.13.1" ## centos yum install ImageMagick-devel + gem 'certified' end -gem 'certified' +gem 'net-ssh', '2.9.1' +gem 'jenkins_api_client' +gem 'nokogiri' gem 'wechat',path: 'lib/wechat' gem 'grack', path:'lib/grack' @@ -31,7 +34,6 @@ gem 'acts-as-taggable-on', '2.4.1' gem 'spreadsheet' gem 'ruby-ole' gem 'rails_kindeditor',path:'lib/rails_kindeditor' -#gem "rmagick", ">= 2.0.0" gem 'binding_of_caller' gem 'chinese_pinyin' # gem 'sunspot_rails', '~> 1.3.3' @@ -81,7 +83,7 @@ group :assets do gem 'coffee-rails', '~> 3.2.1' # See https://github.com/sstephenson/execjs#readme for more supported runtimes - gem 'therubyracer', :platforms => :ruby + # gem 'therubyracer', :platforms => :ruby gem 'uglifier', '>= 1.0.3' end diff --git a/app/api/mobile/api.rb b/app/api/mobile/api.rb index c86a36d05..c555eb633 100644 --- a/app/api/mobile/api.rb +++ b/app/api/mobile/api.rb @@ -18,11 +18,13 @@ module Mobile require_relative 'apis/blog_comments' require_relative 'apis/new_comment' require_relative 'apis/praise' + require_relative 'apis/resources' class API < Grape::API version 'v1', using: :path format :json content_type :json, "application/json;charset=UTF-8" + use ActionDispatch::Session::CookieStore use Mobile::Middleware::ErrorHandler helpers do @@ -34,6 +36,10 @@ module Mobile raise('Unauthorized. 用户认证失败.') unless current_user end + def session + env['rack.session'] + end + def current_user openid = params[:openid] if openid @@ -66,9 +72,9 @@ module Mobile mount Apis::BlogComments mount Apis::NewComment mount Apis::Praise + mount Apis::Resources - #add_swagger_documentation ({api_version: 'v1', base_path: 'http://u06.shellinfo.cn/trustie/api'}) - #add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development? + add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development? end end diff --git a/app/api/mobile/apis/activities.rb b/app/api/mobile/apis/activities.rb index 49fdaff8f..661925012 100644 --- a/app/api/mobile/apis/activities.rb +++ b/app/api/mobile/apis/activities.rb @@ -9,7 +9,7 @@ module Mobile params do requires :page, type: Integer - requires :openid, type: String + requires :token, type: String end post do authenticate! diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index 3a36a9e37..42303b63d 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -14,8 +14,9 @@ module Mobile optional :token, type: String end get do + authenticate! cs = CoursesService.new - courses = cs.course_list(params,current_user.nil? ? User.find(2):current_user) + courses = cs.user_courses_list(current_user) present :data, courses, with: Mobile::Entities::Course present :status, 0 end @@ -97,25 +98,20 @@ module Mobile desc "加入课程" params do - requires :course_password, type: String + requires :token, type: String + requires :invite_code, type: String, desc: '邀请码' end - post ":id" do + post "join" do authenticate! cs = CoursesService.new - status = cs.join_course({:object_id => params[:id],:course_password => params[:course_password]},current_user) - out = {status: status[:state]} - message = case status[:state] - when 0; "加入成功" - when 1; "密码错误" - when 2; "课程已过期 请联系课程管理员重启课程。(在配置课程处)" - when 3; "您已经加入了课程" - when 4; "您加入的课程不存在" - when 5; "您还未登录" - else; "未知错误,请稍后再试" - end - out.merge(message: message) + 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]) + } end + desc "退出课程" params do requires :token, type: String @@ -201,6 +197,7 @@ module Mobile end route_param :id do get do + authenticate! cs = CoursesService.new course = cs.show_course(params,(current_user.nil? ? User.find(2):current_user)) #course = Course.find(params[:id]) @@ -388,7 +385,16 @@ module Mobile end - + desc '获取测验列表' + params do + requires :token, type:String + end + get ':course_id/exercises' do + authenticate! + exercises = Course.find(params[:course_id]).exercises + present :data,exercises,with:Mobile::Entities::Exercise + present :status,0 + end end end diff --git a/app/api/mobile/apis/issues.rb b/app/api/mobile/apis/issues.rb index b767bd768..4a6417cb4 100644 --- a/app/api/mobile/apis/issues.rb +++ b/app/api/mobile/apis/issues.rb @@ -8,7 +8,8 @@ module Mobile desc "get special issuse" get ':id' do - user = UserWechat.find_by_openid(params[:openid]).user + authenticate! + user = current_user issue = Issue.find params[:id] present :data, issue, with: Mobile::Entities::Issue,user: user present :status, 0 diff --git a/app/api/mobile/apis/journal_for_messages.rb b/app/api/mobile/apis/journal_for_messages.rb index 15a571a82..5f2d01185 100644 --- a/app/api/mobile/apis/journal_for_messages.rb +++ b/app/api/mobile/apis/journal_for_messages.rb @@ -7,7 +7,8 @@ module Mobile desc "get special journal" get ':id' do - user = UserWechat.find_by_openid(params[:openid]).user + authenticate! + user = current_user jour = JournalsForMessage.find params[:id] present :data, jour, with: Mobile::Entities::Jours,user: user present :status, 0 diff --git a/app/api/mobile/apis/messages.rb b/app/api/mobile/apis/messages.rb index ae2f9a39c..bab82de8d 100644 --- a/app/api/mobile/apis/messages.rb +++ b/app/api/mobile/apis/messages.rb @@ -7,7 +7,8 @@ module Mobile desc "get special topic" get ':id' do - user = UserWechat.find_by_openid(params[:openid]).user + authenticate! + user = current_user message = Message.find params[:id] present :data, message, with: Mobile::Entities::Message,user: user present :status, 0 diff --git a/app/api/mobile/apis/new_comment.rb b/app/api/mobile/apis/new_comment.rb index 694ec0613..5b7159301 100644 --- a/app/api/mobile/apis/new_comment.rb +++ b/app/api/mobile/apis/new_comment.rb @@ -11,12 +11,12 @@ module Mobile params do requires :type, type: String requires :content, type: String - requires :openid, type: String + requires :token, type: String end post ':id' do + authenticate! type = params[:type] result = 1 - current_user = UserWechat.find_by_openid(params[:openid]).user if params[:content]!="" && current_user case type when "HomeworkCommon" diff --git a/app/api/mobile/apis/newss.rb b/app/api/mobile/apis/newss.rb index 8bdd460cc..d42177783 100644 --- a/app/api/mobile/apis/newss.rb +++ b/app/api/mobile/apis/newss.rb @@ -7,7 +7,8 @@ module Mobile desc "get special news" get ':id' do - user = UserWechat.find_by_openid(params[:openid]).user + authenticate! + user = current_user news = News.find params[:id] present :data, news, with: Mobile::Entities::News,user: user present :status, 0 diff --git a/app/api/mobile/apis/praise.rb b/app/api/mobile/apis/praise.rb index 57dbd0729..834d1195b 100644 --- a/app/api/mobile/apis/praise.rb +++ b/app/api/mobile/apis/praise.rb @@ -9,12 +9,13 @@ module Mobile params do requires :type, type: String - requires :openid, type: String + requires :token, type: String end post ':id' do + authenticate! obj_id = params[:id] obj_type = params[:type] - user = UserWechat.find_by_openid(params[:openid]).user + user = current_user pts = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",obj_id,obj_type.to_s,user.id).first if pts.blank? praise_or_cancel(obj_type,obj_id,user,1) diff --git a/app/api/mobile/apis/resources.rb b/app/api/mobile/apis/resources.rb new file mode 100644 index 000000000..fca94a642 --- /dev/null +++ b/app/api/mobile/apis/resources.rb @@ -0,0 +1,55 @@ +#coding=utf-8 +module Mobile + module Apis + class Resources < Grape::API + + resource :resources do + + desc '获取所有课件' + params do + requires :token, type: String + end + get do + authenticate! + data = current_user.course_attachments + present :data, data, with: Mobile::Entities::Attachment + present :status, 0 + + end + + + + desc '获取所有作业' + params do + requires :token, type: String + end + get 'homeworks' do + authenticate! + + homeworks = current_user.homework_commons + + present :data, homeworks, with: Mobile::Entities::Homework + present :status, 0 + + end + + desc '获取所有测验' + params do + requires :token, type: String + end + get 'exercies' do + authenticate! + + exercises = current_user.exercises + present :data, exercises, with: Mobile::Entities::Exercise + present :status, 0 + 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 6ce3cacbb..b5ee14d19 100644 --- a/app/api/mobile/apis/users.rb +++ b/app/api/mobile/apis/users.rb @@ -4,6 +4,48 @@ module Mobile class Users < Grape::API resource :users do + desc "查询是否已绑定" + params do + requires :openid, type: String, desc: 'wechat openid' + end + post 'isbind' do + openid = params[:openid] + uw = UserWechat.where(openid: openid).first + raise "还未绑定trustie帐户" unless uw + + user = uw.user + ::ApiKey.delete_all(user_id: user.id) + key = ::ApiKey.create!(user_id: user.id) + present status: 0, token: key.access_token + end + + desc "绑定微信用户" + params do + requires :login, type: String, desc: 'username' + requires :password, type: String, desc: 'password' + end + post 'wxbind' do + openid = session[:wechat_openid] + logger.debug "openid ============== #{openid}" + raise "无法获取到openid,请在微信中打开本页面" unless openid + uw = UserWechat.where(openid: openid).first + raise "此微信号已绑定用户(#{uw.user.login}), 不能重复绑定" if uw + + user, last_login_on = User.try_to_login(params[:login], params[:password]) + raise "用户名或密码错误,请重新输入" unless user + #补全用户信息 + + raise "此用户已经绑定过公众号, 请换一个帐户试试" if user.user_wechat + + UserWechat.create!( + openid: openid, + user: user + ) + # ws = WechatService.new + # ws.binding_succ_notice(user.id, "您已成功绑定Trustie平台", user.login, format_time(Time.now)) + present status: 0, message: '您已成功绑定Trustie平台' + end + desc "注册用户" params do requires :login, type: String, desc: 'username' diff --git a/app/api/mobile/apis/whomeworks.rb b/app/api/mobile/apis/whomeworks.rb index a88d509a3..c8377aa0d 100644 --- a/app/api/mobile/apis/whomeworks.rb +++ b/app/api/mobile/apis/whomeworks.rb @@ -7,7 +7,8 @@ module Mobile desc "get one homework" get ':id' do - user = UserWechat.find_by_openid(params[:openid]).user + authenticate! + user = current_user homework = HomeworkCommon.find params[:id] present :data, homework, with: Mobile::Entities::Whomework,user: user present :status, 0 diff --git a/app/api/mobile/entities/course.rb b/app/api/mobile/entities/course.rb index 50812b349..487a75c4d 100644 --- a/app/api/mobile/entities/course.rb +++ b/app/api/mobile/entities/course.rb @@ -45,6 +45,8 @@ module Mobile course_expose :tea_id course_expose :term course_expose :time + course_expose :invite_code + course_expose :qrcode course_expose :updated_at course_expose :course_student_num expose :teacher, using: Mobile::Entities::User do |c, opt| diff --git a/app/api/mobile/entities/exercise.rb b/app/api/mobile/entities/exercise.rb new file mode 100644 index 000000000..3218264fb --- /dev/null +++ b/app/api/mobile/entities/exercise.rb @@ -0,0 +1,8 @@ +module Mobile + module Entities + class Exercise < Grape::Entity + expose :exercise_name + expose :exercise_description + end + end +end diff --git a/app/api/mobile/entities/user.rb b/app/api/mobile/entities/user.rb index 8c6a839b3..2eb20f0db 100644 --- a/app/api/mobile/entities/user.rb +++ b/app/api/mobile/entities/user.rb @@ -26,6 +26,8 @@ module Mobile u.nil? || u.user_extensions.nil? ? "" : u.user_extensions.student_id when :realname u.nil? ? "" : get_user_realname(u) + when :name + u.nil? ? "" : u.show_name end end end @@ -57,6 +59,11 @@ module Mobile user_expose :student_num # 活跃值 user_expose :active_count + + user_expose :role_name + + user_expose :name + end end diff --git a/app/assets/javascripts/quality_analyses.js.coffee b/app/assets/javascripts/quality_analyses.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/quality_analyses.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/javascripts/syllabuses.js.coffee b/app/assets/javascripts/syllabuses.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/syllabuses.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/quality_analyses.css.scss b/app/assets/stylesheets/quality_analyses.css.scss new file mode 100644 index 000000000..9404eb70f --- /dev/null +++ b/app/assets/stylesheets/quality_analyses.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the QualityAnalyses controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/syllabuses.css.scss b/app/assets/stylesheets/syllabuses.css.scss new file mode 100644 index 000000000..2576e25f0 --- /dev/null +++ b/app/assets/stylesheets/syllabuses.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the syllabuses controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index d3f681a06..4014a91bd 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -67,12 +67,15 @@ class AdminController < ApplicationController def excellent_all_courses name = params[:name] @order = "" - if params[:order] == 'asc' - courses = Course.find_by_sql("SELECT c.*,count(c.id) FROM courses c,course_activities ca WHERE c.id = ca.course_id AND c.name like '%#{name}%' GROUP BY c.id ORDER BY count(c.id) asc, c.id desc") + @sort = "" + if params[:sort] && (params[:order] == 'act') + courses = Course.find_by_sql("SELECT c.*,count(c.id) FROM courses c,course_activities ca WHERE c.id = ca.course_id AND c.name like '%#{name}%' GROUP BY c.id ORDER BY count(c.id) #{params[:sort]}, c.id desc") @order = params[:order] - elsif params[:order] == 'desc' - courses = Course.find_by_sql("SELECT c.*,count(c.id) FROM courses c,course_activities ca WHERE c.id = ca.course_id AND c.name like '%#{name}%' GROUP BY c.id ORDER BY count(c.id) DESC, c.id desc") + @sort = params[:sort] + elsif params[:sort] && (params[:order] == 'time') + courses = Course.find_by_sql("SELECT * FROM courses WHERE name like '%#{name}%' ORDER BY time #{params[:sort]},id desc") @order = params[:order] + @sort = params[:sort] else courses = Course.like(name).order('created_at desc') end @@ -99,6 +102,22 @@ class AdminController < ApplicationController end end + #取消精品 + def cancel_excellent_course + @course = Course.find params[:id] + unless @course.nil? + if @course.is_excellent == 1 || @course.excellent_option == 1 + @course.update_column('is_excellent', 0) + @course.update_column('excellent_option', 0) + end + end + respond_to do |format| + format.html{ + redirect_to excellent_courses_url + } + end + end + #管理员界面课程资源列表 def course_resource_list diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index cbce67618..b1aae9b26 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -916,4 +916,11 @@ class ApplicationController < ActionController::Base call_hook(:controller_account_success_authentication_after, {:user => user }) end + def user_unlogged_check + if !User.current.logged? + render(:partial => 'organizations/unlogged_tip') + return false + end + true + end end diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index fe3c3272a..960bc61e6 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -265,6 +265,10 @@ class AttachmentsController < ApplicationController @history.save #历史记录保存完毕 #将最新保存的记录 数据替换到 需要修改的文件记录 @old_attachment.attributes = @attachment.attributes.dup.except("id","container_id","container_type","is_public","downloads", "quotes") + # 如果附件描述被修改,则保存附件 + unless params[:description] == @attachment.description + @old_attachment.description = params[:description] + end @old_attachment.save #删除当前记录 @attachment.delete diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index e421b8c69..7dea90e4b 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -74,7 +74,7 @@ class CoursesController < ApplicationController else @state = 5 #未登录 end - @object_id = params[:object_id] + @object_id = @course.id if @course respond_to do |format| format.js #{ render :partial => 'set_join', :locals => {:user => @user, :course => @course, :object_id => params[:object_id]} } end @@ -1224,7 +1224,7 @@ class CoursesController < ApplicationController def member_to_xls homeworks, course, members,groups xls_report = StringIO.new book = Spreadsheet::Workbook.new - sheet1 = book.create_worksheet :name => "student" + sheet1 = book.create_worksheet :name => "总成绩" blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10 #sheet1.row(0).default_format = blue #sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_class),l(:excel_f_score),l(:excel_commit_time)]) @@ -1268,6 +1268,121 @@ class CoursesController < ApplicationController count_row += 1 end + homeworks.each_with_index do |home, i| + sheet = book.create_worksheet :name => "第#{i+1}次作业" + sheet[0,0] = "课程编号" + sheet[0,1] = course.id + sheet[1,0] = "课程学期" + sheet[1,1] = course.time.to_s+"年"+course.term + sheet[2,0] = "课程名称" + sheet[2,1] = course.name + sheet[3,0] = "教师团队" + sheet[3,1] = (searchTeacherAndAssistant course).map{|member| member.user.show_name}.join('、') + sheet[4,0] = "主讲教师" + sheet[4,1] = course.teacher.show_name + sheet[4,0] = "作业批次" + sheet[4,1] = "第#{i+1}次作业" + sheet[4,0] = "作业名称" + sheet[4,1] = home.name + if home.homework_type == 1 #普通作业 + if home.anonymous_comment ==0 + sheet.row(5).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_homework_name),l(:excel_homework_des), + l(:excel_t_score),l(:excel_ta_score), l(:excel_n_score),l(:excel_a_penalty),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)]) + else + sheet.row(5).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_homework_name),l(:excel_homework_des), + l(:excel_t_score),l(:excel_ta_score),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)]) + end + count_row = 6 + items = home.student_works.order("work_score desc") + items.each_with_index do |stu, j| + sheet[count_row,0]= j + 1 + sheet[count_row,1] = stu.user.show_name + sheet[count_row,2] = stu.user.login + sheet[count_row,3] = stu.user.user_extensions.student_id + sheet[count_row,4] = stu.name + sheet[count_row,5] = strip_html stu.description + sheet[count_row,6] = stu.teacher_score.nil? ? l(:label_without_score) : stu.teacher_score.round(2) + sheet[count_row,7] = stu.teaching_asistant_score.nil? ? l(:label_without_score) : stu.teaching_asistant_score.round(2) + if home.anonymous_comment ==0 + sheet[count_row,8] = stu.student_score.nil? ? l(:label_without_score) : stu.student_score.round(2) + sheet[count_row,9] = (home.teacher_priority == 1 && !stu.teacher_score.nil?) ? 0 : stu.absence_penalty + sheet[count_row,10] = (home.teacher_priority == 1 && !stu.teacher_score.nil?) ? 0 : stu.late_penalty + sheet[count_row,11] = stu.work_score.nil? ? l(:label_without_score) : stu.work_score.round(2) + sheet[count_row,12] = format_time(stu.created_at) + else + sheet[count_row,8] = (home.teacher_priority == 1 && !stu.teacher_score.nil?) ? 0 : stu.late_penalty + sheet[count_row,9] = stu.work_score.nil? ? l(:label_without_score) : stu.work_score.round(2) + sheet[count_row,10] = format_time(stu.created_at) + end + count_row += 1 + end + elsif home.homework_type == 2 #编程作业 + if home.anonymous_comment ==0 + sheet.row(5).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_homework_name),l(:excel_homework_des), + l(:excel_t_score),l(:excel_ta_score), l(:excel_s_score),l(:excel_n_score),l(:excel_a_penalty),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)]) + else + sheet.row(5).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_homework_name),l(:excel_homework_des), + l(:excel_t_score),l(:excel_ta_score), l(:excel_s_score),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)]) + end + count_row = 6 + items = home.student_works.order("work_score desc") + items.each_with_index do |stu, j| + sheet[count_row,0]= j + 1 + sheet[count_row,1] = stu.user.show_name + sheet[count_row,2] = stu.user.login + sheet[count_row,3] = stu.user.user_extensions.student_id + sheet[count_row,4] = stu.name + sheet[count_row,5] = stu.description + sheet[count_row,6] = stu.teacher_score.nil? ? l(:label_without_score) : stu.teacher_score.round(2) + sheet[count_row,7] = stu.teaching_asistant_score.nil? ? l(:label_without_score) : stu.teaching_asistant_score.round(2) + sheet[count_row,8] = stu.system_score.nil? ? l(:label_without_score) : stu.system_score.round(2) + if home.anonymous_comment ==0 + sheet[count_row,9] = stu.student_score.nil? ? l(:label_without_score) : stu.student_score.round(2) + sheet[count_row,10] = (home.teacher_priority == 1 && !stu.teacher_score.nil?) ? 0 : stu.absence_penalty + sheet[count_row,11] = (home.teacher_priority == 1 && !stu.teacher_score.nil?) ? 0 : stu.late_penalty + sheet[count_row,12] = stu.work_score.nil? ? l(:label_without_score) : stu.work_score.round(2) + sheet[count_row,13] = format_time(stu.created_at) + else + sheet[count_row,9] = (home.teacher_priority == 1 && !stu.teacher_score.nil?) ? 0 : stu.late_penalty + sheet[count_row,10] = stu.work_score.nil? ? l(:label_without_score) : stu.work_score.round(2) + sheet[count_row,11] = format_time(stu.created_at) + end + count_row += 1 + end + elsif home.homework_type == 3 #分组作业 + if home.anonymous_comment ==0 + sheet.row(5).concat([l(:excel_rank),l(:excel_group_member),l(:excel_homework_name),l(:excel_homework_project),l(:excel_homework_des), + l(:excel_t_score),l(:excel_ta_score),l(:excel_n_score),l(:excel_a_penalty),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)]) + else + sheet.row(5).concat([l(:excel_rank),l(:excel_group_member),l(:excel_homework_name),l(:excel_homework_project),l(:excel_homework_des), + l(:excel_t_score),l(:excel_ta_score),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)]) + end + count_row = 6 + items = home.student_works.order("work_score desc") + items.each_with_index do |stu, j| + sheet[count_row,0] = j + 1 + sheet[count_row,1] = get_group_member_names stu + sheet[count_row,2] = stu.name + sheet[count_row,3] = (stu.project_id == 0 || stu.project_id.nil?) ? l(:excel_no_project) : stu.project.name + sheet[count_row,4] = strip_html stu.description + sheet[count_row,5] = stu.teacher_score.nil? ? l(:label_without_score) : stu.teacher_score.round(2) + sheet[count_row,6] = stu.teaching_asistant_score.nil? ? l(:label_without_score) : stu.teaching_asistant_score.round(2) + if home.anonymous_comment ==0 + sheet[count_row,7] = stu.student_score.nil? ? l(:label_without_score) : stu.student_score.round(2) + sheet[count_row,8] = (home.teacher_priority == 1 && !stu.teacher_score.nil?) ? 0 : stu.absence_penalty + sheet[count_row,9] = (home.teacher_priority == 1 && !stu.teacher_score.nil?) ? 0 : stu.late_penalty + sheet[count_row,10] = stu.work_score.nil? ? l(:label_without_score) : stu.work_score.round(2) + sheet[count_row,11] = format_time(stu.created_at) + else + sheet[count_row,7] = (home.teacher_priority == 1 && !stu.teacher_score.nil?) ? 0 : stu.late_penalty + sheet[count_row,8] = stu.work_score.nil? ? l(:label_without_score) : stu.work_score.round(2) + sheet[count_row,9] = format_time(stu.created_at) + end + count_row += 1 + end + end + end + =begin group0 = CourseGroup.new(); group0.id = 0; diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index b1e5456c5..e4f637b6d 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -49,6 +49,11 @@ class ExerciseController < ApplicationController return end @exercise = Exercise.find params[:id] + @exercise.course_messages.each do |message| + if User.current.id == message.user_id && message.viewed == 0 + message.update_attributes(:viewed => true) if message.viewed == 0 + end + end @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? exercise_end = @exercise.end_time > Time.now if @exercise.time == -1 diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 7ec796b61..f06725d01 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -26,7 +26,7 @@ class FilesController < ApplicationController before_filter :authorize, :except => [:create,:getattachtype,:quote_resource_show,:search,:searchone4reload,:search_project,:quote_resource_show_project, :search_tag_attachment,:subfield_upload_file,:search_org_subfield_tag_attachment, :search_tag_attachment,:quote_resource_show_org_subfield,:find_org_subfield_attache, - :search_files_in_subfield,:upload_files_menu,:file_hidden,:republish_file] + :search_files_in_subfield,:upload_files_menu,:file_hidden,:republish_file,:update_file_description] helper :sort include SortHelper @@ -483,6 +483,7 @@ class FilesController < ApplicationController if !attachments.empty? && attachments[:files] && tag_name != "" attachments[:files].each do |attachment| attachment.tag_list.add(tag_name) + attachment.description = params[:description] attachment.save end end @@ -493,6 +494,7 @@ class FilesController < ApplicationController if !attachments.empty? && attachments[:files] && tag_name != "" attachments[:files].each do |attachment| attachment.tag_list.add(tag_name) + attachment.description = params[:description] attachment.save end end @@ -600,6 +602,7 @@ class FilesController < ApplicationController if !attachments.empty? && attachments[:files] && tag_name != "" attachments[:files].each do |attachment| attachment.tag_list.add(tag_name) + attachment.description = params[:description] attachment.save end end @@ -610,6 +613,7 @@ class FilesController < ApplicationController if !attachments.empty? && attachments[:files] && tag_name != "" attachments[:files].each do |attachment| attachment.tag_list.add(tag_name) + attachment.description = params[:description] attachment.save end end @@ -911,5 +915,10 @@ class FilesController < ApplicationController def upload_files_menu -end + end + def update_file_description + @attachment = Attachment.find(params[:id]) + @attachment.description = params[:description] + @attachment.save + end end diff --git a/app/controllers/org_member_controller.rb b/app/controllers/org_member_controller.rb index 642a100c3..2eaa790cd 100644 --- a/app/controllers/org_member_controller.rb +++ b/app/controllers/org_member_controller.rb @@ -54,4 +54,8 @@ class OrgMemberController < ApplicationController def index end + + def deleteOrgMember + destroy + end end diff --git a/app/controllers/org_subfields_controller.rb b/app/controllers/org_subfields_controller.rb index 159648f34..2b41983cc 100644 --- a/app/controllers/org_subfields_controller.rb +++ b/app/controllers/org_subfields_controller.rb @@ -9,14 +9,15 @@ class OrgSubfieldsController < ApplicationController @subfield = OrgSubfield.create(:name => params[:name], :organization_id => params[:organization_id], :priority => @organization.org_subfields.order("priority").last.priority + 1) if !params[:sub_dir].blank? sql = "select subfield_subdomain_dirs.* from subfield_subdomain_dirs, org_subfields where subfield_subdomain_dirs.org_subfield_id = org_subfields.id "+ - "and org_subfields.organization_id=#{@organization.id} and subfield_subdomain_dirs.name='#{params[:sub_dir]}'" + "and org_subfields.organization_id=#{@organization.id} and subfield_subdomain_dirs.name='#{params[:sub_dir]}'" if SubfieldSubdomainDir.find_by_sql(sql).count == 0 SubfieldSubdomainDir.create(:org_subfield_id => @subfield.id, :name => params[:sub_dir].downcase) end end - @subfield.update_attributes(:field_type => params[:field_type]) + #默认类型为帖子 + @subfield.update_attributes(:field_type => params[:field_type]||"Post") # admin配置的类型 - update_status_by_type(@subfield, params[:field_type]) + update_status_by_type(@subfield, params[:field_type]||"Post") else @res = false end @@ -56,6 +57,10 @@ class OrgSubfieldsController < ApplicationController @org_subfield = OrgSubfield.find_by_sql("select distinct org_subfields.* from org_subfields,"+ "subfield_subdomain_dirs where org_subfields.id = subfield_subdomain_dirs.org_subfield_id and "+ " org_subfields.organization_id=#{@organization.id} and subfield_subdomain_dirs.name='#{params[:sub_dir_name]}'").first + if @org_subfield.nil? + render_404 + return + end if @org_subfield.field_type == 'Post' @org_subfield_ids = @org_subfield.org_document_comments.map(&:id) << 0 @org_activities = OrgActivity.where("(org_act_type='OrgDocumentComment'and org_act_id in (#{@org_subfield_ids.join(",")})) || (container_type='OrgSubfield' and container_id=#{@org_subfield.id})").order('updated_at desc').page(params[:page] || 1).per(10) diff --git a/app/controllers/praise_tread_controller.rb b/app/controllers/praise_tread_controller.rb index 0c665341a..b6eb54d2f 100644 --- a/app/controllers/praise_tread_controller.rb +++ b/app/controllers/praise_tread_controller.rb @@ -1,12 +1,12 @@ class PraiseTreadController < ApplicationController accept_api_auth :tread_plus,:praise_plus - before_filter :require_login,:only => [:praise_plus,:tread_plus] + # before_filter :require_login,:only => [:praise_plus,:tread_plus] + before_filter :user_unlogged_check,:only => [:praise_plus,:tread_plus,:praise_minus] def praise_plus @obj = nil @activity = false - if request.get? @obj_id = params[:obj_id] @obj_type = params[:obj_type] diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index c8b272480..8664a1372 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -100,8 +100,8 @@ class ProjectsController < ApplicationController render_404 end - def course - render_404 + def courserender_404 + end # Time 2015-01-29 11:19:11 @@ -299,6 +299,8 @@ class ProjectsController < ApplicationController if params[:jump] && redirect_to_project_menu_item(@project, params[:jump]) return end + + logger.debug "111111111"*100 # over @author = params[:user_id].blank? ? nil : User.active.find(params[:user_id]) @page = params[:page] ? params[:page].to_i + 1 : 0 @@ -319,6 +321,7 @@ class ProjectsController < ApplicationController else @events_pages = ForgeActivity.includes(:project).where("forge_activities.project_id = ? and projects.is_public = ? and forge_act_type != ? ",@project,1, "Document").order("created_at desc").page(params['page'|| 1]).per(10); end + logger.debug "2"*100 # g = Gitlab.client unless @project.gpid.nil? || @project.project_score.changeset_num == 0 # rep_statics_commit = @project.rep_statics.order("commits_num desc") @@ -332,12 +335,20 @@ class ProjectsController < ApplicationController @a_commits_del = rep_statics_code.map {|s| s.del.to_i } @a_commits_changeset = rep_statics_code.map {|s| s.changeset.to_i } g = Gitlab.client + logger.debug "3"*100 begin - g_branch = g.project(@project.gpid).default_branch.to_s - rescue - logger.error("get gitlab project failed!") + gid = @project.gpid + logger.debug "31"*100 + g_branch = g.project(gid) + logger.debug "4"*100 + g_branch = g_branch.default_branch.to_s + logger.debug "5"*100 + rescue =>e + logger.error("get gitlab project failed: " + e) end + logger.debug "6"*100 @rev = g_branch.nil? ? "master" : g_branch + logger.debug "7"*100 end # 根据对应的请求,返回对应的数据 respond_to do |format| @@ -393,7 +404,7 @@ class ProjectsController < ApplicationController unless @project.gpid.nil? g = Gitlab.client @gitlab_branches = g.branches(@project.gpid) - @branch_names = g.branches(@project.gpid).map{|b| b.name} + @branch_names = @gitlab_branches.map{|b| b.name} @gitlab_default_branch = g.project(@project.gpid).default_branch end end @@ -645,7 +656,7 @@ class ProjectsController < ApplicationController params[:project][:is_public] ? @project.is_public = 1 : @project.is_public = 0 params[:project][:hidden_repo] ? @project.hidden_repo = 1 : @project.hidden_repo = 0 # 更新公开私有时同步gitlab公开私有 - unless @project.gpid.nil? + if !@project.gpid.nil? && @project.is_public != (params[:project][:is_public] == "on" ? true : false) g = Gitlab.client params[:project][:is_public] ? g.edit_project(@project.gpid, 20, params[:branch]) : g.edit_project(@project.gpid, 0, params[:branch]) end diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb new file mode 100644 index 000000000..83e5960b9 --- /dev/null +++ b/app/controllers/quality_analysis_controller.rb @@ -0,0 +1,99 @@ +class QualityAnalysisController < ApplicationController + before_filter :find_project_by_project_id#, :except => [:getattachtype] + before_filter :authorize + layout "base_projects" + include ApplicationHelper + require 'jenkins_api_client' + require 'nokogiri' + require 'json' + require 'open-uri' + + def show + + end + + def create + gitlab_address = Redmine::Configuration['gitlab_address'] + jenkins_address = Redmine::Configuration['jenkins_address'] + @client = JenkinsApi::Client.new(:server_url => jenkins_address, + :username => "temp", + :password => '123123') + #@client.exists?(job_name) + @g = Gitlab.client + user_name = User.find(params[:user_id]).try(:login) + branch = params[:branch].nil? ? "master" : params[:branch] + language = params[:language] + path = params[:path] + identifier = params[:identifier] + qa = QualityAnalysis.where(:project_id => @project.id, :author_login => user_name).first + version = qa.nil? ? 1 : qa.sonar_version + 1 + properties = "sonar.projectKey=#{user_name}:#{identifier} + sonar.projectName=#{user_name}:#{identifier} + sonar.projectVersion=#{version} + sonar.sources=#{path} + sonar.language=#{language.downcase} + sonar.sourceEncoding=utf-8" + git_url = gitlab_address.to_s+"/"+@project.owner.to_s+"/"+ identifier + "."+"git" + + # # # modify config + @doc = Nokogiri::XML(File.open(File.join(Rails.root, 'tmp', 'config.xml'))) + @doc.at_xpath("//hudson.plugins.git.UserRemoteConfig/url").content = git_url + @doc.at_xpath("//hudson.plugins.git.BranchSpec/name").content = "*/#{branch}" + @doc.at_xpath("//hudson.plugins.sonar.SonarRunnerBuilder/properties").content = properties #sonar-properties + # + # replace config.xml of jenkins + @client = @client.job.create("#{user_name}_#{identifier}", @doc.to_xml) + # relace gitlab hook + # genkins address + @g.add_project_hook(@project.gpid, jenkins_address + "/project/#{user_name}_#{identifier}") + if qa.nil? + QualityAnalysis.create(:project_id => @project.id, :author_login => user_name, :rep_identifier => identifier, :sonar_version => version, :path => path, :branch => branch, :language => language) + + else + qa.update_attribute(:sonar_version, version) + end + end + + def index + @sonar_address = Redmine::Configuration['sonar_address'] + # if params[:resource_id].nil? + # @name_flag = true + # @quality_analyses = QualityAnalysis.where(:project_id => @project.id) + # # @quality_analyses.map {|qa| qa.} + # # if @quality_analyses.count > 0 + # # @quality_analyses.each do |qa| + # # ["Hjqreturn:cc_rep", "Hjqreturn:putong", "Hjqreturn:sonar_rep2", "shitou:sonar_rep"] + # # + # # end + # # end + # # projects_date = open(@sonar_address + "/api/projects/index").read + # # arr = JSON.parse(projects_date).map {|m| m["nm"]} + # # arr.map + # else + qa = QualityAnalysis.where(:project_id => @project.id).first + @resource_id = qa.author_login+":"+qa.rep_identifier + @name_flag = false + 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 + @complexity =JSON.parse(complexity_date).first + 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 + end + + # Find project of id params[:project_id] + def find_project_by_project_id + @project = Project.find(params[:project_id]) + rescue ActiveRecord::RecordNotFound + render_404 + end + + # Authorize the user for the requested action + def authorize(ctrl = params[:controller], action = params[:action], global = false) + unless @project.archived? && @project.gpid.nil? + true + else + render_403 :message => :notice_not_authorized_archived_project + end + end + +end diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 857f98afc..cbb5b2f69 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -30,11 +30,13 @@ class RepositoriesController < ApplicationController menu_item :settings, :only => [:new, :create, :edit, :update, :destroy, :committers] default_search_scope :changesets - before_filter :find_project_by_project_id, :only => [:new, :create, :newrepo, :stats] + before_filter :find_project_by_project_id, :only => [:new, :create, :newrepo, :stats, :quality_analysis] before_filter :find_repository, :only => [:edit, :update, :destroy, :committers] before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo, :to_gitlab, :forked, :project_archive] 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] + before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :commit_diff, :project_archive, :quality_analysis] + # 链接gitlab + before_filter :connect_gitlab, :only => [:quality_analysis] accept_rss_auth :revisions # hidden repositories filter // 隐藏代码过滤器 before_filter :check_hidden_repo, :only => [:show, :stats, :revisions, :revision, :diff ] @@ -43,6 +45,7 @@ class RepositoriesController < ApplicationController helper :project_score #@root_path = RepositoriesHelper::ROOT_PATH $g=Gitlab.client + require 'net/ssh' rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed def new @@ -306,6 +309,37 @@ update end end + def quality_analysis + gitlab_branches = @g.branches(@project.gpid) + @branch_names = gitlab_branches.map{|b| b.name} + @gitlab_default_branch = @g.project(@project.gpid).default_branch + # language = params[:language] + # branch = params[:branch] + # path = params[:path] + # user_name = User.find(@project.user_id).try(:login) + # rep_name = params[:repository_id] + # host = "192.168.0.200" + # port = "1125" + # username = "git" + # password = "123123" + # server_cmd1 = "sh gitclone.sh" + " " + user_name + " " + rep_name + # # 连接到远程主机 foobar + # ssh = Net::SSH.start(host, username, :port => port, :password => password) do |ssh| + # result = ssh.exec!(server_cmd1) + # path = "/home/git/repo/" + user_name + "/" + rep_name + # # sonar 分析 + # # server_cmd2 + # # 删除clone的版本库 + # # server_cmd3 + # end + respond_to do |format| + format.js + format.html{ + render :layout => "base_projects" + } + end + end + def destroy DestroyRepositoryTask.new.destroy(User.current.id, @repository.id) @repository.hidden = true @@ -360,7 +394,7 @@ update # ip = RepositoriesHelper::REPO_IP_ADDRESS gitlab_address = Redmine::Configuration['gitlab_address'] # REDO:需优化,仅测试用 - @zip_path = gitlab_address.to_s + "/api/v3/projects/" + @project.gpid.to_s + "/repository/archive?&private_token=YTyCv4978MXmdL2B9C62" + @zip_path = Gitlab.endpoint.to_s + "/projects/" + @project.gpid.to_s + "/repository/archive?&private_token=" + Gitlab.private_token if @repository.type.to_s == "Repository::Gitlab" @repos_url = gitlab_address.to_s+"/"+@project.owner.to_s+"/"+@repository.identifier+"."+"git" else @@ -615,6 +649,14 @@ update project.project_score.update_attribute(:commit_time, date.created_at) end + # 链接gitlab + def connect_gitlab + @g = Gitlab.client + unless @project.gpid.nil? + @g_project = @g.project(@project.gpid) + end + end + def find_repository @repository = Repository.find(params[:id]) @project = @repository.project diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 10431f01a..661770206 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -1096,7 +1096,8 @@ class StudentWorkController < ApplicationController all_student_ids = "(" + pro.members.map{|member| member.user_id}.join(",") + ")" end all_students = User.where("id in #{all_student_ids}") - @commit_student_ids = @homework.student_work_projects.map{|student| student.user_id} + student_work_id = @homework.student_work_projects.where("user_id=? and student_work_id is not null",User.current.id).first.nil? ? -1 : @homework.student_work_projects.where("user_id=?",User.current.id).first.student_work_id + @commit_student_ids = @homework.student_work_projects.where("student_work_id != #{student_work_id}").map{|student| student.user_id} @users = searchstudent_by_name all_students,name respond_to do |format| format.js @@ -1115,6 +1116,20 @@ class StudentWorkController < ApplicationController end end + def get_user_infor + req = Hash.new(false) + user = User.where("id = #{params[:user_id].to_i}").first + if user + req[:id] = user.id + req[:name] = user.show_name + req[:student_id] = user.user_extensions.student_id + req[:valid] = true + else + req[:valid] = false + end + render :json => req + end + private def searchstudent_by_name users, name mems = [] @@ -1194,13 +1209,18 @@ class StudentWorkController < ApplicationController sheet1 = book.create_worksheet :name => "homework" blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10 sheet1.row(0).default_format = blue - if @homework.homework_type == 1 #匿评作业 - sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_homework_name),l(:excel_homework_des), - l(:excel_t_score),l(:excel_ta_score), l(:excel_n_score),l(:excel_f_score),l(:excel_commit_time)]) + if @homework.homework_type == 1 #普通作业 + if @homework.anonymous_comment ==0 + sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_homework_name),l(:excel_homework_des), + l(:excel_t_score),l(:excel_ta_score), l(:excel_n_score),l(:excel_a_penalty),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)]) + else + sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_homework_name),l(:excel_homework_des), + l(:excel_t_score),l(:excel_ta_score),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)]) + end count_row = 1 items.each do |homework| sheet1[count_row,0]=homework.user.id - sheet1[count_row,1] = homework.user.lastname.to_s + homework.user.firstname.to_s + sheet1[count_row,1] = homework.user.show_name sheet1[count_row,2] = homework.user.login sheet1[count_row,3] = homework.user.user_extensions.student_id sheet1[count_row,4] = homework.user.mail @@ -1208,18 +1228,31 @@ class StudentWorkController < ApplicationController sheet1[count_row,6] = strip_html homework.description 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) - sheet1[count_row,9] = homework.student_score.nil? ? l(:label_without_score) : homework.student_score.round(2) - sheet1[count_row,10] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : homework.score.round(2) : l(:label_without_score) - sheet1[count_row,11] = format_time(homework.created_at) + if @homework.anonymous_comment ==0 + sheet1[count_row,9] = homework.student_score.nil? ? l(:label_without_score) : homework.student_score.round(2) + sheet1[count_row,10] = (@homework.teacher_priority == 1 && !homework.teacher_score.nil?) ? 0 : homework.absence_penalty + sheet1[count_row,11] = (@homework.teacher_priority == 1 && !homework.teacher_score.nil?) ? 0 : homework.late_penalty + sheet1[count_row,12] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : homework.score.round(2) : l(:label_without_score) + sheet1[count_row,13] = format_time(homework.created_at) + else + sheet1[count_row,9] = (@homework.teacher_priority == 1 && !homework.teacher_score.nil?) ? 0 : homework.late_penalty + sheet1[count_row,10] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : homework.score.round(2) : l(:label_without_score) + sheet1[count_row,11] = format_time(homework.created_at) + end count_row += 1 end elsif @homework.homework_type == 2 #编程作业 - sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_homework_name),l(:excel_homework_des), - l(:excel_t_score),l(:excel_ta_score), l(:excel_s_score),l(:excel_n_score),l(:excel_f_score),l(:excel_commit_time)]) + if @homework.anonymous_comment ==0 + sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_homework_name),l(:excel_homework_des), + l(:excel_t_score),l(:excel_ta_score), l(:excel_s_score),l(:excel_n_score),l(:excel_a_penalty),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)]) + else + sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_homework_name),l(:excel_homework_des), + l(:excel_t_score),l(:excel_ta_score), l(:excel_s_score),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)]) + end count_row = 1 items.each do |homework| sheet1[count_row,0]=homework.user.id - sheet1[count_row,1] = homework.user.lastname.to_s + homework.user.firstname.to_s + sheet1[count_row,1] = homework.user.show_name sheet1[count_row,2] = homework.user.login sheet1[count_row,3] = homework.user.user_extensions.student_id sheet1[count_row,4] = homework.user.mail @@ -1228,11 +1261,48 @@ class StudentWorkController < ApplicationController 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) sheet1[count_row,9] = homework.system_score.nil? ? l(:label_without_score) : homework.system_score.round(2) - sheet1[count_row,10] = homework.student_score.nil? ? l(:label_without_score) : homework.student_score.round(2) - sheet1[count_row,11] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : homework.score.round(2) : l(:label_without_score) - sheet1[count_row,12] = format_time(homework.created_at) + if @homework.anonymous_comment ==0 + sheet1[count_row,10] = homework.student_score.nil? ? l(:label_without_score) : homework.student_score.round(2) + sheet1[count_row,11] = (@homework.teacher_priority == 1 && !homework.teacher_score.nil?) ? 0 : homework.absence_penalty + sheet1[count_row,12] = (@homework.teacher_priority == 1 && !homework.teacher_score.nil?) ? 0 : homework.late_penalty + sheet1[count_row,13] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : homework.score.round(2) : l(:label_without_score) + sheet1[count_row,14] = format_time(homework.created_at) + else + sheet1[count_row,10] = (@homework.teacher_priority == 1 && !homework.teacher_score.nil?) ? 0 : homework.late_penalty + sheet1[count_row,11] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : homework.score.round(2) : l(:label_without_score) + sheet1[count_row,12] = format_time(homework.created_at) + end count_row += 1 end + elsif @homework.homework_type == 3 #分组作业 + if @homework.anonymous_comment ==0 + sheet1.row(0).concat([l(:excel_group_member),l(:excel_homework_name),l(:excel_homework_project),l(:excel_homework_des), + l(:excel_t_score),l(:excel_ta_score),l(:excel_n_score),l(:excel_a_penalty),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)]) + else + sheet1.row(0).concat([l(:excel_group_member),l(:excel_homework_name),l(:excel_homework_project),l(:excel_homework_des), + l(:excel_t_score),l(:excel_ta_score),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)]) + end + count_row = 1 + items.each do |homework| + sheet1[count_row,0] = get_group_member_names homework + sheet1[count_row,1] = homework.name + sheet1[count_row,2] = (homework.project_id == 0 || homework.project_id.nil?) ? l(:excel_no_project) : homework.project.name + sheet1[count_row,3] = strip_html homework.description + sheet1[count_row,4] = homework.teacher_score.nil? ? l(:label_without_score) : homework.teacher_score.round(2) + sheet1[count_row,5] = homework.teaching_asistant_score.nil? ? l(:label_without_score) : homework.teaching_asistant_score.round(2) + if @homework.anonymous_comment ==0 + sheet1[count_row,6] = homework.student_score.nil? ? l(:label_without_score) : homework.student_score.round(2) + sheet1[count_row,7] = (@homework.teacher_priority == 1 && !homework.teacher_score.nil?) ? 0 : homework.absence_penalty + sheet1[count_row,8] = (@homework.teacher_priority == 1 && !homework.teacher_score.nil?) ? 0 : homework.late_penalty + sheet1[count_row,9] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : homework.score.round(2) : l(:label_without_score) + sheet1[count_row,10] = format_time(homework.created_at) + else + sheet1[count_row,6] = (@homework.teacher_priority == 1 && !homework.teacher_score.nil?) ? 0 : homework.late_penalty + sheet1[count_row,7] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : homework.score.round(2) : l(:label_without_score) + sheet1[count_row,8] = format_time(homework.created_at) + end + count_row += 1 + end end book.write xls_report xls_report.string diff --git a/app/controllers/syllabuses_controller.rb b/app/controllers/syllabuses_controller.rb new file mode 100644 index 000000000..69982b99a --- /dev/null +++ b/app/controllers/syllabuses_controller.rb @@ -0,0 +1,23 @@ +class SyllabusesController < ApplicationController + + before_filter :is_logged, :only => [:index, :show] + before_filter :find_syllabus, :only => [:show] + def index + user = User.current + @syllabuses = user.syllabuses + end + + def show + @courses = @syllabus.courses + + end + + private + def find_syllabus + @syllabus = Syllabus.find params[:id] + end + + def is_logged + redirect_to signin_path unless User.current.logged? + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index cad57b49f..b7972ff6f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -87,7 +87,10 @@ class UsersController < ApplicationController #展开所有回复 def show_all_replies - @comment = JournalsForMessage.find params[:comment].to_i + case params[:type] + when 'JournalsForMessage' + @comment = JournalsForMessage.find params[:comment].to_i + end end #二级回复 @@ -95,6 +98,7 @@ class UsersController < ApplicationController case params[:type] when 'HomeworkCommon' @reply = JournalsForMessage.find params[:reply_id] + @type = 'HomeworkCommon' if params[:user_activity_id] @user_activity_id = params[:user_activity_id] else @@ -102,6 +106,11 @@ class UsersController < ApplicationController end @is_in_course = params[:is_in_course].to_i @course_activity = params[:course_activity].to_i + when 'JournalsForMessage' + @reply = JournalsForMessage.find params[:reply_id] + @user_activity_id = params[:user_activity_id] + @activity_id = params[:activity_id] + @type = 'JournalsForMessage' end respond_to do |format| format.js @@ -130,9 +139,12 @@ class UsersController < ApplicationController onclick_time = User.current.onclick_time.onclick_time messages.each do |message_all| # 未读的消息存放在数组 - if (message_all.message_type != "SystemMessage"&& !message_all.message.nil? && message_all.message.viewed == 0) || (message_all.message_type == "SystemMessage"&& !message_all.message.nil? && message_all.message.created_at > onclick_time) - @message_alls << message_all.message - break if @message_alls.length == 5 + mess = message_all.message + if (message_all.message_type != "SystemMessage"&& !mess.nil? && (mess.viewed == 0 || !mess.viewed)) || (message_all.message_type == "SystemMessage"&& !mess.nil? && mess.created_at > onclick_time) + unless (message_all.message_type == 'CourseMessage' && mess && mess.course && mess.course.is_delete == 1) + @message_alls << mess + end + break if @message_alls.length == 10 end end end @@ -154,33 +166,41 @@ class UsersController < ApplicationController update_message_viewed(@user) end # @new_message_count = forge_querys.count + forum_querys.count + course_querys.count + user_querys.count + courses = @user.courses.where("is_delete = 1") + course_ids = courses.empty? ? "(-1)" : "(" + courses.map{|course| course.id}.join(",") + ")" case params[:type] when nil # 系统消息为管理员发送,我的消息中包含有系统消息 @message_alls = [] messages = MessageAll.where("(user_id =? and message_type !=?) or message_type =?" ,@user.id, "SystemMessage", "SystemMessage").includes(:message).order("created_at desc") messages.each do |message_all| - @message_alls << message_all.message + mess = message_all.message + unless (message_all.message_type == 'CourseMessage' && mess && mess.course && mess.course.is_delete == 1) + @message_alls << mess + end end when 'unviewed' @message_alls = [] - messages = MessageAll.where("user_id =?", @user.id).includes(:message).order("created_at desc") + messages = MessageAll.where("message_alls.user_id =?", @user.id).includes(:message).order("created_at desc") messages.each do |message_all| # 在点击或者刷新消息列表后未读的消息存放在数组 - if message_all.message_type != "SystemMessage"&& !message_all.message.nil? && message_all.message.viewed == 0 - @message_alls << message_all.message + mess = message_all.message + if message_all.message_type != "SystemMessage"&& !mess.nil? && (mess.viewed == 0 || !mess.viewed) + unless (message_all.message_type == 'CourseMessage' && mess && mess.course && mess.course.is_delete == 1) + @message_alls << mess + end end end #课程相关消息 when 'homework' - @message_alls = CourseMessage.where("course_message_type in ('HomeworkCommon','StudentWorksScore','JournalsForMessage','StudentWork','Exercise') and user_id =?", @user.id).order("created_at desc") + @message_alls = CourseMessage.where("course_message_type in ('HomeworkCommon','StudentWorksScore','JournalsForMessage','StudentWork','Exercise') and user_id =? and course_id NOT IN #{course_ids}", @user.id).order("created_at desc") when 'course_message' - @message_alls = CourseMessage.where("course_message_type =? and user_id =?", "Message", @user.id).order("created_at desc") + @message_alls = CourseMessage.where("course_message_type =? and user_id =? and course_id NOT IN #{course_ids}", "Message", @user.id).order("created_at desc") when 'course_news' # 课程通知包含发布的通知和回复的通知 - @message_alls = CourseMessage.where("course_message_type in ('News', 'Comment') and user_id =?", @user.id).order("created_at desc") + @message_alls = CourseMessage.where("course_message_type in ('News', 'Comment') and user_id =? and course_id NOT IN #{course_ids}", @user.id).order("created_at desc") when 'poll' - @message_alls = CourseMessage.where("course_message_type =? and user_id =?", "Poll", @user.id).order("created_at desc") + @message_alls = CourseMessage.where("course_message_type =? and user_id =? and course_id NOT IN #{course_ids}", "Poll", @user.id).order("created_at desc") #项目相关消息 when 'issue' @message_alls = ForgeMessage.where("forge_message_type in ('Issue', 'Journal') and user_id =?" , @user.id).order("created_at desc") @@ -1478,8 +1498,8 @@ class UsersController < ApplicationController # 减少数据库交互 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}").map { |blog| blog.id}.join(",") - blog_ids = "(" + watched_user_blog_ids + ")" + watched_user_blog_ids = Blog.select("id").where("author_id in #{user_ids}") + blog_ids = watched_user_blog_ids.empty? ? "(-1)" : "(" + watched_user_blog_ids.map { |blog| blog.id}.join(",") + ")" @user_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}) "+ @@ -3250,7 +3270,11 @@ class UsersController < ApplicationController @journals = obj.comments.reorder("created_on desc") when 'JournalsForMessage' obj = JournalsForMessage.where('id = ?', params[:id].to_i).first - @journals = obj.children.reorder("created_on desc") + journals = [] + @journals = get_all_children(journals, obj) + @type = 'JournalsForMessage' + @user_activity_id = params[:div_id].to_i if params[:div_id] + @allow_delete = params[:allow_delete] when 'Issue' obj = Issue.where('id = ?', params[:id].to_i).first @journals = obj.journals.reorder("created_on desc") diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb index 169a33fce..4a79d6d93 100644 --- a/app/controllers/wechats_controller.rb +++ b/app/controllers/wechats_controller.rb @@ -3,10 +3,12 @@ class WechatsController < ActionController::Base wechat_responder include ApplicationHelper - + ROOT_URL = ENV["wechat_url"] || "#{Setting.protocol}://#{Setting.host_name}" + #ROOT_URL = "http://www.trustie.net" # default text responder when no other match on :text do |request, content| - request.reply.text "您的意见已收到,感谢您的反馈!" # Just echo + #邀请码 + sendBindClass(request, {invite_code: content}) end # When receive 'help', will trigger this responder @@ -35,13 +37,13 @@ class WechatsController < ActionController::Base # When subscribe user scan scene_id in public account on :scan, with: 'scene_id' do |request, ticket| - request.reply.text "Subscribe user #{request[:FromUserName]} Ticket #{ticket}" + sendBindClass(request, {ticket: ticket}) end # When no any on :scan responder can match subscribe user scaned scene_id on :event, with: 'scan' do |request| if request[:EventKey].present? - request.reply.text "event scan got EventKey #{request[:EventKey]} Ticket #{request[:Ticket]}" + sendBindClass(request, {ticket: request[:Ticket]}) end end @@ -62,6 +64,9 @@ class WechatsController < ActionController::Base request.reply.text "User: #{request[:FromUserName]} click #{key}" end + on :click, with: 'DEV' do |request, key| + request.reply.text "此功能正在开发中,很快就会上线,谢谢!" + end # When user view URL in the menu button on :view, with: 'http://wechat.somewhere.com/view_url' do |request, view| request.reply.text "#{request[:FromUserName]} view #{view}" @@ -128,12 +133,36 @@ class WechatsController < ActionController::Base default_msg(request) end + on :click, with: 'JOIN_CLASS' do |request, key| + uw = user_binded?(request[:FromUserName]) + unless uw + sendBind(request) + else + request.reply.text "请直接回复5位班级邀请码\n(不区分大小写):" + end + end + + + def sendBindClass(request, params) + begin + uw = user_binded?(request[:FromUserName]) + if !uw + return sendBind(request) + else + return join_class(params, uw.user, request) + end + rescue => e + logger.error e.inspect + logger.error e.backtrace.join("\n") + return request.reply.text e + end + end + def default_msg(request) uw = user_binded?(request[:FromUserName]) if uw && uw.user request.reply.text "欢迎回来, #{uw.user.show_name}" else - request.reply.text "欢迎关注Trustie创新实践社区" sendBind(request) end end @@ -145,8 +174,8 @@ class WechatsController < ActionController::Base 您还未绑定确实的用户,请先绑定,谢谢!" } } request.reply.news(news) do |article, n, index| # article is return object - url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{login_wechat_url}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect" - pic_url = "#{Setting.protocol}://#{Setting.host_name}/images/weixin_pic.jpg" + url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{ROOT_URL+'/wechat/user_activities'}&response_type=code&scope=snsapi_base&state=login#wechat_redirect" + pic_url = "#{ROOT_URL}/images/weixin_pic.jpg" article.item title: "#{n[:title]}", description: n[:content], pic_url: pic_url, @@ -154,18 +183,52 @@ class WechatsController < ActionController::Base end end + def join_class(params, user, request) + course = nil + course = Course.where(qrcode: params[:ticket]).first if params[:ticket] + course = Course.where(invite_code: params[:invite_code]).first if params[:invite_code] + raise "班级不存在,请确认您的邀请码是否输入正确,谢谢!" unless course + + cs = CoursesService.new + status = cs.join_course({invite_code: course.invite_code}, user) + logger.info status + if status[:state] != 0 + raise CoursesService::JoinCourseError.message(status[:state]) + end + + news = (1..1).each_with_object([]) { |n, memo| memo << { title: '恭喜您成功加入班级,开始学习吧!', + content: "课程名称: #{course.name}\n班级名称: #{course.name}\n任课老师: #{course.teacher.show_name}\n进入班级,和小伙伴愉快的学习吧!"} } + return request.reply.news(news) do |article, n, index| # article is return object + url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{ROOT_URL+'/wechat/user_activities?id='+course.id.to_s}&response_type=code&scope=snsapi_base&state=myclass#wechat_redirect" + pic_url = "#{ROOT_URL}/images/wechat/class.jpg" + article.item title: "#{n[:title]}", + description: n[:content], + pic_url: pic_url, + url: url + end + + end + ### controller method module Controllers - def get_open_id + def get_bind begin - code = params[:code] || session[:wechat_code] openid = get_openid_from_code(code) raise "无法获取到微信openid" unless openid - render :json => {status:0, openid: openid} + + uw = UserWechat.where(openid: openid).first + raise "还未绑定trustie帐户" unless uw + logger.debug "get_bind ============= #{uw}" + + user = uw.user + ::ApiKey.delete_all(user_id: user.id) + key = ::ApiKey.create!(user_id: user.id) + + render :json =>{status: 0, token: key.access_token} rescue Exception=>e - render :json => {status: -1, msg: e.message} + render :json => {status: -1, message: e.message} end end @@ -175,14 +238,14 @@ class WechatsController < ActionController::Base code = params[:code] || session[:wechat_code] openid = get_openid_from_code(code) - raise "无法获取到openid" unless openid - raise "此微信号已绑定用户, 不能重复绑定" if user_binded?(openid) + raise "无法获取到openid,请在微信中打开本页面" unless openid + raise "此微信号已绑定用户,不能重复绑定" if user_binded?(openid) user, last_login_on = User.try_to_login(params[:username], params[:password]) - raise "用户名或密码错误,请重新输入" unless user + raise "用户名或密码错误,请重新输入" unless user #补全用户信息 - raise "此用户已经绑定过公众号, 请换一个帐户试试" if user.user_wechat + raise "此用户已经绑定过公众号,请换一个帐户试试" if user.user_wechat UserWechat.create!( openid: openid, @@ -206,19 +269,26 @@ class WechatsController < ActionController::Base def user_activities session[:wechat_code] = params[:code] if params[:code] - code = params[:code] || session[:wechat_code] - openid = get_openid_from_code(code) - @wechat_user = user_binded?(openid) - unless @wechat_user - redirect_to login_wechat_path - return + @path = '/'+(params[:state] || '') + open_id = get_openid_from_code(params[:code]) rescue + unless open_id + render 'wechats/open_wechat', layout: nil and return + end + if params[:state] == 'myclass' + @course_id = params[:id]; end + session[:wechat_openid] = open_id + if params[:code] + redirect_to "/wechat/user_activities##{@path}?id=#{params[:id]}" and return + end render 'wechats/user_activities', layout: nil end + private def get_openid_from_code(code) + return 'oCnvgvz8R7QheXE-R9Kkr39j8Ndg' if code =='only-for-test' openid = session[:wechat_openid] unless openid diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index 22b7f1f52..668269a26 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -54,15 +54,16 @@ class WordsController < ApplicationController :reply_id => reply_user_id, :notes => content, :is_readed => false} - @jfm = add_reply_adapter options + @activity = params[:activity_id].nil? ? JournalsForMessage.find(parent_id) : JournalsForMessage.find(params[:activity_id].to_i) + @jfm = add_reply_adapter(@activity, options) @save_succ = true if @jfm.errors.empty? if @save_succ - update_course_activity('JournalsForMessage',parent_id) - update_user_activity('JournalsForMessage',parent_id) - update_forge_activity('JournalsForMessage',parent_id) - update_org_activity('JournalsForMessage',parent_id) - update_principal_activity('JournalsForMessage',parent_id) - (JournalsForMessage.find parent_id).update_attribute(:updated_on,Time.now) + update_course_activity('JournalsForMessage',@activity.id) + update_user_activity('JournalsForMessage',@activity.id) + update_forge_activity('JournalsForMessage',@activity.id) + update_org_activity('JournalsForMessage',@activity.id) + update_principal_activity('JournalsForMessage',@activity.id) + @activity.update_attribute(:updated_on,Time.now) end respond_to do |format| # format.html { @@ -76,8 +77,6 @@ class WordsController < ApplicationController format.js { #@reply_type = params[:reply_type] @user_activity_id = params[:user_activity_id] - @activity = JournalsForMessage.find(parent_id) - @is_activity = params[:is_activity] if params[:is_activity] } end @@ -92,13 +91,14 @@ class WordsController < ApplicationController elsif @journal_destroyed.jour_type == "Course" @course = Course.find @journal_destroyed.jour_id @jours_count = @course.journals_for_messages.where('m_parent_id IS NULL').count + @user_activity_id = params[:user_activity_id] if params[:user_activity_id] + @activity = JournalsForMessage.where("id = #{params[:activity_id].to_i}").first if params[:activity_id] elsif @journal_destroyed.jour_type == "Principal" @user = User.find(@journal_destroyed.jour_id) @jours_count = @user.journals_for_messages.where('m_parent_id IS NULL').count @is_user = true @user_activity_id = params[:user_activity_id] if params[:user_activity_id] - @is_activity = params[:is_activity].to_i if params[:is_activity] - @activity = @journal_destroyed.parent if @journal_destroyed.parent + @activity = JournalsForMessage.where("id = #{params[:activity_id].to_i}").first if params[:activity_id] unless @activity redirect_to feedback_path(@user) return @@ -374,28 +374,44 @@ class WordsController < ApplicationController obj end - def add_reply_adapter options + def add_reply_adapter obj, options #modify by nwb #添加对课程留言的支持 #留言回复应该不关系其所属的Class,而关心的是其所属的父留言 - obj = obj_distinguish_url_origin || User.find_by_id(2) - if obj.kind_of? User - obj.add_jour(nil, nil, nil, options) - elsif obj.kind_of? Project - Project.add_new_jour(nil, nil, obj.id, options) - elsif obj.kind_of? Course - Course.add_new_jour(nil, nil, obj.id, options) - elsif obj.kind_of? Bid - obj.add_jour(nil, nil, nil, options) - elsif obj.kind_of? Contest - obj.add_jour(nil, nil, obj.id, options) #new added - elsif obj.kind_of? Softapplication - obj.add_jour(nil, nil, obj.id, options) #new added - elsif obj.kind_of? HomeworkAttach - obj.add_jour(nil, nil, obj.id, options) #new added - else - raise "create reply obj unknow type.#{obj.class}" + case obj.jour_type + when 'Principal' + obj.jour.add_jour(nil, nil, nil, options) + when 'Project' + Project.add_new_jour(nil, nil, obj.jour_id, options) + when 'Course' + Course.add_new_jour(nil, nil, obj.jour_id, options) + when 'Bid' + obj.jour.add_jour(nil, nil, nil, options) + when 'Contest' + obj.jour.add_jour(nil, nil, obj.jour_id, options) + when 'Softapplication' + obj.jour.add_jour(nil, nil, obj.jour_id, options) + when 'HomeworkAttach' + obj.jour.add_jour(nil, nil, obj.jour_id, options) end + # obj = obj_distinguish_url_origin || User.find_by_id(2) + # if obj.kind_of? User + # obj.add_jour(nil, nil, nil, options) + # elsif obj.kind_of? Project + # Project.add_new_jour(nil, nil, obj.id, options) + # elsif obj.kind_of? Course + # Course.add_new_jour(nil, nil, obj.id, options) + # elsif obj.kind_of? Bid + # obj.add_jour(nil, nil, nil, options) + # elsif obj.kind_of? Contest + # obj.add_jour(nil, nil, obj.id, options) #new added + # elsif obj.kind_of? Softapplication + # obj.add_jour(nil, nil, obj.id, options) #new added + # elsif obj.kind_of? HomeworkAttach + # obj.add_jour(nil, nil, obj.id, options) #new added + # else + # raise "create reply obj unknow type.#{obj.class}" + # end end #######end of message end diff --git a/app/helpers/api_helper.rb b/app/helpers/api_helper.rb index fb1231287..e993b120f 100644 --- a/app/helpers/api_helper.rb +++ b/app/helpers/api_helper.rb @@ -489,4 +489,26 @@ module ApiHelper self.update_attribute(:praise_num, self.praise_num.to_i - num) end + + class Errors + def self.define_error(arr) + @errors = {} + arr.each_with_index { |item, index| + if index %2 == 1 + @errors[arr[index-1]] = item + end + } + if arr.count % 2== 1 + @default_error = arr.last + else + @default_error = "未知错误" + end + + end + + def self.message(msg_id) + @errors[msg_id] || @default_error + end + end + end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 46fdb02f3..ee2e2d74a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -3127,6 +3127,26 @@ def get_reply_parents parents_rely, comment parents_rely end +#获取回复的所有父节点(不包括根节点) +def get_reply_parents_no_root parents_rely, comment + if !comment.parent.nil? && !comment.parent.parent.nil? + parents_rely << comment.parent + get_reply_parents_no_root parents_rely, comment.parent + end + parents_rely +end + +#获取留言的所有子节点 +def get_all_children result, jour + if jour.kind_of? JournalsForMessage + jour.children.each do |jour_child| + result << jour_child + get_all_children result, jour_child + end + end + result.sort! { |a,b| b.created_on <=> a.created_on } +end + #将有置顶属性的提到数组前面 def sort_by_sticky topics tmpTopics = [] @@ -3283,3 +3303,20 @@ def get_hw_index(hw,is_teacher) index = hw_ids.index(hw.id) return index end + +def get_group_member_names work + result = "" + unless work.nil? + work.student_work_projects.each do |member| + user = User.where(:id => member.user_id).first + unless user.nil? + if result != "" + result += "、#{user.show_name}" + else + result += user.show_name + end + end + end + end + result +end diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index c10652c6f..bb144472b 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -44,9 +44,9 @@ module CoursesHelper def visible_excellent_course obj # if course.is_pu end - + # 返回x项目成员数量,即roles表中定义的所有成员 - def projectCount project + def projectCount project #searchCountByRoles project, AllPeople project.members.count end @@ -147,10 +147,10 @@ module CoursesHelper # 返回学生数量,即roles表中定义的Reporter #def studentCount project - # searchStudent(project).count - # or - # searchStudent(project).count - # end + # searchStudent(project).count + # or + # searchStudent(project).count + # end # 判断用户是否是课程的管理员 # add by nwb @@ -225,11 +225,11 @@ module CoursesHelper #end # 注意:此方法有问题,速度慢且结果不准 - # alias studentCountOrigin studentCount + # alias studentCountOrigin studentCount #def studentCount course - # count = studentCountOrigin course - #garble count - # end + # count = studentCountOrigin course + #garble count + # end #获取课程所有成员 def course_all_member course @@ -265,7 +265,7 @@ module CoursesHelper def garble count count = count.round( 1-count.to_s.size ).to_i return count.to_s if count.to_s.size.eql?(1) - count.to_s << '+' + count.to_s << '+' end # ===================================================================================== @@ -274,7 +274,7 @@ module CoursesHelper #searchPeopleByRoles(project, TeacherRoles) members = [] project.members.includes(:user).each do |m| - members << m if m && m.user && m.user.allowed_to?(:as_teacher,project) + members << m if m && m.user && m.user.allowed_to?(:as_teacher,project) end members end @@ -304,8 +304,8 @@ module CoursesHelper members end - - + + def searchStudent_by_name project, name #searchPeopleByRoles(project, StudentRoles) members = [] @@ -324,29 +324,29 @@ module CoursesHelper mems = [] if name != "" name = name.to_s.downcase - members.each do |m| + members.each do |m| username = m.user[:lastname].to_s.downcase + m.user[:firstname].to_s.downcase if(m.user[:login].to_s.downcase.include?(name) || m.user.user_extensions[:student_id].to_s.downcase.include?(name) || username.include?(name)) mems << m end end else - mems = members - end + mems = members + end mems end def searchgroupmember_by_name members, name, group #searchPeopleByRoles(project, StudentRoles) mems = [] if name != "" - members.each do |m| - if m.course_group_id == group.id - username = m.user[:lastname].to_s + m.user[:firstname].to_s - if(m.user[:login].to_s.include?(name) || m.user.user_extensions[:student_id].to_s.include?(name) || username.include?(name)) - mems << m + members.each do |m| + if m.course_group_id == group.id + username = m.user[:lastname].to_s + m.user[:firstname].to_s + if(m.user[:login].to_s.include?(name) || m.user.user_extensions[:student_id].to_s.include?(name) || username.include?(name)) + mems << m + end + end end - end - end else mems = members end @@ -458,7 +458,7 @@ module CoursesHelper content = content_tag('ul', content) content_tag('div', content, :class => "tabs") end - + def findCourseTime project str = "" begin @@ -683,9 +683,9 @@ module CoursesHelper #file_count Attachment.where(container_id: @course_ids, container_type: Course).where("created_on>?", date_from).each do |attachment| if attachment.is_public? || User.current.member_of_course?(@course) || User.current.admin? - activities[attachment.container_id]+=1 + activities[attachment.container_id]+=1 else - activities[attachment.container_id] + activities[attachment.container_id] end end @@ -704,8 +704,8 @@ module CoursesHelper #news News.where(course_id: @course_ids).where("created_on>?",date_from).each do |news| if news.author.member_of_course?(@course) - activities[news.course_id]+=1 - end + activities[news.course_id]+=1 + end end #homework_count diff --git a/app/helpers/quality_analysis_helper.rb b/app/helpers/quality_analysis_helper.rb new file mode 100644 index 000000000..9c6c07109 --- /dev/null +++ b/app/helpers/quality_analysis_helper.rb @@ -0,0 +1,97 @@ +# encoding: utf-8 +module QualityAnalysisHelper + + def sqale_rating_status val + arr = [] + if val.to_i > 0 && val.to_i < 5 + arr << "很好" + arr << "b_green2" + elsif val.to_i > 5 && val.to_i < 10 + arr << "较好" + arr << "b_slow_yellow" + elsif val.to_i > 10 && val.to_i < 20 + arr << "中等" + arr << "b_yellow" + elsif val.to_i > 20 && val.to_i < 50 + arr << "较差" + arr << "b_slow_red" + elsif val.to_i > 20 + arr << "很差" + arr << "b_red" + end + end + + def complexity_status val + arr = [] + if val.to_i < 10 + arr << "良好" + arr << "b_green2" + elsif val.to_i > 10 && val.to_i < 15 + arr << "较高" + arr << "b_yellow" + elsif val.to_i > 15 + arr << "很高" + arr << "b_red" + end + end + + def duplicated_lines_density_status val + arr = [] + if val.to_i < 30 + arr << "良好" + arr << "b_green2" + elsif val.to_i > 30 && val.to_i < 50 + arr << "较高" + arr << "b_yellow" + elsif val.to_i > 50 + arr << "很高" + arr << "b_red" + end + end + + def comment_lines_density_status val + arr = [] + if val.to_i < 20 + arr << "较低" + arr << "b_yellow" + elsif val.to_i > 20 && val.to_i < 50 + arr << "正常" + arr << "b_green2" + elsif val.to_i > 50 + arr << "较高" + arr << "b_red" + end + end + + def score_sqale_rating val + if val.to_i > 0 && val.to_i < 5 + "5" + elsif val.to_i > 5 && val.to_i < 10 + "4" + elsif val.to_i > 10 && val.to_i < 20 + "3" + elsif val.to_i > 20 && val.to_i < 50 + "2" + elsif val.to_i > 20 + "1" + end + end + + def lines_scale val + if val.to_i < 5000 + "小型" + elsif val.to_i >5000 && val.to_i < 50000 + "中型" + else + "大型" + end + end + + #统计答题百分比,统计结果保留两位小数 + def statistics_result_percentage(e, t) + e = e.to_f + t = t.to_f + t == 0 ? 0 : format("%.2f", e*100/t) + end + +end diff --git a/app/helpers/syllabuses_helper.rb b/app/helpers/syllabuses_helper.rb new file mode 100644 index 000000000..dac84937b --- /dev/null +++ b/app/helpers/syllabuses_helper.rb @@ -0,0 +1,2 @@ +module SyllabusesHelper +end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 44b919121..4a6dbc6b6 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -147,7 +147,9 @@ module UsersHelper # 统计未读消息数 def unviewed_message(user) - course_count = CourseMessage.where("user_id =? and viewed =?", user, 0).count + courses = user.courses.where("is_delete = 1") + course_ids = courses.empty? ? "(-1)" : "(" + courses.map{|course| course.id}.join(",") + ")" + course_count = CourseMessage.where("user_id =? and viewed =? and course_id not in #{course_ids}", user, 0).count forge_count = ForgeMessage.where("user_id =? and viewed =?", user, 0).count org_count = OrgMessage.where("user_id =? and viewed =?", user, 0).count user_feedback_count = UserFeedbackMessage.where("user_id =? and viewed =?", user, 0).count diff --git a/app/models/course.rb b/app/models/course.rb index 69dbec5d0..f286a2443 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -1,3 +1,5 @@ +#coding=utf-8 + require 'elasticsearch/model' class Course < ActiveRecord::Base include Redmine::SafeAttributes @@ -24,6 +26,7 @@ class Course < ActiveRecord::Base #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表 + belongs_to :syllabus # has_many :bid has_many :members, :include => [:principal, :roles], :conditions => "#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}" has_many :memberships, :class_name => 'Member' @@ -64,7 +67,7 @@ class Course < ActiveRecord::Base acts_as_attachable :view_permission => :view_course_files, :delete_permission => :manage_files - validates_presence_of :password, :term,:name + 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_length_of :description, :maximum => 10000 @@ -91,6 +94,7 @@ class Course < ActiveRecord::Base acts_as_customizable + scope :not_deleted, lambda{where(is_delete: 0)} scope :all_course scope :active, lambda { where(:status => STATUS_ACTIVE) } scope :status, lambda {|arg| where(arg.blank? ? nil : {:status => arg.to_i}) } @@ -404,6 +408,7 @@ class Course < ActiveRecord::Base self.course_messages << CourseMessage.new(:user_id => self.tea_id, :course_id => self.id, :viewed => false) end + #项目与课程分离后,很多课程的名称等信息为空,这些数据信息存储在项目表中!!就是数据兼容的问题 #def name # read_attribute('name') || Project.find_by_identifier(self.extra).try(:name) @@ -421,12 +426,14 @@ class Course < ActiveRecord::Base # __elasticsearch__.delete_document # end def create_course_ealasticsearch_index + return if Rails.env.development? if self.is_public == 1 and self.is_delete == 0 #公开 和 没有被删除的课程才被索引 self.__elasticsearch__.index_document end end def update_course_ealasticsearch_index + return if Rails.env.development? if self.is_public == 1 and self.is_delete == 0 #如果是初次更新成为公开或者恢复被删除的情况,会报错,那么这条记录尚未被索引过。没有报错就是更新的其他属性 begin self.__elasticsearch__.update_document @@ -443,6 +450,7 @@ class Course < ActiveRecord::Base end def delete_course_ealasticsearch_index + return if Rails.env.development? begin self.__elasticsearch__.delete_document rescue => e @@ -450,6 +458,36 @@ class Course < ActiveRecord::Base end end + # 延迟生成邀请码 + def invite_code + return generate_invite_code + end + + # 生成邀请码 + CODES = %W(2 3 4 5 6 7 8 9 A B C D E F G H J K L N M O P Q R S T U V W X Y Z) + def generate_invite_code + code = read_attribute(:invite_code) + if !code || code.size <5 + code = CODES.sample(5).join + return generate_invite_code if Course.where(invite_code: code).present? + self[:invite_code] = code + save! && reload + end + code + end + + + def generate_qrcode + ticket = self.qrcode + if !ticket || ticket.size < 10 + response = Wechat.api.qrcode_create_scene(invite_code) + logger.debug "response = #{response}" + self.qrcode = response['ticket'] + save! && reload + ticket = qrcode + end + ticket + end end diff --git a/app/models/project.rb b/app/models/project.rb index ceec0e182..bbc639f3d 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -155,7 +155,7 @@ class Project < ActiveRecord::Base #ActiveModel::Dirty 这里有一个changed方法。对任何对象都可以用 after_save :update_inherited_members, :if => Proc.new {|project| project.inherit_members_changed?} # 创建project之后默认创建一个board,之后的board去掉了board的概念 - after_create :create_board_sync,:acts_as_forge_activities,:create_project_ealasticsearch_index + after_create :create_board_sync,:acts_as_forge_activities, :create_project_ealasticsearch_index before_destroy :delete_all_members,:delete_project_ealasticsearch_index after_update :update_project_ealasticsearch_index def remove_references_before_destroy diff --git a/app/models/quality_analysis.rb b/app/models/quality_analysis.rb new file mode 100644 index 000000000..229be9826 --- /dev/null +++ b/app/models/quality_analysis.rb @@ -0,0 +1,7 @@ +class QualityAnalysis < ActiveRecord::Base + attr_accessible :author_login, :project_id, :rep_identifier, :sonar_version, :branch, :path, :rep_identifier, :language + + def user_rep_name + self.author_login+":"+self.rep_identifier + end +end diff --git a/app/models/sonar_analysis.rb b/app/models/sonar_analysis.rb new file mode 100644 index 000000000..0bb2089de --- /dev/null +++ b/app/models/sonar_analysis.rb @@ -0,0 +1,3 @@ +class SonarAnalysis < ActiveRecord::Base + attr_accessible :author_login, :project_id, :rep_identifier +end diff --git a/app/models/syllabus.rb b/app/models/syllabus.rb new file mode 100644 index 000000000..7d6319955 --- /dev/null +++ b/app/models/syllabus.rb @@ -0,0 +1,5 @@ +class Syllabus < ActiveRecord::Base + belongs_to :user + has_many :courses + attr_accessible :description, :title +end diff --git a/app/models/user.rb b/app/models/user.rb index 44ef54c95..daf1237cf 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -90,6 +90,7 @@ class User < Principal has_many :homework_users has_many :homework_attaches, :through => :homework_users has_many :homework_evaluations + has_many :syllabuses, :dependent => :destroy #问卷相关关关系 has_many :poll_users, :dependent => :destroy has_many :poll_votes, :dependent => :destroy @@ -144,6 +145,7 @@ class User < Principal has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy has_many :principal_acts, :class_name => 'PrincipalActivity',:as =>:principal_act ,:dependent => :destroy has_many :file_commit, :class_name => 'Attachment', :foreign_key => 'author_id', :conditions => "container_type = 'Project' or container_type = 'Version'" + has_many :course_attachments , :class_name => 'Attachment', :foreign_key => 'author_id', :conditions => "container_type = 'Course'" #### # added by bai has_many :join_in_contests, :dependent => :destroy @@ -247,7 +249,7 @@ class User < Principal before_save :update_hashed_password before_destroy :remove_references_before_destroy,:delete_user_ealasticsearch_index # added by fq - after_create :act_as_activity, :add_onclick_time, :act_as_principal_activity,:create_user_ealasticsearch_index + after_create :act_as_activity, :add_onclick_time, :act_as_principal_activity,:create_user_ealasticsearch_index,:add_new_jour # end # 更新邮箱用户或用户名的同事,同步更新邀请信息 after_update :update_invite_list,:update_user_ealasticsearch_index @@ -1144,6 +1146,22 @@ class User < Principal end end + #为新注册用户发送留言 + def add_new_jour + if Message.where("id=19278").any? and Message.where("id=19291").any? and Message.where("id=19292").any? + lead_message1 = Message.find(19278) + notes1 = lead_message1.content + # lead_message2 = Message.find(19292) + # notes2 = lead_message2.content + # lead_message3 = Message.find(19291) + # notes3 = lead_message3.content + # # user_id 默认为课程使者创建 + self.journals_for_messages << JournalsForMessage.new(:user_id => 1, :notes => notes1, :reply_id => 0, :status => true, :is_readed => false, :private => 0) + # self.journals_for_messages << JournalsForMessage.new(:user_id => 1, :notes => notes2, :reply_id => 0, :status => true, :is_readed => false, :private => 0) + # self.journals_for_messages << JournalsForMessage.new(:user_id => 1, :notes => notes3, :reply_id => 0, :status => true, :is_readed => false, :private => 0) + end + end + # 更新邮箱的同事,更新invite_lists表中的邮箱信息 def update_invite_list invite_lists = InviteList.where("user_id =?",self.id).all diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 2c8387349..dce3e1f18 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -32,6 +32,18 @@ class CoursesService course_list end + + def user_courses_list(current_user) + courses = current_user.courses.not_deleted + courses.inject([]) {|course_list, course| + course_list << {:course => course,:img_url => url_to_avatar(course), + :current_user_is_member => current_user.member_of_course?(course), + :current_user_is_teacher => is_course_teacher(current_user,course), + course_student_num: searchStudent(course).count + } + } + end + #搜索课程 def search_course params,current_user courses_all = Course.all_course @@ -68,7 +80,6 @@ class CoursesService if current_user.nil? || !(current_user.admin? || c.is_public == 1 || (c.is_public == 0 && current_user.member_of_course?(c))) raise '403' end - @teachers= searchTeacherAndAssistant(c) #@canShowCode = isCourseTeacher(User.current.id,course) && params[:role] != '1' case params[:role] when '1' @@ -87,7 +98,11 @@ class CoursesService gender = m.user.user_extensions.gender.nil? ? 0 : m.user.user_extensions.gender work_unit = get_user_work_unit m.user location = get_user_location m.user - users << {:id => m.user.id, :img_url => img_url, :nickname => m.user.login, :gender => gender, :work_unit => work_unit, :mail => m.user.mail, :location => location, :brief_introduction => m.user.user_extensions.brief_introduction,:realname=>m.user.realname} + users << {:id => m.user.id, :img_url => img_url, :nickname => m.user.login, :gender => gender, + :work_unit => work_unit, :mail => m.user.mail, :location => location, + role_name: m.roles.first.name, + name: m.user.show_name, + :brief_introduction => m.user.user_extensions.brief_introduction,:realname=>m.user.realname} end users end @@ -162,6 +177,9 @@ class CoursesService #显示课程 def show_course(params,current_user) course = Course.find(params[:id]) + course.generate_invite_code + course.generate_qrcode + if course.school work_unit = course.school.name else @@ -193,7 +211,7 @@ class CoursesService @course.extra = 'course' + DateTime.parse(Time.now.to_s).strftime('%Y-%m-%d_%H-%M-%S').to_s @course.send(:safe_attributes=, params[:course], current_user) #@course.safe_attributes(current_user,params[:course]) - @course.password = params[:course][:password] + #@course.password = params[:course][:password] @course.tea_id = current_user.id @course.term = params[:term] @course.time = params[:time] @@ -252,7 +270,7 @@ class CoursesService def edit_course(params,course,current_user) course.send(:safe_attributes=, params[:course], current_user) #course.safe_attributes = params[:course] - course.password = params[:course][:password] + #course.password = params[:course][:password] course.time = params[:time] course.term = params[:term] course.end_time = params[:end_time] @@ -300,23 +318,27 @@ class CoursesService @state end + class JoinCourseError < Errors + define_error [ + 0, '加入成功', + 1, '密码错误', + 2, '课程已过期 请联系课程管理员重启课程。', + 3, '您已经加入了课程', + 4, '您加入的课程不存在', + 5, '您还未登录', + 6, '申请成功,请等待审核完毕', + 7, '您已经发送过申请了,请耐心等待', + 8, '您已经是该课程的教师了', + 9, '您已经是该课程的教辅了', + 10, '您已经是该课程的管理员了', + '未知错误,请稍后再试' + ] + end #加入课程 #object_id:课程id #course_password :加入课程的密码 - #@state == 0 加入成功 - #@state == 1 密码错误 - #@state == 2 课程已过期 请联系课程管理员重启课程。(在配置课程处) - #@state == 3 您已经加入了课程 - #@state == 4 您加入的课程不存在 - #@state == 5 您还未登录 - #@state == 6 申请成功,请等待审核完毕 - #@state == 7 您已经发送过申请了,请耐心等待 - #@state == 8 您已经是该课程的教师了 - #@state == 9 您已经是该课程的教辅了 - #@state == 10 您已经是该课程的管理员了 - #@state 其他 未知错误,请稍后再试 def join_course params,current_user - course = Course.find_by_id params[:object_id] + course = Course.find_by_invite_code(params[:invite_code]) if params[:invite_code] @state = 10 if course @@ -326,7 +348,7 @@ class CoursesService if current_user.member_of_course?(course) #如果已经是成员 member = course.members.where("user_id=#{current_user.id} and course_id=#{course.id}")[0] roleName = member.roles[0].name if member - if params[:course_password] == course.password + if params[:invite_code].present? #如果加入角色为学生 并且当前是学生 if params[:role] == "10" && roleName == "Student" @state = 3 @@ -341,7 +363,7 @@ class CoursesService #如果加入角色为教师或者教辅,并且当前是学生,或者是要成为教辅,当前不是教辅,或者要成为教师,当前不是教师。那么要发送请求 elsif (params[:role] != "10" && roleName == "Student") || (params[:role] == "7" && roleName != "TeachingAsistant" ) || (params[:role] == "9" && roleName != "Teacher" ) #如果已经发送过消息了,那么就要给个提示 - if CourseMessage.where("course_message_type = 'JoinCourseRequest' and user_id = #{course.tea_id} and content = #{params[:role]} and course_message_id = #{User.current.id} and course_id = #{course.id} and status = 0 ").count != 0 + if CourseMessage.where("course_message_type = 'JoinCourseRequest' and user_id = #{course.tea_id} and course_message_id = #{User.current.id} and course_id = #{course.id} and status = 0 ").count != 0 @state = 7 else Mailer.run.join_course_request(course, User.current, params[:role]) @@ -352,19 +374,19 @@ class CoursesService elsif params[:role] == "10" && roleName != "Student" member.role_ids = [params[:role]] member.save - StudentsForCourse.create(:student_id => current_user.id, :course_id => params[:object_id]) + StudentsForCourse.create(:student_id => current_user.id, :course_id => course.id) @state = 0 end else @state = 1 end else - if params[:course_password] == course.password + if params[:invite_code].present? if params[:role] == "10" || params[:role] == nil members = [] members << Member.new(:role_ids => [10], :user_id => current_user.id) course.members << members - StudentsForCourse.create(:student_id => current_user.id, :course_id => params[:object_id]) + StudentsForCourse.create(:student_id => current_user.id, :course_id => course.id) @state = 0 else #如果已经发送过消息了,那么就要给个提示 diff --git a/app/views/account/login.html.erb b/app/views/account/login.html.erb index f2b43c9a3..23acabd1f 100644 --- a/app/views/account/login.html.erb +++ b/app/views/account/login.html.erb @@ -2,32 +2,6 @@ <%= stylesheet_link_tag 'leftside'%> -
在这里,您的创新意识和创新潜力将得到充分发挥!目前已有超过200所高校和科研机构在平台中开展在线协同开发、协同学习和协同研究。
<%= flash.empty? || flash[:error].nil? ? "" : flash[:error].html_safe %>
+在这里,您的创新意识和创新潜力将得到充分发挥!目前已有超过200所高校和科研机构在平台中开展在线协同开发、协同学习和协同研究。
+描述:
+邀请码
+<%=@course.generate_invite_code %>
+<%= time_from_now(document.created_at) %><%= link_to document.creator.show_name, user_path(document.creator), :class => "por_hot_name link-blue", :target => "_blank" %>
- <%=render :partial =>"organizations/organization_content_extension", :locals => {:user_activity_id => document.id, :content=> document.content, :maxheight => 80, :maxwordsnum => 90, :maxwidth => 0, :cl => "por_hot_txt_r"} %> +<%= time_from_now(document.created_at) %><%= link_to document.creator.show_name, user_path(document.creator), :class => "por_hot_name link-blue", :target => "_blank" %>
+ <%=render :partial =>"organizations/organization_content_extension", :locals => {:user_activity_id => document.id, :content=> document.content, :maxheight => 80, :maxwordsnum => 90, :maxwidth => 0, :cl => "por_hot_txt_r"} %> +<%= time_from_now(message.created_on) %><%= link_to message.author.show_name, user_path(message.author), :class => "por_hot_name link-blue", :target => "_blank" %>
- <%=render :partial =>"organizations/organization_content_extension", :locals => {:user_activity_id => message.id, :content=> content, :maxheight => 80, :maxwordsnum => 90, :maxwidth => 0, :cl => "por_hot_txt_r"} %> +<%= time_from_now(message.created_on) %><%= link_to message.author.show_name, user_path(message.author), :class => "por_hot_name link-blue", :target => "_blank" %>
+ <%=render :partial =>"organizations/organization_content_extension", :locals => {:user_activity_id => message.id, :content=> content, :maxheight => 80, :maxwordsnum => 90, :maxwidth => 0, :cl => "por_hot_txt_r"} %> +<%= time_from_now(news.created_on) %><%= link_to news.author.show_name, user_path(news.author), :class => "por_hot_name link-blue", :target => "_blank" %>
- <%=render :partial =>"organizations/organization_content_extension", :locals => {:user_activity_id => news.id, :content=> news.description, :maxheight => 80, :maxwordsnum => 90, :maxwidth => 0, :cl => "por_hot_txt_r"} %> +<%= time_from_now(news.created_on) %><%= link_to news.author.show_name, user_path(news.author), :class => "por_hot_name link-blue", :target => "_blank" %>
+ <%=render :partial =>"organizations/organization_content_extension", :locals => {:user_activity_id => news.id, :content=> news.description, :maxheight => 80, :maxwordsnum => 90, :maxwidth => 0, :cl => "por_hot_txt_r"} %> +<%= student.my_workplace %>
- -- <% unless student.my_blogs_count == 0 %> - 博客 <%= student.my_blogs_count %> - <% end %> - <% unless student.courses.count == 0 %> - 课程 <%= student.courses.count %> - <% end %> -
-质量等级
+<%= @complexity["msr"][9]["frmt_val"] %>
+复杂度
+<%= @complexity["msr"][6]["val"] %>
+代码重复度
+<%= @complexity["msr"][7]["frmt_val"] %>
+注释率
+<%= @complexity["msr"][5]["frmt_val"] %>
+代码行数
+<%= @complexity["msr"][0]["frmt_val"] %>
+文件
+<%= @complexity["msr"][2]["frmt_val"] %>
+目录
+<%= @complexity["msr"][3]["frmt_val"] %>
+类
+<%= @complexity["msr"][1]["frmt_val"] %>
+方法
+<%= @complexity["msr"][4]["frmt_val"] %>
+<%= link_to l(:button_back), :action => 'show', :id => @project %>
+<% html_title(l(:label_repository), l(:label_statistics)) -%> \ No newline at end of file diff --git a/app/views/repositories/quality_analysis.js.erb b/app/views/repositories/quality_analysis.js.erb new file mode 100644 index 000000000..bafe28cdf --- /dev/null +++ b/app/views/repositories/quality_analysis.js.erb @@ -0,0 +1,8 @@ +$('#ajax-modal').html('<%= escape_javascript( render :partial => 'repositories/quality_analysis', :locals => {}) %>'); +showModal('ajax-modal', '615px'); +$('#ajax-modal').siblings().remove(); +$('#ajax-modal').before(""); +$('#ajax-modal').parent().css("top","20%").css("left","32%").css("border","3px solid #269ac9"); +$('#ajax-modal').parent().addClass("popbox_polls"); + + diff --git a/app/views/repositories/show.html.erb b/app/views/repositories/show.html.erb index 43be57760..22a64a219 100644 --- a/app/views/repositories/show.html.erb +++ b/app/views/repositories/show.html.erb @@ -2,7 +2,13 @@序号 | <% if @homework.homework_type != 3 %> - + diff --git a/app/views/student_work/_evaluation_un_title.html.erb b/app/views/student_work/_evaluation_un_title.html.erb index c4a6a3e9b..1b3683506 100644 --- a/app/views/student_work/_evaluation_un_title.html.erb +++ b/app/views/student_work/_evaluation_un_title.html.erb @@ -1,7 +1,3 @@ - - |
---|
序号 | diff --git a/app/views/student_work/_no_teacher_score_notice.html.erb b/app/views/student_work/_no_teacher_score_notice.html.erb index 5a8c768cc..0926e3c74 100644 --- a/app/views/student_work/_no_teacher_score_notice.html.erb +++ b/app/views/student_work/_no_teacher_score_notice.html.erb @@ -1,7 +1,8 @@
---|