添加了提交作业

exceptionHandle
fanqiang 12 years ago
parent 9221d1b376
commit 805ad6600b

@ -121,7 +121,9 @@ private
@attachment = Attachment.find(params[:id]) @attachment = Attachment.find(params[:id])
# Show 404 if the filename in the url is wrong # Show 404 if the filename in the url is wrong
raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename
unless @attachment.container_type == 'Bid' || @attachment.container_type == 'HomeworkAttach'
@project = @attachment.project @project = @attachment.project
end
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
render_404 render_404
end end

@ -3,10 +3,13 @@ class BidsController < ApplicationController
#Added by young #Added by young
menu_item :respond menu_item :respond
menu_item :project, :only => :show_project menu_item :project, :only => :show_project
menu_item :homework_respond, :only => :homework_respond
#Ended by young #Ended by young
before_filter :find_bid, :only => [:show, :show_project, :create, :destroy, :more, :back, :add, :new] before_filter :find_bid, :only => [:show, :show_project, :create, :destroy, :more, :back, :add, :new, :homework_respond, :add_homework]
helper :watchers helper :watchers
helper :attachments
include AttachmentsHelper
def index def index
# Modified by nie # Modified by nie
# @requirement_title = "4" # @requirement_title = "4"
@ -117,6 +120,10 @@ class BidsController < ApplicationController
# @project = Project.where("id in []", a) # @project = Project.where("id in []", a)
@user = @bid.author @user = @bid.author
@bidding_project = @bid.biding_projects @bidding_project = @bid.biding_projects
if @bid.homework_type == 1
@homework = HomeworkAttach.new
@homework_list = @bid.homeworks
end
respond_to do |format| respond_to do |format|
if @bid.reward_type == 3 if @bid.reward_type == 3
format.html { format.html {
@ -329,6 +336,8 @@ class BidsController < ApplicationController
@bid.budget = 0 @bid.budget = 0
@bid.author_id = User.current.id @bid.author_id = User.current.id
@bid.commit = 0 @bid.commit = 0
@bid.homework_type = params[:bid][:homework_type]
@bid.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads]))
# @bid. # @bid.
if @bid.save if @bid.save
HomeworkForCourse.create(:project_id => params[:course_id], :bid_id => @bid.id) HomeworkForCourse.create(:project_id => params[:course_id], :bid_id => @bid.id)
@ -342,7 +351,23 @@ class BidsController < ApplicationController
@bid.safe_attributes = params[:bid] @bid.safe_attributes = params[:bid]
render :action => 'new_bid' render :action => 'new_bid'
end end
end
def add_homework
# homework = HomeworkAttach.create(:bid_id => @bid.id, :user_id => User.current.id)
# homework.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads]))
@homework = HomeworkAttach.new
@homework.bid_id = @bid.id
@homework.user_id = User.current.id
@homework.save_attachments(params[:attachments])
@homework.save
@homework_list = @bid.homeworks
end
def homework_respond
@user = @bid.author
render :layout => 'base_homework'
end end
def more def more

@ -6,7 +6,7 @@ class CoursesController < ApplicationController
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] == '123' if params[:course_password].to_i == Course.find_by_extra(course.identifier).state
members = [] members = []
members << Member.new(:role_ids => [5], :user_id => User.current.id) members << Member.new(:role_ids => [5], :user_id => User.current.id)
course.members << members course.members << members

@ -39,6 +39,8 @@ class ProjectsController < ApplicationController
before_filter :authorize_global, :only => [:new, :create] before_filter :authorize_global, :only => [:new, :create]
before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ] before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ]
#by young #by young
# before_filter :member, :file, :statistics, :watcherlist
# modified by fq
before_filter :file, :statistics, :watcherlist before_filter :file, :statistics, :watcherlist
# #
accept_rss_auth :index accept_rss_auth :index
@ -518,6 +520,9 @@ class ProjectsController < ApplicationController
# end # end
def file def file
# if @project.project_type == 1
# render :layout => 'base_courses'
# end
# @course_tag = params[:course] # @course_tag = params[:course]
# if @course_tag == '1' # if @course_tag == '1'
# render :layout => 'base_courses' # render :layout => 'base_courses'

@ -133,4 +133,17 @@ module ProjectsHelper
Project.tagged_with(tag_name).order('updated_on desc') Project.tagged_with(tag_name).order('updated_on desc')
end end
# added by fq
def homework_type_option
type = []
option1 = []
option2 = []
option1 << '提交附件'
option1 << 1
option2 << '提交项目'
option2 << 2
type << option1
type << option2
end
end end

@ -46,9 +46,10 @@ module WatchersHelper
link_to text, url, :remote => true, :method => method, :class => css link_to text, url, :remote => true, :method => method, :class => css
end end
# added by fq
def join_in_course(course, user) def join_in_course(course, user)
return '' unless user && user.logged? return '' unless user && user.logged?
joined = user.join_in?(course) joined = user.member_of?(course)
text = joined ? '退出课程' : '加入课程' text = joined ? '退出课程' : '加入课程'
url_t = join_path(:object_id => course.id) url_t = join_path(:object_id => course.id)
url_f = try_join_path(:object_id => course.id) url_f = try_join_path(:object_id => course.id)

@ -1,6 +1,6 @@
####by fq ####by fq
class Bid < ActiveRecord::Base class Bid < ActiveRecord::Base
#attr_accessible :author_id, :budget, :deadline, :name, :description attr_accessible :author_id, :budget, :deadline, :name, :description, :homework_type
include Redmine::SafeAttributes include Redmine::SafeAttributes
belongs_to :author, :class_name => 'User', :foreign_key => :author_id belongs_to :author, :class_name => 'User', :foreign_key => :author_id
@ -11,6 +11,9 @@ class Bid < ActiveRecord::Base
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
has_many :homework_for_courses, :dependent => :destroy has_many :homework_for_courses, :dependent => :destroy
has_many :courses, :through => :homework_for_courses, :source => :project has_many :courses, :through => :homework_for_courses, :source => :project
has_many :homeworks, :class_name => 'HomeworkAttach', :dependent => :destroy
acts_as_attachable
NAME_LENGTH_LIMIT = 60 NAME_LENGTH_LIMIT = 60
DESCRIPTION_LENGTH_LIMIT = 250 DESCRIPTION_LENGTH_LIMIT = 250

@ -0,0 +1,9 @@
class HomeworkAttach < ActiveRecord::Base
attr_accessible :bid_id, :user_id
belongs_to :user
belongs_to :bid
acts_as_attachable
end

@ -57,6 +57,7 @@ class Project < ActiveRecord::Base
has_many :homeworks, :through => :homework_for_courses, :source => :bid, :dependent => :destroy has_many :homeworks, :through => :homework_for_courses, :source => :bid, :dependent => :destroy
has_many :students_for_courses, :dependent => :destroy has_many :students_for_courses, :dependent => :destroy
has_many :student, :through => :students_for_courses, :source => :user has_many :student, :through => :students_for_courses, :source => :user
# has_one :cour, :class_name => 'Course', :foreign_key => :extra, :dependent => :destroy
# end # end
#ADDED BY NIE #ADDED BY NIE
@ -1040,6 +1041,7 @@ class Project < ActiveRecord::Base
def update_position_under_parent def update_position_under_parent
set_or_update_position_under(parent) set_or_update_position_under(parent)
end end
def course def course
@course @course
end end

@ -19,7 +19,7 @@
<% elsif bid.reward_type == 2%> <% elsif bid.reward_type == 2%>
<strong><%= l(:label_bids_reward_method) %><span style="color: #15bccf;font-family: 14px; font-family: 微软雅黑"><%= bid.budget%></span></strong> <strong><%= l(:label_bids_reward_method) %><span style="color: #15bccf;font-family: 14px; font-family: 微软雅黑"><%= bid.budget%></span></strong>
<% else %> <% else %>
<strong><%= l(:label_bids_reward_method) %><span style="color: #00aa83;font-family: 14px; font-family: 微软雅黑"><%= l(:label_bids_credit) %>&nbsp;<%= bid.budget%>&nbsp;<%= l(:label_bids_credit_number) %></span></strong> <!-- <strong><%= l(:label_bids_reward_method) %><span style="color: #00aa83;font-family: 14px; font-family: 微软雅黑"><%= l(:label_bids_credit) %>&nbsp;<%= bid.budget%>&nbsp;<%= l(:label_bids_credit_number) %></span></strong> -->
<% end %> <% end %>
<!-- <td style="color: rgb(255, 0, 0);"><strong><%= l(:label_price) %><%= l(:label_RMB_sign) %><%= bid.budget%></strong></td> --> <!-- <td style="color: rgb(255, 0, 0);"><strong><%= l(:label_price) %><%= l(:label_RMB_sign) %><%= bid.budget%></strong></td> -->

@ -0,0 +1,17 @@
<div id="put-bid-form" style="display: none">
<%= form_for "bid_for_save", :remote=>true, :url => {:controller => 'bids', :action => 'add_homework'},
:update => "bidding_project_list",
:complete => '$("#put-bid-form").hide();' do |f| %>
<fieldset><legend><%= l(:label_attachment_plural) %></legend>
<p><%= render :partial => 'attachments/form', :locals => {:container => @homework} %></p>
</fieldset>
<%= submit_tag l(:button_create) %>
<% end %>
</div>
<div class='icon icon-add'>
<%= toggle_link l(:button_bidding), 'put-bid-form' %>
</div>
<div id='bidding_project_list'>
<%= render :partial => 'homework_list', :locals => {:homework => @homework_list} %>
</div>

@ -0,0 +1,30 @@
<!-- fq -->
<%= render_flash_messages %>
<% @homework_list.each do |homework|%>
<% if homework.attachments.any?%>
<table width="660px" border="0" align="center">
<tr>
<td colspan="2" valign="top" width="50" ><%= link_to image_tag(url_to_avatar(homework.user), :class => "avatar"), user_path(homework.user), :class => "avatar" %></td>
<td>
<table width="580px" border="0">
<tr>
<td colspan="2" valign="top"><strong> <%= link_to homework.user, user_path(homework.user)%></strong> <span class="font_lighter">提交了作业</span></td>
</tr>
<tr>
<td colspan="2" width="580px" >
<p class="font_description">
<% options = {:author => true} %>
<%= render :partial => 'attachments/links',
:locals => {:attachments => homework.attachments, :options => options} %>
<% end %>
</p></td>
</tr>
</table></td>
</tr>
</table>
<div class="line_under"></div>
<% end %>

@ -0,0 +1,4 @@
$('#bidding_project_list').html('<%= escape_javascript(render(:partial => 'homework_list', :locals => {:homework => @homework_list})) %>');
$("#project_id").val("请选择项目");
$("#bid_message").val("#{l(:label_bid_reason)} ");
$("#put-bid-form").hide();

@ -20,7 +20,6 @@
<% elsif @bid.reward_type == 2%> <% elsif @bid.reward_type == 2%>
<td><strong><%= l(:label_bids_reward_method) %><span style="color: #15bccf;font-family: 14px; font-family: 微软雅黑"><%= @bid.budget%></span></strong></td> <td><strong><%= l(:label_bids_reward_method) %><span style="color: #15bccf;font-family: 14px; font-family: 微软雅黑"><%= @bid.budget%></span></strong></td>
<% else %> <% else %>
<td><strong><%= l(:label_bids_reward_method) %><span style="color: #00aa83;font-family: 14px; font-family: 微软雅黑"><%= l(:label_bids_credit) %>&nbsp;<%= @bid.budget%>&nbsp;<%= l(:label_bids_credit_number) %></span></strong></td>
<% end %> <% end %>
</tr> </tr>
</table></td> </table></td>
@ -31,7 +30,13 @@
<tr> <tr>
<td></td> <td></td>
</tr> </tr>
<tr><td style="font-size: 13px; color: rgb(0,0,0);"><%= @bid.description %></td></tr> <tr><td style="font-size: 13px; color: rgb(0,0,0);"><%= @bid.description %>
<% if @bid.attachments.any?%>
<% options = {:author => true} %>
<%= render :partial => 'attachments/links',
:locals => {:attachments => @bid.attachments, :options => options} %>
<% end %>
</td></tr>
</table> </table>
</div> </div>

@ -1,4 +1,7 @@
<!-- fq --> <!-- fq -->
<% if @bid.homework_type == 1%>
<%= render :partial => 'homework' %>
<% else %>
<style> <style>
input[type="submit"].bid_btn { input[type="submit"].bid_btn {
vertical-align: middle; vertical-align: middle;
@ -84,3 +87,4 @@
<div id='bidding_project_list'> <div id='bidding_project_list'>
<%= render :partial => 'project_list', :locals => {:bidding_project => @bidding_project} %> <%= render :partial => 'project_list', :locals => {:bidding_project => @bidding_project} %>
</div> </div>
<% end %>

@ -111,6 +111,7 @@
<ul> <ul>
<li><%= link_to(l(:label_question_student), { :controller => 'bids', :action => 'show' })%></li> <li><%= link_to(l(:label_question_student), { :controller => 'bids', :action => 'show' })%></li>
<li><%= link_to(l(:label_homework_commit), { :controller => 'bids', :action => 'show_project' })%></li> <li><%= link_to(l(:label_homework_commit), { :controller => 'bids', :action => 'show_project' })%></li>
<li><%= link_to(l(:label_homework_respond), { :controller => 'bids', :action => 'homework_respond' })%></li>
<ul> <ul>
</div> </div>
<%= yield %> <%= yield %>

@ -32,5 +32,10 @@
</p> --> </p> -->
<p><%= f.text_field :deadline, :required => true, :size => 60, :style => "width:150px;", :placeholder => "#{l(:label_deadline)}" %><%= calendar_for('bid_deadline')%> <p><%= f.text_field :deadline, :required => true, :size => 60, :style => "width:150px;", :placeholder => "#{l(:label_deadline)}" %><%= calendar_for('bid_deadline')%>
</p> </p>
<p><%= f.select :homework_type, homework_type_option%>
</p>
<p><%= hidden_field_tag 'course_id', @project.id%> <p><%= hidden_field_tag 'course_id', @project.id%>
</p> </p>
<fieldset><legend><%= l(:label_attachment_plural) %></legend>
<p><%= render :partial => 'attachments/form', :locals => {:container => @homework} %></p>
</fieldset>

@ -10,7 +10,7 @@
<%= text_field_tag 'course_password', nil%> <%= text_field_tag 'course_password', nil%>
<p class="buttons"> <p class="buttons">
<%= submit_tag l(:button_add), :name => nil, :onclick => "hideModal(this);" %> <%= submit_tag '加入', :name => nil, :onclick => "hideModal(this);" %>
<%= submit_tag l(:button_cancel), :name => nil, :onclick => "hideModal(this);", :type => 'button' %> <%= submit_tag l(:button_cancel), :name => nil, :onclick => "hideModal(this);", :type => 'button' %>
</p> </p>
<% end %> <% end %>

@ -15,13 +15,6 @@
<td width="500"> <td width="500">
<table border="0"> <table border="0">
<tr><td> <tr><td>
<% if bid.reward_type.nil? or bid.reward_type == 1%>
<strong><%= l(:label_bids_reward_method) %><span style="color: #ed8924;font-family: 14px; font-family: 微软雅黑"><%= l(:label_call_bonus) %>&nbsp;<%= l(:label_RMB_sign) %><%= bid.budget%></span></strong>
<% elsif bid.reward_type == 2%>
<strong><%= l(:label_bids_reward_method) %><span style="color: #15bccf;font-family: 14px; font-family: 微软雅黑"><%= bid.budget%></span></strong>
<% else %>
<strong><%= l(:label_bids_reward_method) %><span style="color: #00aa83;font-family: 14px; font-family: 微软雅黑"><%= l(:label_bids_credit) %>&nbsp;<%= bid.budget%>&nbsp;<%= l(:label_bids_credit_number) %></span></strong>
<% end %>
<!-- <td style="color: rgb(255, 0, 0);"><strong><%= l(:label_price) %><%= l(:label_RMB_sign) %><%= bid.budget%></strong></td> --> <!-- <td style="color: rgb(255, 0, 0);"><strong><%= l(:label_price) %><%= l(:label_RMB_sign) %><%= bid.budget%></strong></td> -->
</td> </td>

@ -1251,6 +1251,8 @@ zh:
label_user_response: 用户反馈 label_user_response: 用户反馈
label_bidding_project: 参与项目 label_bidding_project: 参与项目
button_bidding: 我要参加 button_bidding: 我要参加
field_homework_type: 作业类型
label_homework_respond: 作业情况
label_new_call: 发布需求 label_new_call: 发布需求
label_user_information: "与我相关" label_user_information: "与我相关"
@ -1418,6 +1420,7 @@ zh:
label_welcome_trustie: Trustie label_welcome_trustie: Trustie
label_welcome_trustie_description: 面向有创意和激情的高校大学生与创业者,提供社交化的项目管理、协同研究、软件开发和众包平台。 label_welcome_trustie_description: 面向有创意和激情的高校大学生与创业者,提供社交化的项目管理、协同研究、软件开发和众包平台。
label_user_project: 项目 label_user_project: 项目
label_user_course: 课程
label_bid_respond_quote: 回复 label_bid_respond_quote: 回复
label_bid_if_agreement: 如果喜欢我,请点击我 label_bid_if_agreement: 如果喜欢我,请点击我
label_bid_respond_delete: 删除 label_bid_respond_delete: 删除

@ -437,10 +437,12 @@ RedmineApp::Application.routes.draw do
match 'calls/:id/show_project', :controller => 'bids', :action => 'show_project', :as => 'project_for_bid' match 'calls/:id/show_project', :controller => 'bids', :action => 'show_project', :as => 'project_for_bid'
match 'calls/:id/show_project_homework', :controller => 'bids', :action => 'show_project_homework', :as => 'project_for_bid' # by huang match 'calls/:id/show_project_homework', :controller => 'bids', :action => 'show_project_homework', :as => 'project_for_bid' # by huang
match 'calls/:id/add', :controller => 'bids', :action => 'add' match 'calls/:id/add', :controller => 'bids', :action => 'add'
match 'calls/:id/add_homework', :controller => 'bids', :action => 'add_homework'
match 'words/add_project_respond', :controller => 'words', :action => 'add_project_respond' match 'words/add_project_respond', :controller => 'words', :action => 'add_project_respond'
match 'projects/:id/feedback', :to => 'projects#feedback', :via => :get, :as => 'project_feedback' match 'projects/:id/feedback', :to => 'projects#feedback', :via => :get, :as => 'project_feedback'
match 'calls/create_bid', :to => 'bids#create_bid' match 'calls/create_bid', :to => 'bids#create_bid'
match 'calls/create_homework', :to => 'bids#create_homework' match 'calls/create_homework', :to => 'bids#create_homework'
match 'calls/:id/homework_respond', :to => 'bids#homework_respond'
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' delete 'join_in/join', :to => 'courses#unjoin'

@ -0,0 +1,5 @@
class AddHomeworkTypeToBid < ActiveRecord::Migration
def change
add_column :bids, :homework_type, :integer
end
end

@ -0,0 +1,10 @@
class CreateHomeworkAttaches < ActiveRecord::Migration
def change
create_table :homework_attaches do |t|
t.integer :bid_id
t.integer :user_id
t.timestamps
end
end
end

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130911005626) do ActiveRecord::Schema.define(:version => 20130913125835) do
create_table "a_user_watchers", :force => true do |t| create_table "a_user_watchers", :force => true do |t|
t.string "name" t.string "name"
@ -90,6 +90,7 @@ ActiveRecord::Schema.define(:version => 20130911005626) do
t.datetime "updated_on", :null => false t.datetime "updated_on", :null => false
t.integer "commit" t.integer "commit"
t.integer "reward_type" t.integer "reward_type"
t.integer "homework_type"
end end
create_table "boards", :force => true do |t| create_table "boards", :force => true do |t|
@ -259,6 +260,13 @@ ActiveRecord::Schema.define(:version => 20130911005626) do
add_index "groups_users", ["group_id", "user_id"], :name => "groups_users_ids", :unique => true add_index "groups_users", ["group_id", "user_id"], :name => "groups_users_ids", :unique => true
create_table "homework_attaches", :force => true do |t|
t.integer "bid_id"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "homework_for_courses", :force => true do |t| create_table "homework_for_courses", :force => true do |t|
t.integer "project_id" t.integer "project_id"
t.integer "bid_id" t.integer "bid_id"

@ -218,6 +218,7 @@ end
Redmine::MenuManager.map :bid_menu do |menu| Redmine::MenuManager.map :bid_menu do |menu|
menu.push :respond, { :controller => 'bids', :action => 'show' }, :caption => :label_user_response menu.push :respond, { :controller => 'bids', :action => 'show' }, :caption => :label_user_response
menu.push :project, { :controller => 'bids', :action => 'show_project' }, :caption => :label_bidding_project menu.push :project, { :controller => 'bids', :action => 'show_project' }, :caption => :label_bidding_project
# menu.push :homework_respond, {:controller => 'bids', :action => 'homework_respond'}
end end
Redmine::MenuManager.map :application_menu do |menu| Redmine::MenuManager.map :application_menu do |menu|
# Empty # Empty

Loading…
Cancel
Save