改了个课程截至日期,并且在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 class CoursesController < ApplicationController
include CoursesHelper
before_filter :require_login, :only => [:join, :unjoin] before_filter :require_login, :only => [:join, :unjoin]
before_filter :allow_join, :only => [:join]
def join def join
if User.current.logged? if User.current.logged?
course = Project.find(params[:object_id]) 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 = []
members << Member.new(:role_ids => [10], :user_id => User.current.id) members << Member.new(:role_ids => [10], :user_id => User.current.id)
course.members << members course.members << members
@ -16,6 +19,9 @@ class CoursesController < ApplicationController
else else
@state = 1 @state = 1
end end
else
@state = 2
end
end end
respond_to do |format| respond_to do |format|
# format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}} # 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]} } format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => Project.find(params[:object_id]), :object_id => params[:object_id]} }
end end
end end
private
def allow_join
course_endTime_timeout? Project.find(params[:object_id])
end
end end

View File

@ -45,9 +45,10 @@ class ProjectsController < ApplicationController
# menu_item l(:label_settings), :only => settings # 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 :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, # 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, # :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] # :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 :authorize_global, :only => [:new, :create]
before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy, :calendar] before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy, :calendar]
#by young #by young
@ -558,7 +559,8 @@ class ProjectsController < ApplicationController
"show_documents" => true, "show_documents" => true,
"show_messages" => true, "show_messages" => true,
"show_news" => true, "show_news" => true,
"show_bids" => true "show_bids" => true,
"show_journals_for_messages" => true
} }
@date_to ||= Date.today + 1 @date_to ||= Date.today + 1
@date_from = @date_to - @days @date_from = @date_to - @days
@ -569,6 +571,7 @@ class ProjectsController < ApplicationController
:with_subprojects => @with_subprojects, :with_subprojects => @with_subprojects,
:author => @author) :author => @author)
@activity.scope_select {|t| !has["show_#{t}"].nil?} @activity.scope_select {|t| !has["show_#{t}"].nil?}
# logger.debug "=========================================#{@activity.scope}"
# @activity.scope = (@author.nil? ? :default : :all) if @activity.scope.empty? # @activity.scope = (@author.nil? ? :default : :all) if @activity.scope.empty?
#Added by young #Added by young
events = @activity.events(@date_from, @date_to) events = @activity.events(@date_from, @date_to)
@ -801,6 +804,35 @@ class ProjectsController < ApplicationController
end end
# 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 private
# Validates parent_id param according to user's permissions # Validates parent_id param according to user's permissions

View File

@ -79,6 +79,11 @@ module CoursesHelper
str str
end 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 def members_to_user_ids members
people = [] people = []
members.each { |member| members.each { |member|
@ -86,5 +91,17 @@ module CoursesHelper
} }
people people
end 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 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 ") WHERE project_type = 0 ORDER BY grade DESC LIMIT #{limit} ) AS t ON p.id = t.project_id ")
end end
# 判断课程是否结束 # 判断课程是否结束,快别用,这个定日子的方法有问题
def course_timeout? project def course_timeout? project
return true if (project.nil? && project.course_extra.nil?) return true if (project.nil? && project.course_extra.nil?)
courses_year = project.course_extra.time courses_year = project.course_extra.time

View File

@ -22,11 +22,6 @@ module WelcomeHelper
include CoursesHelper include CoursesHelper
include ProjectsHelper 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) def welcome_join_in_course(project, user)
if(user.logged? && if(user.logged? &&
!(course_timeout? project) && !(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 %>
<% if @state == 0 %> <% if @state == 0 %>
alert("加入成功") alert("加入成功")
<% else %> <% elsif @state == 1 %>
alert("密码错误") alert("密码错误")
<% elsif @state == 2 %>
alert("课程已过期")
<% else %>
alert("未知错误,请稍后再试")
<% end %> <% end %>
<% end %> <% end %>

View File

@ -71,10 +71,11 @@
<td class="info-course"><%= @project.name %></td> <td class="info-course"><%= @project.name %></td>
</tr> </tr>
<tr><td align="center"> <tr><td align="center">
<div id=join_in_course> <div id="join_in_course">
<%if User.current.logged? %> <%if User.current.logged? %>
<% if @course.teacher.id == User.current.id %> <% if @course.teacher.id == User.current.id %>
<%= link_to l(:label_course_modify_settings), {:controller => 'projects', :action => 'settings', :id => @project} %> <%= link_to l(:label_course_modify_settings), {:controller => 'projects', :action => 'settings', :id => @project} %>
<%= render :partial => 'courses/set_course_time'%>
<% else %> <% else %>
<%= join_in_course(@project, User.current) %></div> <%= join_in_course(@project, User.current) %></div>

View File

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

View File

@ -47,12 +47,12 @@
</p> </p>
<div class="buttons_for_course" style="margin-top:30px;margin-left:144px"> <div class="buttons_for_course" style="margin-top:30px;margin-left:144px">
<span class="info"></span> <span class="info"></span>
<% if(!course_timeout? @project) %> <% if(course_timeout? @project) %>
<%= join_in_course_for_list(@project, User.current,['regular'])%>
<% else %>
<span class="font_lighter"> <span class="font_lighter">
课程学期已结束 课程学期已结束
</span> </span>
<% else %>
<%= join_in_course_for_list(@project, User.current,['regular'])%>
<% end -%> <% end -%>
</div> </div>
</div> </div>
@ -61,7 +61,7 @@
<div class="add-info"> <div class="add-info">
<div class="main-language" style="margin-left: 30px;margin-top:-10px"> <div class="main-language" style="margin-left: 30px;margin-top:-10px">
<%= content_tag "span","#{l(:label_duration_time)}:", :class => "course-font"%> <%= content_tag "span","#{l(:label_duration_time)}:", :class => "course-font"%>
<%= findCourseTime @project %> <%= get_course_term @project %>
</div> </div>
</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> <span class='font_lighter' title =<%=project.description.to_s%>><%=project.description.truncate(25, omission: '...')%></span>
</div> </div>
<div style="position:absolute; bottom:0;right:0;margin:5px 10px 5px 5px ;"> <div style="position:absolute; bottom:0;right:0;margin:5px 10px 5px 5px ;">
<% if !course_endTime_timeout?(project)%>
<%= join_in_course(project, User.current)%> <%= join_in_course(project, User.current)%>
<% end %>
</div> </div>
</li> </li>
<% end; reset_cycle %> <% end; reset_cycle %>

View File

@ -234,7 +234,9 @@ zh:
field_summary: 摘要 field_summary: 摘要
field_is_required: 必填 field_is_required: 必填
field_firstname: 名字 field_firstname: 名字
field_firstname_eg: '(例:张三丰,请填写[三丰])'
field_lastname: 姓氏 field_lastname: 姓氏
field_lastname_eg: '(例:张三丰,请填写[张])'
field_mail: 邮件地址 field_mail: 邮件地址
field_filename: 文件 field_filename: 文件
field_filesize: 大小 field_filesize: 大小

View File

@ -175,6 +175,8 @@ RedmineApp::Application.routes.draw do
resources :bids, :only=>[:edit,:update,:show] resources :bids, :only=>[:edit,:update,:show]
resources :projects do resources :projects do
member do member do
post 'finishcourse'
post 'restartcourse'
get 'settings(/:tab)', :action => 'settings', :as => 'settings' get 'settings(/:tab)', :action => 'settings', :as => 'settings'
#by young #by young
get 'member', :controller => 'projects', :action => 'member', :as => 'member' get 'member', :controller => 'projects', :action => 'member', :as => 'member'
@ -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/statistics', :to => 'repositories#stats'
get 'projects/:id/repository/:repository_id/graph', :to => 'repositories#graph' get 'projects/:id/repository/:repository_id/graph', :to => 'repositories#graph'
get 'projects/:id/repository/:repository_id/changes(/*path(.:ext))', get 'projects/:id/repository/:repository_id/changes(/*path(.:ext))', :to => 'repositories#changes'
:to => 'repositories#changes'
get 'projects/:id/repository/:repository_id/revisions/:rev', :to => 'repositories#revision' get 'projects/:id/repository/:repository_id/revisions/:rev', :to => 'repositories#revision'
get 'projects/:id/repository/:repository_id/revision', :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/statistics', :to => 'repositories#stats'
get 'projects/:id/repository/graph', :to => 'repositories#graph' get 'projects/:id/repository/graph', :to => 'repositories#graph'
get 'projects/:id/repository/changes(/*path(.:ext))', get 'projects/:id/repository/changes(/*path(.:ext))', :to => 'repositories#changes'
:to => 'repositories#changes'
get 'projects/:id/repository/revisions', :to => 'repositories#revisions' get 'projects/:id/repository/revisions', :to => 'repositories#revisions'
get 'projects/:id/repository/revisions/:rev', :to => 'repositories#revision' get 'projects/:id/repository/revisions/:rev', :to => 'repositories#revision'