diff --git a/app/controllers/admin/budgets_controller.rb b/app/controllers/admin/budgets_controller.rb index 0821b2ba1..88fbdf5c9 100644 --- a/app/controllers/admin/budgets_controller.rb +++ b/app/controllers/admin/budgets_controller.rb @@ -71,8 +71,8 @@ class Admin::BudgetsController < Admin::BaseController valid_attributes = [:phase, :currency_symbol, :help_link, - :budget_milestone_tags, - :budget_valuation_tags, + :milestone_tag_list, + :valuation_tag_list, administrator_ids: [], valuator_ids: [], tracker_ids: [] diff --git a/app/helpers/budgets_helper.rb b/app/helpers/budgets_helper.rb index 3d594005e..906132464 100644 --- a/app/helpers/budgets_helper.rb +++ b/app/helpers/budgets_helper.rb @@ -55,13 +55,13 @@ module BudgetsHelper def investment_tags_select_options(budget) tags = budget.investments.tags_on(:valuation_tags).order(:name).pluck(:name) - tags = tags.concat budget.budget_valuation_tags.split(",") if budget.budget_valuation_tags.present? + tags = tags.concat budget.valuation_tag_list tags.uniq end def investment_milestone_tags_select_options(budget) tags = budget.investments.tags_on(:milestone_tags).order(:name).pluck(:name) - tags = tags.concat budget.budget_milestone_tags.split(",") if budget.budget_milestone_tags.present? + tags = tags.concat budget.milestone_tag_list tags.uniq end diff --git a/app/models/budget.rb b/app/models/budget.rb index 41a6c0869..c0c772598 100644 --- a/app/models/budget.rb +++ b/app/models/budget.rb @@ -4,6 +4,9 @@ class Budget < ApplicationRecord include StatsVersionable include Reportable + acts_as_taggable_on :valuation_tags + acts_as_taggable_on :milestone_tags + translates :name, touch: true include Globalizable diff --git a/app/views/admin/budgets/_form.html.erb b/app/views/admin/budgets/_form.html.erb index c1d81fc09..93c827512 100644 --- a/app/views/admin/budgets/_form.html.erb +++ b/app/views/admin/budgets/_form.html.erb @@ -40,10 +40,14 @@
- <%= f.text_field :budget_milestone_tags, placeholder: t("admin.budget_investments.edit.tags_placeholder") %> + <%= f.text_field :milestone_tag_list, + value: @budget.milestone_tag_list.sort.join(","), + placeholder: t("admin.budget_investments.edit.tags_placeholder") %>
- <%= f.text_field :budget_valuation_tags, placeholder: t("admin.budget_investments.edit.tags_placeholder") %> + <%= f.text_field :valuation_tag_list, + value: @budget.valuation_tag_list.sort.join(","), + placeholder: t("admin.budget_investments.edit.tags_placeholder") %>
<%= f.text_field :help_link %> diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml index 7d2651fac..5fde670bc 100644 --- a/config/locales/en/activerecord.yml +++ b/config/locales/en/activerecord.yml @@ -141,8 +141,8 @@ en: description_finished: "Description when the budget is finished" phase: "Phase" currency_symbol: "Currency" - budget_milestone_tags: "Milestone tags" - budget_valuation_tags: "Valuation tags" + milestone_tag_list: "Milestone tags" + valuation_tag_list: "Valuation tags" help_link: "Help link" budget/translation: name: "Name" diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml index 84ea180d6..b9bc5c083 100644 --- a/config/locales/es/activerecord.yml +++ b/config/locales/es/activerecord.yml @@ -143,8 +143,8 @@ es: description_finished: "Descripción cuando el presupuesto ha finalizado / Resultados" phase: "Fase" currency_symbol: "Divisa" - budget_milestone_tags: "Etiquetas de seguimiento" - budget_valuation_tags: "Etiquetas de evaluación" + milestone_tag_list: "Etiquetas de seguimiento" + valuation_tag_list: "Etiquetas de evaluación" help_link: "Enlace de ayuda" budget/translation: name: "Nombre" diff --git a/db/migrate/20191031173943_use_acts_as_taggable_in_budgets.rb b/db/migrate/20191031173943_use_acts_as_taggable_in_budgets.rb new file mode 100644 index 000000000..9fc7eacb9 --- /dev/null +++ b/db/migrate/20191031173943_use_acts_as_taggable_in_budgets.rb @@ -0,0 +1,9 @@ +class UseActsAsTaggableInBudgets < ActiveRecord::Migration[5.0] + def change + remove_column :budgets, :budget_milestone_tags, :string + remove_column :budgets, :budget_valuation_tags, :string + + add_column :tags, :budgets_count, :integer, default: 0 + add_index :tags, :budgets_count + end +end diff --git a/db/schema.rb b/db/schema.rb index 3d88ed7a7..ac6912bbc 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20191031172132) do +ActiveRecord::Schema.define(version: 20191031173943) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -408,8 +408,6 @@ ActiveRecord::Schema.define(version: 20191031172132) do t.text "description_publishing_prices" t.text "description_informing" t.string "help_link" - t.string "budget_milestone_tags" - t.string "budget_valuation_tags" end create_table "campaigns", force: :cascade do |t| @@ -1487,6 +1485,8 @@ ActiveRecord::Schema.define(version: 20191031172132) do t.integer "budget/investments_count", default: 0 t.integer "legislation/proposals_count", default: 0 t.integer "legislation/processes_count", default: 0 + t.integer "budgets_count", default: 0 + t.index ["budgets_count"], name: "index_tags_on_budgets_count", using: :btree t.index ["debates_count"], name: "index_tags_on_debates_count", using: :btree t.index ["legislation/processes_count"], name: "index_tags_on_legislation/processes_count", using: :btree t.index ["legislation/proposals_count"], name: "index_tags_on_legislation/proposals_count", using: :btree