diff --git a/app/api/mobile/entities/course_dynamic.rb b/app/api/mobile/entities/course_dynamic.rb index fe31668ff..6077a8722 100644 --- a/app/api/mobile/entities/course_dynamic.rb +++ b/app/api/mobile/entities/course_dynamic.rb @@ -4,56 +4,50 @@ module Mobile include Redmine::I18n def self.course_dynamic_expose(field) expose field do |c,opt| - if field == :update_time - (format_time(c[field]) if (c.is_a?(Hash) && c.key?(field))) - elsif field == :news_count - obj = nil - c[:dynamics].each do |d| - if d[:type] == 1 - obj = d[:count] - end - end - obj - elsif field == :document_count - obj = nil - c[:dynamics].each do |d| - if d[:type] == 3 - obj = d[:count] - end - end - obj - elsif field == :topic_count - obj = nil - c[:dynamics].each do |d| - if d[:type] == 2 - obj = d[:count] - end - end - obj - elsif field == :homework_count - obj = nil - c[:dynamics].each do |d| - if d[:type] == 4 - obj = d[:count] - end - end - obj - else + # if field == :news_count + # obj = nil + # c[:dynamics].each do |d| + # if d[:type] == 1 + # obj = d[:count] + # end + # end + # obj + # elsif field == :document_count + # obj = nil + # c[:dynamics].each do |d| + # if d[:type] == 3 + # obj = d[:count] + # end + # end + # obj + # elsif field == :topic_count + # obj = nil + # c[:dynamics].each do |d| + # if d[:type] == 2 + # obj = d[:count] + # end + # end + # obj + # elsif field == :homework_count + # obj = nil + # c[:dynamics].each do |d| + # if d[:type] == 4 + # obj = d[:count] + # end + # end + # obj + # else c[field] if (c.is_a?(Hash) && c.key?(field)) - end + # end end end - course_dynamic_expose :type - course_dynamic_expose :count course_dynamic_expose :course_name course_dynamic_expose :course_term course_dynamic_expose :course_time course_dynamic_expose :course_id course_dynamic_expose :course_img_url course_dynamic_expose :message - course_dynamic_expose :update_time - course_dynamic_expose :count course_dynamic_expose :news_count course_dynamic_expose :document_count course_dynamic_expose :topic_count @@ -63,62 +57,32 @@ module Mobile course_dynamic_expose :current_user_is_member course_dynamic_expose :current_user_is_teacher - expose :documents,using:Mobile::Entities::Attachment do |f,opt| - obj = nil - f[:dynamics].each do |d| - if d[:type] == 3 - obj = d[:documents] - end - end - obj - end + # expose :documents,using:Mobile::Entities::Attachment do |f,opt| + # obj = nil + # f[:dynamics].each do |d| + # if d[:type] == 3 + # obj = d[:documents] + # end + # end + # obj + # end expose :topics,using:Mobile::Entities::Message do |f,opt| - obj = nil - f[:dynamics].each do |d| - if d[:type] == 2 - obj = d[:topics] - end - end - obj + f[:topics] end expose :homeworks,using:Mobile::Entities::Homework do |f,opt| - obj = nil - f[:dynamics].each do |d| - if d[:type] == 4 - obj = d[:homeworks] - end - end - obj + f[:homeworks] end expose :news,using:Mobile::Entities::News do |f,opt| - obj = nil - f[:dynamics].each do |d| - if d[:type] == 1 - obj = d[:news] - end - end - obj + f[:news] end expose :better_students,using:Mobile::Entities::User do |f,opt| - obj = nil - f[:dynamics].each do |d| - if d[:type] == 6 - obj = d[:better_students] - end - end - obj + f[:better_students] end expose :active_students,using:Mobile::Entities::User do |f,opt| - obj = nil - f[:dynamics].each do |d| - if d[:type] == 7 - obj = d[:active_students] - end - end - obj + f[:active_students] end end diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 086ecfb7f..a44b58789 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -337,6 +337,19 @@ class AdminController < ApplicationController format.html end end + + #学校列表 + def schools + @school_name = params[:school_name] + if @school_name + @schools = School.where("name like '%#{@school_name}%'") + else + @schools = School.all + end + respond_to do |format| + format.html + end + end #移动端版本管理 def mobile_version @versions = PhoneAppVersion.reorder('created_at desc') diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index a0a61786c..1623979f0 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -20,11 +20,10 @@ class CoursesController < ApplicationController menu_item l(:label_sort_by_influence), :only => :index before_filter :can_show_course, :except => [] - before_filter :logged_user_by_apptoken,:only => [:show,:new_homework,:feedback] - before_filter :find_course, :except => [ :index, :search,:list, :new,:join,:unjoin, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,:view_homework_attaches,:join_private_courses] - before_filter :authorize_course, :only => [:show, :settings, :edit, :update, :modules, :close, :reopen, :view_homework_attaches, :course] - before_filter :authorize_course_global, :only => [:view_homework_attaches, :new,:create] - before_filter :require_admin, :only => [:copy, :archive, :unarchive, :destroy, :calendar] + before_filter :logged_user_by_apptoken,:only => [:show,:feedback] + before_filter :find_course, :except => [ :index, :search, :new,:join,:unjoin, :create, :new_join, :course,:join_private_courses] + before_filter :authorize_course, :only => [:show, :settings, :update, :course] + before_filter :authorize_course_global, :only => [:new,:create] before_filter :toggleCourse, :only => [:finishcourse, :restartcourse] before_filter :require_login, :only => [:join, :unjoin] @@ -605,7 +604,7 @@ class CoursesController < ApplicationController def toggleCourse @course_prefs = Course.find_by_extra(@course.extra) - unless (@course_prefs.teacher == User.current || User.current.admin?) + unless (User.current.allowed_to?(:as_teacher,@course_prefs) || User.current.admin?) render_403 end end @@ -809,6 +808,12 @@ class CoursesController < ApplicationController end end + #删除课程 + #删除课程只是将课程的is_delete状态改为false,is_delete为false状态的课程只有管理员可以看到 + def destroy + + end + private def allow_join course if course_endTime_timeout? course diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 04a07e9a8..e3424707f 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -1,6 +1,7 @@ class HomeworkCommonController < ApplicationController require 'net/http' require 'json' + require "base64" layout "base_courses" before_filter :find_course, :only => [:index,:new,:create,:next_step] before_filter :find_homework, :only => [:edit,:update,:alert_anonymous_comment,:start_anonymous_comment,:stop_anonymous_comment,:destroy] @@ -18,28 +19,28 @@ class HomeworkCommonController < ApplicationController end def new - @homework_type = "1" - - @homework = HomeworkCommon.new - @homework.safe_attributes = params[:homework_common] - @homework.late_penalty = 0 - @homework.end_time = (Time.now + 3600 * 24).strftime('%Y-%m-%d') - @homework.publish_time = Time.now.strftime('%Y-%m-%d') - - if @homework_type == "1" - #匿评作业相关属性 - @homework_detail_manual = HomeworkDetailManual.new - @homework_detail_manual.ta_proportion = 0.6 - @homework_detail_manual.absence_penalty = 0 - @homework_detail_manual.evaluation_num = 3 - @homework_detail_manual.evaluation_start = Time.now.strftime('%Y-%m-%d') - @homework_detail_manual.evaluation_end = (Time.now + 3600 * 24).strftime('%Y-%m-%d') - @homework.homework_detail_manual = @homework_detail_manual - elsif @homework_type == "2" - #编程作业相关属性 - @homework_detail_programing = HomeworkDetailPrograming.new - @homework.homework_detail_programing = @homework_detail_programing - end + # @homework_type = "1" + # + # @homework = HomeworkCommon.new + # @homework.safe_attributes = params[:homework_common] + # @homework.late_penalty = 0 + # @homework.end_time = (Time.now + 3600 * 24).strftime('%Y-%m-%d') + # @homework.publish_time = Time.now.strftime('%Y-%m-%d') + # + # if @homework_type == "1" + # #匿评作业相关属性 + # @homework_detail_manual = HomeworkDetailManual.new + # @homework_detail_manual.ta_proportion = 0.6 + # @homework_detail_manual.absence_penalty = 0 + # @homework_detail_manual.evaluation_num = 3 + # @homework_detail_manual.evaluation_start = Time.now.strftime('%Y-%m-%d') + # @homework_detail_manual.evaluation_end = (Time.now + 3600 * 24).strftime('%Y-%m-%d') + # @homework.homework_detail_manual = @homework_detail_manual + # elsif @homework_type == "2" + # #编程作业相关属性 + # @homework_detail_programing = HomeworkDetailPrograming.new + # @homework.homework_detail_programing = @homework_detail_programing + # end respond_to do |format| format.html end @@ -99,12 +100,13 @@ class HomeworkCommonController < ApplicationController question = {title:homework.name,content:homework.description} question[:input] = [] question[:output] = [] - if params[:input] && params[:output] + if params[:input] && params[:output] && params[:result] params[:input].each do |k,v| if params[:output].include? k homework_test = HomeworkTest.new homework_test.input = v homework_test.output = params[:output][k] + homework_test.result = params[:result][k] homework.homework_tests << homework_test question[:input] << homework_test.input question[:output] << homework_test.output @@ -144,6 +146,8 @@ class HomeworkCommonController < ApplicationController end if homework.save + homework_detail_programing.save if homework_detail_programing + homework_detail_manual.save if homework_detail_manual respond_to do |format| format.html { flash[:notice] = l(:notice_successful_create) @@ -209,7 +213,7 @@ class HomeworkCommonController < ApplicationController end if @homework.homework_type == 2 && @homework_detail_programing #编程作业 - @homework_detail_programing.language = "C++" + @homework_detail_programing.language = params[:language] @homework_detail_programing.standard_code = params[:standard_code] @homework_detail_programing.ta_proportion = params[:ta_proportion] || 0.6 homework_tests = @homework.homework_tests @@ -236,6 +240,24 @@ class HomeworkCommonController < ApplicationController end end end + + #发送修改作业的请求 + question = {title:@homework.name,content:@homework.description} + question[:input] = [] + question[:output] = [] + @homework.homework_tests.each do |test| + question[:input] << test.input + question[:output] << test.output + end + uri = URI("http://192.168.80.21:8080/api/questions/#{@homework_detail_programing.question_id}.json") + body = question.to_json + res = Net::HTTP.new(uri.host, uri.port).start do |client| + request = Net::HTTP::Put.new(uri.path) + request.body = body + request["Content-Type"] = "application/json" + client.request(request) + end + result = JSON.parse(res.body) end @homework.save_attachments(params[:attachments]) @@ -331,6 +353,23 @@ class HomeworkCommonController < ApplicationController end end + def programing_test + test = {language:params[:language],src:Base64.encode64(params[:src]),input:[params[:input]],output:[params[:output]]} + @index = params[:index] + uri = URI('http://192.168.80.21:8080/api/realtime.json') + body = test.to_json + res = Net::HTTP.new(uri.host, uri.port).start do |client| + request = Net::HTTP::Post.new(uri.path) + request.body = body + request["Content-Type"] = "application/json" + client.request(request) + end + result = JSON.parse(res.body) + result["results"].each do |re| + @result = re["status"] + end + end + private #获取课程 def find_course diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index 56b4a30fc..185e7128e 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -71,10 +71,15 @@ class NewsController < ApplicationController scope = @course ? @course.news.course_visible : News.course_visible @news_count = scope.count - #@news_pages = Paginator.new @news_count, @limit, params['page'] - #@offset ||= scope_page.offset - scope_order = scope.all(:include => [:author, :course], - :order => "#{News.table_name}.created_on DESC") + @q = params[:subject] + if params[:subject].nil? + scope_order = scope.all(:include => [:author, :course], + :order => "#{News.table_name}.created_on DESC") + else + scope_order = scope.where("#{News.table_name}.title like '#{'%' << params[:subject].to_s << '%'}'").all(:include => [:author, :course], + :order => "#{News.table_name}.created_on DESC") + end + # :offset => @offset, # :limit => @limit) @newss = paginateHelper scope_order,10 @@ -83,6 +88,7 @@ class NewsController < ApplicationController @news = News.new render :layout => 'base_courses' } + format.js format.api format.atom { render_feed(@newss, :title => (@course ? @course.name : Setting.app_title) + ": #{l(:label_news_plural)}") } end @@ -141,7 +147,7 @@ class NewsController < ApplicationController ids = params[:asset_id].split(',') update_kindeditor_assets_owner ids,@news.id,OwnerTypeHelper::NEWS end - # ض̬ļ¼add start + # ������ض�̬�ļ�¼add start teachers = searchTeacherAndAssistant(@course) for teacher in teachers if(teacher.user_id != User.current.id) @@ -155,7 +161,7 @@ class NewsController < ApplicationController notify.save() end end - # ض̬ļ¼add end + # ������ض�̬�ļ�¼add end render_attachment_warning_if_needed(@news) flash[:notice] = l(:notice_successful_create) redirect_to course_news_index_url(@course) diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index 758747e02..dda5b81b2 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -137,11 +137,19 @@ class PollController < ApplicationController @poll_questions.poll_answers.new question_option end end - if @poll_questions.save - respond_to do |format| - format.js - end + # 如果是插入的话,那么从插入的这个id以后的question_num都将要+1 + if params[:quest_id] + @is_insert = true + @poll.poll_questions.where("question_number > #{params[:quest_num].to_i}").update_all(" question_number = question_number + 1") + @poll_question_num = params[:quest_num].to_i + @poll_questions.question_number = params[:quest_num].to_i + 1 end + if @poll_questions.save + respond_to do |format| + format.js + end + end + end #修改题目 @@ -328,6 +336,37 @@ class PollController < ApplicationController end end + + def import_poll + @poll = Poll.find(params[:to_id]) + question_num = @poll.poll_questions.select("max(question_number) question_number").first.question_number + import_poll = Poll.find(params[:import_id]) + import_poll.poll_questions.each_with_index do |question,index| + option = { + :is_necessary => question.is_necessary, + :question_title => question.question_title, + :question_type => question.question_type, + :question_number => question_num + index+1 + } + poll_questions = @poll.poll_questions.new option + for i in 1..question.poll_answers.count + answer = question.poll_answers[i-1][:answer_text] + question_option = { + :answer_position => i, + :answer_text => answer + } + poll_questions.poll_answers.new question_option + end + @poll.poll_questions << poll_questions + end + if @poll.save + @poll = Poll.find(params[:to_id]) + respond_to do |format| + format.js + end + end + end + #重新发布问卷 def republish_poll @poll.poll_questions.each do |poll_question| diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 2efaf591a..09ae5ad79 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -150,11 +150,15 @@ class ProjectsController < ApplicationController end def new - @issue_custom_fields = IssueCustomField.sorted.all - @trackers = Tracker.sorted.all - @project = Project.new - @project.safe_attributes = params[:project] - render :layout => 'base' + if User.current.login? + @issue_custom_fields = IssueCustomField.sorted.all + @trackers = Tracker.sorted.all + @project = Project.new + @project.safe_attributes = params[:project] + render :layout => 'base' + else + redirect_to signin_url + end end def share @@ -167,6 +171,10 @@ class ProjectsController < ApplicationController end def create + unless User.current.login? + redirect_to signin_url + return + end @issue_custom_fields = IssueCustomField.sorted.all @trackers = Tracker.sorted.all @project = Project.new @@ -280,11 +288,11 @@ class ProjectsController < ApplicationController # 根据私密性,取出符合条件的所有数据 if User.current.member_of?(@project) || User.current.admin? - @events_pages = ForgeActivity.where("project_id = ?",@project).order("created_at desc").page(params['page'|| 1]).per(20); + @events_pages = ForgeActivity.where("project_id = ? and forge_act_type != ?",@project, "Document" ).order("created_at desc").page(params['page'|| 1]).per(20); #events = @activity.events(@date_from, @date_to) else @events_pages = ForgeActivity.includes(:project).where("forge_activities.project_id = ? and projects.is_public - = ?",@project,1).order("created_at desc") + = ? and forge_act_type != ? ",@project,1, "Document").order("created_at desc") .page(params['page'|| 1]).per(10); # @events = @activity.events(@date_from, @date_to, :is_public => 1) end diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 272ae1d37..7b364a46b 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -449,6 +449,8 @@ update def stats @project_id = params[:id] @repository_id = @repository.identifier + # 提交次数统计 + @status_commit_count = Changeset.count(:conditions => ["#{Changeset.table_name}.repository_id = ?", @repository.id]) render :layout => 'base_projects' end @@ -459,6 +461,12 @@ update data = graph_commits_per_month(@repository) when "commits_per_author" data = graph_commits_per_author(@repository) + when "author_commits_per_month" + data = graph_author_commits_per_month(@repository) + when "author_commits_six_month" + data = author_commits_six_month(@repository) + when "author_code_six_months" + data = author_code_six_month(@repository) end if data headers["Content-Type"] = "image/svg+xml" @@ -484,7 +492,18 @@ update if params[:repository_id].present? @repository = @project.repositories.find_by_identifier_param(params[:repository_id]) else - @repository = @project.repository + # 多版本库,如果一个版本库为空则去下一个 + rep_count = @project.repositories.count + if @project.repository.nil? + for i in 0..rep_count + unless @project.repositories[i].nil? + @repository = @project.repositories[i] + break + end + end + else + @repository = @project.repository + end end (render_404; return false) unless @repository @path = params[:path].is_a?(Array) ? params[:path].join('/') : params[:path].to_s @@ -606,6 +625,123 @@ update ) graph.burn end + + # 用户最近一年的提交次数 + def graph_author_commits_per_month(repository) + @date_to = Date.today + @date_from = @date_to << 12 + @date_from = Date.civil(@date_from.year, @date_from.month, @date_from.day) + commits_by_author = Changeset.count(:all, :group => :committer, + :conditions => ["#{Changeset.table_name}.repository_id = ? AND #{Changeset.table_name}.commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to]) + commits_by_author = commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}.last(25) + + fields = commits_by_author.collect {|r| r.first} + commits_data = commits_by_author.collect {|r| r.last} + + fields = fields + [""]*(10 - fields.length) if fields.length<10 + commits_data = commits_data + [0]*(10 - commits_data.length) if commits_data.length<10 + + # Remove email adress in usernames + fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') } + + graph = SVG::Graph::BarHorizontal.new( + :height => 400, + :width => 600, + :fields => fields, + :stack => :side, + :scale_integers => true, + :show_data_values => true, + :rotate_y_labels => false, + :graph_title => l(:label_author_commits_year), + :show_graph_title => true, + :no_css => true + ) + graph.add_data( + :data => commits_data, + :title => l(:label_revision_commit_count) + ) + graph.burn + end + + # 用户最近六个月的提交次数 + def author_commits_six_month(repository) + @date_to = Date.today + @date_from = @date_to << 6 + @date_from = Date.civil(@date_from.year, @date_from.month, @date_from.day) + commits_by_author = Changeset.count(:all, :group => :committer, + :conditions => ["#{Changeset.table_name}.repository_id = ? AND #{Changeset.table_name}.commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to]) + commits_by_author = commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}.last(25) + + fields = commits_by_author.collect {|r| r.first} + commits_data = commits_by_author.collect {|r| r.last} + + fields = fields + [""]*(10 - fields.length) if fields.length<10 + commits_data = commits_data + [0]*(10 - commits_data.length) if commits_data.length<10 + + # Remove email adress in usernames + fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') } + + graph = SVG::Graph::BarHorizontal.new( + :height => 400, + :width => 600, + :fields => fields, + :stack => :side, + :scale_integers => true, + :show_data_values => true, + :rotate_y_labels => false, + :graph_title => l(:label_author_commits_six_month), + :show_graph_title => true + ) + graph.add_data( + :data => commits_data, + :title => l(:label_revision_commit_count) + ) + graph.burn + end + + # 最近六个月代码量统计 + def author_code_six_month(repository) + @date_to = Date.today + @date_from = @date_to << 6 + @date_from = Date.civil(@date_from.year, @date_from.month, @date_from.day) + commits_by_author = Changeset.count(:group => :committer, :conditions => ["#{Changeset.table_name}.repository_id = ? AND #{Changeset.table_name}.commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to]) + commits_by_author = commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}.last(40) + all_author = [] + commits_by_author.each do |cba| + all_author << cba.first + end + # all_author = all_author.collect {|c| c.gsub(%r{/ /<.+@.+>}, '') } + all_author = all_author.collect {|c| c.split.first } + commits_by_author = repository.commits(all_author, "#{@date_from}", "#{@date_to}", repository.id == 150 ? "szzh" : 'master') + + fields = commits_by_author.collect {|r| r.first} + commits_data = commits_by_author.collect {|r| r.last} + + fields = fields + [""]*(10 - fields.length) if fields.length<10 + commits_data = commits_data + [0]*(10 - commits_data.length) if commits_data.length<10 + + # Remove email adress in usernames + fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') } + + graph = SVG::Graph::BarHorizontal.new( + :height => 400, + :width => 600, + :fields => fields, + :stack => :side, + :scale_integers => true, + :show_data_values => true, + :rotate_y_labels => false, + :graph_title => l(:label_author_code_six_month), + :show_graph_title => true + ) + graph.add_data( + :data => commits_data, + :title => l(:lable_revision_code_count) + ) + graph.burn + end + + def check_hidden_repo project = Project.find(params[:id]) if !User.current.member_of?(project) diff --git a/app/controllers/school_controller.rb b/app/controllers/school_controller.rb index 008fe00fc..3e0c280ac 100644 --- a/app/controllers/school_controller.rb +++ b/app/controllers/school_controller.rb @@ -4,28 +4,21 @@ class SchoolController < ApplicationController def upload uploaded_io = params[:logo] - school_id = 0 - schools = School.where("name = ?", params[:school]) - - schools.each do |s| - school_id = s.id - end - + school_id ||= params[:id] unless uploaded_io.nil? File.open(Rails.root.join('public', 'images', 'school', school_id.to_s+'.png'), 'wb') do |file| file.write(uploaded_io.read) end - s1 = School.find(school_id) s1.logo_link = '/images/school/'+school_id.to_s+'.png' s1.save - - - end + end + redirect_to admin_schools_url(:school_name => params[:school_name]) end def upload_logo - + @school = School.find params[:id] + @school_name = params[:school_name] end #获取制定学校开设的课程数 diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 209fa7269..3e1e0ba29 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -157,7 +157,7 @@ class StudentWorkController < ApplicationController end def edit - if @homework.homework_type == 2 #编程作业不能修改作业 + if !User.current.admin? && @homework.homework_type == 2 #编程作业不能修改作业 render_403 else respond_to do |format| @@ -396,6 +396,7 @@ class StudentWorkController < ApplicationController if student_work_test.result == 0 student_score_count += 1 end + student_work_test.error_msg = params[:compile_error_msg] student_work_test.save! end end @@ -444,7 +445,7 @@ class StudentWorkController < ApplicationController #判断是不是当前作品的提交者 #提交者 && (非匿评作业 || 未开启匿评) 可以编辑作品 def author_of_work - render_403 unless (User.current.id == @work.user_id || User.current.admin?) && (@homework.homework_type != 1 || @homework.homework_detail_manual.comment_status == 1 ) + render_403 unless User.current.admin? || (User.current.id == @work.user_id && @homework.homework_type != 1 || @homework.homework_detail_manual.comment_status == 1 ) end def teacher_of_course @@ -467,22 +468,60 @@ 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 - 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_t_score),l(:excel_ta_score),l(:excel_n_score),l(:excel_f_score),l(:excel_commit_time)]) - 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,2] = homework.user.login - sheet1[count_row,3] = homework.user.user_extensions.student_id - sheet1[count_row,4] = homework.user.mail - sheet1[count_row,5] = homework.name - sheet1[count_row,6] = homework.teacher_score.nil? ? l(:label_without_score) : format("%.2f",homework.teacher_score) - sheet1[count_row,7] = homework.teaching_asistant_score.nil? ? l(:label_without_score) : format("%.2f",homework.teaching_asistant_score) - sheet1[count_row,8] = homework.student_score.nil? ? l(:label_without_score) : format("%.2f",homework.student_score) - sheet1[count_row,9] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : format("%.2f",homework.score) : l(:label_without_score) - sheet1[count_row,10] = format_time(homework.created_at) - count_row += 1 + if @homework.homework_type == 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_t_score),l(:excel_ta_score),l(:excel_f_score),l(:excel_commit_time)]) + 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,2] = homework.user.login + sheet1[count_row,3] = homework.user.user_extensions.student_id + sheet1[count_row,4] = homework.user.mail + sheet1[count_row,5] = homework.name + sheet1[count_row,6] = homework.teacher_score.nil? ? l(:label_without_score) : format("%.2f",homework.teacher_score) + sheet1[count_row,7] = homework.teaching_asistant_score.nil? ? l(:label_without_score) : format("%.2f",homework.teaching_asistant_score) + # sheet1[count_row,8] = homework.student_score.nil? ? l(:label_without_score) : format("%.2f",homework.student_score) + sheet1[count_row,8] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : format("%.2f",homework.score) : l(:label_without_score) + sheet1[count_row,9] = format_time(homework.created_at) + count_row += 1 + end + elsif @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_t_score),l(:excel_ta_score), l(:excel_n_score),l(:excel_f_score),l(:excel_commit_time)]) + 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,2] = homework.user.login + sheet1[count_row,3] = homework.user.user_extensions.student_id + sheet1[count_row,4] = homework.user.mail + sheet1[count_row,5] = homework.name + sheet1[count_row,6] = homework.teacher_score.nil? ? l(:label_without_score) : format("%.2f",homework.teacher_score) + sheet1[count_row,7] = homework.teaching_asistant_score.nil? ? l(:label_without_score) : format("%.2f",homework.teaching_asistant_score) + sheet1[count_row,8] = homework.student_score.nil? ? l(:label_without_score) : format("%.2f",homework.student_score) + sheet1[count_row,9] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : format("%.2f",homework.score) : l(:label_without_score) + sheet1[count_row,10] = format_time(homework.created_at) + 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_t_score),l(:excel_ta_score), l(:excel_s_score),l(:excel_f_score),l(:excel_commit_time)]) + 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,2] = homework.user.login + sheet1[count_row,3] = homework.user.user_extensions.student_id + sheet1[count_row,4] = homework.user.mail + sheet1[count_row,5] = homework.name + sheet1[count_row,6] = homework.teacher_score.nil? ? l(:label_without_score) : format("%.2f",homework.teacher_score) + sheet1[count_row,7] = homework.teaching_asistant_score.nil? ? l(:label_without_score) : format("%.2f",homework.teaching_asistant_score) + sheet1[count_row,8] = homework.student_score.nil? ? l(:label_without_score) : format("%.2f",homework.student_score) + sheet1[count_row,9] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : format("%.2f",homework.score) : l(:label_without_score) + sheet1[count_row,10] = format_time(homework.created_at) + count_row += 1 + end end book.write xls_report xls_report.string diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index d6597f3da..0c5b441d4 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -112,39 +112,20 @@ class UsersController < ApplicationController #added by young def user_projects - - #add by huang unless User.current.admin? if !@user.active? #|| (@user != User.current && @memberships.empty? && events.empty?) render_404 return end end - #end - # if User.current.admin? - # @memberships = @user.memberships.all(conditions: "projects.project_type = #{Project::ProjectType_project}") - # else - # cond = Project.visible_condition(User.current) + " AND projects.project_type <> 1" - # @memberships = @user.memberships.all(:conditions => cond) - # end - #events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 20) - #@events_by_day = events.group_by(&:event_date) - # @state = 0 - - limit = 10; - query = Project.joins("join members m on #{Project.table_name}.id=m.project_id") - query = query.where("m.user_id = ? and #{Project.table_name}.project_type=?",@user.id,Project::ProjectType_project) + projects = @user.projects.visible.order("updated_on desc") if(params[:status] == '1') - query = query.where("#{Project.table_name}.user_id = ?",@user.id); + projects = projects.where("projects.user_id = ?",@user.id) elsif(params[:status] == '2') - query = query.where("#{Project.table_name}.user_id <> ?",@user.id); + projects = projects.where("projects.user_id <> ?",@user.id) end - @obj_count = query.count(); - - @obj_pages = Paginator.new @obj_count,limit,params['page'] - @list = query.order("#{Project.table_name}.updated_on desc,#{Project.table_name}.id desc").limit(limit).offset(@obj_pages.offset).all(); - @params = params - + @list = paginateHelper projects,10 + @params = params[:status] respond_to do |format| format.html{render :layout=>'base_users_new'} format.api @@ -262,75 +243,33 @@ class UsersController < ApplicationController def user_courses unless User.current.admin? - if !@user.active? #|| (@user != User.current && @memberships.empty? && events.empty?) + if !@user.active? render_404 return end end - - #@user.coursememberships.all(:conditions => Course.visible_condition(User.current)) - - limit = 10; - query = Course.joins("join members m on #{Course.table_name}.id=m.course_id") - query = query.where("m.user_id = ?",@user.id) + courses = @user.courses.visible.order("created_at desc") if(params[:status] == '1') - query = query.where("endup_time >= ? or endup_time is null or endup_time=''",Time.now); + courses = courses.where("endup_time >= ? or endup_time is null or endup_time=''",Time.now) elsif(params[:status] == '2') - query = query.where("endup_time < ?",Time.now); + courses = courses.where("endup_time < ?",Time.now) end - @obj_count = query.count(); - - @obj_pages = Paginator.new @obj_count,limit,params['page'] - @list = query.order("#{Course.table_name}.updated_at desc,#{Course.table_name}.id desc").limit(limit).offset(@obj_pages.offset).all(); - @params = params + @list = paginateHelper courses,10 + @params = params[:status] render :layout=>'base_users_new' - - # if User.current == @user || User.current.admin? - # membership = @user.coursememberships.all - # else - # membership = @user.coursememberships.all(:conditions => Course.visible_condition(User.current)) - # end - # - # membership.sort! {|older, newer| newer.created_on <=> older.created_on } - # @memberships = [] - # membership.collect { |e| - # @memberships.push(e) - # } - # ## 判断课程是否过期 [需封装] - # @memberships_doing = [] - # @memberships_done = [] - # #now_time = Time.now.year - # @memberships.map { |e| - # #end_time = e.course.get_time.year - # isDone = course_endTime_timeout?(e.course) - # if isDone - # @memberships_done.push e - # else - # @memberships_doing.push e - # end - # } - # respond_to do |format| - # format.html - # format.api - # end end # modified by fq def user_newfeedback - @jours = @user.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC') - @jours.update_all(:is_readed => true, :status => false) - @jours.each do |journal| + jours = @user.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC') + jours.update_all(:is_readed => true, :status => false) + jours.each do |journal| fetch_user_leaveWord_reply(journal).update_all(:is_readed => true, :status => false) end - - #@limit = 10 - #@feedback_count = @jours.count - #@feedback_pages = Paginator.new @feedback_count, @limit, params['page'] - #@offset ||= @feedback_pages.offset - @jour = paginateHelper @jours,10 + @jour = paginateHelper jours,10 @state = false + render :layout=>'base_users_new' end - # end def user_comments @@ -448,7 +387,7 @@ class UsersController < ApplicationController def user_courses4show query = Course.joins("join members m on #{Course.table_name}.id=m.course_id") - query = query.where("m.user_id = ?",@user.id) + query = query.where("m.user_id = ?",@user.id).order("#{Course.table_name}.id desc") if User.current == @user #看自己 else if @user.user_extensions!=nil && @user.user_extensions.identity == 0 #看老师 @@ -456,13 +395,12 @@ class UsersController < ApplicationController query = query.where("r.role_id in(3,7,9)") end query = query.where(Course.table_name+".is_public = 1") - # or exists (select 1 from courses c2,members m2 where c2.id=m2.course_id and c2.id=#{Course.table_name}.id and m2.user_id= User.current.id) end if params[:lastid]!=nil && !params[:lastid].empty? - query = query.where("( (#{Course.table_name}.updated_at=? and #{Course.table_name}.id < ?) or #{Course.table_name}.updated_at)",params[:lasttime],params[:lastid],params[:lasttime]) + query = query.where(" #{Course.table_name}.id < ?",params[:lastid],) end - @list = query.order("#{Course.table_name}.updated_at desc,#{Course.table_name}.id desc").limit(8).all + @list = query.limit(8) render :layout=>nil end @@ -483,95 +421,6 @@ class UsersController < ApplicationController render :layout=>nil end - # def user_course_activities - # @list = [] - # lastid = nil - # if params[:lastid]!=nil && !params[:lastid].empty? - # lastid = params[:lastid]; - # end - # - # user_ids = [] - # if @user == User.current - # watcher = User.watched_by(@user) - # watcher.push(User.current) - # user_ids = watcher.map{|x| x.id} - # else - # user_ids << @user.id - # end - # - # query_rec_count = 8 - # query_times = 10 #query_times次没查到query_rec_count条记录就不查了 - # query_i = 0; - # while( true ) - # query_i = query_i+1 - # if(query_i>query_times) - # break - # end - # query = Activity.where(user_id: user_ids) - # if(lastid != nil) - # query = query.where("id < ?",lastid) - # end - # lastid,item_list = query_activities(query,'course'); - # for item in item_list - # @list << item - # if @list.count() >= query_rec_count - # break - # end - # end - # if @list.count() >= query_rec_count - # break - # end - # if lastid == nil - # break - # end - # end - # render :layout=>nil - # end - # - # def user_project_activities - # @list = [] - # lastid = nil - # if params[:lastid]!=nil && !params[:lastid].empty? - # lastid = params[:lastid]; - # end - # - # user_ids = [] - # if @user == User.current - # watcher = User.watched_by(@user) - # watcher.push(User.current) - # user_ids = watcher.map{|x| x.id} - # else - # user_ids << @user.id - # end - # - # query_rec_count = 8 - # query_times = 10 #query_times次没查到query_rec_count条记录就不查了 - # query_i = 0; - # while( true ) - # query_i = query_i+1 - # if(query_i>query_times) - # break - # end - # query = Activity.where(user_id: user_ids) - # if(lastid != nil) - # query = query.where("id < ?",lastid) - # end - # lastid,item_list = query_activities(query,'project'); - # for item in item_list - # @list << item - # if @list.count() >= query_rec_count - # break - # end - # end - # if @list.count() >= query_rec_count - # break - # end - # if lastid == nil - # break - # end - # end - # render :action=>'user_course_activities',:layout=>nil - # end def user_course_activities lastid = nil if params[:lastid]!=nil && !params[:lastid].empty? @@ -630,7 +479,7 @@ class UsersController < ApplicationController query = query.where("#{Activity.table_name}.id < ?",lastid) end query = query.order("#{Activity.table_name}.id desc") - @list = query_activities(query); + @list = query_activities(query) render :action=>'user_course_activities',:layout=>nil end diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 9ce107f8b..6b14db9bb 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -100,44 +100,6 @@ class WelcomeController < ApplicationController @course_page = FirstPage.find_by_page_type('course') @school_id = params[:school_id] || User.current.user_extensions.school.try(:id) || 117 @logoLink ||= logolink() - - ##3-8月份为查找春季课程,9-2月份为查找秋季课程 - #month_now = Time.now.strftime("%m").to_i - #year_now = Time.new.strftime("%Y").to_i - #(month_now >= 3 && month_now < 9) ? course_term = l(:label_spring) : course_term = l(:label_autumn) - ##year_now -= 1 if year_now < 3 - #@school_id.nil? ? @cur_school_course = [] : @cur_school_course = find_miracle_course(10,7,@school_id, year_now, course_term) - ##未登录或者当前学校未开设课程 - #if @cur_school_course.empty? - # @has_course = false - # User.current.logged? ? course_count = 9 : course_count = 10 - # @cur_school_course += find_all_new_hot_course(course_count, @school_id, year_now, course_term) - # while @cur_school_course.count < 9 do - # if course_term == l(:label_spring) - # course_term = l(:label_autumn) - # year_now -= 1 - # else - # course_term = l(:label_spring) - # end - # @cur_school_course += find_all_new_hot_course((10-@cur_school_course.count), nil, year_now, course_term) - # end - #else - # if @cur_school_course.count < 9 - # @has_course = false - # @cur_school_course += find_all_new_hot_course(9-@cur_school_course.count, @school_id, year_now, course_term) - # if @cur_school_course.count < 9 - # if course_term == l(:label_spring) - # course_term = l(:label_autumn) - # year_now -= 1 - # else - # course_term = l(:label_spring) - # end - # @cur_school_course += find_all_new_hot_course(9-@cur_school_course.count, nil, year_now, course_term) - # end - # else - # @has_course = true - # end - #end end def logolink() diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index 161791954..fc723d5d5 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -4,7 +4,7 @@ class WordsController < ApplicationController include ApplicationHelper before_filter :find_user, :only => [:new, :create, :destroy, :more, :back] def create - if params[:new_form][:user_message].size>0 + if params[:new_form][:user_message].size>0 && User.current.logged? unless params[:user_id].nil? if params[:reference_content] message = params[:new_form][:user_message] + "\n" + params[:reference_content] @@ -18,22 +18,13 @@ class WordsController < ApplicationController list = User.find(refer_user_id).add_jour(User.current, message, refer_user_id) end @jour = list.last - # @user.count_new_jour - # if a_message.size > 5 - # @message = a_message[-5, 5] - # else - # @message = a_message - # end - # @message_count = a_message.count end end - # @jours = @user.journals_for_messages.where('m_parent_id IS NULL').reverse - # @jour = paginateHelper @jours,10 + jours = @user.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC') + @jour = paginateHelper jours,10 respond_to do |format| - # format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}} format.js - #format.api { render_api_ok } end end @@ -93,7 +84,6 @@ class WordsController < ApplicationController end respond_to do |format| format.js - #format.api { render_api_ok } end end @@ -206,7 +196,15 @@ class WordsController < ApplicationController flash[:error] = feedback.errors.full_messages[0] redirect_to project_feedback_url(params[:id]) end + end + #给用户留言 + def leave_user_message + @user = User.find(params[:id]) + if params[:new_form][:user_message].size>0 && User.current.logged? && @user + @user.add_jour(User.current, params[:new_form][:user_message]) + end + redirect_to feedback_path(@user) end # add by nwb diff --git a/app/helpers/api_helper.rb b/app/helpers/api_helper.rb index 1f34112ad..f26f5c19b 100644 --- a/app/helpers/api_helper.rb +++ b/app/helpers/api_helper.rb @@ -1,5 +1,11 @@ # encoding: utf-8 module ApiHelper + ONE_MINUTE = 60 * 1000 + ONE_HOUR = 60 * ONE_MINUTE + ONE_DAY = 24 * ONE_HOUR + ONE_MONTH = 30 * ONE_DAY + + ONE_YEAR = 12 * ONE_MONTH #获取用户的工作单位 def get_user_work_unit user work_unit = "" @@ -163,5 +169,37 @@ module ApiHelper end + # 获取当前时间 + def time_from_now time + lastUpdateTime = time.to_i*1000 + + currentTime = Time.now.to_i*1000 + timePassed = currentTime - lastUpdateTime; + timeIntoFormat = 0 + updateAtValue = "" + if timePassed < 0 + updateAtValue = "时间有问题" + elsif timePassed < ONE_MINUTE + updateAtValue = "一分钟前" + elsif timePassed < ONE_HOUR + timeIntoFormat = timePassed / ONE_MINUTE + updateAtValue = timeIntoFormat.to_s + "分钟前" + elsif (timePassed < ONE_DAY) + timeIntoFormat = timePassed / ONE_HOUR + updateAtValue = timeIntoFormat.to_s + "小时前" + elsif (timePassed < ONE_MONTH) + timeIntoFormat = timePassed / ONE_DAY + updateAtValue = timeIntoFormat.to_s + "天前" + elsif (timePassed < ONE_YEAR) + timeIntoFormat = timePassed / ONE_MONTH + updateAtValue = timeIntoFormat.to_s + "个月前" + else + timeIntoFormat = timePassed / ONE_YEAR + updateAtValue = timeIntoFormat.to_s + "年前" + end + updateAtValue + + end + end \ No newline at end of file diff --git a/app/helpers/members_helper.rb b/app/helpers/members_helper.rb index 06b154d36..9dd0bed8c 100644 --- a/app/helpers/members_helper.rb +++ b/app/helpers/members_helper.rb @@ -38,7 +38,7 @@ module MembersHelper scope = [] end principals = paginateHelper scope,10 - s = content_tag('ul', project_member_check_box_tags_ex('membership[user_ids][]', principals), :class => 'mb5') + s = content_tag('ul', project_member_check_box_tags_ex('membership[user_ids][]', principals), :class => 'mb5', :id => 'principals') links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true){|text, parameters, options| link_to text, autocomplete_project_memberships_path(project, parameters.merge(:q => params[:q],:flag => true, :format => 'js')), :remote => true } diff --git a/app/helpers/praise_tread_helper.rb b/app/helpers/praise_tread_helper.rb index 90ce6d61d..c142f0973 100644 --- a/app/helpers/praise_tread_helper.rb +++ b/app/helpers/praise_tread_helper.rb @@ -20,9 +20,9 @@ module PraiseTreadHelper # when 0 # return @record.tread_num.nil? ? 0 : @record.tread_num # end - return (@record.praise_num.to_i-@record.tread_num.to_i) + return ((@record.praise_num.nil? ? 0 : @record.praise_num.to_i)-(@record.tread_num.nil? ? 0 : @record.tread_num.to_i)) else - return 0 + return 0 end end diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 5cbc3af5a..c77eba0c5 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -236,13 +236,14 @@ module RepositoriesHelper # 判断项目是否有主版本库 def judge_main_repository(pro) if pro.repositories.blank? - return false + status = false else - pro.repositories.sort.each do |rep| - rep.is_default? - return true + pro.repositories.each do |rep| + status = true and break if rep.is_default? + status = false end end + status end # def cvs_field_tags(form, repository) # content_tag('p', form.text_field( diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index d4f9e4eb8..5553990e6 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -328,109 +328,55 @@ module UsersHelper return [0,[]] end list = query.order("updated_on desc").limit(10).all - return [count,list]; + return [count,list] end def get_create_course_count(user) - return Course.where("tea_id = ?",user.id).count() + if user == User.current + user.courses.count + else + user.courses.where("is_public = 1").count + end end def get_join_course_count(user) - return user.coursememberships.count() - get_create_course_count(user) + user.coursememberships.count - get_create_course_count(user) end def get_homework_commons_count(user) - return HomeworkCommon.where("user_id = ?",user.id).count() + HomeworkCommon.where("user_id = ?",user.id).count end def get_projectandcourse_attachment_count(user) - return Attachment.where("author_id = ? and container_type in ('Project','Course')",user.id).count() + Attachment.where("author_id = ? and container_type in ('Project','Course')",user.id).count end def get_create_project_count(user) - return Project.where("user_id = ? and project_type = ?",user.id,Project::ProjectType_project).count() + Project.where("user_id = ? and project_type = ?",user.id,Project::ProjectType_project).count end def get_join_project_count(user) - return user.memberships.count(conditions: "projects.project_type = #{Project::ProjectType_project}") - get_create_project_count(user) + user.memberships.count(conditions: "projects.project_type = #{Project::ProjectType_project}") - get_create_project_count(user) end def get_create_issue_count(user) - return Issue.where("author_id = ?",user.id).count() + Issue.where("author_id = ?",user.id).count end def get_resolve_issue_count(user) - return Issue.where("assigned_to_id = ? and status_id=3",user.id).count() + Issue.where("assigned_to_id = ? and status_id=3",user.id).count end def get_anonymous_evaluation_count(user) - return StudentWorksScore.where("user_id = ? and reviewer_role=3",user.id).count() + StudentWorksScore.where("user_id = ? and reviewer_role=3",user.id).count end - - # def query_activities(query,type) - # query_rec_count = 8 - # # query = query.where("act_type='JournalsForMessage'") - # #query = query.where("act_type not in (?)", ['JournalsForMessage','Message','HomeworkCommon','News','Issue','Journal','Poll']) - # list = query.order("id desc").limit(query_rec_count).all - # - # result = []; - # for item in list - # container = get_activity_container(item,type) - # if( activity_is_show(item,container) ) - # result << { :item=>item,:e=>container } - # end - # end - # return [lastid,result] - # end - # def get_activity_container activity,type - # e = nil; - # if type == 'Project' - # if activity.act_type == 'Poll' - # # 项目没有问卷 - # # e = Project.find_by_id(activity.act.polls_group_id) - # else - # e = activity.act.project if activity.act.respond_to?('project') - # end - # end - # if type == 'Course' - # if activity.act_type == 'Poll' - # e = Course.find_by_id(activity.act.polls_group_id) - # else - # e = activity.act.course if activity.act.respond_to?('course') - # end - # end - # - # return e; - # end def query_activities(query) - list = query.limit(8).all - result = []; + list = query.limit(13).all + result = [] for item in list container = get_activity_container(item) result << { :item=>item,:e=>container } end - return result - end - def get_activity_container activity - return activity.activity_container - # if type == 'Project' - # return activity.act.project if activity.act.respond_to?('project') - # end - # if type == 'Course' - # if activity.act_type == 'Poll' - # return Course.find_by_id(activity.act.polls_group_id) - # end - # return activity.act.course if activity.act.respond_to?('course') - # end - # return nil; + result + end + + def get_activity_container activity + return activity.activity_container end - # def activity_is_show(activity,e) - # if(!e) - # return false - # end - # - # if activity.user_id == User.current.id - # return true - # end - # if( e.visible? ) - # return true - # end - # return false - # end def get_activity_act_showname_htmlclear(activity) str = get_activity_act_showname(activity) str = str.gsub(/<.*>/,'') @@ -529,14 +475,14 @@ module UsersHelper when "Issue" return '发表了问题' when "Journal" - return '回复了问题' + return '更新了问题' when "JournalsForMessage" return e.class.to_s == 'Course' ? '发表了留言' : '提交了反馈' #return ( activity.act.reply_id == nil || activity.act.reply_id == 0 ) ? '' : '' when "Message" return ( activity.act.parent_id == nil || activity.act.parent_id == '' ) ? '发布了帖子' : '回复了帖子' when "Poll" - return '发布了问卷' + return '创建了问卷' else return '有了新动态' end diff --git a/app/models/homework_test.rb b/app/models/homework_test.rb index 7c477bfaf..4ed290ecd 100644 --- a/app/models/homework_test.rb +++ b/app/models/homework_test.rb @@ -2,5 +2,5 @@ class HomeworkTest < ActiveRecord::Base attr_accessible :input, :output, :homework_common_id belongs_to :homework_common - has_one :student_work_test + has_many :student_work_test end diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 5ae9df001..a25aff6bb 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -388,7 +388,8 @@ class Mailer < ActionMailer::Base @user = applied.user recipients = @project.manager_recipients s = l(:text_applied_project, :id => "##{@user.show_name}", :project => @project.name) - @applied_url = url_for(:controller => 'projects', :action => 'settings', :id => @project.id,:tab=>'members') + @token = Token.get_token_from_user(@user, 'autologin') + @applied_url = url_for(:controller => 'projects', :action => 'settings', :id => @project.id,:tab=>'members', :token => @token.value) mail :to => recipients, :subject => s end diff --git a/app/models/repository/git.rb b/app/models/repository/git.rb index c1f0020eb..7c484e87f 100644 --- a/app/models/repository/git.rb +++ b/app/models/repository/git.rb @@ -38,6 +38,12 @@ class Repository::Git < Repository 'Git' end + def commits(authors, start_date, end_date, branch='master') + scm.commits(authors, start_date, end_date,branch).map {|commit| + [commit[:author], commit[:num]] + } + end + def report_last_commit extra_report_last_commit end diff --git a/app/models/student_work_test.rb b/app/models/student_work_test.rb index 2e6efdf0a..413528b82 100644 --- a/app/models/student_work_test.rb +++ b/app/models/student_work_test.rb @@ -1,6 +1,6 @@ # encoding: utf-8 class StudentWorkTest < ActiveRecord::Base - attr_accessible :student_work_id, :homework_test_id, :result + attr_accessible :student_work_id, :homework_test_id, :result, :error_msg belongs_to :homework_test belongs_to :student_work diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 185f448ce..c2944fed5 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -654,36 +654,42 @@ class CoursesService return end if current_user == @user || current_user.admin? - membership = @user.coursememberships.page(1).per(15) + membership = @user.coursememberships else - membership = @user.coursememberships.page(1).per(15).all(:conditions => Course.visible_condition(current_user)) + membership = @user.coursememberships.all(:conditions => Course.visible_condition(current_user)) end if membership.nil? || membership.count == 0 raise l(:label_no_courses, :locale => get_user_language(current_user)) end - membership.sort! { |older, newer| newer.created_on <=> older.created_on } + #membership.sort! { |older, newer| newer.created_on <=> older.created_on } #定义一个数组集合,存放hash数组,该hash数组包括课程的信息,并包含课程的最新发布的资源,最新的讨论区留言,最新的作业,最新的通知 result = [] #对用户所有的课程进行循环,找到每个课程最新发布的资源,最新的讨论区留言,最新的作业,最新的通知,并存进数组 + membership.each do |mp| course = mp.course latest_course_dynamics = [] + notices_count = 0 + topic_count = 0 + topics = nil + homeworkss = nil + notices = nil # 课程通知 latest_news = course.news.page(1).per(2).order("created_on desc") unless latest_news.first.nil? - latest_course_dynamics << {:type => 1, :time => latest_news.first.created_on,:count=>course.news.count, - :news => latest_news.all} + notices_count = course.news.count + notices = latest_news.all + latest_course_dynamics << {:time => latest_news.first.created_on } end - # 课程讨论区 latest_message = course.boards.first.topics.page(1).per(2) unless latest_message.first.nil? - latest_course_dynamics << {:type => 2, :time => latest_message.first.created_on, :count =>course.boards.nil? ? 0 : course.boards.first.topics.count, - :topics => latest_message.all} + topic_count = course.boards.nil? ? 0 : course.boards.first.topics.count + topics = latest_message.all + latest_course_dynamics << {:time => latest_message.first.created_on} end - # 课程资源 # latest_attachment = course.attachments.order("created_on desc").page(1).per(2) # unless latest_attachment.first.nil? @@ -694,14 +700,17 @@ class CoursesService #课程作业 已经交的学生列表(暂定显示6人),未交的学生列表,作业的状态 homeworks = course.homework_commons.page(1).per(2).order('created_at desc') unless homeworks.first.nil? - latest_course_dynamics << {:type => 4, :time => homeworks.first.updated_at, :count=>course.homework_commons.count , :homeworks => homeworks} + homeworkss = homeworks + latest_course_dynamics << {:time => homeworks.first.updated_at} end latest_course_dynamics.sort! { |order, newer| newer[:time] <=> order[:time] } # 课程学霸 学生总分数排名靠前的5个人 homework_count = course.homework_commons.count sql = "select users.*,ROUND(sum(student_works.final_score),2) score from student_works left outer join users on student_works.user_id = users.id" << " where homework_common_id in ( select id from homework_commons where homework_commons.course_id = #{course.id}) GROUP BY student_works.user_id ORDER BY score desc limit 0,4" + better_students = User.find_by_sql(sql) + # 找出在课程讨论区发帖回帖数最多的 active_students = [] sql1 = " select users.*,count(author_id)*2 active_count from messages " << @@ -710,20 +719,41 @@ class CoursesService " GROUP BY messages.author_id ORDER BY count(author_id) desc " << " limit 0,4" active_students = User.find_by_sql(sql1) + if homework_count != 0 && !better_students.empty? - latest_course_dynamics <<{:type=> 6,:time=>"1970-01-01 0:0:0 +0800",:count=> 4,:better_students=> better_students} + latest_course_dynamics <<{:time=>"1970-01-01 0:0:0 +0800"} end unless active_students.empty? - latest_course_dynamics <<{:type=> 7,:time=>"1970-01-01 0:0:0 +0800",:count=> 4,:active_students=>active_students} + latest_course_dynamics <<{:time=>"1970-01-01 0:0:0 +0800"} end latest_course_dynamic = latest_course_dynamics.first unless latest_course_dynamic.nil? - result << {:course_name => course.name,:current_user_is_member => current_user.member_of_course?(course),:current_user_is_teacher => is_course_teacher(current_user,course), :course_id => course.id, :course_img_url => url_to_avatar(course), :course_time => course.time, :course_term => course.term,:message => "", :dynamics => latest_course_dynamics, - :course_student_num=>course ? course.members.count : 0,:time_from_now=> distance_of_time_in_words(Time.now, latest_course_dynamic[:time].to_time) << "前",:time=>latest_course_dynamic[:time].to_time} + result << {:course_name => course.name, + :current_user_is_member => current_user.member_of_course?(course), + :current_user_is_teacher => is_course_teacher(current_user,course), + :course_id => course.id, + :course_img_url => url_to_avatar(course), + :course_time => course.time, + :course_term => course.term, + :news_count => notices_count, + :homework_count => homework_count, + :topic_count => topic_count, + :news => notices, + :homeworks => homeworkss, + :topics => topics, + :better_students => better_students, + :active_students => active_students, + :message => "", + :course_student_num=>course ? course.members.count : 0, + #:time_from_now=> distance_of_time_in_words(Time.now, latest_course_dynamic[:time].to_time) << "前", + :time_from_now=>time_from_now(latest_course_dynamic[:time].to_time), #.strftime('%Y-%m-%d %H:%M:%S').to_s, + :time=>latest_course_dynamic[:time].to_time} end + end #返回数组集合 result.sort! { |order, newer| newer[:time] <=> order[:time] } + result end diff --git a/app/views/account/lost_password.html.erb b/app/views/account/lost_password.html.erb index 8ed93f36c..3c6c57f52 100644 --- a/app/views/account/lost_password.html.erb +++ b/app/views/account/lost_password.html.erb @@ -9,7 +9,7 @@
- <%= text_field_tag 'mail', nil, :size => 40 %> + <%= text_field_tag 'mail', nil, :size => 40, :placeholder => '请输入注册邮箱'%> <%= submit_tag l(:button_submit) %>
+ 序号 + | ++ LOGO + | ++ 学校名称 + | ++ |
---|---|---|---|
+ <%= school.id %> + | ++ <%= image_tag(school.logo_link,width:40,height:40) %> + | + ++ <%= link_to("修改", upload_logo_school_path(school.id,:school_name => @school_name), :class => 'icon icon-copy') %> + <%#= link_to(l(:button_delete), organization_path(school.id), :method => :delete,:confirm => l(:text_are_you_sure), :class => 'icon icon-del') %> + | +
- <%= content_tag('span', link_to("#{@course_activity_count[@course.id]}", course_path(@course)), :class => "info") %> + <%= content_tag('span', link_to("#{course_activity_count @course}", course_path(@course)), :class => "info") %> <%= content_tag('span', l(:label_x_activity, :count => @course_activity_count[@course.id])) %>
diff --git a/app/views/courses/_new_groups_name.html.erb b/app/views/courses/_new_groups_name.html.erb index 39fa33677..fc2c5a62d 100644 --- a/app/views/courses/_new_groups_name.html.erb +++ b/app/views/courses/_new_groups_name.html.erb @@ -31,7 +31,7 @@ <% if @canShowCode%> <%= form_tag(updategroupname_course_path(@course,:group_id => group.id), method: 'get', remote:true, :id => 'update_group_'+group.id.to_s) do %> <% end %> @@ -47,7 +47,7 @@- 输入 - | -- 输出 - | -
- <%=test.input%> + 输入 | - <%= test.output%> + 输出 |