diff --git a/app/controllers/ingredients_controller.rb b/app/controllers/ingredients_controller.rb index d335cd6..636b2e8 100644 --- a/app/controllers/ingredients_controller.rb +++ b/app/controllers/ingredients_controller.rb @@ -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 = [] diff --git a/app/views/ingredients/_list.html.erb b/app/views/ingredients/_list.html.erb new file mode 100644 index 0000000..741eb4b --- /dev/null +++ b/app/views/ingredients/_list.html.erb @@ -0,0 +1,38 @@ +<% if @ingredients.many? %> + + + + + + + + + + + + <% @ingredients.each do |i| %> + <% next if i.new_record? %> + + + + + + + + <% end %> + +
<%= l(:field_name) %><%= l(:field_reference) %><%= l(:field_group) %><%= l(:field_source) %><%= l(:field_action) %>
+ <%= link_to '', toggle_ingredient_path(i), { + remote: true, + method: :post, + class: "icon icon-eye" + } + %> + <%= i.name %> + <%= i.ref_amount %> [<%= i.ref_unit.shortname %>]<%= i.group %> + <%= i.source.name if i.source.present? %> + <%= ", #{i.source_ident}" if i.source_ident.present? %> + <%= delete_link ingredient_path(i), data: {} %>
+<% else %> +

<%= l(:label_no_data) %>

+<% end %> diff --git a/app/views/ingredients/index.html.erb b/app/views/ingredients/index.html.erb index aa317b7..01b6261 100644 --- a/app/views/ingredients/index.html.erb +++ b/app/views/ingredients/index.html.erb @@ -48,33 +48,6 @@

<%= t ".heading" %>

-<% if @ingredients.many? %> - - - - - - - - - - - - <% @ingredients.each do |i| %> - <% next if i.new_record? %> - - - - - - - - <% end %> - -
<%= l(:field_name) %><%= l(:field_reference) %><%= l(:field_group) %><%= l(:field_source) %><%= l(:field_action) %>
<%= i.name %><%= i.ref_amount %> [<%= i.ref_unit.shortname %>]<%= i.group %> - <%= i.source.name if i.source.present? %> - <%= ", #{i.source_ident}" if i.source_ident.present? %> - <%= delete_link ingredient_path(i), data: {} %>
-<% else %> -

<%= l(:label_no_data) %>

-<% end %> +
+ <%= render :partial => 'ingredients/list' %> +
diff --git a/app/views/ingredients/toggle.js.erb b/app/views/ingredients/toggle.js.erb new file mode 100644 index 0000000..dbf0a07 --- /dev/null +++ b/app/views/ingredients/toggle.js.erb @@ -0,0 +1,3 @@ +$('div[id^=flash_]').remove(); +$('#content').prepend('<%= escape_javascript(render_flash_messages) %>'); +$('#ingredients').html('<%= escape_javascript(render :partial => 'ingredients/list') %>'); diff --git a/assets/images/eye.png b/assets/images/eye.png new file mode 100644 index 0000000..e788ad6 Binary files /dev/null and b/assets/images/eye.png differ diff --git a/assets/stylesheets/body_tracking.css b/assets/stylesheets/body_tracking.css index 0a1b032..d7b2f7c 100644 --- a/assets/stylesheets/body_tracking.css +++ b/assets/stylesheets/body_tracking.css @@ -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); } diff --git a/config/routes.rb b/config/routes.rb index c52acc8..730031d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/init.rb b/init.rb index ab1b3ab..f16870c 100644 --- a/init.rb +++ b/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],