需求里面添加了用户和项目与需求的联系

This commit is contained in:
baiyu 2013-10-19 09:35:14 +08:00
parent 9fa9aa0fb8
commit 0206d3f2c3
8 changed files with 165 additions and 6 deletions

View File

@ -6,7 +6,8 @@ class BidsController < ApplicationController
menu_item :homework_respond, :only => :homework_respond
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]
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]
before_filter :require_login,:only => [:set_reward]
helper :watchers
@ -235,6 +236,60 @@ class BidsController < ApplicationController
end
end
def show_bid_project
bids = Bid.where('parent_id = ?', @bid.id)
@projects = []
for bid in bids
@projects += bid.biding_projects
end
respond_to do |format|
if @bid.reward_type == 3
format.html {
render :layout => 'base_homework'
}
elsif @bid.reward_type == 1
format.html {
render :layout => 'base_bids'
}
else
format.html {
render :layout => 'base_contest'
}
end
format.api
end
end
def show_bid_user
bids = Bid.where('parent_id = ?', @bid.id)
@users = []
for bid in bids
for project in bid.projects
@users += project.users
end
end
respond_to do |format|
if @bid.reward_type == 3
format.html {
render :layout => 'base_homework'
}
elsif @bid.reward_type == 1
format.html {
render :layout => 'base_bids'
}
else
format.html {
render :layout => 'base_contest'
}
end
format.api
end
end
def show_project
# flash[:notice] = ""
@membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))

View File

@ -105,4 +105,24 @@ module BidsHelper
def get_prize(b_project)
b_project.get_reward
end
def count_bid_project
bids = Bid.where('parent_id = ?', @bid.id)
@projects = []
for bid in bids
@projects += bid.biding_projects
end
@projects.count
end
def count_bid_user
bids = Bid.where('parent_id = ?', @bid.id)
@users = []
for bid in bids
for project in bid.projects
@users += project.users
end
end
@users.count
end
end

View File

@ -7,11 +7,14 @@ class Bid < ActiveRecord::Base
belongs_to :course
has_many :biding_projects, :dependent => :destroy
has_many :projects, :through => :biding_projects
has_many :projects_member, :class_name => 'User', :through => :projects
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
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 :fork_homework, :class_name => 'Bid', :conditions => "#{Bid.table_name}.parent_id = #{id}"
acts_as_attachable

View File

@ -8,7 +8,7 @@
</div>
<% end %>
<table width="1000px" border="0" style="padding-left: 15px">
<td class="font_lighter" style="font-size: 15px;"><%= l(:label_homework_project) %>(<%= @bidding_project.count%>)</td>
<td class="font_lighter" style="font-size: 15px;"><%= l(:label_homework_project) %>(<%= bidding_project.count%>)</td>
<td>
<% if User.current.logged? && (!Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.roles&Role.where('id = ? or id = ?', 5, 7)).size >0) %>
@ -18,7 +18,7 @@
<% end %>
</td>
</table>
<!-- <% @bidding_project.each do |b_project|%>
<!-- <% bidding_project.each do |b_project|%>
<table width="90%" border="0" align='center'>
<tr>
<td>
@ -63,7 +63,7 @@
<% else %>
<table width="1000px" border="0" style="padding-left: 15px">
<td class="font_lighter" style="font-size: 15px;"><%= l(:label_bidding_project) %>(<%= @bidding_project.count%>)</td>
<td class="font_lighter" style="font-size: 15px;"><%= l(:label_bidding_project) %>(<%= bidding_project.count%>)</td>
<% if User.current.logged? %>
<td>
<div class='icon icon-add'>
@ -72,7 +72,7 @@
<% end %>
</table>
<!-- <% @bidding_project.each do |b_project|%>
<!-- <% bidding_project.each do |b_project|%>
<table width="90%" border="0" align='center'>
<tr>
<td>
@ -112,4 +112,4 @@
</table>
<% end %> -->
<% end %>
<%= render :partial=> "list_projects",:locals => {:bidding_project => @bidding_project,:bid => @bid }%>
<%= render :partial=> "list_projects",:locals => {:bidding_project => bidding_project,:bid => @bid }%>

View File

@ -0,0 +1,42 @@
<% @projects.each do |b_project|%>
<table width="90%" border="0" align='center'>
<tr>
<td>
<table width="660px" border="0" align='center'>
<tr>
<td width="50px" valign="top" colspan="2" align="middle">
<div style="width: 50px; height: 50px;">
<%= link_to image_tag(url_to_avatar(b_project.project), :class => 'avatar3'), :class => "avatar" %>
</div></td>
<td width="60%" valign="top">
<table width="100%" valign="top">
<tr>
<td colspan="2" valign="top"><strong><%= link_to(b_project.project.name, project_path(b_project.project)) %></strong><a class="font_lighter"><%= l(:label_jion_bidding_homework)%></a></td>
</tr>
<tr></tr>
<tr>
<td valign="top"><%= b_project.project.description %></td>
</tr>
<tr>
<td valign="top"><a class="font_lighter"><%=format_time(b_project.created_at) %></a></td>
</tr>
</table></td>
<td width="30%">
<div class="bid-user-message" style="border-left: 1px solid rgb(225, 225, 225); margin-left: 20px; padding-left: 20px;">
<table width="100%">
<tr>
<td><%= l(:label_bidding_user_studentcode) %> : <%= @user.user_extensions.student_id %></td>
</tr>
<tr>
<td><%= l(:label_bidding_user_homework) %> : <%= link_to(b_project.user.name, user_path(b_project.user)) %></td>
</tr>
<tr>
<td style=" word-wrap: break-word; word-break: break-all"><%= l(:label_bidding_reason_homewrok) %> : <%= b_project.description %></td>
</tr>
</table>
</div></td>
</tr>
</table></td>
</tr>
</table>
<% end %>

View File

@ -0,0 +1,30 @@
<div class="inf_user_image">
<% for user in @users %>
<ul class="list_watch"><li>
<table width="660px" border="0" align="center">
<tr>
<td colspan="2" valign="top" width="50" ><%= link_to image_tag(url_to_avatar(user), :class => "avatar"), user_path(user), :title => "#{user.name}" %></td>
<td><table width="580px" border="0">
<tr>
<td colspan="2" valign="top"><strong><%= content_tag "div", link_to_user(user), :class => "project_avatar_name" %>
</td>
</tr>
<tr>
<td colspan="2" width="580px" ><p class="font_description">
<% unless user.memberships.empty? %>
<%= l(:label_x_contribute_to, :count => user.memberships.count) %>
<% for member in user.memberships %>
<%= link_to_project(member.project) %><%= (user.memberships.last == member) ? '' : '' %>
<% end %>
<% end %>
</p></td>
</tr>
<tr>
<td width="200" align="right" class="font_lighter"><%= l(:label_user_joinin) %><%= format_date(user.created_on) %>
</td>
</tr>
</table></td>
</tr>
</table></li></ul>
<% end %>
</div>

View File

@ -72,6 +72,13 @@
<td><div style="color: rgb(255, 0, 0); font-size: 14px"><%= l(:label_has_been)%>&nbsp;<%= link_to(Bid.where('parent_id = ?', @bid.id).count, show_course_path(@bid), :class => 'reference') %>&nbsp;
<%= l(:label_course_userd_by)%></div></td>
</tr>
<tr>
<td><div style="color: rgb(255, 0, 0); font-size: 14px">有&nbsp;<%= link_to(count_bid_project, show_bid_project_path(@bid), :class => 'reference') %>&nbsp;
个项目正在应标需求</div></td>
</tr>
<td><div style="color: rgb(255, 0, 0); font-size: 14px">有&nbsp;<%= link_to(count_bid_user, show_bid_user_path(@bid), :class => 'reference') %>&nbsp;
个用户正在努力完成此需求</div></td>
</tr>
</table>
<div>
<%= link_to l(:label_x_followers, :count => @bid.watcher_users.count)+"("+@bid.watcher_users.count.to_s+")", respond_path(@bid) %> &nbsp;

View File

@ -456,6 +456,8 @@ RedmineApp::Application.routes.draw do
match 'project/enterprise_course', :to => 'projects#enterprise_course'
match 'project/course_enterprise', :to => 'projects#course_enterprise'
match 'calls/:id/show_course', :to => 'bids#show_course', :as => 'show_course'
match 'calls/:id/show_bid_project', :to => 'bids#show_bid_project', :as => 'show_bid_project'
match 'calls/:id/show_bid_user', :to => 'bids#show_bid_user', :as => 'show_bid_user'
post 'join_in/join', :to => 'courses#join', :as => 'join'
delete 'join_in/join', :to => 'courses#unjoin'