diff --git a/app/controllers/quantities_controller.rb b/app/controllers/quantities_controller.rb
index 1136c76..4889123 100644
--- a/app/controllers/quantities_controller.rb
+++ b/app/controllers/quantities_controller.rb
@@ -1,6 +1,6 @@
class QuantitiesController < ApplicationController
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
def index
@@ -26,6 +26,11 @@ class QuantitiesController < ApplicationController
redirect_to project_quantities_url(@project)
end
+ def toggle
+ @quantity.update(primary: !@quantity.primary)
+ redirect_to project_quantities_url(@project)
+ end
+
private
def quantity_params
diff --git a/app/views/quantities/index.html.erb b/app/views/quantities/index.html.erb
index f9f8d37..bcd54a4 100644
--- a/app/views/quantities/index.html.erb
+++ b/app/views/quantities/index.html.erb
@@ -45,7 +45,11 @@
<%= q.name %> |
<%= q.domain %> |
<%= q.description %> |
- <%= delete_link quantity_path(q), data: {} %> |
+
+ <%= 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: {} %>
+ |
<% end %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 17eb5eb..585f381 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -10,6 +10,7 @@ en:
field_domain: 'Domain'
field_parent_quantity: 'Parent'
field_shortname: 'Short name'
+ button_toggle: 'Toggle'
activerecord:
errors:
models:
diff --git a/config/routes.rb b/config/routes.rb
index 076193d..bfdc24c 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -11,7 +11,9 @@ resources :projects do
get 'nutrients', on: :collection
end
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]
end
end
diff --git a/init.rb b/init.rb
index ea7f4e8..6f87ae9 100644
--- a/init.rb
+++ b/init.rb
@@ -24,7 +24,7 @@ Redmine::Plugin.register :body_tracking do
:body_trackers => [:defaults],
:ingredients => [:create, :destroy, :import],
:sources => [:create, :destroy],
- :quantities => [:create, :destroy],
+ :quantities => [:create, :destroy, :toggle],
:units => [:create, :destroy],
}, require: :loggedin
end