Skip to content

Commit

Permalink
Improve venues#index
Browse files Browse the repository at this point in the history
  • Loading branch information
raghubetina committed Nov 28, 2016
1 parent 9170a53 commit 72956a9
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 106 deletions.
4 changes: 2 additions & 2 deletions app/controllers/venues_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
class VenuesController < ApplicationController
def index
@q = Venue.ransack(params[:q])
@venues = @q.result(:distinct => true).includes(:bookmarks, :neighborhood, :fans, :specialties).page(params[:page]).per(10)
@venues = @q.result(:distinct => true).includes(:bookmarks, :neighborhood, :fans, :specialties).page(params[:page]).per(100)
@location_hash = Gmaps4rails.build_markers(@venues.where.not(:address_latitude => nil)) do |venue, marker|
marker.lat venue.address_latitude
marker.lng venue.address_longitude
marker.infowindow "<h5><a href='/venues/#{venue.id}'>#{venue.created_at}</a></h5><small>#{venue.address_formatted_address}</small>"
marker.infowindow "<h5><a href='/venues/#{venue.id}'>#{venue.name}</a></h5><small>#{venue.address_formatted_address}</small>"
end

render("venues/index.html.erb")
Expand Down
2 changes: 2 additions & 0 deletions app/views/dishes/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,5 @@
<%= paginate @dishes, theme: 'twitter-bootstrap-4' %>
</div>
</div>
</div>
</div>
147 changes: 44 additions & 103 deletions app/views/venues/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,127 +1,68 @@
<div class="page-header">
<h1>
Venues
<a href="/venues/new" class="btn btn-lg btn-success">New Venue</a>
</h1>
</div><div class="row mb-1">
<div class="col-md-12">
<%= search_form_for @q, :class => "collapse", :id => "venues_filters" do |f| %>
<p class="lead">Narrow results:</p>
<div class="row mt-2 mb-1">
<div class="col-md-3">
<%= search_form_for @q, :class => collapse_search_form, :id => "venues_filters" do |f| %>
<p class="lead">Narrow results:</p>

<div class="form-group">
<%= f.label :name_cont, "Name contains" %>
<%= f.text_field :name_cont, :class => "form-control", :placeholder => "Name contains" %>
</div>

<div class="form-group">
<%= f.label :created_at, "Created at" %>
<div class="row">
<div class='col-md-6 mb-1'>
<div class='input-group date' id='created_atgteqPicker'>
<%= f.text_field :created_at_gteq, :class => "form-control", :placeholder => "Created at greater than or equal to" %>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>

<div class='col-md-6'>
<div class='input-group date' id='created_atlteqPicker'>
<%= f.text_field :created_at_lteq, :class => "form-control", :placeholder => "Created at less than or equal to" %>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(function () {
$('#created_atgteqPicker').datetimepicker({
format: 'YYYY-MM-DD hh:mm:SS'
});
$('#created_atlteqPicker').datetimepicker({
useCurrent: false,
format: 'YYYY-MM-DD hh:mm:SS'
});
$('#created_atgteqPicker').on("dp.change", function (e) {
$('#created_atlteqPicker').data("DateTimePicker").minDate(e.date);
});
$('#created_atlteqPicker').on("dp.change", function (e) {
$('#created_atgteqPicker').data("DateTimePicker").maxDate(e.date);
});
});
</script>
<div class="form-group">
<%= f.label :name_cont, "Name contains" %>
<%= f.text_field :name_cont, :class => "form-control", :placeholder => "Name contains" %>
</div>

<div class="form-group">
<%= f.label :bookmarks_notes_cont, "Bookmark notes contains" %>
<%= f.text_field :bookmarks_notes_cont, :class => "form-control", :placeholder => "Bookmark notes contains" %>
<div class="form-group">
<%= f.label :bookmarks_notes_or_specialties_name_cont, "Bookmarks keyword" %>
<%= f.text_field :bookmarks_notes_or_specialties_name_cont, :class => "form-control", :placeholder => "Enter a keyword..." %>
</div>

<div class="form-group">
<div class="form-group">
<%= f.label :neighborhood_name_cont, "Neighborhood name contains" %>
<%= f.text_field :neighborhood_name_cont, :class => "form-control", :placeholder => "Neighborhood name contains" %>
</div>

<div class="form-group">
<%= f.label :fans_username_cont, "User username contains" %>
<%= f.text_field :fans_username_cont, :class => "form-control", :placeholder => "User username contains" %>
<div class="form-group">
<%= f.label :neighborhood_city_cont, "City name contains" %>
<%= f.text_field :neighborhood_city_cont, :class => "form-control", :placeholder => "City name contains" %>
</div>

<div class="form-group">
<%= f.label :specialties_name_cont, "Dish name contains" %>
<%= f.text_field :specialties_name_cont, :class => "form-control", :placeholder => "Dish name contains" %>
<div class="form-group">
<%= f.label :neighborhood_state_cont, "State name contains" %>
<%= f.text_field :neighborhood_state_cont, :class => "form-control", :placeholder => "State name contains" %>
</div>

<%= f.submit :class => "btn btn-primary btn-block mb-1" %>
<%= f.submit :class => "btn btn-primary btn-block mb-1" %>

<a href="/venues" class="btn btn-default btn-block mb-1">Clear filters</a>
<a href="/venues" class="btn btn-default btn-block mb-1">Clear filters</a>
<% end %>
<a class="btn btn-default btn-block mb-1" data-toggle="collapse" href="#venues_filters">
Show Filters
</a>
</div>
</div>

<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-body">
<div id="location_map" style="height: 360px;"></div>
</div>

<div class="row m-b-2">
<div class="col-md-12">
<div>
<div id="location_map" style="height: 480px;"></div>
</div>
</div>
</div>
<ul class="list-group">
<% @venues.order(:name).each do |venue| %>
<li class="list-group-item">
<a href="/venues/<%= venue.id %>">
<%= venue.name %>
</a>

<div class="row">
<div class="col-md-12">
<table class="table table-striped table-hover">
<tr>
<th>Name</th>
<th>Address</th>
<th>Neighborhood</th>
<th>Actions</th>
</tr>
<small class="text-muted pull-right">
<%= venue.neighborhood.name %>,
<%= venue.neighborhood.city %>
</small>
</li>
<% end %>
</ul>

<% @venues.each do |venue| %>
<tr>
<td><%= venue.name %></td>
<td><%= venue.address %></td>
<td>
<% if venue.neighborhood.present? %>
<a href="/neighborhoods/<%= venue.neighborhood.id %>">
<%= venue.neighborhood.name %>
</a>
<% end %>
</td>
<td>
<a href="/venues/<%= venue.id %>" class="btn btn-primary">Show</a>
<a href="/venues/<%= venue.id %>/edit" class="btn btn-warning">Edit</a>
<a href="/delete_venue/<%= venue.id %>" class="btn btn-danger" rel="nofollow">Delete</a>
</td>
</tr>
<% end %>
</table>
<%= paginate @venues, theme: 'twitter-bootstrap-4' %>

<div class="panel-footer text-center">
<%= paginate @venues, theme: 'twitter-bootstrap-4' %>
</div>
</div>
</div>
</div>

Expand All @@ -134,4 +75,4 @@
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
});
</script>
</script>
2 changes: 1 addition & 1 deletion app/views/venues/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
Popular dishes here
</li>

<% @venue.specialties.order(:name).each do |dish| %>
<% @venue.specialties.order(:name).distinct.each do |dish| %>
<li class="list-group-item">
<a href="/dishes/<%= dish.id %>">
<%= dish.name %>
Expand Down

0 comments on commit 72956a9

Please sign in to comment.