diff --git a/app/controllers/avatar_controller.rb b/app/controllers/avatar_controller.rb index fa7eb6052..b7dec5453 100644 --- a/app/controllers/avatar_controller.rb +++ b/app/controllers/avatar_controller.rb @@ -55,17 +55,20 @@ class AvatarController < ApplicationController # saved = @avatar.save begin f = Magick::ImageList.new(diskfile) - width = 300.0 - proportion = (width/f[0].columns) - height = (f[0].rows*proportion) - f.resize_to_fill!(width,height) - # f.scale!(width,height) - f.write(diskfile) + # gif格式不再做大小处理 + if f.format != 'GIF' + width = 300.0 + proportion = (width/f[0].columns) + height = (f[0].rows*proportion) + f.resize_to_fill!(width,height) + f.write(diskfile) + end + rescue Exception => e logger.error "[Error] avatar : avatar_controller#upload ===> #{e}" end - + respond_to do |format| format.js format.api { diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index c42944947..aa5e2c2a6 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -502,45 +502,7 @@ class CoursesController < ApplicationController end - def get_course_activity courses, activities - @course_ids=activities.keys() - days = Setting.activity_days_default.to_i - date_to ||= Date.today + 1 - date_from = date_to - days-1.years - - #file_count - Attachment.where(container_id: @course_ids, container_type: Course).where("created_on>?", date_from).each do |attachment| - activities[attachment.container_id]+=1 - end - - #message_count - Board.where(course_id: @course_ids).each do |board| -# activities[board.course_id]+=1 - activities[board.course_id]+=board.messages.where("updated_on>?", date_from).count - end - - #news - News.where(course_id: @course_ids).where("created_on>?",date_from).each do |news| - activities[news.course_id]+=1 - end - - #feedbackc_count - JournalsForMessage.where(jour_id: @course_ids, jour_type: Course).each do |jourformess| - activities[jourformess.jour_id]+=1 - end - - #activities!=0 - i=0; - courses.each do |course| - id=course.id - if activities[id]==0 - activities[id]=1 - end - end - - return activities - end def toggleCourse @course_prefs = Course.find_by_extra(@course.extra) @@ -643,6 +605,15 @@ class CoursesController < ApplicationController events = @activity.events(@date_from, @date_to, :is_public => 1) end + # 无新动态时,显示老动态 + if events.count == 0 + if User.current.member_of_course?(@course)|| User.current.admin? + events = @activity.events + else + events = @activity.events(:is_public => 1) + end + end + @offset, @limit = api_offset_and_limit({:limit => 10}) @events_count = events.count @events_pages = Paginator.new @events_count, @limit, params['page'] diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 3d541fd61..031f78277 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -57,36 +57,45 @@ class FilesController < ApplicationController elsif params[:course_id] @isproject = false + sort = "" if params[:sort] - if params[:sort].include?":" - @orderBy = params[:sort].split(":")[0] - @orderType = params[:sort].split(":")[1].split(",")[0] - else - @orderBy = params[:sort].split(",")[0] - @orderType = "asc" + params[:sort].split(",").each do |sort_type| + order_by = sort_type.split(":") + + case order_by[0] + when "filename" + attribute = "filename" + when "size" + attribute = "filesize" + when "attach_type" + attribute = "attachtype" + when "content_type" + attribute = "created_on" + when "field_file_dense" + attribute = "is_public" + when "downloads" + attribute = "downloads" + when "created_on" + attribute = "created_on" + end + + if order_by.count == 1 + sort += "#{Attachment.table_name}.#{attribute} desc " + elsif order_by.count == 2 + sort += "#{Attachment.table_name}.#{attribute} #{order_by[1]} " + end + if sort_type != params[:sort].split(",").last + sort += "," + end end end - - if @orderBy=="size" - @orderBy="filesize" - elsif @orderBy=="field_file_dense" - @orderBy="is_public" - elsif @orderBy=="attach_type" - @orderBy="attachtype" - elsif @orderBy=="content_type" - @orderBy="attachtype" - end - - if @orderBy - @containers = [ Course.includes(:attachments).reorder("#{Attachment.table_name}.#{@orderBy} #{@orderType}").find(@course.id)] - else - @containers = [ Course.includes(:attachments).reorder("#{Attachment.table_name}.created_on desc").find(@course.id)] - end + @containers = [ Course.includes(:attachments).reorder(sort).find(@course.id)] show_attachments @containers render :layout => 'base_courses' end + end def new @@ -226,6 +235,7 @@ class FilesController < ApplicationController elsif @course @containers = [ Course.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@course.id)] end + show_attachments @containers @attachtype = params[:type].to_i @contenttype = params[:contentType].to_s diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index ee42c2c6a..c0561bd1c 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -42,7 +42,7 @@ class ProjectsController < ApplicationController before_filter :authorize_global, :only => [:new, :create,:view_homework_attaches] before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy, :calendar] before_filter :file, :statistics, :watcherlist - before_filter :find_project_repository, :only => [:show] + #before_filter :find_project_repository, :only => [:show] # 除非项目内人员,不可查看成员, TODO: 完了写报表里去 before_filter :memberAccess, only: :member @@ -106,7 +106,7 @@ class ProjectsController < ApplicationController def index #调用存储过程更新提交次数 - ActiveRecord::Base.connection.execute("CALL sp_project_status_cursor();") + #ActiveRecord::Base.connection.execute("CALL sp_project_status_cursor();") #Modified by nie @project_type = params[:project_type].to_i per_page_option = 10 @@ -594,6 +594,7 @@ class ProjectsController < ApplicationController "show_news" => true, "show_bids" => true, "show_contests" => true, + "show_wiki_edits"=>true, "show_journals_for_messages" => true } @date_to ||= Date.today + 1 diff --git a/app/controllers/trackers_controller.rb b/app/controllers/trackers_controller.rb index de686493b..a317f82de 100644 --- a/app/controllers/trackers_controller.rb +++ b/app/controllers/trackers_controller.rb @@ -21,7 +21,7 @@ class TrackersController < ApplicationController before_filter :require_admin, :except => :index before_filter :require_admin_or_api_request, :only => :index accept_api_auth :index - + include CoursesHelper def index respond_to do |format| format.html { @@ -37,8 +37,13 @@ class TrackersController < ApplicationController def new @tracker ||= Tracker.new(params[:tracker]) @trackers = Tracker.sorted.all - @projects = Project.all + @projects = Project.where("project_type = #{Project::ProjectType_project}").all @courses = Course.all + @course_activity_count=Hash.new + @courses.each do |course| + @course_activity_count[course.id]=0 + end + @course_activity_count=get_course_activity @courses,@course_activity_count end def create @@ -58,7 +63,8 @@ class TrackersController < ApplicationController def edit @tracker ||= Tracker.find(params[:id]) - @projects = Project.all + @projects = Project.where("project_type = #{Project::ProjectType_project}").all + @courses = Course.all end def update diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 98b24bc12..d15036fa0 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -46,6 +46,7 @@ class UsersController < ApplicationController #william before_filter :require_login, :only => [:tag_save,:tag_saveEx] + #before_filter :refresh_changests, :only =>[:user_activities,:user_courses,:user_projects,:user_newfeedback] helper :sort @@ -68,6 +69,17 @@ class UsersController < ApplicationController # fq helper :words + + def refresh_changests + if !(@user.nil?) && !(@user.memberships.nil?) + @user.memberships.each do |member| + unless member.project.nil? + member.project.repository.fetch_changesets if Setting.autofetch_changesets? + end + end + end + end + #added by young def user_projects diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 4e7cf0ce9..0d9206738 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -151,7 +151,7 @@ class WelcomeController < ApplicationController def entry_select #@first_page = FirstPage.where("page_type = 'project'").first url = request.original_url.gsub('/','') - if url.include?(Setting.host_course) + if url.include?(Setting.host_course.gsub('/','')) if @first_page.show_course == 1 course render :course @@ -160,7 +160,7 @@ class WelcomeController < ApplicationController end return 0 - elsif url.include?(Setting.host_contest) + elsif url.include?(Setting.host_contest.gsub('/','')) if @first_page.show_contest == 1 contest render :contest @@ -169,7 +169,7 @@ class WelcomeController < ApplicationController end return 0 - elsif url.include?(Setting.host_user) + elsif url.include?(Setting.host_user.gsub('/','')) redirect_to(:controller => "users", :action => "index") end diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index 2d03b2112..f2502e03e 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -90,7 +90,6 @@ class WordsController < ApplicationController end def destroyJournal - @journalP=JournalsForMessage.find(params[:object_id]) @journalP.destroy diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index d075f67ae..a005b299b 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -480,4 +480,45 @@ module CoursesHelper type end + #获取课程动态 + def get_course_activity courses, activities + @course_ids=activities.keys() + + days = Setting.activity_days_default.to_i + date_to ||= Date.today + 1 + date_from = date_to - days-1.years + + #file_count + Attachment.where(container_id: @course_ids, container_type: Course).where("created_on>?", date_from).each do |attachment| + activities[attachment.container_id]+=1 + end + + #message_count + Board.where(course_id: @course_ids).each do |board| +# activities[board.course_id]+=1 + activities[board.course_id]+=board.messages.where("updated_on>?", date_from).count + end + + #news + News.where(course_id: @course_ids).where("created_on>?",date_from).each do |news| + activities[news.course_id]+=1 + end + + #feedbackc_count + JournalsForMessage.where(jour_id: @course_ids, jour_type: Course).each do |jourformess| + activities[jourformess.jour_id]+=1 + end + + #activities!=0 + i=0; + courses.each do |course| + id=course.id + if activities[id]==0 + activities[id]=1 + end + end + + return activities + end + end diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 315a86340..637c92db3 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -326,7 +326,7 @@ module IssuesHelper if detail.property == 'attr' && detail.prop_key == 'description' s = l(:text_journal_changed_no_detail, :label => label) unless no_html - diff_link = link_to 'diff', + diff_link = link_to l(:label_diff), {:controller => 'journals', :action => 'diff', :id => detail.journal_id, :detail_id => detail.id, :only_path => options[:only_path]}, :title => l(:label_view_diff) diff --git a/app/helpers/project_score_helper.rb b/app/helpers/project_score_helper.rb index bdb070cc2..104cd16cb 100644 --- a/app/helpers/project_score_helper.rb +++ b/app/helpers/project_score_helper.rb @@ -71,11 +71,24 @@ module ProjectScoreHelper pss = ProjectScore.where("project_id = '#{project.id}'") if pss.nil? || pss.count == 0 ps = ProjectScore.new + ps.issue_num = issue_num(project) + ps.board_message_num = board_message_num(project) + ps.changeset_num = changesets_num(project) + ps.documents_num = documents_num(project) + ps.issue_journal_num = issue_journal_num(project) + ps.news_num = news_num(project) + ps.score = result ps.project = project ps.save else ps = pss.first + ps.issue_num = issue_num(project) + ps.board_message_num = board_message_num(project) + ps.changeset_num = changesets_num(project) + ps.documents_num = documents_num(project) + ps.issue_journal_num = issue_journal_num(project) + ps.news_num = news_num(project) ps.score = result ps.save end @@ -95,4 +108,15 @@ module ProjectScoreHelper end end + def get_project_score project + pss = ProjectScore.where("project_id = '#{project.id}'") + ps = nil + if pss.nil? || pss.count == 0 + ps = nil + else + ps = pss.first + end + ps + end + end \ No newline at end of file diff --git a/app/models/changeset.rb b/app/models/changeset.rb index f2228e699..b9ce4acf5 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -63,7 +63,7 @@ class Changeset < ActiveRecord::Base includes(:repository => :project).where(Project.allowed_to_condition(args.shift || User.current, :view_changesets, *args)) } - after_create :scan_for_issues,:be_user_score # user_score + after_create :scan_for_issues,:refresh_changests#:be_user_score # user_score after_update :be_user_score after_destroy :down_user_score before_create :before_create_cs @@ -305,10 +305,13 @@ class Changeset < ActiveRecord::Base # update user score def be_user_score UserScore.project(:push_code, self.user,self, { changeset_id: self.id }) - #更新用户等级 - UserLevels.update_user_level(self.user) - update_changeset(self.user,1) - update_changeset(self.user,2,self.repository.project) + unless self.user.nil? + #更新用户等级 + UserLevels.update_user_level(self.user) + update_changeset(self.user,1) + update_changeset(self.user,2,self.repository.project) + end + end #积分刷新 @@ -318,4 +321,11 @@ class Changeset < ActiveRecord::Base update_changeset(self.user,2,self.repository.project) end + #刷新本次提交(补全相关信息如:user_id等) + def refresh_changests + unless self.repository.nil? + self.repository.fetch_changesets if Setting.autofetch_changesets? + end + end + end diff --git a/app/models/option_number.rb b/app/models/option_number.rb index 8ba32a575..0ddea1bff 100644 --- a/app/models/option_number.rb +++ b/app/models/option_number.rb @@ -1,4 +1,14 @@ class OptionNumber < ActiveRecord::Base attr_accessible :attachment, :changeset, :document, :follow, :issue_done_ratio, :issues_status, :memo, :messages_for_issues, :post_issue, :praise_by_one, :praise_by_three, :praise_by_two, :replay_for_memo, :replay_for_message, :score_type, :total_score, :tread, :tread_by_one, :tread_by_three, :tread_by_two, :user_id + def self.get_user_option_number user_id + result = nil + unless user_id.nil? + ons = OptionNumber.find_all_by_user_id(user_id); + unless (ons .nil? && ons.count > 0) + result = ons.first + end + end + result + end end diff --git a/app/models/repository.rb b/app/models/repository.rb index 260069f94..5680f05a7 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -39,7 +39,8 @@ class Repository < ActiveRecord::Base validates_length_of :password, :maximum => 255, :allow_nil => true validates_length_of :identifier, :maximum => IDENTIFIER_MAX_LENGTH, :allow_blank => true validates_presence_of :identifier#, :unless => Proc.new { |r| r.is_default? || r.set_as_default? } - validates_uniqueness_of :identifier, :scope => :project_id, :allow_blank => true + #validates_uniqueness_of :identifier, :scope => :project_id, :allow_blank => true + validates_uniqueness_of :identifier, :allow_blank => true validates_exclusion_of :identifier, :in => %w(show entry raw changes annotate diff show stats graph) # donwcase letters, digits, dashes, underscores but not digits only validates_format_of :identifier, :with => /^[a-z0-9_\-]+$/, :allow_blank => true diff --git a/app/models/tracker.rb b/app/models/tracker.rb index d487de67e..6a0069975 100644 --- a/app/models/tracker.rb +++ b/app/models/tracker.rb @@ -32,6 +32,7 @@ class Tracker < ActiveRecord::Base end has_and_belongs_to_many :projects + has_and_belongs_to_many :courses has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => "#{table_name_prefix}custom_fields_trackers#{table_name_suffix}", :association_foreign_key => 'custom_field_id' acts_as_list diff --git a/app/views/boards/_course_show.html.erb b/app/views/boards/_course_show.html.erb index ca33b7516..35e066d45 100644 --- a/app/views/boards/_course_show.html.erb +++ b/app/views/boards/_course_show.html.erb @@ -37,7 +37,7 @@
<%= l(:label_homeworks_form_new_description) %>
-<%= f.text_field :name, :required => true, :size => 60, :style => "width:490px;", :maxlength => Bid::NAME_LENGTH_LIMIT %>
++ <%= f.text_field :name, :required => true, :size => 60, :style => "width:490px;", :maxlength => Bid::NAME_LENGTH_LIMIT, :onblur => "regexName();" %> -
<%= f.text_area :description, :rows => 8, :class => 'wiki-edit', :style => "font-size:small;width:490px;margin-left:10px;", :maxlength => Bid::DESCRIPTION_LENGTH_LIMIT %>
+ ++ +
<%= f.text_area :description, :rows => 8, :class => 'wiki-edit', :style => "font-size:small;width:490px;", :maxlength => Bid::DESCRIPTION_LENGTH_LIMIT %>
<% time = (Time.now + 3600 * 24).strftime('%Y-%m-%d') %> -<%= f.text_field(:deadline, :required => true, :size => 60, :style => "width:150px;",:value => "#{time}",:readonly => "readonly") %><%= calendar_for('bid_deadline')%> +
<%= f.text_field(:deadline, :required => true, :size => 60, :style => "width:150px;",:value => "#{time}", :onchange => "regexDeadLine();") %><%= calendar_for('bid_deadline')%> + + +
<%= f.select :is_evaluation, is_evaluation_option %>
diff --git a/app/views/courses/new_homework.html.erb b/app/views/courses/new_homework.html.erb index b3fff9e5f..e339db2d7 100644 --- a/app/views/courses/new_homework.html.erb +++ b/app/views/courses/new_homework.html.erb @@ -1,9 +1,60 @@ + +diff --git a/app/views/messages/edit.html.erb b/app/views/messages/edit.html.erb index 2577a4634..62d29ebd8 100644 --- a/app/views/messages/edit.html.erb +++ b/app/views/messages/edit.html.erb @@ -4,7 +4,7 @@ <%= course_board_breadcrumb(@message) %> <% end %> -
<%= link_to image_tag("/images/praise_tread/praise_true.png",weight:"22px", height:"22px",:title => l(:label_issue_praise)), - :controller=>"praise_tread",:action=>"praise_plus",:remote=>true,:obj_id => obj.id,:obj_type => obj.class,:horizontal => horizontal %> | -<%= get_praise_num(obj)%> | -<%= link_to image_tag("/images/praise_tread/tread_true.png",weight:"22px", height:"22px",:title => l(:label_issue_tread)),:controller=>"praise_tread", - :action=>"tread_plus",:remote=>true,:obj_id => obj.id,:obj_type => obj.class,:horizontal => horizontal %> | -
<%= link_to image_tag("/images/praise_tread/praise_true.png",weight:"22px", height:"22px",:title => l(:label_issue_praise)), + :controller=>"praise_tread",:action=>"praise_plus",:remote=>true,:obj_id => obj.id,:obj_type => obj.class,:horizontal => horizontal %> | +<%= get_praise_num(obj)%> | +<%= image_tag "/images/praise_tread/tread_true.png",weight:"22px", height:"22px",:title => l(:label_issues_score_not_enough) %> | +
<%= link_to image_tag("/images/praise_tread/praise_true.png",weight:"22px", height:"22px",:title => l(:label_issue_praise)), + :controller=>"praise_tread",:action=>"praise_plus",:remote=>true,:obj_id => obj.id,:obj_type => obj.class,:horizontal => horizontal %> | +<%= get_praise_num(obj)%> | +<%= link_to image_tag("/images/praise_tread/tread_true.png",weight:"22px", height:"22px",:title => l(:label_issue_tread)),:controller=>"praise_tread", + :action=>"tread_plus",:remote=>true,:obj_id => obj.id,:obj_type => obj.class,:horizontal => horizontal %> | +
<%= link_to image_tag("/images/praise_tread/praise_true.png",weight:"22px", height:"22px",:title => l(:label_issue_praise)), - :controller=>"praise_tread",:action=>"praise_plus",:remote=>true,:obj_id => obj.id,:obj_type => obj.class ,:horizontal => horizontal %> | -
<%= get_praise_num(obj)%> | -
<%= link_to image_tag("/images/praise_tread/tread_true.png",weight:"22px", height:"22px",:title => l(:label_issue_tread)),:controller=>"praise_tread", - :action=>"tread_plus",:remote=>true,:obj_id => obj.id,:obj_type => obj.class ,:horizontal => horizontal %> | -
<%= link_to image_tag("/images/praise_tread/praise_true.png",weight:"22px", height:"22px",:title => l(:label_issue_praise)), + :controller=>"praise_tread",:action=>"praise_plus",:remote=>true,:obj_id => obj.id,:obj_type => obj.class ,:horizontal => horizontal %> | +
<%= get_praise_num(obj)%> | +
<%= image_tag "/images/praise_tread/tread_true.png",weight:"22px", height:"22px",:title => l(:label_issues_score_not_enough) %> | +
<%= link_to image_tag("/images/praise_tread/praise_true.png",weight:"22px", height:"22px",:title => l(:label_issue_praise)), + :controller=>"praise_tread",:action=>"praise_plus",:remote=>true,:obj_id => obj.id,:obj_type => obj.class ,:horizontal => horizontal %> | +
<%= get_praise_num(obj)%> | +
<%= link_to image_tag("/images/praise_tread/tread_true.png",weight:"22px", height:"22px",:title => l(:label_issue_tread)),:controller=>"praise_tread", + :action=>"tread_plus",:remote=>true,:obj_id => obj.id,:obj_type => obj.class ,:horizontal => horizontal %> | +
<%= h act.description %>
+<%= textAreailizable act, :description %>
<%= textilizable e.notes %>
<%= textAreailizable e.notes %>