This commit is contained in:
z9hang 2014-06-18 17:35:26 +08:00
commit 3c89de4c81
9 changed files with 69 additions and 8 deletions

View File

@ -77,6 +77,7 @@ class HomeworkAttachController < ApplicationController
if bid.homeworks.where("user_id = ?",User.current).count == 0 if bid.homeworks.where("user_id = ?",User.current).count == 0
user_id = params[:user_id] user_id = params[:user_id]
bid_id = params[:bid_id] bid_id = params[:bid_id]
project_id = params[:new_form][:project_id]
sta = 0 sta = 0
name = params[:new_form][:name] name = params[:new_form][:name]
description = params[:new_form][:description] description = params[:new_form][:description]
@ -85,7 +86,8 @@ class HomeworkAttachController < ApplicationController
:state => sta, :state => sta,
:name => name, :name => name,
:description => description, :description => description,
:bid_id => bid_id :bid_id => bid_id,
:project_id => project_id
} }
@ -177,8 +179,10 @@ class HomeworkAttachController < ApplicationController
if User.current.admin? || User.current.member_of?(course) if User.current.admin? || User.current.member_of?(course)
name = params[:homework_name] name = params[:homework_name]
description = params[:homework_description] description = params[:homework_description]
project_id = params[:homework_attach][:project_id]
@homework.name = name @homework.name = name
@homework.description = description @homework.description = description
@homework.project_id = project_id
if params[:attachments] if params[:attachments]
@homework.save_attachments(params[:attachments]) @homework.save_attachments(params[:attachments])
end end
@ -196,7 +200,7 @@ class HomeworkAttachController < ApplicationController
def destroy def destroy
#@homework = HomeworkAttach.find(params[:id]) #@homework = HomeworkAttach.find(params[:id])
if User.current.admin? || User.current == @homework if User.current.admin? || User.current == @homework.user
if @homework.destroy if @homework.destroy
respond_to do |format| respond_to do |format|
format.html { redirect_to project_for_bid_path @homework.bid } format.html { redirect_to project_for_bid_path @homework.bid }

View File

@ -54,4 +54,16 @@ module HomeworkAttachHelper
raise RuntimeError, 'unknow type, Please input you type into this helper.' raise RuntimeError, 'unknow type, Please input you type into this helper.'
end end
end end
def user_projects_option
projects = Project.where("id < 8")
type = []
projects.each do |project|
option = []
option << project.name
option << project.id
type << option
end
type
end
end end

View File

@ -9,6 +9,7 @@ class HomeworkAttach < ActiveRecord::Base
has_many :homework_users, :dependent => :destroy has_many :homework_users, :dependent => :destroy
has_many :users, :through => :homework_users has_many :users, :through => :homework_users
seems_rateable :allow_update => true, :dimensions => :quality seems_rateable :allow_update => true, :dimensions => :quality
belongs_to :project
safe_attributes "bid_id", safe_attributes "bid_id",
"user_id" "user_id"
@ -30,7 +31,7 @@ class HomeworkAttach < ActiveRecord::Base
result result
end end
def project def project_for_homework
work = HomeworkForCourse.find_by_bid_id(self.bid_id) work = HomeworkForCourse.find_by_bid_id(self.bid_id)
if work if work
work.project work.project

View File

@ -30,6 +30,7 @@ class Project < ActiveRecord::Base
# Specific overidden Activities # Specific overidden Activities
belongs_to :homework_attach
has_many :time_entry_activities has_many :time_entry_activities
has_many :members, :include => [:principal, :roles], :conditions => "#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}" has_many :members, :include => [:principal, :roles], :conditions => "#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}"
has_many :memberships, :class_name => 'Member' has_many :memberships, :class_name => 'Member'

View File

@ -42,11 +42,17 @@
<div class="box" id="content1"> <div class="box" id="content1">
<%= form_for(@homework) do |f|%> <%= form_for(@homework) do |f|%>
<p style=" padding: 3px 0 3px 0;padding-left: 50px; clear:left;"> <p style=" padding: 3px 0 3px 0;padding-left: 50px; clear:left;">
<strong>标 题:</strong> <strong>标&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;题:</strong>&nbsp;
<%= f.text_field :name, :required => true, :name => "homework_name", :size => 60, :style => "width:490px;"%> <%= f.text_field :name, :required => true, :name => "homework_name", :size => 60, :style => "width:490px;"%>
</p> </p>
<p style=" padding: 3px 0 3px 0;padding-left: 50px; clear:left;"> <p style=" padding: 3px 0 3px 0;padding-left: 50px; clear:left;">
<strong style="vertical-align: top">描 述:</strong> <strong>提交项目:</strong>
<%= f.select :project_id, options_for_select(user_projects_option,@homework.project.id),:name => "project_id", :required => true%>
<%= link_to '创建项目', new_project_path(course: 0, project_type: 0), :target => '_blank' %>
<p class="font_lighter" style="padding-left:120px;clear:left;">提交项目可以为空</p>
</p>
<p style=" padding: 3px 0 3px 0;padding-left: 50px; clear:left;">
<strong style="vertical-align: top">描&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;述:</strong>&nbsp;
<span style="margin-left:-10px;padding-right: 20px;"> <span style="margin-left:-10px;padding-right: 20px;">
<%= f.text_area :description, :rows => 8, :name => "homework_description", :class => 'wiki-edit', :style => "font-size:small;width:490px;margin-left:10px;" %> <%= f.text_area :description, :rows => 8, :name => "homework_description", :class => 'wiki-edit', :style => "font-size:small;width:490px;margin-left:10px;" %>
</span> </span>

View File

@ -26,6 +26,12 @@
<strong>标 题:</strong> <strong>标 题:</strong>
<%= f.text_field "name", :required => true, :size => 60, :style => "width:490px;" %> <%= f.text_field "name", :required => true, :size => 60, :style => "width:490px;" %>
</p> </p>
<p style=" padding: 3px 0 3px 0;padding-left: 50px; clear:left;">
<strong>提交项目:</strong>
<%= f.select :project_id, options_for_select(user_projects_option),:name => "project_id", :required => true%>
<%= link_to '创建项目', new_project_path(course: 0, project_type: 0), :target => '_blank' %>
<p class="font_lighter" style="padding-left:120px;clear:left;">提交项目可以为空</p>
</p>
<p style=" padding: 3px 0 3px 0;padding-left: 50px; clear:left;"> <p style=" padding: 3px 0 3px 0;padding-left: 50px; clear:left;">
<strong style="vertical-align: top">描 述:</strong> <strong style="vertical-align: top">描 述:</strong>
<span style="margin-left:-10px;padding-right: 20px;"> <span style="margin-left:-10px;padding-right: 20px;">

View File

@ -0,0 +1,5 @@
class AddProjectIdToHomeworkAttach < ActiveRecord::Migration
def change
add_column :homework_attaches, :project_id, :integer, default: 0
end
end

View File

@ -0,0 +1,25 @@
class RemoveDataToHomeworkAttach < ActiveRecord::Migration
def up
bidding_projects = BidingProject.joins(:bid).where("bids.reward_type = 3")
bidding_projects.each do |biding|
homework = HomeworkAttach.new
homework.project_id = biding.project_id
homework.bid_id = biding.bid_id
homework.created_at = biding.created_at
homework.updated_at = biding.updated_at
homework.reward = biding.reward
homework.description = biding.description
homework.user_id = biding.user_id
homework.state = 0
homework.save
end
end
def down
bidding_projects = BidingProject.joins(:bid).where("bids.reward_type = 3")
bidding_projects.each do |biding|
homework = HomeworkAttach.where("bid_id = #{biding.bid_id} and user_id = #{biding.user_id}")
homework.first.destroy
end
end
end

View File

@ -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 => 20140617013146) do ActiveRecord::Schema.define(:version => 20140618020535) do
create_table "activities", :force => true do |t| create_table "activities", :force => true do |t|
t.integer "act_id", :null => false t.integer "act_id", :null => false
@ -348,12 +348,13 @@ ActiveRecord::Schema.define(:version => 20140617013146) do
create_table "homework_attaches", :force => true do |t| create_table "homework_attaches", :force => true do |t|
t.integer "bid_id" t.integer "bid_id"
t.integer "user_id" t.integer "user_id"
t.datetime "created_at", :null => false t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false t.datetime "updated_at", :null => false
t.string "reward" t.string "reward"
t.string "name" t.string "name"
t.string "description" t.string "description"
t.integer "state" t.integer "state"
t.integer "project_id", :default => 0
end end
create_table "homework_for_courses", :force => true do |t| create_table "homework_for_courses", :force => true do |t|