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

Release/0.24 stable bcn #23

Draft
wants to merge 10 commits into
base: release/0.24-stable
Choose a base branch
from
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[5.2]
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[5.2]
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 @@ -155,7 +155,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
@@ -1,14 +1,16 @@
// = require ./progressFixed
// = require decidim/focus_mode
// = require_self

$(() => {
const $projects = $("#projects, #project");
const $budgetSummaryTotal = $(".budget-summary__total");
const $budgetExceedModal = $("#budget-excess");
const $budgetSummary = $(".budget-summary__progressbox");
const $voteButton = $(".budget-vote-button");
const totalAllocation = parseInt($budgetSummaryTotal.attr("data-total-allocation"), 10);

const cancelEvent = (event) => {
$(event.currentTarget).removeClass("loading-spinner");
event.stopPropagation();
event.preventDefault();
};
Expand All @@ -23,11 +25,19 @@ $(() => {
return false;
}

$voteButton.on("click", "span", (event) => {
$(".budget-list__action").click();
});

$projects.on("click", ".budget-list__action", (event) => {
const currentAllocation = parseInt($budgetSummary.attr("data-current-allocation"), 10);
const $currentTarget = $(event.currentTarget);
const projectAllocation = parseInt($currentTarget.attr("data-allocation"), 10);

if(!$currentTarget.attr("data-open")) {
$currentTarget.addClass("loading-spinner");
}

if ($currentTarget.attr("disabled")) {
cancelEvent(event);
} else if (($currentTarget.attr("data-add") === "true") && ((currentAllocation + projectAllocation) > totalAllocation)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@
border-bottom-right-radius: $card-border-radius;
border-bottom: $border;
}

&-cell {
display: grid;
grid-template-columns: 1fr 40px;

.budget-list__data {
grid-column: span 2;
background: none;
}

@include breakpoint(medium){
grid-template-columns: 1fr 40px 15em;
grid-template-rows: 1fr;

.budget-list__data {
background: $card-secondary-bg;
grid-column: 3;
}
}
}
}

&__image{
Expand Down Expand Up @@ -54,6 +74,11 @@
padding: $card-padding;
display: flex;
align-items: center;

&.flex-horizontal {
flex-direction: column;
align-items: flex-start;
}
}

.card__text--status{
Expand All @@ -79,10 +104,18 @@
min-width: 7rem;
flex-direction: row;
justify-content: flex-end;
flex-basis: 12rem;
flex-basis: 14rem;
padding: 1rem $card-padding;
}

.loading-spinner {
margin: 0 !important;
position: relative;
&:before {
position: absolute;
}
}

&:last-child{
margin-bottom: 0;
}
Expand Down
Loading