Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom/0.26 #22

Draft
wants to merge 6 commits into
base: release/0.26-stable
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
</div>

<div class="row column">
<%= form.translated :text_field, :description %>
<%= form.translated :text_field, :title %>
</div>

<div class="row column">
<%= form.translated :editor, :description %>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
<thead>
<tr>
<th><%= t("models.timeline_entry.fields.entry_date", scope: "decidim.accountability") %></th>
<th><%= t("models.timeline_entry.fields.description", scope: "decidim.accountability") %></th>
<th><%= t("models.timeline_entry.fields.title", scope: "decidim.accountability") %></th>
<th class="actions"><%= t("actions.title", scope: "decidim.accountability") %></th>
</tr>
</thead>
<tbody>
<% timeline_entries.each do |timeline_entry| %>
<tr data-id="<%= timeline_entry.id %>">
<td><%= timeline_entry.entry_date %><br></td>
<td><%= translated_attribute(timeline_entry.description) %></td>
<td><%= translated_attribute(timeline_entry.title) %></td>
<td class="table-list__actions">
<% 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" %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@
<%= timeline_entry.entry_date %>
</span>
<h4 class="timeline__title">
<%= translated_attribute timeline_entry.description %>
<%= translated_attribute timeline_entry.title %>
</h4>

<% if translated_attribute(timeline_entry.description).present? %>
<div class="timeline__description__description">
<%== translated_attribute timeline_entry.description %>
</div>
<% end %>
</div>
</div>
</li>
Expand Down
3 changes: 2 additions & 1 deletion decidim-accountability/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -159,8 +160,8 @@ en:
progress: Progress
timeline_entry:
fields:
description: Description
entry_date: Date
title: Title
result_m:
executed: Executed
view: View
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddTitleToTimelineEntries < ActiveRecord::Migration[6.0]
def change
add_column :decidim_accountability_timeline_entries, :title, :jsonb
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

class MoveLegacyDescriptionToTitleOfTimelineEntries < ActiveRecord::Migration[6.0]
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
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ module Decidim::Accountability
let(:result) { create :result, component: current_component }

let(:date) { "2017-8-23" }
let(:title) { "Title" }
let(:description) { "description" }

let(:form) do
double(
invalid?: invalid,
decidim_accountability_result_id: result.id,
entry_date: date,
title: { en: title },
description: { en: description }
)
end
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
7 changes: 7 additions & 0 deletions decidim-accountability/spec/types/integration_schema_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -159,6 +160,9 @@
timelineEntries {
id
createdAt
title {
translation(locale:"#{locale}")
}
description {
translation(locale:"#{locale}")
}
Expand Down Expand Up @@ -265,6 +269,9 @@
timelineEntries {
id
createdAt
title {
translation(locale:"#{locale}")
}
description {
translation(locale:"#{locale}")
}
Expand Down
8 changes: 8 additions & 0 deletions decidim-accountability/spec/types/timeline_entry_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")}}' }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 11 additions & 1 deletion decidim-core/app/helpers/decidim/participatory_space_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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