Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactoring code #2

Open
wants to merge 1 commit into
base: gather_and_gown_master
Choose a base branch
from
Open
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
22 changes: 8 additions & 14 deletions app/controllers/spree/venues_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module Spree
class VenuesController < Spree::BaseController
def index
# user_location = Geocoder.coordinates(params[:zipcode].first)
if params[:zipcode].present?
user_location = Spree::Venue.create(address: params[:zipcode] )
if params[:zipcode].present?
user_location = Spree::Venue.create(address: params[:zipcode] )
session[:location] = [user_location.latitude, user_location.longitude]
@venues = Spree::Venue.by_distance_from_latlong(user_location.latitude, user_location.longitude)
elsif session[:location].present?
Expand Down Expand Up @@ -52,21 +52,15 @@ def fliter_venues_near_by
venues_list = []
user_location = session[:location]
venues = Spree::Venue.by_distance_from_latlong(user_location[0], user_location[1])
if params[:sliver].present?
sliver_near_by = venues.select {|v| v.rank == "sliver" && v.miles < 51}
sliver_near_by.present? if venues_list += sliver_near_by
end
if params[:gold].present?
gold_near_by = venues.select {|v| v.rank == "gold" && v.miles < 51}
gold_near_by.present? if venues_list += gold_near_by
end
if params[:platinum].present?
platinum_near_by = venues.select {|v| v.rank == "platinum" && v.miles < 51}
platinum_near_by.present? if venues_list += platinum_near_by

if params[:rank].present?
venues_near_by = venues.select {|v| params[:rank].keys.include?(v.rank) && v.miles < 51}
venues_near_by.present? if venues_list += venues_near_by
end

if venues_list.present?
render json:{ venues: venues_list, user_location: user_location}
else
else
render json:{ message: "There are no stores within 50 miles", user_location: user_location, venues: venues_list}
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/spree/admin/venues/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<div class="four colums alpha">
<div class="field">
<%= f.label :venue_rank %>
<%= f.select :rank, ["sliver","gold", "platinum"], selected: @venue.rank, class: "fullwidth title" %>
<%= f.select :rank, venue_ranks, selected: @venue.rank, class: "fullwidth title" %>
<%= f.error_message_on :rank %>
</div>
</div>
Expand Down
18 changes: 6 additions & 12 deletions app/views/spree/venues/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,12 @@
<%= render partial: 'tier_alert' %>

<h6 id="storeTiers">STORE TIERS <i class="fa fa-info"></i></h6>
<label class="checked">
<i class="fa fa-check"></i>
<input class="rank" type="checkbox" name="platium" value="sliver"/>
</label><span>platium</span>
<label class="checked">
<i class="fa fa-check"></i>
<input class="rank" type="checkbox" name="gold" value="gold"/>
</label><span>gold</span>
<label class="checked">
<i class="fa fa-check"></i>
<input class="rank" type="checkbox" name="sliver" value="platinum"/>
</label><span>sliver</span>
<% venue_ranks.each do |rank| %>
<label class="checked">
<i class="fa fa-check"></i>
<input class="rank" type="checkbox" name="rank[<%= rank %>]" value="<%= rank %>"/>
</label><span><%= rank.capitalize %></span>
<% end %>
</div> <!-- rank-checkboxes -->
</div> <!-- col-md-5 -->
</div> <!-- .search-control -->
Expand Down