Added Ingredient#toggle and dimming hidden items
This commit is contained in:
parent
3cec0847df
commit
67efb6c6bc
@ -2,7 +2,7 @@ class IngredientsController < ApplicationController
|
||||
require 'csv'
|
||||
|
||||
before_action :find_project_by_project_id, only: [:index, :create, :import, :nutrients]
|
||||
before_action :find_ingredient, only: [:destroy]
|
||||
before_action :find_ingredient, only: [:destroy, :toggle]
|
||||
before_action :authorize
|
||||
|
||||
def index
|
||||
@ -33,6 +33,11 @@ class IngredientsController < ApplicationController
|
||||
redirect_to project_ingredients_url(@project)
|
||||
end
|
||||
|
||||
def toggle
|
||||
@ingredient.update(hidden: !@ingredient.hidden)
|
||||
@ingredients = @project.ingredients.includes(:ref_unit, :source)
|
||||
end
|
||||
|
||||
def import
|
||||
warnings = []
|
||||
|
||||
|
38
app/views/ingredients/_list.html.erb
Normal file
38
app/views/ingredients/_list.html.erb
Normal file
@ -0,0 +1,38 @@
|
||||
<% if @ingredients.many? %>
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= l(:field_name) %></th>
|
||||
<th><%= l(:field_reference) %></th>
|
||||
<th><%= l(:field_group) %></th>
|
||||
<th><%= l(:field_source) %></th>
|
||||
<th style="width:15%"><%= l(:field_action) %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @ingredients.each do |i| %>
|
||||
<% next if i.new_record? %>
|
||||
<tr id="ingredient-<%= i.id %>" class="ingredient <%= 'hidden' if i.hidden %>">
|
||||
<td class="name">
|
||||
<%= link_to '', toggle_ingredient_path(i), {
|
||||
remote: true,
|
||||
method: :post,
|
||||
class: "icon icon-eye"
|
||||
}
|
||||
%>
|
||||
<%= i.name %>
|
||||
</td>
|
||||
<td class="reference value"><%= i.ref_amount %> [<%= i.ref_unit.shortname %>]</td>
|
||||
<td class="group"><%= i.group %></td>
|
||||
<td class="source">
|
||||
<%= i.source.name if i.source.present? %>
|
||||
<%= ", #{i.source_ident}" if i.source_ident.present? %>
|
||||
</td>
|
||||
<td class="action"><%= delete_link ingredient_path(i), data: {} %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% else %>
|
||||
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||
<% end %>
|
@ -48,33 +48,6 @@
|
||||
</div>
|
||||
|
||||
<h2><%= t ".heading" %></h2>
|
||||
<% if @ingredients.many? %>
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= l(:field_name) %></th>
|
||||
<th><%= l(:field_reference) %></th>
|
||||
<th><%= l(:field_group) %></th>
|
||||
<th><%= l(:field_source) %></th>
|
||||
<th style="width:15%"><%= l(:field_action) %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @ingredients.each do |i| %>
|
||||
<% next if i.new_record? %>
|
||||
<tr id="ingredient-<%= i.id %>" class="ingredient <%= 'hidden' if i.hidden %>">
|
||||
<td class="name"><%= i.name %></td>
|
||||
<td class="reference value"><%= i.ref_amount %> [<%= i.ref_unit.shortname %>]</td>
|
||||
<td class="group"><%= i.group %></td>
|
||||
<td class="source">
|
||||
<%= i.source.name if i.source.present? %>
|
||||
<%= ", #{i.source_ident}" if i.source_ident.present? %>
|
||||
</td>
|
||||
<td class="action"><%= delete_link ingredient_path(i), data: {} %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% else %>
|
||||
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||
<% end %>
|
||||
<div id='ingredients'>
|
||||
<%= render :partial => 'ingredients/list' %>
|
||||
</div>
|
||||
|
3
app/views/ingredients/toggle.js.erb
Normal file
3
app/views/ingredients/toggle.js.erb
Normal file
@ -0,0 +1,3 @@
|
||||
$('div[id^=flash_]').remove();
|
||||
$('#content').prepend('<%= escape_javascript(render_flash_messages) %>');
|
||||
$('#ingredients').html('<%= escape_javascript(render :partial => 'ingredients/list') %>');
|
BIN
assets/images/eye.png
Normal file
BIN
assets/images/eye.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 433 B |
@ -1,4 +1,5 @@
|
||||
table.list tr.quantity.primary td.name {font-weight: bold;}
|
||||
table.list tr.ingredient.hidden {opacity: 0.4}
|
||||
table.list td.action,
|
||||
table.list td.value {text-align: right;}
|
||||
table.list td.action,
|
||||
@ -6,3 +7,4 @@ table.list td.name {white-space: nowrap;}
|
||||
|
||||
.icon-move-left { background-image: url(../images/1leftarrow.png); }
|
||||
.icon-move-right { background-image: url(../images/1rightarrow.png); }
|
||||
.icon-eye { background-image: url(../images/eye.png); }
|
||||
|
@ -7,6 +7,7 @@ resources :projects do
|
||||
post 'defaults', on: :collection
|
||||
end
|
||||
resources :ingredients, :only => [:index, :create, :destroy] do
|
||||
post 'toggle', on: :member
|
||||
post 'import', on: :collection
|
||||
get 'nutrients', on: :collection
|
||||
end
|
||||
|
2
init.rb
2
init.rb
@ -22,7 +22,7 @@ Redmine::Plugin.register :body_tracking do
|
||||
}, read: true
|
||||
permission :manage_common, {
|
||||
:body_trackers => [:defaults],
|
||||
:ingredients => [:create, :destroy, :import],
|
||||
:ingredients => [:create, :destroy, :toggle, :import],
|
||||
:sources => [:create, :destroy],
|
||||
:quantities => [:create, :destroy, :toggle, :up, :down, :left, :right],
|
||||
:units => [:create, :destroy],
|
||||
|
Reference in New Issue
Block a user