Skip to content

Commit

Permalink
Merge branch 'expertiza:beta' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
LeooHsiang committed Mar 10, 2022
2 parents 1c2840c + 33b5c64 commit 6c08f31
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 44 deletions.
6 changes: 6 additions & 0 deletions app/controllers/join_team_requests_controller.rb
Expand Up @@ -36,6 +36,12 @@ def create
@join_team_request.team_id = params[:team_id]

participant = Participant.where(user_id: session[:user][:id], parent_id: params[:assignment_id]).first
team = Team.find(params[:team_id])
if team.participants.include? participant
flash[:error] = 'You already belong to the team'
redirect_back
return
end
@join_team_request.participant_id = participant.id
respond_to do |format|
if @join_team_request.save
Expand Down
6 changes: 4 additions & 2 deletions app/controllers/sign_up_sheet_controller.rb
Expand Up @@ -400,7 +400,9 @@ def save_topic_deadlines

# This method is called when a student click on the trumpet icon. So this is a bad method name. --Yang
def show_team
if !(assignment = Assignment.find(params[:assignment_id])).nil? && !(topic = SignUpTopic.find(params[:id])).nil?
assignment = Assignment.find(params[:assignment_id])
topic = SignUpTopic.find(params[:id])
if assignment && topic
@results = ad_info(assignment.id, topic.id)
@results.each do |result|
result.keys.each do |key|
Expand Down Expand Up @@ -480,7 +482,7 @@ def update_max_choosers(topic)
# clicks to see ads related to a topic
def ad_info(_assignment_id, topic_id)
@ad_information = []
@signed_up_teams = SignedUpTeam.where('topic_id = ?', topic_id.to_s)
@signed_up_teams = SignedUpTeam.where(topic_id: topic_id)
# Iterate through the results of the query and get the required attributes
@signed_up_teams.each do |signed_up_team|
team = signed_up_team.team
Expand Down
108 changes: 67 additions & 41 deletions app/views/sign_up_sheet/show_team.html.erb
@@ -1,46 +1,72 @@
<h2>
Partner Advertisements for Topic: <%= SignUpTopic.find(params[:id]).topic_name %>
</h2>


<table class="general">
<tr>
<th width="500">Team Name</th>
<th width="500">Members</th>
<th width="500">Desired Qualifications</th>
<th width="500">Action</th>
</tr>

<% count=0 %>
<% @results.each {|result|
%>
<%
team_members = ""
TeamsUser.where(team_id: result[:team_id]).each{|teamuser|
team_members+=User.find(teamuser.user_id).name+" "
}
if result[:advertise_for_partner] == true || result[:advertise_for_partner] == 1
%>
<tr>
<td align="center" width="500"><%= result[:name] %></td>
<td align="center" width="500"><%= team_members %></td>
<td align="center" width="500"><%= result[:comments_for_advertisement] %></td>
<% if Participant.where(parent_id: result[:assignment_id], user_id: session[:user].id).first!=nil %>
<td align="center"><%= link_to "Request invitation", :controller => 'join_team_requests', :action => 'new',
:assignment_id=>result[:assignment_id],
:topic_id=>result[:topic_id],
:team_id=>result[:team_id]
%>

<img src="/assets/info.png" title="Send request to join this team">
</td>
<%else%>
<td></td>
<% end
end %>

</tr>
</h2>

<table class="general">
<tr>
<th width="500">Team Name</th>
<th width="500">Members</th>
<th width="500">Desired Qualifications</th>
<th width="500">Action</th>
</tr>

<% requestors = [] %>
<% requestors_names = [] %>
<%# @results is the ad_info for an assignment's topic %>
<% @results.each {|result| %>
<%# Create a list of hashed requestors which have asked to join the team %>
<%
@join_team_requests = JoinTeamRequest.where(team_id: result[:team_id])
@join_team_requests.each do |join_team_request|
if join_team_request.status=='P'
requestors_names << User.find(Participant.find(join_team_request.participant_id).user_id).name
requestors << {name: User.find(Participant.find(join_team_request.participant_id).user_id).name, request_id: join_team_request.id}
end
end
%>
<%
team_members = []
TeamsUser.where(team_id: result[:team_id]).each{|teamuser|
team_members << User.find(teamuser.user_id).name
}
if result[:advertise_for_partner]|| result[:advertise_for_partner] == 1
%>
<tr>
<td align="center" width="500"><%= result[:name] %></td>
<td align="center" width="500"><%= team_members.join(', ') %></td>
<td align="center" width="500"><%= result[:comments_for_advertisement] %></td>
<% if Participant.where(parent_id: result[:assignment_id], user_id: session[:user].id).first && !team_members.include?(session[:user].name) && !requestors_names.include?(session[:user].name) %>
<td align="center"><%= link_to "Request invitation", :controller => 'join_team_requests', :action => 'new',
:assignment_id=>result[:assignment_id],
:topic_id=>result[:topic_id],
:team_id=>result[:team_id]
%>
<img src="/assets/info.png" title="Send request to join this team">
</td>
<% else %>
<% if team_members.include?(session[:user].name) %>
<td align="center"><img src="/assets/info.png" title="You're a member of this team and cannot request to join!"></td>
<% else %>
<%
desired_id = -1
requestors.each do |requestor|
if requestor[:name] == session[:user].name
desired_id = requestor[:request_id]
end
end
%>
<td align="center"><%= link_to "Edit invitation", :controller => 'join_team_requests', :action => 'edit',
:id=>desired_id
%>
<img src="/assets/info.png" title="Edit your request to join this team">
</td>
<% end %>
<% end %>
</tr>
<% end %>
<% } %>

</table>
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/sign_up_sheet_controller_spec.rb
Expand Up @@ -735,7 +735,7 @@

describe '#show_team' do
it 'renders show_team page' do
allow(SignedUpTeam).to receive(:where).with('topic_id = ?', '1').and_return([signed_up_team])
allow(SignedUpTeam).to receive(:where).with(topic_id: 1).and_return([signed_up_team])
allow(TeamsUser).to receive(:where).with(team_id: 1).and_return([double('TeamsUser', user_id: 1)])
allow(User).to receive(:find).with(1).and_return(student)
params = { assignment_id: 1, id: 1 }
Expand Down

0 comments on commit 6c08f31

Please sign in to comment.