From ce9f011694e272610070c9ec5840351cfc849edf Mon Sep 17 00:00:00 2001 From: cryptogopher Date: Mon, 23 Sep 2019 15:05:26 +0200 Subject: [PATCH] Added Source perms and routing Added Quantity displayed defaults --- app/models/quantity.rb | 6 ++++++ config/routes.rb | 1 + db/migrate/001_create_units.rb | 8 ++++---- init.rb | 2 ++ 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/models/quantity.rb b/app/models/quantity.rb index c065821..9e755ff 100644 --- a/app/models/quantity.rb +++ b/app/models/quantity.rb @@ -13,4 +13,10 @@ class Quantity < ActiveRecord::Base validate if: -> { parent.present? } do errors.add(:parent, :parent_domain_mismatch) unless domain == parent.domain end + + after_initialize do + if new_record? + self.displayed = false if self.displayed.nil? + end + end end diff --git a/config/routes.rb b/config/routes.rb index 884543f..225a237 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,6 +9,7 @@ resources :projects do resources :ingredients, :only => [:index, :create, :destroy] do post 'import', on: :collection end + resources :sources, :only => [:index, :create, :destroy] resources :quantities, :only => [:index, :create, :destroy] resources :units, :only => [:index, :create, :destroy] end diff --git a/db/migrate/001_create_units.rb b/db/migrate/001_create_units.rb index 076963e..41df336 100644 --- a/db/migrate/001_create_units.rb +++ b/db/migrate/001_create_units.rb @@ -54,13 +54,13 @@ class CreateUnits < ActiveRecord::Migration # https://www.fsai.ie/uploadedFiles/Consol_Reg1169_2011.pdf # https://www.fsai.ie/legislation/food_legislation/food_information_fic/nutrition_labelling.html e = Quantity.create project: nil, domain: :diet, parent: nil, name: "Energy", - description: "Total energy" + description: "Total energy", displayed: true Quantity.create project: nil, domain: :diet, parent: nil, name: "Proteins", - description: "Total amount of proteins" + description: "Total amount of proteins", displayed: true f = Quantity.create project: nil, domain: :diet, parent: nil, name: "Fats", - description: "Total lipids, including phospholipids" + description: "Total lipids, including phospholipids", displayed: true f1 = Quantity.create project: nil, domain: :diet, parent: f, name: "Fatty acids", description: "" f2 = Quantity.create project: nil, domain: :diet, parent: f1, name: "Saturated", @@ -87,7 +87,7 @@ class CreateUnits < ActiveRecord::Migration description: "Docosahexaenoic acid" c1 = Quantity.create project: nil, domain: :diet, parent: nil, name: "Carbohydrates", - description: "Total amount of carbohydrates" + description: "Total amount of carbohydrates", displayed: true c2 = Quantity.create project: nil, domain: :diet, parent: c1, name: "Digestible", description: "" c3 = Quantity.create project: nil, domain: :diet, parent: c2, name: "Sugars", diff --git a/init.rb b/init.rb index 4772de5..fe7474a 100644 --- a/init.rb +++ b/init.rb @@ -14,12 +14,14 @@ Redmine::Plugin.register :body_tracking do permission :view_body_trackers, { :body_trackers => [:index], :ingredients => [:index], + :sources => [:index], :quantities => [:index], :units => [:index], }, read: true permission :manage_common, { :body_trackers => [:defaults], :ingredients => [:create, :destroy, :import], + :sources => [:create, :destroy], :quantities => [:create, :destroy], :units => [:create, :destroy], }, require: :loggedin