bit of UI cleanup

This commit is contained in:
Dan Elbert 2017-02-21 12:57:56 -06:00
parent 2ea20048d4
commit 977e0e8d6a
10 changed files with 69 additions and 24 deletions

View File

@ -21,20 +21,14 @@ module ApplicationHelper
nav = [ nav = [
nav_item('Recipes', recipes_path, 'recipes'), nav_item('Recipes', recipes_path, 'recipes'),
nav_item('Ingredients', ingredients_path, 'ingredients'), nav_item('Ingredients', ingredients_path, 'ingredients'),
nav_item('Logs', logs_path, 'logs'), nav_item('Logs', logs_path, 'logs', current_user?),
nav_item('Calculator', calculator_path, 'calculator'), nav_item('Calculator', calculator_path, 'calculator'),
nav_item('About', about_path, 'home') nav_item('About', about_path, 'home'),
nav_item('Notes', notes_path, 'notes', current_user?),
nav_item('Admin', admin_users_path, 'admin/users', current_user? && current_user.admin?)
] ]
if current_user nav.compact
nav << nav_item('Notes', notes_path, 'notes')
end
if current_user && current_user.admin?
nav << nav_item('Admin', admin_users_path, 'admin/users')
end
nav
end end
def profile_nav_items def profile_nav_items
@ -57,8 +51,8 @@ module ApplicationHelper
end end
end end
def nav_item(name, url, controller = nil) def nav_item(name, url, controller = nil, visible = true)
content_tag('li', link_to(name, url), class: active_for_controller(controller)) !visible ? nil : content_tag('li', link_to(name, url), class: active_for_controller(controller))
end end
def active_for_controller(controller) def active_for_controller(controller)

View File

@ -8,7 +8,9 @@
<p>No Ingredients</p> <p>No Ingredients</p>
<% else %> <% else %>
<%= link_to 'New Ingredient', new_ingredient_path, class: 'btn btn-default' %> <% if current_user? %>
<%= link_to 'New Ingredient', new_ingredient_path, class: 'btn btn-default' %>
<% end %>
<br/> <br/>
@ -19,22 +21,26 @@
<th>USDA</th> <th>USDA</th>
<th>KCal per 100g</th> <th>KCal per 100g</th>
<th>Density (oz/cup)</th> <th>Density (oz/cup)</th>
<th></th> <% if current_user? %>
<th></th>
<% end %>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<% decorate(@ingredients, IngredientDecorator).each do |ingredient| %> <% decorate(@ingredients, IngredientDecorator).each do |ingredient| %>
<tr> <tr>
<td><%= link_to ingredient.name, edit_ingredient_path(ingredient) %></td> <td><%= link_to_if current_user?, ingredient.name, edit_ingredient_path(ingredient) %></td>
<td><%= ingredient.ndbn_check %></td> <td><%= ingredient.ndbn_check %></td>
<td><%= ingredient.kcal %></td> <td><%= ingredient.kcal %></td>
<td><%= ingredient.density %></td> <td><%= ingredient.density %></td>
<td> <% if current_user? %>
<%= link_to ingredient, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-xs btn-danger' do %> <td>
<span class="glyphicon glyphicon-remove"></span> <%= link_to ingredient, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-xs btn-danger' do %>
<% end %> <span class="glyphicon glyphicon-remove"></span>
</td> <% end %>
</td>
<% end %>
</tr> </tr>
<% end %> <% end %>
</tbody> </tbody>
@ -43,7 +49,9 @@
<br/> <br/>
<%= link_to 'New Ingredient', new_ingredient_path, class: 'btn btn-default' %> <% if current_user? %>
<%= link_to 'New Ingredient', new_ingredient_path, class: 'btn btn-default' %>
<% end %>
</div> </div>

View File

@ -0,0 +1,3 @@
<li>
<%= link_to_unless current_page.first?, raw(t 'views.pagination.first'), url, :remote => remote %>
</li>

View File

@ -0,0 +1,3 @@
<li class='disabled'>
<%= content_tag :a, raw(t 'views.pagination.truncate') %>
</li>

View File

@ -0,0 +1,3 @@
<li>
<%= link_to_unless current_page.last?, raw(t 'views.pagination.last'), url, {:remote => remote} %>
</li>

View File

@ -0,0 +1,3 @@
<li>
<%= link_to_unless current_page.last?, raw(t 'views.pagination.next'), url, :rel => 'next', :remote => remote %>
</li>

View File

@ -0,0 +1,9 @@
<% if page.current? %>
<li class='active'>
<%= content_tag :a, page, remote: remote, rel: (page.next? ? 'next' : (page.prev? ? 'prev' : nil)) %>
</li>
<% else %>
<li>
<%= link_to page, url, remote: remote, rel: (page.next? ? 'next' : (page.prev? ? 'prev' : nil)) %>
</li>
<% end %>

View File

@ -0,0 +1,15 @@
<%= paginator.render do -%>
<ul class="pagination">
<%= first_page_tag unless current_page.first? %>
<%= prev_page_tag unless current_page.first? %>
<% each_page do |page| -%>
<% if page.left_outer? || page.right_outer? || page.inside_window? -%>
<%= page_tag page %>
<% elsif !page.was_truncated? -%>
<%= gap_tag %>
<% end -%>
<% end -%>
<%= next_page_tag unless current_page.last? %>
<%= last_page_tag unless current_page.last? %>
</ul>
<% end -%>

View File

@ -0,0 +1,3 @@
<li>
<%= link_to_unless current_page.first?, raw(t 'views.pagination.previous'), url, :rel => 'prev', :remote => remote %>
</li>

View File

@ -9,7 +9,9 @@
<p>No Recipes</p> <p>No Recipes</p>
<% else %> <% else %>
<%= link_to 'New Recipe', new_recipe_path, class: 'btn btn-default' %><br/> <% if current_user? %>
<%= link_to 'New Recipe', new_recipe_path, class: 'btn btn-default' %><br/>
<% end %>
<%= paginate @recipes %> <%= paginate @recipes %>
@ -69,7 +71,9 @@
<br> <br>
<%= link_to 'New Recipe', new_recipe_path, class: 'btn btn-default' %> <% if current_user? %>
<%= link_to 'New Recipe', new_recipe_path, class: 'btn btn-default' %><br/>
<% end %>
</div> </div>
</div> </div>