1
0

Added toggling Quantity primary-ness

This commit is contained in:
cryptogopher 2019-10-26 01:03:06 +02:00
parent baadd647f8
commit 2176ef77f3
5 changed files with 16 additions and 4 deletions

View File

@ -1,6 +1,6 @@
class QuantitiesController < ApplicationController class QuantitiesController < ApplicationController
before_action :find_project_by_project_id, only: [:index, :create] before_action :find_project_by_project_id, only: [:index, :create]
before_action :find_quantity, only: [:destroy] before_action :find_quantity, only: [:destroy, :toggle]
before_action :authorize before_action :authorize
def index def index
@ -26,6 +26,11 @@ class QuantitiesController < ApplicationController
redirect_to project_quantities_url(@project) redirect_to project_quantities_url(@project)
end end
def toggle
@quantity.update(primary: !@quantity.primary)
redirect_to project_quantities_url(@project)
end
private private
def quantity_params def quantity_params

View File

@ -45,7 +45,11 @@
<td class="name"><span><%= q.name %></span></td> <td class="name"><span><%= q.name %></span></td>
<td class="domain"><%= q.domain %></td> <td class="domain"><%= q.domain %></td>
<td class="description"><%= q.description %></td> <td class="description"><%= q.description %></td>
<td class="action"><%= delete_link quantity_path(q), data: {} %></td> <td class="action">
<%= link_to l(:button_toggle), toggle_quantity_path(q),
{method: :post, class: "icon #{q.primary ? "icon-fav" : "icon-fav-off"}"} %>
<%= delete_link quantity_path(q), data: {} %>
</td>
</tr> </tr>
<% end %> <% end %>
</tbody> </tbody>

View File

@ -10,6 +10,7 @@ en:
field_domain: 'Domain' field_domain: 'Domain'
field_parent_quantity: 'Parent' field_parent_quantity: 'Parent'
field_shortname: 'Short name' field_shortname: 'Short name'
button_toggle: 'Toggle'
activerecord: activerecord:
errors: errors:
models: models:

View File

@ -11,7 +11,9 @@ resources :projects do
get 'nutrients', on: :collection get 'nutrients', on: :collection
end end
resources :sources, :only => [:index, :create, :destroy] resources :sources, :only => [:index, :create, :destroy]
resources :quantities, :only => [:index, :create, :destroy] resources :quantities, :only => [:index, :create, :destroy] do
post 'toggle', on: :member
end
resources :units, :only => [:index, :create, :destroy] resources :units, :only => [:index, :create, :destroy]
end end
end end

View File

@ -24,7 +24,7 @@ Redmine::Plugin.register :body_tracking do
:body_trackers => [:defaults], :body_trackers => [:defaults],
:ingredients => [:create, :destroy, :import], :ingredients => [:create, :destroy, :import],
:sources => [:create, :destroy], :sources => [:create, :destroy],
:quantities => [:create, :destroy], :quantities => [:create, :destroy, :toggle],
:units => [:create, :destroy], :units => [:create, :destroy],
}, require: :loggedin }, require: :loggedin
end end