增加了竞赛的“加入”
This commit is contained in:
parent
b22077033a
commit
005e0802d4
|
@ -8,7 +8,10 @@ class BidsController < ApplicationController
|
|||
menu_item :homework_statistics, :only => :homework_statistics
|
||||
#Ended by young
|
||||
before_filter :find_bid, :only => [:show, :show_project, :create,:destroy,:more,:back,:add,:new,:show_results,:set_reward, :add_homework, :fork, :create_fork,
|
||||
:show_course, :show_bid_project, :show_bid_user]
|
||||
:show_course, :show_bid_project, :show_bid_user, :join_in_contest, :unjoin_in_contest, :new_join]
|
||||
# added by fq
|
||||
before_filter :require_login, :only => [:join_in_contest, :unjoin_in_contest]
|
||||
# end
|
||||
before_filter :require_login,:only => [:set_reward, :destroy, :add, :new, ]
|
||||
|
||||
helper :watchers
|
||||
|
@ -209,6 +212,41 @@ class BidsController < ApplicationController
|
|||
|
||||
end
|
||||
end
|
||||
|
||||
def join_in_contest
|
||||
if @bid.reward_type == 2 && params[:course_password] == @bid.password
|
||||
JoinInContest.create(:user_id => User.current.id, :bid_id => @bid.id)
|
||||
@state = 0
|
||||
else
|
||||
@state = 1
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
# format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
|
||||
# TO_DO
|
||||
format.js { render :partial => 'set_join', :locals => {:user => User.current, :object_id => params[:id]} }
|
||||
end
|
||||
end
|
||||
|
||||
def unjoin_in_contest
|
||||
|
||||
joined = JoinInContest.where('bid_id = ? and user_id = ?', @bid.id, User.current.id)
|
||||
|
||||
joined.each do |join|
|
||||
join.delete
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
# format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
|
||||
format.js { render :partial => 'set_join', :locals => {:user => User.current, :object_id => params[:id]} }
|
||||
end
|
||||
end
|
||||
|
||||
def new_join
|
||||
# added by fq
|
||||
|
||||
|
||||
end
|
||||
|
||||
def show_course
|
||||
bids = Bid.where('parent_id = ?', @bid.id)
|
||||
|
@ -338,13 +376,13 @@ class BidsController < ApplicationController
|
|||
@homework = HomeworkAttach.new
|
||||
@homework_list = @bid.homeworks
|
||||
if params[:student_id].present?
|
||||
@temp = []
|
||||
@homework_list.each do |pro|
|
||||
if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id
|
||||
@temp << pro
|
||||
end
|
||||
@temp
|
||||
end
|
||||
@temp = []
|
||||
@homework_list.each do |pro|
|
||||
if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id
|
||||
@temp << pro
|
||||
end
|
||||
@temp
|
||||
end
|
||||
@homework_list = @temp
|
||||
end
|
||||
end
|
||||
|
@ -536,6 +574,7 @@ class BidsController < ApplicationController
|
|||
@bid.reward_type = 2
|
||||
@bid.budget = params[:bid][:budget]
|
||||
@bid.deadline = params[:bid][:deadline]
|
||||
@bid.password = params[:bid][:password] #added by bai
|
||||
@bid.author_id = User.current.id
|
||||
@bid.commit = 0
|
||||
if @bid.save
|
||||
|
|
|
@ -56,9 +56,9 @@ module WatchersHelper
|
|||
url_f = try_join_path(:object_id => course.id)
|
||||
method = joined ? 'delete' : 'post'
|
||||
if joined
|
||||
link_to text, url_t, :remote => true, :method => method, :id => 'join', :confirm => l(:text_are_you_sure_out), :class => []+options
|
||||
link_to text, url_t, :remote => true, :method => method, :id => "#{course.id}", :confirm => l(:text_are_you_sure_out), :class => []+options
|
||||
else
|
||||
link_to text, url_f, :remote => true, :method => method, :id => 'join', :class => []+options
|
||||
link_to text, url_f, :remote => true, :method => method, :id => "#{course.id}", :class => []+options
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -76,6 +76,25 @@ module WatchersHelper
|
|||
end
|
||||
end
|
||||
|
||||
#added by bai
|
||||
def join_in_contest(bid, user, options=[])
|
||||
if bid.reward_type == 2
|
||||
return '' unless user && user.logged?
|
||||
joined = user.join_in_contest?(bid)
|
||||
text = joined ? l(:label_exit_contest) : l(:label_join_contest)
|
||||
url_t = join_in_contest_path(:id => bid.id)
|
||||
url_f = try_join_in_contest_path(:id => bid.id)
|
||||
# url = join_in_contest_path(:id => bid.id)
|
||||
method = joined ? 'delete' : 'post'
|
||||
if joined
|
||||
link_to text, url_t, :remote => true, :method => method, :id => "#{bid.id}", :confirm => l(:text_are_you_sure_out), :class => []+options
|
||||
else
|
||||
link_to text, url_f, :remote => true, :method => method, :id => "#{bid.id}", :class => []+options
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Returns the css class used to identify watch links for a given +object+
|
||||
def watcher_css(objects)
|
||||
objects = Array.wrap(objects)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
####by fq
|
||||
class Bid < ActiveRecord::Base
|
||||
attr_accessible :author_id, :budget, :deadline, :name, :description, :homework_type
|
||||
attr_accessible :author_id, :budget, :deadline, :name, :description, :homework_type, :password
|
||||
include Redmine::SafeAttributes
|
||||
|
||||
belongs_to :author, :class_name => 'User', :foreign_key => :author_id
|
||||
|
@ -13,6 +13,7 @@ class Bid < ActiveRecord::Base
|
|||
has_many :homework_for_courses, :dependent => :destroy
|
||||
has_many :courses, :through => :homework_for_courses, :source => :project
|
||||
has_many :homeworks, :class_name => 'HomeworkAttach', :dependent => :destroy
|
||||
has_many :join_in_contests, :dependent => :destroy
|
||||
# has_many :fork_homework, :class_name => 'Bid', :conditions => "#{Bid.table_name}.parent_id = #{id}"
|
||||
|
||||
|
||||
|
@ -63,7 +64,8 @@ class Bid < ActiveRecord::Base
|
|||
'budget',
|
||||
'deadline',
|
||||
'homework_type',
|
||||
'reward_type'
|
||||
'reward_type',
|
||||
'password'
|
||||
|
||||
|
||||
# safe_attributes 'name',
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
class JoinInContest < ActiveRecord::Base
|
||||
attr_accessible :bid_id, :user_id
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :bid
|
||||
|
||||
validates_presence_of :user_id, :bid_id
|
||||
|
||||
|
||||
end
|
|
@ -90,6 +90,7 @@ class User < Principal
|
|||
has_many :students_for_courses
|
||||
has_many :courses, :through => :students_for_courses, :source => :project
|
||||
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
|
||||
has_many :join_in_contests, :dependent => :destroy
|
||||
#####
|
||||
|
||||
######added by nie
|
||||
|
@ -167,6 +168,16 @@ class User < Principal
|
|||
self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id, :status => true)
|
||||
end
|
||||
|
||||
# 判断用户是否加入了竞赛中 fq
|
||||
def join_in_contest?(bid)
|
||||
joined = JoinInContest.where('user_id = ? and bid_id =?', self.id, bid.id)
|
||||
if joined.size > 0
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
### fq
|
||||
def join_in?(course)
|
||||
joined = StudentsForCourse.where('student_id = ? and course_id = ?', self.id, course.id)
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
<p><%= f.text_field :name, :required => true, :size => 60, :style => "width:490px;", :maxlength => Bid::NAME_LENGTH_LIMIT, :placeholder => "#{l(:label_contest_name)}" %></p>
|
||||
|
||||
<p style="margin-left:-10px;padding-right: 20px;"><%= f.text_area :description, :rows => 8, :class => 'wiki-edit', :style => "font-size:small;width:490px;margin-left:10px;", :maxlength => Bid::DESCRIPTION_LENGTH_LIMIT, :placeholder => "#{l(:label_contest_description)}" %></p>
|
||||
|
||||
<p style="margin-left:-10px;"><%= f.text_field :password, :size => 60, :style => "width:488px;margin-left: 10px;" %></p>
|
||||
|
||||
<p>
|
||||
<%= f.text_field :budget, :required => true, :size => 60, :style => "width:350px;", :placeholder => l(:label_bids_reward_what) %>
|
||||
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
<!-- added by fq -->
|
||||
<style>
|
||||
input[type="submit"].bid_btn {
|
||||
vertical-align: middle;
|
||||
width: 60px;/*modified by ming*/
|
||||
height: 25px;
|
||||
line-height: 19px;
|
||||
font-size: 14px;
|
||||
color: rgb(0, 0, 0);
|
||||
background: buttonface;/*url("/images/button/bg103.jpg") no-repeat scroll left top transparent;*/
|
||||
padding: 0px 0px 4px 0px;
|
||||
border-radius: 2px;
|
||||
border: 1px solid rgb(148, 148, 148);
|
||||
box-shadow: none;
|
||||
text-shadow: none;
|
||||
/*margin-top: -10px;*/
|
||||
/*margin-right: -4px;*/
|
||||
}
|
||||
input[type="button"].bid_btn {
|
||||
width: 60px;/*modified by ming*/
|
||||
height: 25px;
|
||||
line-height: 19px;
|
||||
font-size: 14px;
|
||||
color: rgb(0, 0, 0);
|
||||
background: buttonface;/*url("/images/button/bg103.jpg") no-repeat scroll left top transparent;*/
|
||||
padding: 0px 0px 4px 0px;
|
||||
border-radius: 2px;
|
||||
border: 1px solid rgb(148, 148, 148);
|
||||
box-shadow: none;
|
||||
text-shadow: none;
|
||||
/*margin-top: -10px;*/
|
||||
margin-right: -2px;
|
||||
}
|
||||
textarea:focus {
|
||||
border: #d5dee9 1px solid;
|
||||
}
|
||||
</style>
|
||||
|
||||
<h3 class="title">请输入竞赛密码</h3>
|
||||
|
||||
<%= form_tag({:controller => 'bids',
|
||||
:action => 'join_in_contest',
|
||||
:id => course.id},
|
||||
:remote => true,
|
||||
:method => :post,
|
||||
:id => 'new-watcher-form') do %>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td align="cneter">
|
||||
</td>
|
||||
|
||||
<%= text_field_tag 'course_password', nil, :size => 45 %>
|
||||
|
||||
<p class="buttons" style="padding-top: 10px; padding-bottom: 1px; margin-bottom: 1px">
|
||||
<%= submit_tag l(:label_new_join), :name => nil, :class => "bid_btn", :onclick => "hideModal(this);" %>
|
||||
<%= submit_tag l(:button_cancel), :name => nil, :class => "bid_btn", :onclick => "hideModal(this);", :type => 'button' %>
|
||||
</td>
|
||||
</tr></table>
|
||||
<% end %>
|
|
@ -0,0 +1,8 @@
|
|||
$("#<%=object_id%>").replaceWith('<%= escape_javascript join_in_contest(@bid, user) %>');
|
||||
<% if @state %>
|
||||
<% if @state == 0 %>
|
||||
alert("加入成功")
|
||||
<% else %>
|
||||
alert("密码错误")
|
||||
<% end %>
|
||||
<% end %>
|
|
@ -0,0 +1,3 @@
|
|||
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'bids/new_join', :locals => {:course => @bid}) %>');
|
||||
showModal('ajax-modal', '400px');
|
||||
$('#ajax-modal').addClass('new-watcher');
|
|
@ -64,7 +64,9 @@
|
|||
<td class="info_font" style=" word-wrap: break-word; word-break: break-all"><%= h @bid.name %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"> <%= watcher_link(@bid, User.current) %> <!-- <%= link_to("选为作业", fork_path(@bid)) %> --></td>
|
||||
<td align="center">
|
||||
<%= join_in_contest(@bid, User.current)%>
|
||||
<%= watcher_link(@bid, User.current) %> <!-- <%= link_to("选为作业", fork_path(@bid)) %> --></td>
|
||||
</tr>
|
||||
</table></td>
|
||||
</tr>
|
||||
|
|
|
@ -70,13 +70,14 @@
|
|||
<td class="info-course"><%= @project.name %></td>
|
||||
</tr>
|
||||
<tr><td align="center">
|
||||
<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} %>
|
||||
<% else %>
|
||||
|
||||
<%= join_in_course(@project, User.current) %></div>
|
||||
<% end %>
|
||||
<% end %> </div>
|
||||
<% unless User.current.member_of?(@project) %>
|
||||
<!-- <%= image_tag "/images/fav.png" %> -->
|
||||
<div style="padding-right: 10px">
|
||||
|
|
|
@ -18,7 +18,12 @@
|
|||
<!-- added by bai 新增开课时间、结课时间、课时 -->
|
||||
|
||||
<%= f.fields_for @course do |m| %>
|
||||
<% unless @course.nil?%>
|
||||
|
||||
|
||||
|
||||
<!-- added by bai 新增开课时间、结课时间、课时 -->
|
||||
|
||||
<% unless @course.nil?%>
|
||||
<p><table><tr><td><span class="info" align="right" style="width: 90px; font-weight: bold ;margin-left:20px"><%= l(:label_setup_time) %><span class="required"> * </span></span>
|
||||
<span class="info" style="width: 10px"><%= text_field_tag :setup_time, @course.setup_time, :placeholder => "在此选择开课日期" %></span>
|
||||
<span><%= calendar_for('setup_time')%></span>
|
||||
|
@ -53,11 +58,12 @@
|
|||
<% end %>
|
||||
|
||||
<!-- end -->
|
||||
<!-- added by bai 增加了“年度”和“学期” -->
|
||||
<p><table><tr><td>
|
||||
|
||||
<!-- added by bai 增加了“年度”和“学期” -->
|
||||
<p><table><tr><td>
|
||||
<% unless @course.nil? %>
|
||||
<% if @course.time == 2008 %>
|
||||
<p><table><tr><td class="info" align="right" style="width: 90px"><strong><%= l(:label_term) %><span class="required"> * </span></strong></td>
|
||||
<p><table><tr><td class="info" align="right" style="width: 90px; margin-left:20px"><strong><%= l(:label_term) %><span class="required"> * </span></strong></td>
|
||||
<td class="info" style="width: 10px">
|
||||
<%= select_tag 'time', "<option value = '2008' selected='selected'>2008</option>
|
||||
<option value = '2009'>2009</option>
|
||||
|
@ -263,7 +269,7 @@
|
|||
<em class="info" style="margin-left:95px;"><%= l(:text_command) %></em>
|
||||
<% end %>
|
||||
<p style="margin-left:-10px;padding-right: 20px;"><%= f.text_area :description, :rows => 8, :class => 'wiki-edit', :style => "font-size:small;width:490px;margin-left:10px;" %></p><!--by young-->
|
||||
<p style="margin-left:-10px;"><em style ="color: #888888;display: block;font-size: 90%;font-style: normal;"><%= f.check_box :is_public, :style => "margin-left:10px;" %></em></p>
|
||||
<p style="margin-left:-10px;"><em style ="color: #888888;display: block;font-size: 90%;font-style: normal;"><%= f.check_box :is_public, :style => "margin-left:10px;" %><%= l(:label_public_info) %></em></p><!-- modified by bai -->
|
||||
<p style="display:none;"><%= f.text_field :project_type, :value => 1 %></p>
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<!--add by huang-->
|
||||
<p>温馨提示:项目可以是一次作业,也可以是别人或者自己创建的一项小工程~</p>
|
||||
<p>温馨提示:这里显示的是您创建或参与的所有项目。</p>
|
||||
<div class="content-title-top-project">
|
||||
<% if @user == User.current %>
|
||||
<%= link_to(l(:label_project_new), {:controller => 'projects', :action => 'new', :course => 0, :project_type => @project_type}, :class => 'icon icon-add') if User.current.allowed_to?(:add_project, nil, :global => true) %>
|
||||
|
|
|
@ -1579,6 +1579,9 @@ zh:
|
|||
zero: "参与了 %{count} 个课程:"
|
||||
one: "参与了 %{count} 个课程:"
|
||||
other: "参与了 %{count} 个课程:"
|
||||
|
||||
label_join_contest: 加入竞赛
|
||||
label_exit_contest: 退出竞赛
|
||||
|
||||
#end
|
||||
|
||||
|
|
|
@ -469,10 +469,13 @@ RedmineApp::Application.routes.draw do
|
|||
|
||||
match 'project/:id/share', :to => 'projects#share', :as => 'share_show' #share
|
||||
|
||||
post 'join_in/join', :to => 'courses#join', :as => 'join'
|
||||
post 'join_in/join', :to => 'courses#join', :as => 'join'
|
||||
delete 'join_in/join', :to => 'courses#unjoin'
|
||||
post 'calls/:id/join_in_contest', :to => 'bids#join_in_contest', :as => 'join_in_contest'
|
||||
delete 'calls/:id/join_in_contest', :to => 'bids#unjoin_in_contest'
|
||||
delete 'attachment/:id', :to => 'attachments#delete_homework'
|
||||
match 'new_join', :to => 'projects#new_join', :as => 'try_join'
|
||||
match 'new_join_in_contest', :to => 'bids#new_join', :as => 'try_join_in_contest'
|
||||
match 'projects/:id/respond', :to => 'projects#project_respond', :via => :post
|
||||
match 'calls/:id/manage',:to => 'bids#manage',:via => [:get,:post]
|
||||
match 'project/course', :to => 'projects#course', :as => 'course' #nyan
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddPasswordToBids < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :bids, :password, :string
|
||||
end
|
||||
end
|
|
@ -0,0 +1,10 @@
|
|||
class CreateJoinInContests < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :join_in_contests do |t|
|
||||
t.integer :user_id
|
||||
t.integer :bid_id
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
|
@ -92,6 +92,7 @@ ActiveRecord::Schema.define(:version => 20131112005309) do
|
|||
t.integer "reward_type"
|
||||
t.integer "homework_type"
|
||||
t.integer "parent_id"
|
||||
t.string "password"
|
||||
end
|
||||
|
||||
create_table "boards", :force => true do |t|
|
||||
|
@ -349,6 +350,13 @@ ActiveRecord::Schema.define(:version => 20131112005309) do
|
|||
add_index "issues", ["status_id"], :name => "index_issues_on_status_id"
|
||||
add_index "issues", ["tracker_id"], :name => "index_issues_on_tracker_id"
|
||||
|
||||
create_table "join_in_contests", :force => true do |t|
|
||||
t.integer "user_id"
|
||||
t.integer "bid_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "journal_details", :force => true do |t|
|
||||
t.integer "journal_id", :default => 0, :null => false
|
||||
t.string "property", :limit => 30, :default => "", :null => false
|
||||
|
|
Loading…
Reference in New Issue