diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb index 1b172e0cc..987881a83 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -28,6 +28,9 @@ class ContestsController < ApplicationController @offset, @limit = api_offset_and_limit({:limit => 10}) @contests = Contest.visible @contests = @contests.like(params[:name]) if params[:name].present? + if params[:contests_search] + (redirect_to contests_path, :notice => l(:label_sumbit_empty);return) if params[:name].blank? + end @contest_count = @contests.count @contest_pages = Paginator.new @contest_count, @limit, params['page'] diff --git a/app/controllers/stores_controller.rb b/app/controllers/stores_controller.rb index 0ed12d76d..fd0d3cf53 100644 --- a/app/controllers/stores_controller.rb +++ b/app/controllers/stores_controller.rb @@ -20,25 +20,27 @@ class StoresController < ApplicationController resultSet = Attachment.where("attachments.container_type IS NOT NULL AND filename LIKE :like ", like: "%#{keywords}%"). reorder("created_on DESC") - result = resultSet.to_a.dup + # result = resultSet.to_a.dup - resultSet.to_a.map { |res| - if(res.container.nil? || - (res.container.class.to_s=="Project" && res.container.is_public == false) || - (res.container.has_attribute?(:project) && res.container.project.is_public == false) || - (res.container.class.to_s=="HomeworkAttach" && res.container.bid.reward_type == 3) || - false - ) - result.delete(res) - end - } - result + # resultSet.to_a.map { |res| + # if(res.container.nil? || + # (res.container.class.to_s=="Project" && res.container.is_public == false) || + # (res.container.has_attribute?(:project) && res.container.project.is_public == false) || + # (res.container.class.to_s=="HomeworkAttach" && res.container.bid.reward_type == 3) || + # false + # ) + # result.delete(res) + # end + # } + # result end LIMIT = 12 unless const_defined?(:LIMIT) def index @projects_attach = project_classification(0).take(LIMIT) - @courses_attach = project_classification(1).take(LIMIT) + @courses_attach = Attachment.includes(:course).where("courses.is_public = ?", 1). + where(container_type: 'Course'). + limit(LIMIT) # @projects_attach = Attachment.includes(:project).where("projects.project_type=? AND projects.is_public = ?", 0, 1). # reorder("#{Attachment.table_name}.downloads DESC"). # limit(LIMIT) diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb index 3e61b2a44..14105bf88 100644 --- a/app/helpers/attachments_helper.rb +++ b/app/helpers/attachments_helper.rb @@ -110,7 +110,7 @@ module AttachmentsHelper # 搜索到的资源 searched_attach = domain.where("filename LIKE :like ", like:"%#{filename_condition}%").limit(limit).order('created_on desc') - searched_attach = private_filter searched_attach + #searched_attach = private_filter searched_attach searched_attach = paginateHelper(searched_attach, 10) s = content_tag('div', attachments_check_box_tags('attachment[attach][]', searched_attach), :id => 'attachments') @@ -149,7 +149,7 @@ module AttachmentsHelper # 搜索到的资源 searched_attach = domain.where("filename LIKE :like ", like:"%#{filename_condition}%").limit(limit).order('created_on desc') - searched_attach = private_filter searched_attach + #searched_attach = private_filter searched_attach searched_attach = paginateHelper(searched_attach, 10) #testattach = Attachment.public_attachments diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 88b55b2bc..80beea16c 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -256,8 +256,8 @@ module CoursesHelper people end # 截至到2014-03-17 这个是最终的判断课程是否过期的方法 - def course_endTime_timeout? project - end_time_str = Course.find_by_extra(project.try(:extra)).try(:endup_time) + def course_endTime_timeout? course + end_time_str = course.try(:endup_time) begin cTime = Time.parse(end_time_str.to_s) rescue TypeError,ArgumentError diff --git a/app/helpers/stores_helper.rb b/app/helpers/stores_helper.rb index c01fae55e..0c7fdac43 100644 --- a/app/helpers/stores_helper.rb +++ b/app/helpers/stores_helper.rb @@ -37,15 +37,24 @@ module StoresHelper WORD_LIMIT = 100 def come_from_local attachment - container = attachment.container case container.class.to_s when 'Message' + # binding.pry # '项目 > zzz > 论坛 > 帖子xxx' # topic_str = container.project.project_type == 0 ? l(:label_board) : l(:label_new_course) - topic_list = link_to l(:label_board), project_boards_path(container.project) - topic_item = link_to container.subject.truncate(WORD_LIMIT, omission: '...'), board_message_path(container.board, container), title: container.subject - project_link(container.project).push(topic_list, topic_item) + + course = container.course + project = container.project + if course.nil? # container is belongs to Project + topic_list = link_to l(:label_board), project_boards_path(container.project) + topic_item = link_to container.subject.truncate(WORD_LIMIT, omission: '...'), board_message_path(container.board, container), title: container.subject + project_link(container.project).push(topic_list, topic_item) + else # container is belongs to Course + topic_list = link_to l(:label_course_news), course_boards_path(course) + topic_item = link_to container.try(:subject).to_s.truncate(WORD_LIMIT, omission: '...'), board_message_path(container.board, container), title: container.subject + project_link(course).push(topic_list, topic_item) + end when 'Issue' # '项目 > zzz > 缺陷 > 问题xxx' issue_list = link_to l(:label_project_issues), project_issues_path(container.project) @@ -58,15 +67,26 @@ module StoresHelper project_link(container.project).push(doc_list, doc_item) when 'News' # '课程 > zzz > 新闻 > 新闻xxx' - news_str = container.project.project_type == 0 ? l(:label_news) : l(:label_course_news) - news_list = link_to news_str, project_news_index_path(container.project) - news_item = link_to container.title.truncate(WORD_LIMIT, omission: '...'), news_path(container), title: container.title - project_link(container.project).push(news_list, news_item) + course = container.course + project = container.project + if course.nil? # container is belongs to Project + news_list = link_to l(:label_news), project_news_index_path(container.project) + news_item = link_to container.title.truncate(WORD_LIMIT, omission: '...'), news_path(container), title: container.title + project_link(container.project).push(news_list, news_item) + else # container is belongs to Course + news_list = link_to l(:label_course_news), course_news_index_path(course) + news_item = link_to container.title.truncate(WORD_LIMIT, omission: '...'), news_path(container), title: container.title + project_link(course).push(news_list, news_item) + end + when 'Project' # '项目 > zzz ' file_str = container.project.project_type == 0 ? l(:project_module_files) : l(:label_course_file) files_list = link_to file_str, project_files_path(container.project) project_link(container).push(files_list) + when 'Course' + files_list = link_to l(:label_course_file), course_files_path(container) + project_link(container).push(files_list) when 'Version' # '项目 > zzz > 里程碑 > xxx' ver_list = link_to l(:label_roadmap), project_roadmap_path(container.project) @@ -91,7 +111,8 @@ module StoresHelper # '竞赛 > xxx ' bid_link(container) else - Rails.logger.error "ERROR: attachment type unkown" + Rails.logger.error "ERROR: attachment type unkown. file:#{__FILE__}, line:#{__LINE__}" + Rails.logger.error "#{container.class.to_s}" [link_to('unkown', '')] end rescue ActionController::RoutingError => e @@ -99,20 +120,6 @@ module StoresHelper [link_to('unkown', '')] end - def project_link project - if project.nil? - Rails.logger.error "ERROR: attachment type unkown #project_link project.nil?" - return [link_to('unkown', '')] - end - project_list = nil - if project.project_type == 0 - project_list = link_to l(:label_project_plural), projects_path - else - project_list = link_to l(:label_new_course), course_path - end - project_item = link_to project.to_s, project_path(project) - [project_list, project_item] - end def bid_link bid bid_list = nil @@ -129,7 +136,7 @@ module StoresHelper Rails.logger.error "ERROR: attachment type unkown #bid_link/when 3" return [link_to('unkown', '#')] end - bid_list = link_to l(:label_homework), project_homework_path(bid.courses.first) + bid_list = link_to l(:label_homework), homework_course_path(bid.courses.first) bid_item = link_to bid.name, respond_path(bid) return project_link(bid.courses.first).push(bid_list, bid_item) else @@ -137,4 +144,28 @@ module StoresHelper end [bid_list, bid_item] end + + + def project_link project + if project.nil? + Rails.logger.error "ERROR: attachment type unkown #project_link project.nil? file: #{__FILE__}, line: #{__LINE__}" + return [link_to('unkown', '')] + end + project_list = nil + klass = project.class.to_s + case klass + when "Project" + project_list = link_to l(:label_project_plural), projects_path + project_item = link_to project.to_s, project_path(project) + [project_list, project_item] + when "Course" + course_list = link_to l(:label_new_course), courses_path + course_item = link_to project.name, course_path(project) + [course_list, course_item] + else + Rails.logger.error "[StoresHelper]: #{klass} =======================================" + [] + end + + end end diff --git a/app/models/contest.rb b/app/models/contest.rb index d41506b87..e1706b166 100644 --- a/app/models/contest.rb +++ b/app/models/contest.rb @@ -24,8 +24,9 @@ class Contest < ActiveRecord::Base validates_length_of :name, :maximum => NAME_LENGTH_LIMIT validates_length_of :description, :maximum => DESCRIPTION_LENGTH_LIMIT - validates_presence_of :author_id, :name, :deadline - validates_format_of :deadline, :with => /^[\d]{4}[-][\d]{1,2}[-][\d]{1,2}$/ + validates_presence_of :author_id, :name, :budget + #validates_format_of :deadline, :with => /^[\d]{4}[-][\d]{1,2}[-][\d]{1,2}$/ + validates_format_of :deadline, :with =>/^[1-9][0-9]{3}\-0?[1-9]|1[12]\-0?[1-9]|[12]\d|3[01]$/ # validates_format_of :budget, :with => /^(\d+)$|^(\d+).([0-9]{2})|^(\d+).([0-9]{1})$/ validate :validate_user after_create :act_as_activity diff --git a/app/models/issue.rb b/app/models/issue.rb index f8837cb6e..550e0dc5d 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -1163,8 +1163,11 @@ class Issue < ActiveRecord::Base else issue_index = 1 self.project.issues.each do |issue| - if self.id > issue.id - ++issue_index + if self.id == nil + issue_index = self.project.issues.count +1 + break + elsif self.id > issue.id + issue_index = issue_index+1 end end issue_index.to_s diff --git a/app/models/journal.rb b/app/models/journal.rb index 8027f18a5..2e9363dd7 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -29,7 +29,7 @@ class Journal < ActiveRecord::Base # end attr_accessor :indice - acts_as_event :title =>Proc.new {|o| status = ((s = o.new_status) ? " (#{s})" : nil); "#{o.issue.tracker} ##{o.issue.inProjectIndex}#{status}: #{o.issue.subject}" }, + acts_as_event :title =>Proc.new {|o| status = ((s = o.new_status) ? " (#{s})" : nil); "#{o.issue.tracker} ##{o.issue.project_index}#{status}: #{o.issue.subject}" }, :description =>:notes, :author => :user, :group => :issue, diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 25d592a24..ef4996eac 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -119,8 +119,9 @@ class Mailer < ActionMailer::Base # Mailer.issue_edit(journal).deliver => sends an email to issue recipients def issue_edit(journal) issue = journal.journalized.reload + issue_id = issue.project_index redmine_headers 'Project' => issue.project.identifier, - 'Issue-Id' => (issue.project.issues.index(issue).to_i + 1).to_s, + 'Issue-Id' => issue_id.to_s, 'Issue-Author' => issue.author.login redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to message_id journal @@ -129,7 +130,7 @@ class Mailer < ActionMailer::Base recipients = journal.recipients # Watchers in cc cc = journal.watcher_recipients - recipients - s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] " + s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] " s << "(#{issue.status.name}) " if journal.new_value_for('status_id') s << issue.subject @issue = issue diff --git a/app/models/user.rb b/app/models/user.rb index 257681cb5..9665a4fb0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -209,10 +209,6 @@ class User < Principal # ====================================================================== - # 集中处理 User 扩展表为空的问题 - # 合并 user_score 属性 - validate :valid_user_extensions - after_save :save_user_extensions def extensions self.user_extensions ||= UserExtensions.new @@ -222,49 +218,6 @@ class User < Principal self.user_score ||= UserScore.new end - alias_method :ori_respond_to?, :respond_to? - def respond_to?(m, include_private = false) - flag = false - flag = ori_respond_to? m.to_sym unless flag - flag = UserExtensions.new.respond_to? m.to_sym unless flag - flag = UserScore.new.respond_to? m.to_sym unless flag - - flag - end - - def method_missing m, *args, &block - if extensions.respond_to? m.to_sym - self.class.send(:define_method, "_meta_#{m}".to_sym) do |*args, &block| - self.extensions.__send__ m.to_sym, *args - end - __send__ "_meta_#{m}".to_sym, *args, &block - - elsif user_score_attr.respond_to? m.to_sym - self.class.send(:define_method, "_meta_#{m}".to_sym) do |*args, &block| - self.user_score_attr.__send__ m.to_sym, *args - end - __send__ "_meta_#{m}".to_sym, *args, &block - - else - super - end - end - - def valid_user_extensions - if !self.extensions.valid? - self.extensions.errors.messages.each do |key, values| - values.each do |value| - self.errors.add key, value - end - end - end - end - - def save_user_extensions - self.extensions.save - self.user_score_attr.save - end - # 集中处理 User 扩展表为空的问题 < end # ====================================================================== #选择项目成员时显示的用户信息文字 diff --git a/app/views/contests/index.html.erb b/app/views/contests/index.html.erb index 670ba27cf..8c999f941 100644 --- a/app/views/contests/index.html.erb +++ b/app/views/contests/index.html.erb @@ -15,7 +15,7 @@
<%= l(:label_course_practice) %> | +<%= l(:label_course_all) %> | <%= l(:label_user_location) %> : | <% if User.current.logged?%> @@ -24,8 +24,8 @@ |
<%= link_to request.host()+"/courses", :controller => 'courses', :action => 'index', :course_type => 1 %> | -<%=link_to l(:field_homepage), home_path %> > <%=link_to l(:label_course_practice), :controller => 'courses', :action => 'index', :course_type => 1 %> | +<%= link_to request.host()+"/courses", :controller => 'courses', :action => 'index' %> | +<%=link_to l(:field_homepage), home_path %> > <%=link_to l(:label_course_all), :controller => 'courses', :action => 'index' %> |