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:
Javi Martín
2019-10-31 21:24:28 +01:00
parent d5cb519819
commit 20001824e5
8 changed files with 29 additions and 13 deletions

View File

@@ -71,8 +71,8 @@ class Admin::BudgetsController < Admin::BaseController
valid_attributes = [:phase, valid_attributes = [:phase,
:currency_symbol, :currency_symbol,
:help_link, :help_link,
:budget_milestone_tags, :milestone_tag_list,
:budget_valuation_tags, :valuation_tag_list,
administrator_ids: [], administrator_ids: [],
valuator_ids: [], valuator_ids: [],
tracker_ids: [] tracker_ids: []

View File

@@ -55,13 +55,13 @@ module BudgetsHelper
def investment_tags_select_options(budget) def investment_tags_select_options(budget)
tags = budget.investments.tags_on(:valuation_tags).order(:name).pluck(:name) 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 tags.uniq
end end
def investment_milestone_tags_select_options(budget) def investment_milestone_tags_select_options(budget)
tags = budget.investments.tags_on(:milestone_tags).order(:name).pluck(:name) 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 tags.uniq
end end

View File

@@ -4,6 +4,9 @@ class Budget < ApplicationRecord
include StatsVersionable include StatsVersionable
include Reportable include Reportable
acts_as_taggable_on :valuation_tags
acts_as_taggable_on :milestone_tags
translates :name, touch: true translates :name, touch: true
include Globalizable include Globalizable

View File

@@ -40,10 +40,14 @@
<div class="margin-top"> <div class="margin-top">
<div class="small-12 medium-9 column end"> <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>
<div class="small-12 medium-9 column end"> <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>
<div class="small-12 medium-9 column end"> <div class="small-12 medium-9 column end">
<%= f.text_field :help_link %> <%= f.text_field :help_link %>

View File

@@ -141,8 +141,8 @@ en:
description_finished: "Description when the budget is finished" description_finished: "Description when the budget is finished"
phase: "Phase" phase: "Phase"
currency_symbol: "Currency" currency_symbol: "Currency"
budget_milestone_tags: "Milestone tags" milestone_tag_list: "Milestone tags"
budget_valuation_tags: "Valuation tags" valuation_tag_list: "Valuation tags"
help_link: "Help link" help_link: "Help link"
budget/translation: budget/translation:
name: "Name" name: "Name"

View File

@@ -143,8 +143,8 @@ es:
description_finished: "Descripción cuando el presupuesto ha finalizado / Resultados" description_finished: "Descripción cuando el presupuesto ha finalizado / Resultados"
phase: "Fase" phase: "Fase"
currency_symbol: "Divisa" currency_symbol: "Divisa"
budget_milestone_tags: "Etiquetas de seguimiento" milestone_tag_list: "Etiquetas de seguimiento"
budget_valuation_tags: "Etiquetas de evaluación" valuation_tag_list: "Etiquetas de evaluación"
help_link: "Enlace de ayuda" help_link: "Enlace de ayuda"
budget/translation: budget/translation:
name: "Nombre" name: "Nombre"

View File

@@ -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

View File

@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@@ -408,8 +408,6 @@ ActiveRecord::Schema.define(version: 20191031172132) do
t.text "description_publishing_prices" t.text "description_publishing_prices"
t.text "description_informing" t.text "description_informing"
t.string "help_link" t.string "help_link"
t.string "budget_milestone_tags"
t.string "budget_valuation_tags"
end end
create_table "campaigns", force: :cascade do |t| 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 "budget/investments_count", default: 0
t.integer "legislation/proposals_count", default: 0 t.integer "legislation/proposals_count", default: 0
t.integer "legislation/processes_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 ["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/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 t.index ["legislation/proposals_count"], name: "index_tags_on_legislation/proposals_count", using: :btree