Skip to content
Open

Ham #42

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/controllers/reasons_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ def create
@reason.user_id = current_user.id
@reason.pair_id = params[:pair_id]


respond_to do |format|
if @reason.save
format.html { redirect_to @reason, notice: 'Reason was successfully created.' }
format.html { redirect_to replacements_path, notice: 'Reason was successfully created.' }
format.json { render :show, status: :created, location: @reason }
else
format.html { render :new }
format.json { render json: @reason.errors, status: :unprocessable_entity }
end
end

end

# PATCH/PUT /reasons/1
Expand Down
11 changes: 11 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class UsersController < ApplicationController

before_action :set_user, only: [:show, :edit, :update, :destroy]

# GET /users
Expand Down Expand Up @@ -61,6 +62,16 @@ def destroy
end
end

def accept_pair
@current_user = User.last.username
@next_to_pair = User.first.username
redirect_to matrix_index_path
end

def replacements
@users = User.all
end

private
# Use callbacks to share common setup or constraints between actions.
def set_user
Expand Down
11 changes: 10 additions & 1 deletion app/controllers/welcome_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
require 'pairings_helper'

class WelcomeController < ApplicationController
include PairingsHelper

def index
@user = User.first

if current_user
@list = pair_me(current_user)
@next_pair = @list[0]
end

end


Expand Down
49 changes: 49 additions & 0 deletions app/helpers/pairings_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module PairingsHelper

# Return an array of potential partners in descending order of attractiveness
def pair_me(primary_user)
# Filter the available partners from the current cohort
# Next version should filter users already paired for today in pair history
available_users = unpaired_users_today(cohort_of_user(primary_user))

available_users = remove_user(available_users, primary_user)

@list_of_users = available_users.shuffle
@list_of_users
end

def save_entire_pair(users=[])
users.each do |user|
pair_id = Pairing.maximum(:pair_id).to_i+1
Pairing.create(pair_id: pair_id, user_id: user.id, cohort_id: user.cohort_id)
end
end

def users_in_same_cohort_as(user)
return User.where(cohort_id: user.cohort_id).find_each.to_a
end

def cohort_of_user(user)
return Cohort.where(id: user.cohort_id).first
end

def remove_user(user_list, reject_user=nil)
return user_list.reject { |user| user == reject_user }
end

def users_in_cohort(cohort)
return User.where(cohort_id: cohort.id).find_each.to_a
end

def unpaired_users_today(cohort)
return users_in_cohort(cohort).reject do |user|
Pairing.where("created_at >= ? AND user_id = ?", Time.zone.now.beginning_of_day, user.id).first != nil
end
end

# def assign_pairs(cohort_name)
# # this is a method used elsewhere
# # odd number should return a final pair of one person
# end

end
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class User < ActiveRecord::Base
def self.create_with_omniauth(auth)
create! do |user|
user.provider = auth.provider
user.cohort = Cohort.first
user.uid = auth.uid
user.name = auth.info.name
user.profile_picture = auth.info.image
Expand Down
16 changes: 10 additions & 6 deletions app/views/users/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
<table>
<thead>
<tr>
<th>Username</th>
<th>Full name</th>
<th>Profile picture</th>
<th>Slack username</th>
<th colspan="3"></th>
</tr>
<th>Username</th>
<th>Full name</th>
<th>Profile picture</th>
<th>Slack username</th>
<th colspan="3"></th>
</tr>
</thead>

<tbody>


<% @users.each do |user| %>
<tr>
<td><%= user.username %></td>
Expand All @@ -29,3 +31,5 @@
</table>

<br>

<%= link_to 'New User', new_user_path %>
4 changes: 4 additions & 0 deletions app/views/users/matrix.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
</br>
<%= "#{@current_user} and #{@next_to_pair}" %>
</br>
<%= "Congratulations on pairing." %>
5 changes: 5 additions & 0 deletions app/views/users/replacements.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ul>
<% for user in @users %>
<li><%= user.username %></li>
<% end %>
</ul>
122 changes: 47 additions & 75 deletions app/views/welcome/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,80 +18,52 @@
</head>

<body>
<header>
<h1>Pairmiscuous</h1>

<h3>"Not Pairing makes Pandas sad"</h3><br>
</header>

<div class="container">
<% unless current_user %>

<div class="loginimage">
<img src=
"http://img04.deviantart.net/7530/i/2015/112/e/e/panda_logo_by_designguru211-d63i4d4.png"><br>
</div>
<br>
<br>
<a class="btn btn-block btn-social btn-github"><i class=
"fa fa-github"></i>
<%=link_to "Sign in with Github", "/auth/github"%></a> <% else %>
<div class="container">

<div class="row">
<div class="githubuserimage col-xs-3 col-sm-2 col-md-2 col-lg-3">
<img src=
"https://avatars1.githubusercontent.com/u/782506?v=3&s=400">

<ul>
<li>
<p><strong>Username:</strong>
<%= @user.username %></p>

<p></p>
</li>

<li>
<p><strong>Full name:</strong>
<%= @user.full_name %></p>
</li>

<li>
<p><strong>Slack username:</strong>
<%= @user.slack_username %></p><%= link_to 'Edit', edit_user_path(@user) %>|
<%= link_to 'Back', users_path %>
</li>
</ul><img src=
"https://avatars0.githubusercontent.com/u/10839432?v=3&s=400">

<p>Github Pairname</p>

<p>Github slack name</p>

<p></p>
</div><br>
<a href="#">Yes</a> <a href="/pairs/new">No (submit
reason)</a><br>

<div class="dropdown">
<button class="btn btn-default dropdown-toggle"
data-toggle="dropdown" id="menu1" type="button">Cohort
<span class="caret"></span></button>

<ul class="dropdown-menu">
<li>
<a href="#" tabindex="-1">April 2015</a>
</li>
</ul><br>
</div>
</div>
</div>

<form>
<div class="form-group"></div><button class="btn btn-default" type=
"submit">Submit</button><br>
<% end %>
</form>
<br>


<header>
<center>
<h1>
Pairmiscuous
</h1>
<h3>"Not Pairing makes Pandas sad"</h3>

</header>
</header>
<div class="container">
<% unless current_user %>
<div class="loginimage">
<center>
<img src="http://img04.deviantart.net/7530/i/2015/112/e/e/panda_logo_by_designguru211-d63i4d4.png">
</div>
<br>
<br>

<GitButton>
<center>
<a class="btn btn-block btn-social btn-github">
<i class="fa fa-github"></i>
<%=link_to "Sign in with Github", "/auth/github"%>
</a>

</GitButton>
<% else %>
<%= "You are paired with #{@next_pair.username}" %>
<img src='<%= @next_pair.profile_picture %>'>
<%= link_to 'Accept', accept_pair_path %>
<%= link_to 'Reject (say reason)', new_reason_path %>

<% end %>
</div>








<script src="node_modules/bootstrap/dist/js/bootstrap.js"></script>


</body>
</html>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
get "/login" => 'sessions#new'
get "/auth/:provider/callback" => "sessions#create"
get "/signout" => "sessions#destroy", :as => :signout
get "/accept_pair" => 'users#accept_pair'
get "/replacements" => 'users#replacements'

# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
Expand Down
2 changes: 1 addition & 1 deletion coverage/.last_run.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"result": {
"covered_percent": 100.0
"covered_percent": 72.89
}
}
Loading