Use acts_as_taggable for budget tags
We were adding columns to the budgets table instead of using the same logic we use everywhere else.
This commit is contained in:
@@ -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: []
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -40,10 +40,14 @@
|
||||
|
||||
<div class="margin-top">
|
||||
<div class="small-12 medium-9 column end">
|
||||
<%= 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") %>
|
||||
</div>
|
||||
<div class="small-12 medium-9 column end">
|
||||
<%= 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") %>
|
||||
</div>
|
||||
<div class="small-12 medium-9 column end">
|
||||
<%= f.text_field :help_link %>
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user