2013-08-04 10:59:25 +08:00
|
|
|
# fq
|
2013-08-01 10:33:49 +08:00
|
|
|
class BidsController < ApplicationController
|
2013-08-10 10:25:30 +08:00
|
|
|
#Added by young
|
|
|
|
menu_item :respond
|
|
|
|
menu_item :project, :only => :show_project
|
|
|
|
#Ended by young
|
2013-08-06 22:26:52 +08:00
|
|
|
before_filter :find_bid, :only => [:show, :show_project, :create, :destroy, :more, :back, :add, :new]
|
2013-08-01 10:33:49 +08:00
|
|
|
|
|
|
|
helper :watchers
|
|
|
|
def index
|
2013-08-06 21:43:06 +08:00
|
|
|
# Modified by nie
|
|
|
|
# @requirement_title = "4"
|
2013-08-15 18:50:44 +08:00
|
|
|
@offset, @limit = api_offset_and_limit({:limit => 10})
|
2013-08-06 21:43:06 +08:00
|
|
|
@bids = Bid.visible
|
|
|
|
@bids = @bids.like(params[:name]) if params[:name].present?
|
|
|
|
@bid_count = @bids.count
|
2013-08-04 10:11:38 +08:00
|
|
|
@bid_pages = Paginator.new @bid_count, @limit, params['page']
|
2013-09-12 10:41:15 +08:00
|
|
|
|
2013-08-05 22:47:01 +08:00
|
|
|
@offset ||= @bid_pages.reverse_offset
|
2013-08-06 21:43:06 +08:00
|
|
|
#@bids = @bids.offset(@offset).limit(@limit).all.reverse
|
2013-09-12 10:41:15 +08:00
|
|
|
# unless @offset == 0
|
|
|
|
# @bids = @bids.offset(@offset).limit(@limit).all.reverse
|
|
|
|
# else
|
|
|
|
# limit = @bid_count % @limit
|
|
|
|
# @bids = @bids.offset(@offset).limit(limit).all.reverse
|
|
|
|
# end
|
|
|
|
#added by nie
|
|
|
|
if params[:bid_sort_type].present?
|
|
|
|
case params[:bid_sort_type]
|
|
|
|
when '0'
|
|
|
|
unless @offset == 0
|
|
|
|
@bids = @bids.offset(@offset).limit(@limit).all.reverse
|
|
|
|
else
|
|
|
|
limit = @bid_count % @limit
|
|
|
|
@bids = @bids.offset(@offset).limit(limit).all.reverse
|
|
|
|
end
|
|
|
|
@s_state = 0
|
|
|
|
when '1'
|
|
|
|
unless @offset == 0
|
|
|
|
@bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse
|
|
|
|
else
|
|
|
|
limit = @bid_count % @limit
|
|
|
|
@bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse
|
|
|
|
end
|
|
|
|
@s_state = 1
|
|
|
|
when '2'
|
|
|
|
unless @offset == 0
|
|
|
|
@bids = @bids.offset(@offset).limit(@limit).all.reverse
|
|
|
|
else
|
|
|
|
limit = @bid_count % @limit
|
|
|
|
@bids = @bids.offset(@offset).limit(@limit).all.reverse
|
|
|
|
end
|
|
|
|
@s_state = 0
|
|
|
|
end
|
2013-08-05 22:47:01 +08:00
|
|
|
else
|
2013-09-12 10:41:15 +08:00
|
|
|
unless @offset == 0
|
|
|
|
@bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse
|
|
|
|
else
|
|
|
|
limit = @bid_count % @limit
|
|
|
|
@bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse
|
|
|
|
end
|
|
|
|
@s_state = 1
|
2013-08-05 22:47:01 +08:00
|
|
|
end
|
2013-09-12 10:41:15 +08:00
|
|
|
#end
|
2013-08-08 10:04:44 +08:00
|
|
|
# @limit = api_offset_and_limit({:limit => 5})
|
|
|
|
# @bids = Bid.visible
|
|
|
|
# @bids = @bids.like(params[:name]) if params[:name].present?
|
|
|
|
# @bid_count = @bids.count
|
|
|
|
# @bid_pages = Paginator.new @bid_count, @limit, params['page']
|
|
|
|
# @offset ||= @bid_pages.reverse_offset
|
|
|
|
# #@bids = @bids.offset(@offset).limit(@limit).all.reverse
|
|
|
|
# unless @offset == 0
|
|
|
|
# @bids = @bid_count.offset(@offset).limit(@limit).all.reverse
|
|
|
|
# else
|
|
|
|
# limit = @bid_count%@limit
|
|
|
|
# @bids = @bid_count.offset(@offset).limit(limit).all.reverse
|
|
|
|
# end
|
|
|
|
# #end
|
2013-08-01 10:33:49 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@user = @bid.author
|
2013-08-15 09:54:08 +08:00
|
|
|
@jours = @bid.journals_for_messages.reverse
|
|
|
|
@limit = 10
|
|
|
|
@feedback_count = @jours.count
|
|
|
|
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
|
|
|
|
@offset ||= @feedback_pages.offset
|
|
|
|
@jour = @jours[@offset, @limit]
|
|
|
|
@state = false
|
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
#
|
|
|
|
# @journals = @bid.journals.includes(:user, :details).reorder("#{Journal.table_name}.id ASC").all
|
2013-08-15 09:54:08 +08:00
|
|
|
# @journals.each_with_index {|j,i| j.indice = i+1}
|
2013-08-01 10:33:49 +08:00
|
|
|
respond_to do |format|
|
2013-09-13 10:11:36 +08:00
|
|
|
if @bid.reward_type == 3
|
2013-08-01 10:33:49 +08:00
|
|
|
format.html {
|
2013-09-13 10:11:36 +08:00
|
|
|
render :layout => 'base_homework'
|
|
|
|
}
|
|
|
|
else
|
|
|
|
format.html {
|
2013-08-01 10:33:49 +08:00
|
|
|
render :layout => 'base_bids'
|
|
|
|
}
|
2013-09-13 10:11:36 +08:00
|
|
|
end
|
2013-08-01 10:33:49 +08:00
|
|
|
format.api
|
2013-09-13 10:11:36 +08:00
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def show_project
|
2013-08-08 22:27:58 +08:00
|
|
|
# flash[:notice] = ""
|
2013-08-01 20:47:00 +08:00
|
|
|
@membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
|
|
|
|
@option = []
|
|
|
|
@membership.each do |membership|
|
|
|
|
@option << membership.project
|
|
|
|
end
|
|
|
|
# a = [1]
|
|
|
|
# @project = Project.where("id in []", a)
|
2013-08-01 10:33:49 +08:00
|
|
|
@user = @bid.author
|
|
|
|
@bidding_project = @bid.biding_projects
|
|
|
|
respond_to do |format|
|
2013-09-13 10:11:36 +08:00
|
|
|
if @bid.reward_type == 3
|
2013-08-01 10:33:49 +08:00
|
|
|
format.html {
|
2013-09-13 10:11:36 +08:00
|
|
|
render :layout => 'base_homework'
|
|
|
|
}
|
|
|
|
else
|
|
|
|
format.html {
|
2013-08-01 10:33:49 +08:00
|
|
|
render :layout => 'base_bids'
|
|
|
|
}
|
2013-09-13 10:11:36 +08:00
|
|
|
end
|
2013-08-01 10:33:49 +08:00
|
|
|
format.api
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-09-13 16:36:36 +08:00
|
|
|
|
|
|
|
##### by huang
|
|
|
|
def show_project_homework
|
|
|
|
# flash[:notice] = ""
|
|
|
|
@membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
|
|
|
|
@option = []
|
|
|
|
@membership.each do |membership|
|
|
|
|
@option << membership.project
|
|
|
|
end
|
|
|
|
# a = [1]
|
|
|
|
# @project = Project.where("id in []", a)
|
|
|
|
@user = @bid.author
|
|
|
|
@bidding_project = @bid.biding_projects
|
|
|
|
respond_to do |format|
|
|
|
|
if @bid.reward_type == 3
|
|
|
|
format.html {
|
|
|
|
render :layout => 'base_homework'
|
|
|
|
}
|
|
|
|
else
|
|
|
|
format.html {
|
|
|
|
render :layout => 'base_bids'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
format.api
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-08-08 10:04:44 +08:00
|
|
|
###添加应标项目
|
2013-08-01 10:33:49 +08:00
|
|
|
def add
|
2013-08-01 20:47:00 +08:00
|
|
|
project = Project.where('name = ?', params[:bid]).first
|
2013-08-01 10:33:49 +08:00
|
|
|
bid_message = params[:bid_for_save][:bid_message]
|
2013-08-08 22:27:58 +08:00
|
|
|
if BidingProject.where("project_id = ? and bid_id = ?", project.id, @bid.id).size == 0
|
|
|
|
if BidingProject.cerate_bidding(@bid.id, project.id, bid_message)
|
|
|
|
flash[:notice] = l(:label_bidding_succeed)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
flash[:error] = l(:label_bidding_fail)
|
|
|
|
end
|
2013-08-01 10:33:49 +08:00
|
|
|
@bidding_project = @bid.biding_projects
|
|
|
|
respond_to do |format|
|
|
|
|
# format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}}
|
2013-08-08 22:27:58 +08:00
|
|
|
# format.html
|
|
|
|
format.html { redirect_to :back }
|
2013-08-01 10:33:49 +08:00
|
|
|
format.js
|
|
|
|
#format.api { render_api_ok }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-08-08 10:04:44 +08:00
|
|
|
## 新建留言
|
2013-08-01 10:33:49 +08:00
|
|
|
def create
|
2013-08-08 10:04:44 +08:00
|
|
|
|
2013-08-15 09:54:08 +08:00
|
|
|
if params[:bid_message][:message].size>0
|
|
|
|
if params[:reference_content]
|
2013-09-12 10:41:15 +08:00
|
|
|
message = params[:bid_message][:message] + "\n" + params[:reference_content]
|
2013-08-15 09:54:08 +08:00
|
|
|
else
|
|
|
|
message = params[:bid_message][:message]
|
|
|
|
end
|
2013-08-06 22:26:52 +08:00
|
|
|
refer_user_id = params[:bid_message][:reference_user_id].to_i
|
|
|
|
@bid.add_jour(User.current, message, refer_user_id)
|
2013-08-01 10:33:49 +08:00
|
|
|
# if a_message.size > 5
|
|
|
|
# @message = a_message[-5, 5]
|
|
|
|
# else
|
|
|
|
# @message = a_message
|
|
|
|
# end
|
|
|
|
# @message_count = a_message.count
|
|
|
|
end
|
2013-08-15 09:54:08 +08:00
|
|
|
@user = @bid.author
|
|
|
|
@jours = @bid.journals_for_messages.reverse
|
|
|
|
@limit = 10
|
|
|
|
@feedback_count = @jours.count
|
|
|
|
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
|
|
|
|
@offset ||= @feedback_pages.offset
|
|
|
|
@jour = @jours[@offset, @limit]
|
|
|
|
@bid.set_commit(@feedback_count)
|
2013-08-01 10:33:49 +08:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
|
|
|
#format.api { render_api_ok }
|
|
|
|
end
|
2013-08-08 10:04:44 +08:00
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
end
|
|
|
|
|
2013-08-08 10:04:44 +08:00
|
|
|
##删除留言
|
2013-08-01 10:33:49 +08:00
|
|
|
def destroy
|
2013-08-15 09:54:08 +08:00
|
|
|
@user = @bid.author
|
2013-09-12 10:41:15 +08:00
|
|
|
if User.current.admin? || User.current.id == @user.id
|
|
|
|
JournalsForMessage.delete_message(params[:object_id])
|
|
|
|
end
|
2013-08-15 09:54:08 +08:00
|
|
|
@jours = @bid.journals_for_messages.reverse
|
|
|
|
@limit = 10
|
|
|
|
@feedback_count = @jours.count
|
|
|
|
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
|
|
|
|
@offset ||= @feedback_pages.offset
|
|
|
|
@jour = @jours[@offset, @limit]
|
|
|
|
|
|
|
|
@bid.set_commit(@feedback_count)
|
2013-08-01 10:33:49 +08:00
|
|
|
# if a_message.size > 5
|
|
|
|
# @message = a_message[-5, 5]
|
|
|
|
# else
|
|
|
|
# @message = a_message
|
|
|
|
# end
|
|
|
|
# @message_count = a_message.count
|
|
|
|
|
|
|
|
respond_to do |format|
|
2013-08-05 22:47:01 +08:00
|
|
|
# format.html
|
2013-08-01 10:33:49 +08:00
|
|
|
format.js
|
|
|
|
#format.api { render_api_ok }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-08-08 10:04:44 +08:00
|
|
|
##引用
|
2013-08-01 10:33:49 +08:00
|
|
|
def new
|
|
|
|
@jour = JournalsForMessage.find(params[:journal_id]) if params[:journal_id]
|
|
|
|
if @jour
|
|
|
|
user = @jour.user
|
|
|
|
text = @jour.notes
|
|
|
|
else
|
|
|
|
user = @bid.author
|
|
|
|
text = @bid.description
|
|
|
|
end
|
|
|
|
# Replaces pre blocks with [...]
|
|
|
|
text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
|
2013-08-15 09:54:08 +08:00
|
|
|
@content = "> #{ll(Setting.default_language, :text_user_wrote, user)}\n> "
|
2013-08-01 10:33:49 +08:00
|
|
|
@content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
|
2013-08-06 22:26:52 +08:00
|
|
|
@id = user.id
|
2013-08-01 10:33:49 +08:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
render_404
|
|
|
|
end
|
2013-08-02 08:53:07 +08:00
|
|
|
|
2013-08-08 10:04:44 +08:00
|
|
|
##新建需求
|
2013-08-01 10:33:49 +08:00
|
|
|
def new_bid
|
2013-08-20 16:32:45 +08:00
|
|
|
@bid = Bid.new
|
|
|
|
@bid.safe_attributes = params[:bid]
|
2013-09-12 10:41:15 +08:00
|
|
|
# if params[:bid_title]
|
|
|
|
# # if params[:bid_budget].to_s =~ /^(\d+)$|^(\d+).([0-9]{2})$/
|
|
|
|
# unless params[:bid_reward_type] == "0"
|
|
|
|
# if params[:bid_deadline].to_s =~ /^[\d]{4}[-][\d]{1,2}[-][\d]{1,2}$/
|
|
|
|
# bid = Bid.creat_bids(params[:bid_budget], params[:bid_deadline], params[:bid_title] , params[:bid_description], params[:bid_reward_type].to_i)
|
|
|
|
# unless bid.watched_by?(User.current)
|
|
|
|
# if bid.add_watcher(User.current)
|
|
|
|
# flash[:notice] = l(:label_bid_succeed)
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
# else
|
|
|
|
# flash[:error] = l(:label_wrong_date)
|
|
|
|
# end
|
|
|
|
# else
|
|
|
|
# flash[:error] = "wrong"
|
|
|
|
# end
|
|
|
|
# # else
|
|
|
|
# # flash[:error] = l(:label_wrong_budget)
|
|
|
|
# # end
|
|
|
|
# end
|
|
|
|
# @limit = 5
|
|
|
|
# @bid_count = Bid.count
|
|
|
|
# @bid_pages = Paginator.new @bid_count, @limit, params['page']
|
|
|
|
# @offset ||= @bid_pages.offset
|
|
|
|
# @bids = Bid.offset(@offset).limit(@limit).all
|
|
|
|
# respond_to do |format|
|
|
|
|
# # format.html
|
|
|
|
# format.html { redirect_to :back }
|
|
|
|
# format.js
|
|
|
|
# # format.api { render_api_ok }
|
|
|
|
# end
|
2013-08-20 16:32:45 +08:00
|
|
|
end
|
2013-09-12 10:41:15 +08:00
|
|
|
|
2013-08-20 16:32:45 +08:00
|
|
|
def create_bid
|
|
|
|
@bid = Bid.new
|
|
|
|
@bid.name = params[:bid][:name]
|
|
|
|
@bid.description = params[:bid][:description]
|
|
|
|
@bid.reward_type = params[:bid_reward_type]
|
|
|
|
@bid.budget = params[:bid][:budget]
|
|
|
|
@bid.deadline = params[:bid][:deadline]
|
|
|
|
@bid.author_id = User.current.id
|
|
|
|
@bid.commit = 0
|
|
|
|
if @bid.save
|
2013-08-22 20:26:56 +08:00
|
|
|
unless @bid.watched_by?(User.current)
|
|
|
|
if @bid.add_watcher(User.current)
|
|
|
|
flash[:notice] = l(:label_bid_succeed)
|
|
|
|
end
|
|
|
|
end
|
2013-08-20 16:32:45 +08:00
|
|
|
redirect_to respond_path(@bid)
|
2013-08-20 17:34:33 +08:00
|
|
|
else
|
|
|
|
@bid.safe_attributes = params[:bid]
|
|
|
|
render :action => 'new_bid'
|
2013-08-04 10:11:38 +08:00
|
|
|
end
|
2013-08-01 10:33:49 +08:00
|
|
|
end
|
2013-09-12 10:41:15 +08:00
|
|
|
|
|
|
|
def create_homework
|
|
|
|
@bid = Bid.new
|
|
|
|
@bid.name = params[:bid][:name]
|
|
|
|
@bid.description = params[:bid][:description]
|
|
|
|
@bid.reward_type = 3
|
|
|
|
# @bid.budget = params[:bid][:budget]
|
|
|
|
@bid.deadline = params[:bid][:deadline]
|
|
|
|
@bid.budget = 0
|
|
|
|
@bid.author_id = User.current.id
|
|
|
|
@bid.commit = 0
|
|
|
|
# @bid.
|
|
|
|
if @bid.save
|
|
|
|
HomeworkForCourse.create(:project_id => params[:course_id], :bid_id => @bid.id)
|
|
|
|
unless @bid.watched_by?(User.current)
|
|
|
|
if @bid.add_watcher(User.current)
|
|
|
|
flash[:notice] = l(:label_bid_succeed)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
redirect_to respond_path(@bid)
|
|
|
|
else
|
|
|
|
@bid.safe_attributes = params[:bid]
|
|
|
|
render :action => 'new_bid'
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2013-08-01 10:33:49 +08:00
|
|
|
|
|
|
|
def more
|
|
|
|
@jour = @bid.journals_for_messages
|
|
|
|
@jour.each_with_index {|j,i| j.indice = i+1}
|
|
|
|
@state = true
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to :back }
|
|
|
|
format.js
|
|
|
|
#format.api { render_api_ok }
|
|
|
|
end
|
|
|
|
end
|
2013-09-12 10:41:15 +08:00
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
|
|
|
|
def back
|
|
|
|
@jour = @bid.journals_for_messages
|
|
|
|
@jour.each_with_index {|j,i| j.indice = i+1}
|
|
|
|
@state = false
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to :back }
|
|
|
|
format.js
|
|
|
|
#format.api { render_api_ok }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def find_bid
|
2013-08-05 22:47:01 +08:00
|
|
|
if params[:id]
|
|
|
|
@bid = Bid.find(params[:id])
|
2013-08-01 10:33:49 +08:00
|
|
|
end
|
|
|
|
rescue
|
|
|
|
render_404
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|