Skip to content

Commit

Permalink
fix order drop down, only orders by age or time, no tiebreaker based …
Browse files Browse the repository at this point in the history
…on votes
  • Loading branch information
aaronwiggins committed Aug 9, 2015
1 parent 8728b4f commit 1abf9a8
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 10 deletions.
2 changes: 2 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ $(function() {
});
});

// order function

$(function() {
$('.order').change(function(){
var selectValue = $(this).val();
Expand Down
21 changes: 16 additions & 5 deletions app/controllers/experiments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,22 @@ def index
end

def order_experiments
if params[:selectValue] == "1"
@sorted_experiments = Experiment.all.sort_by {|e| [e.age, -1*e.experiment_votes.count]}
elsif params[:selectValue] == "2"
@sorted_experiments = Experiment.all.sort_by {|e| [e.complete_time, -1*e.experiment_votes.count]}
end
@experiments = Experiment.text_search(params[:queryValue])
# if params[:selectValue] == "1"
# # if params[:selectValue] == "1" && params[:query]
# # @experiments = Experiment.text_search(params[:query])
# @sorted_experiments = Experiment.text_search(params[:query]).all.sort_by {|e| [e.age, -1*e.experiment_votes.count]}
# # else
# # @sorted_experiments = Experiment.all.sort_by {|e| [e.age, -1*e.experiment_votes.count]}
# # end
# elsif params[:selectValue] == "2"
# if params[:selectValue] == "2" && params[:query]
# #@experiments = Experiment.text_search(params[:query])
# @sorted_experiments = Experiment.text_search(params[:query]).all.sort_by {|e| [e.complete_time, -1*e.experiment_votes.count]}
# else
# @sorted_experiments = Experiment.all.sort_by {|e| [e.complete_time, -1*e.experiment_votes.count]}
# end
# end
end

# end
Expand Down
44 changes: 44 additions & 0 deletions app/views/experiments/_age_ordered.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<div class="index-wrapper">

<% experiments.order(:age).each do |experiment| %>

<div class="index-experiment-card">
<% if experiment.uploaded_file.blank? %>
<a href="<%= url_for experiment %>" class="index-photo" style="background-image: url(<%= image_path "bubbles.jpg" %>)">
<% else %>
<a href="<%= url_for experiment %>" class="index-photo" style="background-image: url('<%= experiment.uploaded_file %>')">
<% end %>
<span class="index-exp-title-bar"><h3 class="index-exp-title"><%= experiment.name %></h3>
<i class="fa fa-thumbs-up index-likes"> <%= pluralize experiment.votes, "like" %></i>
</span>
</a>

<div class="index-info">
<div class="index-exp-ratings">
<span class="ratings-container">
<span class="index-concept-icon">
<% c = experiment.concepts.sample %>
<%= image_tag "#{c.name}.png", class: "concept-img-small" %><br>
<%= link_to c.name, concept_path(c) %>
</span>

<div class="index-time">
<%= image_tag "time.png", class: "icon-small" %><br>
<%= experiment.complete_time %> hour(s)
</div>

<div class="index-age">
<%= image_tag "age.png", class: "icon-small" %><br>
Ages <%= experiment.return_age %>
</div>

<div class="mess-rate-disable index-mess">
<%= rating_for experiment, "name", star_path: '/images/ratyrate', :disable_rate => true %><br>
Mess
</div>
</span>
</div>
</div>
</div>
<% end %>
</div>
5 changes: 2 additions & 3 deletions app/views/experiments/_experiments.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</div>

<div class="index-wrapper">
<% @experiments.each do |experiment| %>
<% @experiments.each do |experiment| %>

<div class="index-experiment-card">
<% if experiment.uploaded_file.blank? %>
Expand All @@ -26,7 +26,6 @@
<a href="<%= url_for experiment %>" class="index-photo" style="background-image: url('<%= experiment.uploaded_file %>')">
<% end %>
<span class="index-exp-title-bar"><h3 class="index-exp-title"><%= experiment.name %></h3>

<i class="fa fa-thumbs-up index-likes"> <%= pluralize experiment.votes, "like" %></i>
</span>
</a>
Expand Down Expand Up @@ -58,6 +57,6 @@
</div>
</div>
</div>
<% end %>
<% end %>
</div>
</div>
44 changes: 44 additions & 0 deletions app/views/experiments/_time_ordered.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<div class="index-wrapper">

<% experiments.order(:complete_time).each do |experiment| %>

<div class="index-experiment-card">
<% if experiment.uploaded_file.blank? %>
<a href="<%= url_for experiment %>" class="index-photo" style="background-image: url(<%= image_path "bubbles.jpg" %>)">
<% else %>
<a href="<%= url_for experiment %>" class="index-photo" style="background-image: url('<%= experiment.uploaded_file %>')">
<% end %>
<span class="index-exp-title-bar"><h3 class="index-exp-title"><%= experiment.name %></h3>
<i class="fa fa-thumbs-up index-likes"> <%= pluralize experiment.votes, "like" %></i>
</span>
</a>

<div class="index-info">
<div class="index-exp-ratings">
<span class="ratings-container">
<span class="index-concept-icon">
<% c = experiment.concepts.sample %>
<%= image_tag "#{c.name}.png", class: "concept-img-small" %><br>
<%= link_to c.name, concept_path(c) %>
</span>

<div class="index-time">
<%= image_tag "time.png", class: "icon-small" %><br>
<%= experiment.complete_time %> hour(s)
</div>

<div class="index-age">
<%= image_tag "age.png", class: "icon-small" %><br>
Ages <%= experiment.return_age %>
</div>

<div class="mess-rate-disable index-mess">
<%= rating_for experiment, "name", star_path: '/images/ratyrate', :disable_rate => true %><br>
Mess
</div>
</span>
</div>
</div>
</div>
<% end %>
</div>
7 changes: 5 additions & 2 deletions app/views/experiments/order_experiments.js.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
$(".index-wrapper").replaceWith("<%= j(render partial: 'experiments/order_experiments', locals: { experiments: @sorted_experiments }) %>");
initStars();
<% if params[:selectValue] == "1" %>
$(".index-wrapper").replaceWith("<%= j(render partial: 'experiments/age_ordered', locals: { experiments: @experiments }) %>");
<% elsif params[:selectValue] == "2" %>
$(".index-wrapper").replaceWith("<%= j(render partial: 'experiments/time_ordered', locals: { experiments: @experiments }) %>");
<% end %>

0 comments on commit 1abf9a8

Please sign in to comment.