改了个课程截至日期,并且在courses_controller中设置了过期不允许加入的设定,目测没什么问题,明天再看看

This commit is contained in:
yanxd 2014-03-17 22:43:38 +08:00
parent 6ac640f36a
commit e0c87996bf
14 changed files with 155 additions and 69 deletions

View File

@ -1,12 +1,15 @@
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
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
@ -16,6 +19,9 @@ class CoursesController < ApplicationController
else
@state = 1
end
else
@state = 2
end
end
respond_to do |format|
# format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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) &&

View File

@ -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 %>

View File

@ -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 %>

View File

@ -71,10 +71,11 @@
<td class="info-course"><%= @project.name %></td>
</tr>
<tr><td align="center">
<div id=join_in_course>
<div id="join_in_course">
<%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) %></div>

View File

@ -26,12 +26,15 @@
</legend>
<div>
<span id = 'name' style = 'display:none'>
<p style="width:400px;padding-left: 26px;">
<%= f.text_field :firstname, :required => true %>
<p style="width:530px;padding-left: 26px;">
<%= f.text_field :lastname, :required => true %>
<span class='font_lighter'><%=l(:field_lastname_eg)%></span>
</p>
<p style="width:400px;padding-left: 26px;">
<%#= f.text_field :lastname, :required => true %>
</p></span>
<p style="width:530px;padding-left: 26px;">
<%= f.text_field :firstname, :required => true %>
<span class='font_lighter'><%=l(:field_firstname_eg)%></span>
</p>
</span>
<span id = 'enterprise' style = 'display:none'>
<p style="width:400px;padding-left: 26px;">企业名<%= text_field_tag :enterprise_name, @user.firstname %>
@ -75,7 +78,7 @@
<p style="width:357px;padding-left: 26px;">
<%= f.text_field :mail, :required => true %>
</p>
<p style="width:426px;padding-left:26px;>
<p style="width:426px;padding-left:26px;">
<%= f.select :language, :Chinese简体中文 => :zh, :English => :en%>
</p>

View File

@ -47,12 +47,12 @@
</p>
<div class="buttons_for_course" style="margin-top:30px;margin-left:144px">
<span class="info"></span>
<% if(!course_timeout? @project) %>
<%= join_in_course_for_list(@project, User.current,['regular'])%>
<% else %>
<% if(course_timeout? @project) %>
<span class="font_lighter">
课程学期已结束
</span>
<% else %>
<%= join_in_course_for_list(@project, User.current,['regular'])%>
<% end -%>
</div>
</div>
@ -61,7 +61,7 @@
<div class="add-info">
<div class="main-language" style="margin-left: 30px;margin-top:-10px">
<%= content_tag "span","#{l(:label_duration_time)}:", :class => "course-font"%>
<%= findCourseTime @project %>
<%= get_course_term @project %>
</div>
</div>

View File

@ -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 %>

View File

@ -126,7 +126,9 @@
<span class='font_lighter' title =<%=project.description.to_s%>><%=project.description.truncate(25, omission: '...')%></span>
</div>
<div style="position:absolute; bottom:0;right:0;margin:5px 10px 5px 5px ;">
<% if !course_endTime_timeout?(project)%>
<%= join_in_course(project, User.current)%>
<% end %>
</div>
</li>
<% end; reset_cycle %>

View File

@ -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: 大小

View File

@ -141,7 +141,7 @@ RedmineApp::Application.routes.draw do
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
@ -175,6 +175,8 @@ RedmineApp::Application.routes.draw do
resources :bids, :only=>[:edit,:update,:show]
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
#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 '/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 '/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 '/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
#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'
@ -355,8 +356,7 @@ RedmineApp::Application.routes.draw do
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'