Skip to content

Commit 2837e19

Browse files
committed
Add versioning pages to initiatives (#5935)
* Add versioning pages to initiatives * Add specs for versioning pages * Add CHANGELOG entry * Normalize i18n file (hopefully) * Use initiatives in diff cell test to test if branch in diff renderer class detection * Remove unrelated lines from Changelog * Undo changes on core
1 parent 1f7f7a3 commit 2837e19

12 files changed

Lines changed: 302 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ Due to [\#5553](https://github.com/decidim/decidim/pull/5553), SSL is turned on
5454
- **decidim-budgets**: Improve the budget page and the project card [\#5809](https://github.com/decidim/decidim/pull/5809)
5555

5656
- **decidim-assemblies** **decidim-conferences** **decidim-participatory-processes**: Notify users on adding roles. [#5886](https://github.com/decidim/decidim/pull/5886)
57+
- **decidim-budgets**: Projects filter by multiple categories [/#5992](https://github.com/decidim/decidim/pull/5992)
58+
- **decidim-initiatives**: Add pages for versioning. [\#5935](https://github.com/decidim/decidim/pull/5935)
5759

5860
### Changed
5961

decidim-core/app/cells/decidim/diff_cell.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ def item
3434

3535
# DiffRenderer class for the current_version's item; falls back to `BaseDiffRenderer`.
3636
def diff_renderer_class
37-
"#{current_version.item_type.deconstantize}::DiffRenderer".constantize
37+
if current_version.item_type.deconstantize == "Decidim"
38+
"#{current_version.item_type.pluralize}::DiffRenderer".constantize
39+
else
40+
"#{current_version.item_type.deconstantize}::DiffRenderer".constantize
41+
end
3842
rescue NameError
3943
Decidim::BaseDiffRenderer
4044
end
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# frozen_string_literal: true
2+
3+
module Decidim
4+
module Initiatives
5+
# Exposes Initiatives versions so users can see how an Initiative
6+
# has been updated through time.
7+
class VersionsController < Decidim::Initiatives::ApplicationController
8+
include ParticipatorySpaceContext
9+
participatory_space_layout
10+
11+
helper Decidim::TraceabilityHelper
12+
helper InitiativeHelper
13+
include NeedsInitiative
14+
15+
helper_method :current_version
16+
17+
private
18+
19+
def current_version
20+
return nil unless params[:id].to_i.positive?
21+
22+
@current_version ||= current_initiative.versions[params[:id].to_i - 1]
23+
end
24+
end
25+
end
26+
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
module Decidim
4+
module Initiatives
5+
class DiffRenderer < BaseDiffRenderer
6+
private
7+
8+
# Lists which attributes will be diffable and how they should be rendered.
9+
def attribute_types
10+
{
11+
description: :i18n_html,
12+
title: :i18n,
13+
state: :string
14+
}
15+
end
16+
end
17+
end
18+
end

decidim-initiatives/app/views/decidim/initiatives/initiatives/show.html.erb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ edit_link(
5454
<%= render partial: "decidim/shared/share_modal" %>
5555
<%= embed_modal_for initiative_initiative_widget_url(current_initiative, format: :js) %>
5656
<%= resource_reference(current_initiative) %>
57+
<div class="tech-info">
58+
<strong class="text-uppercase">
59+
<%= t(".version", number: "#{current_initiative.versions_count}") %>
60+
</strong>
61+
<%= t(".of_versions", number: "#{current_initiative.versions_count}") %>
62+
<%= link_to t(".see_other_versions"), initiative_versions_path(current_initiative) %>
63+
</div>
5764
</div>
5865

5966
<div class="columns mediumlarge-8 mediumlarge-pull-4">
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<div class="card--list__item">
2+
<div class="card--list__text">
3+
<div>
4+
<%= link_to initiative_version_path(initiative, index + 1) do %>
5+
<h6 class="card--list__heading heading6">
6+
<%= t(".version_index", index: index + 1) %>
7+
</h6>
8+
<% end %>
9+
<div class="author-data">
10+
<%= render_resource_editor(version) %>
11+
<%= l version.created_at, format: :decidim_short %>
12+
</div>
13+
</div>
14+
</div>
15+
<div class="card--list__data">
16+
<%= link_to initiative_version_path(initiative, index + 1), class: "card--list__data__icon" do %>
17+
<%= icon "chevron-right" %>
18+
<% end %>
19+
</div>
20+
</div>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<div class="row">
2+
<div class="small-12 columns">
3+
<h2 class="heading2">
4+
<%= t("changes_at_title", scope: "decidim.initiatives.versions.shared", title: translated_attribute(current_initiative.title)) %>
5+
</h2>
6+
7+
<h3 class="section-heading">
8+
<%= t(".title") %>
9+
</h3>
10+
11+
<div class="row">
12+
<div class="mediumlarge-8 columns">
13+
<div class="section">
14+
<div class="card card--list">
15+
<% current_initiative.versions.each_with_index do |version, index| %>
16+
<%= render partial: "version", locals: { version: version, index: index, initiative: current_initiative } %>
17+
<% end %>
18+
</div>
19+
</div>
20+
</div>
21+
22+
<div class="columns section mediumlarge-4 large-3">
23+
<div class="card extra definition-data">
24+
<div class="definition-data__item versions_count">
25+
<span class="definition-data__title"><%= t(".number_of_versions") %></span>
26+
<%= current_initiative.versions.count %>
27+
28+
<%= link_to t("back_to_initiative", scope: "decidim.initiatives.versions.shared"), initiative_path(current_initiative), class: "button button--sc hollow secondary small expanded" %>
29+
</div>
30+
</div>
31+
</div>
32+
</div>
33+
</div>
34+
</div>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<div class="row">
2+
<div class="small-12 columns">
3+
<h2 class="heading2">
4+
<%= t("changes_at_title", scope: "decidim.initiatives.versions.shared", title: translated_attribute(current_initiative.title)) %>
5+
</h2>
6+
7+
<div class="row">
8+
<div class="mediumlarge-8 columns">
9+
<div class="section">
10+
<%= cell("decidim/diff", current_version) %>
11+
</div>
12+
</div>
13+
14+
<div class="columns section mediumlarge-4 large-3">
15+
<div class="card extra definition-data">
16+
<div class="definition-data__item versions_count">
17+
<span class="definition-data__title"><%= t("versions.stats.version_number", scope: "decidim.proposals") %></span>
18+
<%= t(".version_number_out_of_total", current_version: params[:id], total_count: current_initiative.versions_count) %>
19+
<%= link_to t(".show_all_versions"), initiative_versions_path(current_initiative), class: "button button--sc hollow secondary small expanded" %>
20+
<%= link_to link_to t("back_to_initiative", scope: "decidim.initiatives.versions.shared"), initiative_path(current_initiative), class: "button button--sc hollow secondary small expanded" %>
21+
</div>
22+
<% if current_version.whodunnit.present? %>
23+
<div class="definition-data__item last_revision_by">
24+
<span class="definition-data__title"><%= t(".version_author") %></span>
25+
<%= render_resource_editor(current_version) %>
26+
</div>
27+
<% end %>
28+
<div class="definition-data__item versions_count">
29+
<span class="definition-data__title"><%= t(".version_created_at") %></span>
30+
<%= l current_version.created_at, format: :decidim_short %>
31+
</div>
32+
</div>
33+
</div>
34+
</div>
35+
</div>
36+
</div>

decidim-initiatives/app/views/layouts/decidim/_initiative_header.html.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
{
3434
name: t(".initiative_menu_item"),
3535
url: decidim_initiatives.initiative_path(current_participatory_space),
36-
active: is_active_link?(decidim_initiatives.initiative_path(current_participatory_space), :exclusive)
36+
active: is_active_link?(decidim_initiatives.initiative_path(current_participatory_space), :exclusive) ||
37+
is_active_link?(decidim_initiatives.initiative_versions_path(current_participatory_space), :inclusive)
3738
}
3839
] + components.map do |component|
3940
{

decidim-initiatives/config/locales/en.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,10 @@ en:
392392
show:
393393
any_vote_method: This citizen initiative collects both online and in-person signatures.
394394
follow_description: Receive a notification when there are news in this initiative
395+
of_versions: "(of %{number})"
395396
offline_method: This citizen initiative only collects in-person signatures.
397+
see_other_versions: see other versions
398+
version: Version %{number}
396399
signature_identities:
397400
select_identity: Select participant identifier
398401
signatures_count:
@@ -436,6 +439,20 @@ en:
436439
accepted: Accepted
437440
expired: Expired
438441
unavailable_scope: Unavailable scope
442+
versions:
443+
index:
444+
number_of_versions: Versions
445+
title: Versions
446+
shared:
447+
back_to_initiative: Go back to initiative
448+
changes_at_title: Changes at "%{title}"
449+
show:
450+
show_all_versions: Show all versions
451+
version_author: Version author
452+
version_created_at: Version created at
453+
version_number_out_of_total: "%{current_version} out of %{total_count}"
454+
version:
455+
version_index: Version %{index}
439456
menu:
440457
initiatives: Initiatives
441458
resources:

0 commit comments

Comments
 (0)