diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 042e57ee..9e829782 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1,20 +1,26 @@ class CoursesController < ApplicationController - + include CoursesHelper before_filter :require_login, :only => [:join, :unjoin] + before_filter :allow_join, :only => [:join] def join if User.current.logged? course = Project.find(params[:object_id]) - if params[:course_password] == Course.find_by_extra(course.identifier).password - members = [] - members << Member.new(:role_ids => [10], :user_id => User.current.id) - course.members << members - - StudentsForCourse.create(:student_id => User.current.id, :course_id => params[:object_id]) - @state = 0 + if ( !course_endTime_timeout?(course) ) + course_prefs = Course.find_by_extra(course.identifier) + if params[:course_password] == course_prefs.password + members = [] + members << Member.new(:role_ids => [10], :user_id => User.current.id) + course.members << members + + StudentsForCourse.create(:student_id => User.current.id, :course_id => params[:object_id]) + @state = 0 + else + @state = 1 + end else - @state = 1 + @state = 2 end end respond_to do |format| @@ -39,4 +45,11 @@ class CoursesController < ApplicationController format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => Project.find(params[:object_id]), :object_id => params[:object_id]} } end end + + private + + def allow_join + course_endTime_timeout? Project.find(params[:object_id]) + end + end \ No newline at end of file diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 3a75c1e2..16a320e3 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -45,9 +45,10 @@ class ProjectsController < ApplicationController # menu_item l(:label_settings), :only => settings before_filter :find_project, :except => [ :index, :search,:list, :new, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise] - before_filter :authorize, :except => [:new_join, :new_homework, :homework, :statistics, :search, :watcherlist, :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy, :member, :focus, :file, - :statistics, :feedback, :course, :enterprise_course, :course_enterprise, :project_respond, :share, - :show_projects_score, :issue_score_index, :news_score_index, :file_score_index, :code_submit_score_index, :projects_topic_score_index] + # before_filter :authorize, :except => [:new_join, :new_homework, :homework, :statistics, :search, :watcherlist, :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy, :member, :focus, :file, + # :statistics, :feedback, :course, :enterprise_course, :course_enterprise, :project_respond, :share, + # :show_projects_score, :issue_score_index, :news_score_index, :file_score_index, :code_submit_score_index, :projects_topic_score_index] + before_filter :authorize, :only => [:sort_project_demo, :show, :settings, :edit, :sort_project_members, :update, :modules, :close, :reopen] before_filter :authorize_global, :only => [:new, :create] before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy, :calendar] #by young @@ -558,7 +559,8 @@ class ProjectsController < ApplicationController "show_documents" => true, "show_messages" => true, "show_news" => true, - "show_bids" => true + "show_bids" => true, + "show_journals_for_messages" => true } @date_to ||= Date.today + 1 @date_from = @date_to - @days @@ -569,6 +571,7 @@ class ProjectsController < ApplicationController :with_subprojects => @with_subprojects, :author => @author) @activity.scope_select {|t| !has["show_#{t}"].nil?} + # logger.debug "=========================================#{@activity.scope}" # @activity.scope = (@author.nil? ? :default : :all) if @activity.scope.empty? #Added by young events = @activity.events(@date_from, @date_to) @@ -801,6 +804,35 @@ class ProjectsController < ApplicationController end # end + + def finishcourse + course_prefs = Course.find_by_extra(@project.identifier) + # setup_time = Time.parse(course_prefs.setup_time) + # end_time = Time.parse(course_prefs.endup_time) + yesterday = Date.today.prev_day.to_time + + course_prefs.endup_time = yesterday + @save_flag = course_prefs.save + + respond_to do |format| + format.js + end + end + + def restartcourse + course_prefs = Course.find_by_extra(@project.identifier) + day = Time.parse("3000-01-01") + + course_prefs.endup_time = day + @save_flag = course_prefs.save + + respond_to do |format| + format.js { + render action:'finishcourse' + } + end + end + private # Validates parent_id param according to user's permissions diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index ac15bd9b..78e20c2a 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -79,6 +79,11 @@ module CoursesHelper str end + def get_course_term project + str = ( project.try(:course_extra).try(:time).to_s << '.' << project.try(:course_extra).try(:term).to_s ) + str[0..-4] + end + def members_to_user_ids members people = [] members.each { |member| @@ -86,5 +91,17 @@ module CoursesHelper } people end + # 截至到2014-03-17 这个是最终的判断课程是否过期的方法 + def course_endTime_timeout? project + end_time_str = Course.find_by_extra(project.try(:identifier)).try(:endup_time) + begin + cTime = Time.parse(end_time_str.to_s) + rescue TypeError,ArgumentError + cTime = Time.parse("3000-01-01") + end + now = Time.now + + now > cTime + end end diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 1394180e..35314efc 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -286,7 +286,7 @@ module ProjectsHelper WHERE project_type = 0 ORDER BY grade DESC LIMIT #{limit} ) AS t ON p.id = t.project_id ") end - # 判断课程是否结束 + # 判断课程是否结束,快别用,这个定日子的方法有问题 def course_timeout? project return true if (project.nil? && project.course_extra.nil?) courses_year = project.course_extra.time diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index a4e963b4..f548a40f 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -22,11 +22,6 @@ module WelcomeHelper include CoursesHelper include ProjectsHelper - def get_course_term project - str = ( project.try(:course_extra).try(:time).to_s << '.' << project.try(:course_extra).try(:term).to_s ) - str[0..-4] - end - def welcome_join_in_course(project, user) if(user.logged? && !(course_timeout? project) && diff --git a/app/views/courses/_set_course_time.html.erb b/app/views/courses/_set_course_time.html.erb new file mode 100644 index 00000000..7d256903 --- /dev/null +++ b/app/views/courses/_set_course_time.html.erb @@ -0,0 +1,9 @@ +<% + id = "finish_course_tag" +%> + +<% if course_endTime_timeout?(@project) #如果课程已结束%> + <%= link_to '重启课程', restartcourse_project_path, :remote => true, :method => :post, :id => id, :confirm => ('确定要重启课程?') %> +<% else %> + <%= link_to '关闭课程', finishcourse_project_path, :remote => true, :method => :post, :id => id, :confirm => ('确定要关闭课程?') %> +<% end %> diff --git a/app/views/courses/_set_join.js.erb b/app/views/courses/_set_join.js.erb index b0b4e8a9..bcc094de 100644 --- a/app/views/courses/_set_join.js.erb +++ b/app/views/courses/_set_join.js.erb @@ -2,7 +2,11 @@ $("#<%=object_id%>").replaceWith('<%= escape_javascript join_in_course_for_list( <% if @state %> <% if @state == 0 %> alert("加入成功") - <% else %> + <% elsif @state == 1 %> alert("密码错误") + <% elsif @state == 2 %> + alert("课程已过期") + <% else %> + alert("未知错误,请稍后再试") <% end %> <% end %> diff --git a/app/views/layouts/base_courses.html.erb b/app/views/layouts/base_courses.html.erb index c6b51343..e0661ccf 100644 --- a/app/views/layouts/base_courses.html.erb +++ b/app/views/layouts/base_courses.html.erb @@ -71,10 +71,11 @@ <%= @project.name %> -
+
<%if User.current.logged? %> <% if @course.teacher.id == User.current.id %> <%= link_to l(:label_course_modify_settings), {:controller => 'projects', :action => 'settings', :id => @project} %> + <%= render :partial => 'courses/set_course_time'%> <% else %> <%= join_in_course(@project, User.current) %>
diff --git a/app/views/my/account.html.erb b/app/views/my/account.html.erb index 646d6246..cca7b854 100644 --- a/app/views/my/account.html.erb +++ b/app/views/my/account.html.erb @@ -25,13 +25,16 @@ <%= l(:label_information_plural)%>
- +

+ <%= f.text_field :firstname, :required => true %> + <%=l(:field_firstname_eg)%> +

+
@@ -61,7 +61,7 @@
<%= content_tag "span","#{l(:label_duration_time)}:", :class => "course-font"%> - <%= findCourseTime @project %> + <%= get_course_term @project %>
diff --git a/app/views/projects/finishcourse.js.erb b/app/views/projects/finishcourse.js.erb new file mode 100644 index 00000000..a9bcfdd4 --- /dev/null +++ b/app/views/projects/finishcourse.js.erb @@ -0,0 +1,8 @@ +<% if @save_flag %> + <% if Rails.env.development? %> + console.debug('课程修改成功:结束时间改为<%=Course.find_by_extra(@project.identifier).try(:endup_time)%>'); + <% end %> + $('#finish_course_tag').replaceWith("<%= j(render partial: 'courses/set_course_time' )%>") +<% else %> + alert('设置失败,请在论坛提交问题,等待管理员处理。'); +<% end %> diff --git a/app/views/welcome/course.html.erb b/app/views/welcome/course.html.erb index f6774b49..517e81f3 100644 --- a/app/views/welcome/course.html.erb +++ b/app/views/welcome/course.html.erb @@ -126,7 +126,9 @@ ><%=project.description.truncate(25, omission: '...')%>
+ <% if !course_endTime_timeout?(project)%> <%= join_in_course(project, User.current)%> + <% end %>
<% end; reset_cycle %> diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 0c179755..34d159cb 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -234,7 +234,9 @@ zh: field_summary: 摘要 field_is_required: 必填 field_firstname: 名字 + field_firstname_eg: '(例:张三丰,请填写[三丰])' field_lastname: 姓氏 + field_lastname_eg: '(例:张三丰,请填写[张])' field_mail: 邮件地址 field_filename: 文件 field_filesize: 大小 diff --git a/config/routes.rb b/config/routes.rb index 7633a9c9..41106c0a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -46,7 +46,7 @@ RedmineApp::Application.routes.draw do get "tags/show" get "praise_tread/praise_plus" - + get "praise_tread/tread_plus" #end @@ -120,28 +120,28 @@ RedmineApp::Application.routes.draw do match 'user_courses', :to => 'users#user_courses', :via => :get match 'user_homeworks', :to => 'users#user_homeworks', :via => :get match 'watch_projects', :to => 'users#watch_projects', :via => :get - # added by bai + # added by bai match 'show_score', :to => 'users#show_score', :via => :get match 'topic_score_index', :controller => 'users', :action => 'topic_score_index', :via => [:get, :post] match 'project_score_index', :to => 'users#project_score_index', :via => :get match 'activity_score_index', :to => 'users#activity_score_index', :via => :get match 'influence_score_index', :to => 'users#influence_score_index', :via => :get match 'score_index', :to => 'users#score_index', :via => :get - + match 'show_projects_score', :to => 'projects#show_projects_score', :via => [:get, :post] match 'issue_score_index', :to => 'projects#issue_score_index', :via => [:get, :post] match 'news_score_index', :to => 'projects#news_score_index', :via => [:get, :post] match 'file_score_index', :to => 'projects#file_score_index', :via => [:get, :post] match 'code_submit_score_index', :to => 'projects#code_submit_score_index', :via => [:get, :post] match 'projects_topic_score_index', :to => 'projects#projects_topic_score_index', :via => [:get, :post] - # end + # end end end match 'users/:id/user_newfeedback', :to => 'users#user_newfeedback', :via => :get, :as => "feedback" match 'users/:id/user_projects', :controller => 'users', :action => 'user_projects', :via => :get #match 'user/:id/watch_calls', :controller => 'users', :action => 'watch_bids', :via => [:get , :post] -#end + #end match 'my/account', :controller => 'my', :action => 'account', :via => [:get, :post] match 'my/account/destroy', :controller => 'my', :action => 'destroy', :via => [:get, :post] match 'my/page', :controller => 'my', :action => 'page', :via => :get @@ -173,8 +173,10 @@ RedmineApp::Application.routes.draw do delete 'issues/:object_id/watchers/:user_id' => 'watchers#destroy', :object_type => 'issue' resources :bids, :only=>[:edit,:update,:show] - resources :projects do + resources :projects do member do + post 'finishcourse' + post 'restartcourse' get 'settings(/:tab)', :action => 'settings', :as => 'settings' #by young get 'member', :controller => 'projects', :action => 'member', :as => 'member' @@ -196,24 +198,24 @@ RedmineApp::Application.routes.draw do end -#by young - match '/member', :controller => 'projects', :action => 'member', :as => 'member', :via => :get - match '/file', :controller => 'projects', :action => 'file', :as => 'file', :via => :get - match '/statistics', :controller => 'projects', :action => 'statistics', :as => 'statistics', :via => :get -# match '/investor', :controller => 'projects', :action => 'investor', :as => 'investor', :via => :get - match '/homework', :controller => 'projects', :action => 'homework', :as => 'homework', :via => :get - + #by young + match '/member', :controller => 'projects', :action => 'member', :as => 'member', :via => :get + match '/file', :controller => 'projects', :action => 'file', :as => 'file', :via => :get + match '/statistics', :controller => 'projects', :action => 'statistics', :as => 'statistics', :via => :get + # match '/investor', :controller => 'projects', :action => 'investor', :as => 'investor', :via => :get + match '/homework', :controller => 'projects', :action => 'homework', :as => 'homework', :via => :get -# match '/activity', :controller => 'activities', :action => 'index', :as => 'activity', :via => :get -# match '/repository', :controller => 'repositories', :action => 'show', :repository_id => nil, :path => nil, :rev => nil, :as => 'repository', :via => :get -# match '/', :controller => 'projects', :action => 'show', :as => 'project_show', :via => :get -# get 'projects/:project_id/show', :to => 'projects#show', :as => 'project_show' -# get 'projects/:project_id/repository', :to => 'repositories#show', :as => 'project_repository' - -# match '/show', :controller => 'projects', :action => 'show', :as => 'project_show', :via => :get + + # match '/activity', :controller => 'activities', :action => 'index', :as => 'activity', :via => :get + # match '/repository', :controller => 'repositories', :action => 'show', :repository_id => nil, :path => nil, :rev => nil, :as => 'repository', :via => :get + # match '/', :controller => 'projects', :action => 'show', :as => 'project_show', :via => :get + # get 'projects/:project_id/show', :to => 'projects#show', :as => 'project_show' + # get 'projects/:project_id/repository', :to => 'repositories#show', :as => 'project_repository' + + # match '/show', :controller => 'projects', :action => 'show', :as => 'project_show', :via => :get match '/watcherlist', :controller=>'projects', :action=> 'watcherlist', :as => 'watcherlist', :via => :get #add by huang - # matche '/news', :controller => 'news', :action => 'index', :as => 'news', :via => :get -#end + # matche '/news', :controller => 'news', :action => 'index', :as => 'news', :via => :get + #end resources :memberships, :shallow => true, :controller => 'members', :only => [:index, :show, :new, :create, :update, :destroy] do collection do @@ -336,8 +338,7 @@ RedmineApp::Application.routes.draw do get 'projects/:id/repository/:repository_id/statistics', :to => 'repositories#stats' get 'projects/:id/repository/:repository_id/graph', :to => 'repositories#graph' - get 'projects/:id/repository/:repository_id/changes(/*path(.:ext))', - :to => 'repositories#changes' + get 'projects/:id/repository/:repository_id/changes(/*path(.:ext))', :to => 'repositories#changes' get 'projects/:id/repository/:repository_id/revisions/:rev', :to => 'repositories#revision' get 'projects/:id/repository/:repository_id/revision', :to => 'repositories#revision' @@ -348,15 +349,14 @@ RedmineApp::Application.routes.draw do :controller => 'repositories', :format => false, :constraints => { - :action => /(browse|show|entry|raw|annotate|diff)/, - :rev => /[a-z0-9\.\-_]+/ - } + :action => /(browse|show|entry|raw|annotate|diff)/, + :rev => /[a-z0-9\.\-_]+/ + } get 'projects/:id/repository/statistics', :to => 'repositories#stats' get 'projects/:id/repository/graph', :to => 'repositories#graph' - get 'projects/:id/repository/changes(/*path(.:ext))', - :to => 'repositories#changes' + get 'projects/:id/repository/changes(/*path(.:ext))', :to => 'repositories#changes' get 'projects/:id/repository/revisions', :to => 'repositories#revisions' get 'projects/:id/repository/revisions/:rev', :to => 'repositories#revision' @@ -367,9 +367,9 @@ RedmineApp::Application.routes.draw do :controller => 'repositories', :format => false, :constraints => { - :action => /(browse|show|entry|raw|annotate|diff)/, - :rev => /[a-z0-9\.\-_]+/ - } + :action => /(browse|show|entry|raw|annotate|diff)/, + :rev => /[a-z0-9\.\-_]+/ + } get 'projects/:id/repository/:repository_id/:action(/*path(.:ext))', :controller => 'repositories', :action => /(browse|show|entry|raw|changes|annotate|diff)/ @@ -441,7 +441,7 @@ RedmineApp::Application.routes.draw do end end - + match 'workflows', :controller => 'workflows', :action => 'index', :via => :get match 'workflows/edit', :controller => 'workflows', :action => 'edit', :via => [:get, :post] @@ -529,10 +529,10 @@ RedmineApp::Application.routes.draw do match 'project/course', :to => 'projects#course', :as => 'course' #added by william - # match 'calls/:id/set_results',:controller => 'bids', :action => 'set_results',:via => [:get,:post],:as => 'set_results' - # match 'calls/:id/set_prizes',:controller => 'bids',:action => 'set_prizes',:as => 'set_prizes' - match 'calls/:id/set_reward',:controller => 'bids',:action => 'set_reward',:as => 'set_reward' - + # match 'calls/:id/set_results',:controller => 'bids', :action => 'set_results',:via => [:get,:post],:as => 'set_results' + # match 'calls/:id/set_prizes',:controller => 'bids',:action => 'set_prizes',:as => 'set_prizes' + match 'calls/:id/set_reward',:controller => 'bids',:action => 'set_reward',:as => 'set_reward' + ## 测试用 match 'test/index', :controller => 'test', :action => 'index' # added by young