-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1732cef
commit 61d586e
Showing
14 changed files
with
188 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,11 @@ | |
%p | ||
If you're new around here, things might be a bit confusing the first time you register. | ||
Rest assured that any problem you are facing, someone has likely experienced before. | ||
%p | ||
Email [email protected] if you need assistance. | ||
%ul | ||
- # %li= link_to 'Tutorial: Signing up for leagues.afdc.com', 'http://toomuchpete.clarify-it.com/d/fvm4pl' | ||
- # %li= link_to 'Tutorial: Reset or change your password', 'http://toomuchpete.clarify-it.com/d/dh9xta' | ||
- # %li= link_to 'Tutorial: Updating your gRank', 'http://toomuchpete.clarify-it.com/d/ddna6c' | ||
- # %li= link_to 'Tutorial: Registering for a league', 'http://toomuchpete.clarify-it.com/d/9lhk4h' | ||
%li= link_to 'Tutorial: Pairing with another player', 'https://docs.google.com/document/d/1SMOyrNxigKO__k5eSKrKo9DJ0W3YBEVHHbwnZAuSTrE/edit?usp=sharing' | ||
- # %li= link_to 'Tutorial: Pairing with another player', 'https://docs.google.com/document/d/1SMOyrNxigKO__k5eSKrKo9DJ0W3YBEVHHbwnZAuSTrE/edit?usp=sharing' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
= render 'games' | ||
.col-md-4 | ||
= render 'leagues' | ||
= render 'tutorials' | ||
%hr | ||
= render 'sponsors' | ||
- else | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
%p #{@invite.sender.name}: | ||
%p #{@invite.sender.name} & #{@invite.recipient.name}: | ||
|
||
%p | ||
Your request to pair with #{link_to(@invite.recipient.name, user_url(@invite.recipient))} | ||
for #{link_to(@league.name, league_url(@league))} has been #{@invite.status}. | ||
Nice job! You're paired up for #{link_to(@league.name, league_url(@league))}! | ||
|
||
- content_for :callout_box do | ||
Click | ||
=link_to "here", invitations_url | ||
to manage your existing invitations | ||
%b REMEMBER: | ||
%p | ||
Pairing only counts if both players are in the league. Pairing with someone | ||
on the waitlist does not guarantee that person a spot in the league. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
= f.select :gen_availability, [nil, '25%', '50%', '75%', '100%'], label: 'Availability' | ||
- if @registration.league.created_at > Date.new(2019, 4, 11) | ||
= f.select :shirt_size, [nil, 'XXL', 'XL', 'Large', 'Medium', 'Small', 'XS', 'XXS'], label: 'Unisex Shirt Size' | ||
.control-group | ||
.form-group | ||
.controls | ||
= f.check_box :eos_availability, value: 1, label: "Will attend end of season tourney" | ||
- rank_max = 6 if (@registration.league.sport == 'goaltimate' && @registration.user.gender == 'female') | ||
|
@@ -20,6 +20,39 @@ | |
- if permitted_to?(:manage, @registration.league) && @registration.persisted? | ||
= f.text_field :commish_rank, label: 'League Rank' | ||
= f.select :player_strength, [nil, 'Runner', 'Thrower', 'Both'] | ||
- if @league.allow_pairs? && [email protected]? | ||
- received_invites = @registration.received_invitations.outstanding | ||
- if received_invites.count > 0 | ||
.form-group | ||
%label.control-label Accept Pair Invite | ||
.controls | ||
- received_invites.each do |inv| | ||
%label.radio | ||
%input{type: 'radio', name: 'registration[pair_requested_user_id][]', class: 'received_invite_radio', value: inv.sender._id.to_s } | ||
=inv.sender.name | ||
.checkbox | ||
%label{for: 'ignore_received_invites'} | ||
%input{type: 'checkbox', id: 'ignore_received_invites', value: nil, checked: true} | ||
None of the Above | ||
|
||
- invited_user = @registration.sent_invitations.outstanding.first&.recipient | ||
- exclusion_list = PairingCoordinator.new(@league).excluded_players | ||
- exclusion_list.append(current_user._id.to_s) | ||
= render partial: '/user_multiselect', locals: {form: f, fieldname: 'pair_requested_user_id', label: "Invite Pair", users: [invited_user], limit: 1, exclude: exclusion_list} | ||
|
||
- if @registration.linked? | ||
.form-group | ||
%label.control-label Current Pair | ||
- if @registration.cored? | ||
%span.span3.uneditable-input n/a | ||
.controls | ||
%span.help-inline Cored Players Cannot Pair | ||
- else | ||
%span.span3.uneditable-input | ||
= @registration.pair.name | ||
.controls | ||
%span.form-control.help-inline To remove a confirmed pair, email [email protected] | ||
|
||
= f.text_area :notes, rows: 5 | ||
- if @registration.new_record? | ||
.control-group | ||
|
@@ -38,3 +71,23 @@ | |
= f.submit "Register", disable_with: 'Registering...', class: "btn btn-primary" | ||
- else | ||
= f.submit "Update", disable_with: 'Updating...', class: "btn btn-primary" | ||
|
||
|
||
- content_for :page_scripts do | ||
:javascript | ||
$(function(){ | ||
$('#ignore_received_invites').on('change', function(e){ | ||
if ($('#ignore_received_invites').is(':checked')) { | ||
$('.received_invite_radio').prop('checked', false); | ||
$('.user-multi-select .new-user').prop( "disabled", false); | ||
} | ||
}); | ||
|
||
$('.received_invite_radio').on('change', function(e){ | ||
if ($(e.target).is(':checked')) { | ||
$('#ignore_received_invites').prop('checked', false); | ||
$('.user-multi-select a.remove').click(); | ||
$('.user-multi-select .new-user').prop( "disabled", true); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# TODO: Exclude already-paired players from search results | ||
|
||
class PairingCoordinator | ||
attr_reader :league | ||
|
||
def initialize(league) | ||
@league = league | ||
end | ||
|
||
def request_pair(source_player, target_player) | ||
# puts "Requesting pair..." | ||
src_user = load_user(source_player) | ||
# puts "\t Source user loaded (#{source_player} => #{src_user&.name})" | ||
tgt_user = load_user(target_player) | ||
# puts "\t Source user loaded (#{target_player} => #{tgt_user&.name})" | ||
|
||
return false if src_user.nil? | ||
|
||
src_reg = @league.registration_for(src_user) | ||
tgt_reg = @league.registration_for(tgt_user) | ||
|
||
# Check if either player is already paired | ||
return false if src_reg&.linked? | ||
return false if tgt_reg&.linked? | ||
# puts "\t Neither user is paired/cored yet" | ||
|
||
# Cancel all outstanding sent pair requests: | ||
src_reg.sent_invitations.outstanding.update_all(status: "canceled") | ||
return true if tgt_user.nil? | ||
|
||
# Accept outstanding pair invite from the target player, if it exists | ||
if tgt_reg.present? && tgt_reg.sent_invitations.outstanding.where(recipient: src_user).exists? | ||
tgt_reg.sent_invitations.outstanding.where(recipient: src_user).first.accept | ||
# puts "\t Pair Successful!" | ||
return true | ||
end | ||
|
||
if src_reg.sent_invitations.where(recipient: tgt_user).exists? | ||
src_reg.sent_invitations.where(recipient: tgt_user).update(status: "sent") | ||
# puts "\t Reusing old Invite" | ||
return true | ||
end | ||
Invitation.create!(type: "pair", sender: src_user, recipient: tgt_user, handler: @league) | ||
end | ||
|
||
def excluded_players | ||
cored_list = RegistrationGroup.where(league: @league).all.inject([]) {|list, grp| list + grp.member_ids} | ||
captain_list = Team.where(league: @league).all.inject([]) {|list, team| list + team.captains.map(&:id)} | ||
paired_list = @league.registrations.where(:pair_id.exists => true).all.inject([]) {|list, reg| list.append(reg.user_id)} | ||
(cored_list + captain_list + paired_list).to_set.to_a.map(&:to_s) | ||
end | ||
|
||
private | ||
|
||
def load_user(identifier) | ||
if identifier.is_a?(User) | ||
return identifier | ||
end | ||
|
||
if identifier.is_a?(Registration) | ||
return identifier.user | ||
end | ||
|
||
if identifier.is_a?(String) or identifier.is_a?(BSON::ObjectId) | ||
return User.find(identifier) | ||
end | ||
end | ||
end |