From ed847db8804ea274f7aa920b38863548c339e53c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Verg=C3=A9s?= Date: Thu, 5 May 2022 12:40:37 +0200 Subject: [PATCH 1/4] Add timeline entry title in Accountability projects (#9127) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(timeline_entry): add title attribute and move description * feat(timeline_entry): add title to model, form, command and type * feat(timeline_entry): add title to seeds * feat(timeline): add views * chore(i18n): remove description from timeline_entry.fields * feat(timeline_entry): add read more toggle button * chore(timeline_entry): remove read_more toggle * Update decidim-accountability/lib/decidim/accountability/component.rb Co-authored-by: Andrés Pereira de Lucena * feat(i18n): add timeline_entry tittle key Co-authored-by: Andrés Pereira de Lucena --- .../accountability/admin/create_timeline_entry.rb | 9 +++++---- .../accountability/admin/update_timeline_entry.rb | 5 +++-- .../accountability/admin/timeline_entry_form.rb | 3 ++- .../models/decidim/accountability/timeline_entry.rb | 1 + .../admin/timeline_entries/_form.html.erb | 6 +++++- .../admin/timeline_entries/index.html.erb | 4 ++-- .../accountability/results/_timeline.html.erb | 8 +++++++- decidim-accountability/config/locales/en.yml | 3 ++- .../20220331150008_add_title_to_timeline_entries.rb | 7 +++++++ ...gacy_description_to_title_of_timeline_entries.rb | 13 +++++++++++++ .../lib/decidim/accountability/component.rb | 3 ++- .../lib/decidim/accountability/test/factories.rb | 1 + .../lib/decidim/api/timeline_entry_type.rb | 1 + .../commands/admin/create_timeline_entry_spec.rb | 7 +++++++ .../commands/admin/update_timeline_entry_spec.rb | 2 ++ .../spec/forms/admin/timeline_entry_form_spec.rb | 12 +++++++++++- .../spec/types/integration_schema_spec.rb | 7 +++++++ .../spec/types/timeline_entry_type_spec.rb | 8 ++++++++ 18 files changed, 86 insertions(+), 14 deletions(-) create mode 100644 decidim-accountability/db/migrate/20220331150008_add_title_to_timeline_entries.rb create mode 100644 decidim-accountability/db/migrate/20220331150155_move_legacy_description_to_title_of_timeline_entries.rb diff --git a/decidim-accountability/app/commands/decidim/accountability/admin/create_timeline_entry.rb b/decidim-accountability/app/commands/decidim/accountability/admin/create_timeline_entry.rb index dccd44dfaa782..7def45b2d973a 100644 --- a/decidim-accountability/app/commands/decidim/accountability/admin/create_timeline_entry.rb +++ b/decidim-accountability/app/commands/decidim/accountability/admin/create_timeline_entry.rb @@ -25,13 +25,14 @@ def call private - attr_reader :timeline_entry + attr_reader :timeline_entry, :form def create_timeline_entry @timeline_entry = TimelineEntry.create!( - decidim_accountability_result_id: @form.decidim_accountability_result_id, - entry_date: @form.entry_date, - description: @form.description + decidim_accountability_result_id: form.decidim_accountability_result_id, + entry_date: form.entry_date, + title: form.title, + description: form.description ) end end diff --git a/decidim-accountability/app/commands/decidim/accountability/admin/update_timeline_entry.rb b/decidim-accountability/app/commands/decidim/accountability/admin/update_timeline_entry.rb index 57d1152385954..1feee2a24cb3c 100644 --- a/decidim-accountability/app/commands/decidim/accountability/admin/update_timeline_entry.rb +++ b/decidim-accountability/app/commands/decidim/accountability/admin/update_timeline_entry.rb @@ -34,8 +34,9 @@ def call def update_timeline_entry timeline_entry.update!( - entry_date: @form.entry_date, - description: @form.description + entry_date: form.entry_date, + title: form.title, + description: form.description ) end end diff --git a/decidim-accountability/app/forms/decidim/accountability/admin/timeline_entry_form.rb b/decidim-accountability/app/forms/decidim/accountability/admin/timeline_entry_form.rb index cea17aa1c8e58..06057aac52e2a 100644 --- a/decidim-accountability/app/forms/decidim/accountability/admin/timeline_entry_form.rb +++ b/decidim-accountability/app/forms/decidim/accountability/admin/timeline_entry_form.rb @@ -10,10 +10,11 @@ class TimelineEntryForm < Decidim::Form attribute :decidim_accountability_result_id, Integer attribute :entry_date, Decidim::Attributes::LocalizedDate + translatable_attribute :title, String translatable_attribute :description, String validates :entry_date, presence: true - validates :description, translatable_presence: true + validates :title, translatable_presence: true end end end diff --git a/decidim-accountability/app/models/decidim/accountability/timeline_entry.rb b/decidim-accountability/app/models/decidim/accountability/timeline_entry.rb index 2e7a5e0d58e18..90be57c3e430b 100644 --- a/decidim-accountability/app/models/decidim/accountability/timeline_entry.rb +++ b/decidim-accountability/app/models/decidim/accountability/timeline_entry.rb @@ -7,6 +7,7 @@ module Accountability class TimelineEntry < Accountability::ApplicationRecord include Decidim::TranslatableResource + translatable_fields :title translatable_fields :description belongs_to :result, foreign_key: "decidim_accountability_result_id", class_name: "Decidim::Accountability::Result", inverse_of: :timeline_entries end diff --git a/decidim-accountability/app/views/decidim/accountability/admin/timeline_entries/_form.html.erb b/decidim-accountability/app/views/decidim/accountability/admin/timeline_entries/_form.html.erb index a30eb155c8c66..d3b5b0472017e 100644 --- a/decidim-accountability/app/views/decidim/accountability/admin/timeline_entries/_form.html.erb +++ b/decidim-accountability/app/views/decidim/accountability/admin/timeline_entries/_form.html.erb @@ -9,7 +9,11 @@
- <%= form.translated :text_field, :description %> + <%= form.translated :text_field, :title %> +
+ +
+ <%= form.translated :editor, :description %>
diff --git a/decidim-accountability/app/views/decidim/accountability/admin/timeline_entries/index.html.erb b/decidim-accountability/app/views/decidim/accountability/admin/timeline_entries/index.html.erb index ea442c2c133ae..268e715b55486 100644 --- a/decidim-accountability/app/views/decidim/accountability/admin/timeline_entries/index.html.erb +++ b/decidim-accountability/app/views/decidim/accountability/admin/timeline_entries/index.html.erb @@ -13,7 +13,7 @@ <%= t("models.timeline_entry.fields.entry_date", scope: "decidim.accountability") %> - <%= t("models.timeline_entry.fields.description", scope: "decidim.accountability") %> + <%= t("models.timeline_entry.fields.title", scope: "decidim.accountability") %> <%= t("actions.title", scope: "decidim.accountability") %> @@ -21,7 +21,7 @@ <% timeline_entries.each do |timeline_entry| %> <%= timeline_entry.entry_date %>
- <%= translated_attribute(timeline_entry.description) %> + <%= translated_attribute(timeline_entry.title) %> <% if allowed_to? :update, :timeline_entry, timeline_entry: timeline_entry %> <%= icon_link_to "pencil", edit_result_timeline_entry_path(timeline_entry.result, timeline_entry), t("actions.edit", scope: "decidim.accountability"), class: "action-icon--edit" %> diff --git a/decidim-accountability/app/views/decidim/accountability/results/_timeline.html.erb b/decidim-accountability/app/views/decidim/accountability/results/_timeline.html.erb index 0f975caab877b..35cb582da8be2 100644 --- a/decidim-accountability/app/views/decidim/accountability/results/_timeline.html.erb +++ b/decidim-accountability/app/views/decidim/accountability/results/_timeline.html.erb @@ -13,8 +13,14 @@ <%= timeline_entry.entry_date %>

- <%= translated_attribute timeline_entry.description %> + <%= translated_attribute timeline_entry.title %>

+ + <% if translated_attribute(timeline_entry.description).present? %> +
+ <%== translated_attribute timeline_entry.description %> +
+ <% end %> diff --git a/decidim-accountability/config/locales/en.yml b/decidim-accountability/config/locales/en.yml index 419226530b006..5207004161356 100644 --- a/decidim-accountability/config/locales/en.yml +++ b/decidim-accountability/config/locales/en.yml @@ -22,6 +22,7 @@ en: timeline_entry: description: Description entry_date: Date + title: Title models: decidim/accountability/proposal_linked_event: Proposal included in a result decidim/accountability/result_progress_updated_event: Result progress updated @@ -159,8 +160,8 @@ en: progress: Progress timeline_entry: fields: - description: Description entry_date: Date + title: Title result_m: executed: Executed view: View diff --git a/decidim-accountability/db/migrate/20220331150008_add_title_to_timeline_entries.rb b/decidim-accountability/db/migrate/20220331150008_add_title_to_timeline_entries.rb new file mode 100644 index 0000000000000..c0fd23a4dc4e3 --- /dev/null +++ b/decidim-accountability/db/migrate/20220331150008_add_title_to_timeline_entries.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddTitleToTimelineEntries < ActiveRecord::Migration[6.1] + def change + add_column :decidim_accountability_timeline_entries, :title, :jsonb + end +end diff --git a/decidim-accountability/db/migrate/20220331150155_move_legacy_description_to_title_of_timeline_entries.rb b/decidim-accountability/db/migrate/20220331150155_move_legacy_description_to_title_of_timeline_entries.rb new file mode 100644 index 0000000000000..253617a3e7b5b --- /dev/null +++ b/decidim-accountability/db/migrate/20220331150155_move_legacy_description_to_title_of_timeline_entries.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class MoveLegacyDescriptionToTitleOfTimelineEntries < ActiveRecord::Migration[6.1] + class TimelineEntry < ApplicationRecord + self.table_name = :decidim_accountability_timeline_entries + end + + def up + TimelineEntry.find_each do |timeline_entry| + timeline_entry.update!(title: timeline_entry.description, description: nil) + end + end +end diff --git a/decidim-accountability/lib/decidim/accountability/component.rb b/decidim-accountability/lib/decidim/accountability/component.rb index 1c7ad7bc4cdc7..4cdcf968c75f7 100644 --- a/decidim-accountability/lib/decidim/accountability/component.rb +++ b/decidim-accountability/lib/decidim/accountability/component.rb @@ -159,7 +159,8 @@ rand(0..5).times do |i| child_result.timeline_entries.create!( entry_date: child_result.start_date + i.days, - description: Decidim::Faker::Localized.sentence(word_count: 2) + title: Decidim::Faker::Localized.sentence(word_count: 2), + description: Decidim::Faker::Localized.paragraph(sentence_count: 1) ) end diff --git a/decidim-accountability/lib/decidim/accountability/test/factories.rb b/decidim-accountability/lib/decidim/accountability/test/factories.rb index ae1cbeb025c2a..3afc298e19fe6 100644 --- a/decidim-accountability/lib/decidim/accountability/test/factories.rb +++ b/decidim-accountability/lib/decidim/accountability/test/factories.rb @@ -45,6 +45,7 @@ factory :timeline_entry, class: "Decidim::Accountability::TimelineEntry" do result { create(:result) } entry_date { "12/7/2017" } + title { generate_localized_title } description { generate_localized_title } end end diff --git a/decidim-accountability/lib/decidim/api/timeline_entry_type.rb b/decidim-accountability/lib/decidim/api/timeline_entry_type.rb index 9a4fde63275e0..e08bc6090318b 100644 --- a/decidim-accountability/lib/decidim/api/timeline_entry_type.rb +++ b/decidim-accountability/lib/decidim/api/timeline_entry_type.rb @@ -7,6 +7,7 @@ class TimelineEntryType < Decidim::Api::Types::BaseObject field :id, GraphQL::Types::ID, "The internal ID for this timeline entry", null: false field :entry_date, Decidim::Core::DateType, "The entry date for this timeline entry", null: true + field :title, Decidim::Core::TranslatedFieldType, "The title for this timeline entry", null: true field :description, Decidim::Core::TranslatedFieldType, "The description for this timeline entry", null: true field :created_at, Decidim::Core::DateTimeType, "When this timeline entry was created", null: true field :updated_at, Decidim::Core::DateTimeType, "When this timeline entry was updated", null: true diff --git a/decidim-accountability/spec/commands/admin/create_timeline_entry_spec.rb b/decidim-accountability/spec/commands/admin/create_timeline_entry_spec.rb index 3f2166f9f8c2c..6431a0c2fb8a3 100644 --- a/decidim-accountability/spec/commands/admin/create_timeline_entry_spec.rb +++ b/decidim-accountability/spec/commands/admin/create_timeline_entry_spec.rb @@ -12,6 +12,7 @@ module Decidim::Accountability let(:result) { create :result, component: current_component } let(:date) { "2017-8-23" } + let(:title) { "Title" } let(:description) { "description" } let(:form) do @@ -19,6 +20,7 @@ module Decidim::Accountability invalid?: invalid, decidim_accountability_result_id: result.id, entry_date: date, + title: { en: title }, description: { en: description } ) end @@ -44,6 +46,11 @@ module Decidim::Accountability expect(timeline_entry.entry_date).to eq(Date.new(2017, 8, 23)) end + it "sets the title" do + subject.call + expect(translated(timeline_entry.title)).to eq title + end + it "sets the description" do subject.call expect(translated(timeline_entry.description)).to eq description diff --git a/decidim-accountability/spec/commands/admin/update_timeline_entry_spec.rb b/decidim-accountability/spec/commands/admin/update_timeline_entry_spec.rb index 43c27687964b3..47d4f57596c78 100644 --- a/decidim-accountability/spec/commands/admin/update_timeline_entry_spec.rb +++ b/decidim-accountability/spec/commands/admin/update_timeline_entry_spec.rb @@ -14,12 +14,14 @@ module Decidim::Accountability let(:timeline_entry) { create :timeline_entry, result: result } let(:date) { "2017-9-23" } + let(:title) { "New title" } let(:description) { "new description" } let(:form) do double( invalid?: invalid, entry_date: date, + title: { en: title }, description: { en: description } ) end diff --git a/decidim-accountability/spec/forms/admin/timeline_entry_form_spec.rb b/decidim-accountability/spec/forms/admin/timeline_entry_form_spec.rb index 19fc8591e8a73..69f49d2195eab 100644 --- a/decidim-accountability/spec/forms/admin/timeline_entry_form_spec.rb +++ b/decidim-accountability/spec/forms/admin/timeline_entry_form_spec.rb @@ -18,6 +18,9 @@ module Decidim::Accountability let(:result) { create :result, component: current_component } let(:entry_date) { "12/3/2017" } + let(:title) do + Decidim::Faker::Localized.sentence(word_count: 3) + end let(:description) do Decidim::Faker::Localized.sentence(word_count: 3) end @@ -26,6 +29,7 @@ module Decidim::Accountability { decidim_accountability_result_id: result.id, entry_date: entry_date, + title_en: title[:en], description_en: description[:en] } end @@ -38,10 +42,16 @@ module Decidim::Accountability it { is_expected.not_to be_valid } end + describe "when title is missing" do + let(:title) { { en: nil } } + + it { is_expected.not_to be_valid } + end + describe "when description is missing" do let(:description) { { en: nil } } - it { is_expected.not_to be_valid } + it { is_expected.to be_valid } end end end diff --git a/decidim-accountability/spec/types/integration_schema_spec.rb b/decidim-accountability/spec/types/integration_schema_spec.rb index f8971ecee75c7..eb3bb95a8947e 100644 --- a/decidim-accountability/spec/types/integration_schema_spec.rb +++ b/decidim-accountability/spec/types/integration_schema_spec.rb @@ -50,6 +50,7 @@ "timelineEntries" => [ { "createdAt" => result.timeline_entries.first.created_at.iso8601.to_s.gsub("Z", "+00:00"), + "title" => { "translation" => result.timeline_entries.first.title[locale] }, "description" => { "translation" => result.timeline_entries.first.description[locale] }, "entryDate" => result.timeline_entries.first.entry_date.to_s, "id" => result.timeline_entries.first.id.to_s, @@ -159,6 +160,9 @@ timelineEntries { id createdAt + title { + translation(locale:"#{locale}") + } description { translation(locale:"#{locale}") } @@ -265,6 +269,9 @@ timelineEntries { id createdAt + title { + translation(locale:"#{locale}") + } description { translation(locale:"#{locale}") } diff --git a/decidim-accountability/spec/types/timeline_entry_type_spec.rb b/decidim-accountability/spec/types/timeline_entry_type_spec.rb index 8d28c62e7c6fc..b264b1fa0d76b 100644 --- a/decidim-accountability/spec/types/timeline_entry_type_spec.rb +++ b/decidim-accountability/spec/types/timeline_entry_type_spec.rb @@ -26,6 +26,14 @@ module Accountability end end + describe "title" do + let(:query) { '{ title { translation(locale:"en")}}' } + + it "returns the title field" do + expect(response["title"]["translation"]).to eq(model.title["en"]) + end + end + describe "description" do let(:query) { '{ description { translation(locale:"en")}}' } From 10680bfb7a7023f571130ab53b7f98bd510396cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Verg=C3=A9s?= Date: Thu, 5 May 2022 13:01:55 +0200 Subject: [PATCH 2/4] fix rails 6.0 migrations --- .../db/migrate/20220331150008_add_title_to_timeline_entries.rb | 2 +- ...0155_move_legacy_description_to_title_of_timeline_entries.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/decidim-accountability/db/migrate/20220331150008_add_title_to_timeline_entries.rb b/decidim-accountability/db/migrate/20220331150008_add_title_to_timeline_entries.rb index c0fd23a4dc4e3..082e29b91f56d 100644 --- a/decidim-accountability/db/migrate/20220331150008_add_title_to_timeline_entries.rb +++ b/decidim-accountability/db/migrate/20220331150008_add_title_to_timeline_entries.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class AddTitleToTimelineEntries < ActiveRecord::Migration[6.1] +class AddTitleToTimelineEntries < ActiveRecord::Migration[6.0] def change add_column :decidim_accountability_timeline_entries, :title, :jsonb end diff --git a/decidim-accountability/db/migrate/20220331150155_move_legacy_description_to_title_of_timeline_entries.rb b/decidim-accountability/db/migrate/20220331150155_move_legacy_description_to_title_of_timeline_entries.rb index 253617a3e7b5b..1eacf57a97b55 100644 --- a/decidim-accountability/db/migrate/20220331150155_move_legacy_description_to_title_of_timeline_entries.rb +++ b/decidim-accountability/db/migrate/20220331150155_move_legacy_description_to_title_of_timeline_entries.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class MoveLegacyDescriptionToTitleOfTimelineEntries < ActiveRecord::Migration[6.1] +class MoveLegacyDescriptionToTitleOfTimelineEntries < ActiveRecord::Migration[6.0] class TimelineEntry < ApplicationRecord self.table_name = :decidim_accountability_timeline_entries end From b2c058a291752d588689420ad142e3cce684feff Mon Sep 17 00:00:00 2001 From: "Agusti B.R" Date: Wed, 22 Jun 2022 09:31:55 +0200 Subject: [PATCH 3/4] fix(initiatives): admin can manage components --- .../decidim/admin/participatory_space_admin_context.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/decidim-admin/app/controllers/concerns/decidim/admin/participatory_space_admin_context.rb b/decidim-admin/app/controllers/concerns/decidim/admin/participatory_space_admin_context.rb index db9d9141eb0f0..7a66a98ad04fe 100644 --- a/decidim-admin/app/controllers/concerns/decidim/admin/participatory_space_admin_context.rb +++ b/decidim-admin/app/controllers/concerns/decidim/admin/participatory_space_admin_context.rb @@ -54,7 +54,12 @@ def permissions_context end def layout - current_participatory_space_manifest.context(current_participatory_space_context).layout + space_manifest = if current_participatory_space_manifest.is_a? Decidim::ResourceManifest + Decidim.participatory_space_manifests.find { |manifest| manifest.model_class_name == current_participatory_space.class.name } + else + current_participatory_space_manifest + end + space_manifest.context(current_participatory_space_context).layout end end end From 4e1df15802d72b71124fab0d8e77913d6e1c8450 Mon Sep 17 00:00:00 2001 From: "Agusti B.R" Date: Wed, 22 Jun 2022 12:17:44 +0200 Subject: [PATCH 4/4] fix(initiatives): participants can view components --- .../concerns/decidim/participatory_space_context.rb | 7 ++++++- .../helpers/decidim/participatory_space_helpers.rb | 12 +++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/decidim-core/app/controllers/concerns/decidim/participatory_space_context.rb b/decidim-core/app/controllers/concerns/decidim/participatory_space_context.rb index 5a00c873e7ed5..d912295fe16b0 100644 --- a/decidim-core/app/controllers/concerns/decidim/participatory_space_context.rb +++ b/decidim-core/app/controllers/concerns/decidim/participatory_space_context.rb @@ -59,7 +59,12 @@ def authorize_participatory_space end def layout - current_participatory_space_manifest.context(current_participatory_space_context).layout + space_manifest = if current_participatory_space_manifest.is_a? Decidim::ResourceManifest + Decidim.participatory_space_manifests.find { |manifest| manifest.model_class_name == current_participatory_space.class.name } + else + current_participatory_space_manifest + end + space_manifest.context(current_participatory_space_context).layout end # Method for current user can visit the space (assembly or proces) diff --git a/decidim-core/app/helpers/decidim/participatory_space_helpers.rb b/decidim-core/app/helpers/decidim/participatory_space_helpers.rb index 8f1b2ba34de15..e6326bd8ba661 100644 --- a/decidim-core/app/helpers/decidim/participatory_space_helpers.rb +++ b/decidim-core/app/helpers/decidim/participatory_space_helpers.rb @@ -18,7 +18,7 @@ module ParticipatorySpaceHelpers def participatory_space_helpers return @participatory_space_helpers if defined?(@participatory_space_helpers) - helper = current_participatory_space_manifest.context(current_participatory_space_context).helper + helper = participatory_space_manifest.context(current_participatory_space_context).helper klass = Class.new(SimpleDelegator) do include helper.constantize if helper @@ -41,5 +41,15 @@ def participatory_space_wrapper(&block) concat(capture(&block)) end end + + def participatory_space_manifest + @participatory_space_manifest ||= begin + if current_participatory_space_manifest.is_a? Decidim::ResourceManifest + Decidim.participatory_space_manifests.find { |manifest| manifest.model_class_name == current_participatory_space.class.name } + else + current_participatory_space_manifest + end + end + end end end