Skip to content

Commit

Permalink
fix sort and query. now will display by votes if there is a tie
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronwiggins committed Aug 9, 2015
1 parent 1abf9a8 commit e7deae7
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 112 deletions.
25 changes: 6 additions & 19 deletions app/controllers/experiments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def landing_page

def index
if params[:query]
@experiments = Experiment.text_search(params[:query])
@experiments = Experiment.text_search(params[:query]).all.by_votes
if @experiments.length == 0
flash.now[:notice] = "No items found"
end
Expand All @@ -20,26 +20,13 @@ def index
end

def order_experiments
@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
if params[:queryValue] && params[:selectValue] == "1"
@experiments = Experiment.text_search(params[:queryValue]).all.sort_by {|e| [e.age, -1*e.experiment_votes.count]}
elsif params[:queryValue] && params[:selectValue] == "2"
@experiments = Experiment.text_search(params[:queryValue]).all.sort_by {|e| [e.complete_time, -1*e.experiment_votes.count]}
end
end

# end

# GET /experiments/1
# GET /experiments/1.json
def show
Expand Down
44 changes: 0 additions & 44 deletions app/views/experiments/_age_ordered.html.erb

This file was deleted.

44 changes: 0 additions & 44 deletions app/views/experiments/_time_ordered.html.erb

This file was deleted.

7 changes: 2 additions & 5 deletions app/views/experiments/order_experiments.js.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
<% 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 %>
$(".index-wrapper").replaceWith("<%= j(render partial: 'experiments/ordered_experiments', locals: { experiments: @experiments }) %>");
initStars();

0 comments on commit e7deae7

Please sign in to comment.