Skip to content

Commit

Permalink
add extra menu (#138)
Browse files Browse the repository at this point in the history
* add extra menu

* safe split

* add specs

* fix specs

* fix secrets file
  • Loading branch information
microstudi authored Oct 29, 2024
1 parent 09cc537 commit 34fcaba
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 25 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,17 @@ default: &default
- **key**: the identifier for the menu and URL path. For instance, if it is `general_assemblies` we will have a new menu entry for the url `<host>/general_assemblies` and the name specified in the I18n key `decidim.participatory_processes.scoped_participatory_process_slug_prefixes.general_assemblies`.
- **position_in_menu**: Where to place the item in the main menu, the usual "PROCESSES" item have the value `2.0`, lower this number will put it before and vice-versa.
- **slug_prefixes**: and array of prefixes for the slug of the participatory process. All participatory processes that have an slug starting with this word will be listed here and not in the normal "PROCESSES" menu.

#### Extra menu items for participatory processes & assemblies

Extra menu items in a participatory process (or an assembly) can defined in addition to the ones generated by the components.

Works exclusively using ENV vars following this scheme:

1. Add an ENV var like `EXTRA_PROCESS_MENU_***` where `***` is the slug of a participatory process.
2. Set the value of that ENV var to a pair of a model and a slug of a participatory space, separated by a slash `/`, for instance: `Decidim::Assembly/some-assembly` or `Decidim::ParticipatoryProcess/some_process`
3. A new menu item will appear to link the referenced participatory space
4. Also works for assemblies, examples:
`EXTRA_ASSEMBLY_MENU_MY_ASSEMBLY=Decidim::ParticipatoryProcess/my_process`
`EXTRA_PROCESS_MENU_MY_PROCESS=Decidim::Assembly/my_assembly`
`EXTRA_PROCESS_MENU_MY_PROCESS=Decidim::ParticipatoryProcess/my_process`
10 changes: 9 additions & 1 deletion app/packs/stylesheets/somenergia/global_styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,18 @@ a {
color: #fff !important;
text-decoration: none;
}
h1,h2,h3,h4,h5,h6,

h1,
h2,
h3,
h4,
h5,
h6,
&.card {
text-decoration: none;
}
}

.section-heading a {
text-decoration: none;
}
Expand Down Expand Up @@ -174,6 +181,7 @@ h3,
a,
.button {
text-decoration: none;

&:focus {
outline-color: $gray;
}
Expand Down
38 changes: 38 additions & 0 deletions app/views/layouts/decidim/_assembly_navigation.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<%
components = participatory_space.components.published.or(Decidim::Component.where(id: self.try(:current_component)))
items = components.map do |component|
{
name: translated_attribute(component.name),
url: main_component_path(component),
active: is_active_link?(main_component_path(component), :inclusive)
}
end

model, slug = ENV.fetch("EXTRA_ASSEMBLY_MENU_#{current_participatory_space.slug.upcase}", "").split("/")
klass = model&.safe_constantize
if klass
space = klass.find_by(slug: slug)
if space
link = resource_locator(space).path
items << {
name: translated_attribute(space.title),
url: link,
active: is_active_link?(link, :inclusive)
}
end
end
%>
<%=
extended_navigation_bar(([
{
name: t(".assembly_menu_item"),
url: decidim_assemblies.assembly_path(current_participatory_space),
active: is_active_link?(decidim_assemblies.assembly_path(current_participatory_space), :exclusive)
},
participatory_space.members.not_ceased.any? ? {
name: t(".assembly_member_menu_item"),
url: decidim_assemblies.assembly_assembly_members_path(current_participatory_space),
active: is_active_link?(decidim_assemblies.assembly_assembly_members_path(current_participatory_space), :inclusive)
} : nil
] + items).compact)
%>
32 changes: 32 additions & 0 deletions app/views/layouts/decidim/_process_navigation.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<%
components = participatory_space.components.published.or(Decidim::Component.where(id: self.try(:current_component)))

items = components.map do |component|
{
name: translated_attribute(component.name),
url: main_component_path(component),
active: is_active_link?(main_component_path(component), :inclusive)
}
end

model, slug = ENV.fetch("EXTRA_PROCESS_MENU_#{current_participatory_space.slug.upcase}", "").split("/")
klass = model&.safe_constantize
if klass
space = klass.find_by(slug: slug)
if space
link = resource_locator(space).path
items << {
name: translated_attribute(space.title),
url: link,
active: is_active_link?(link, :inclusive)
}
end
end
%>
<%= extended_navigation_bar([{
name: t(".process_menu_item"),
url: decidim_participatory_processes.participatory_process_path(participatory_space),
active: is_active_link?(decidim_participatory_processes.participatory_process_path(participatory_space), :exclusive) ||
is_active_link?(decidim_participatory_processes.all_metrics_participatory_process_path(participatory_space), :exclusive)
}] + items)
%>
59 changes: 37 additions & 22 deletions config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,28 @@ storage_default: &storage_default
auth_provider_x509_cert_url: <%= Decidim::Env.new("GCS_AUTH_PROVIDER_X509_CERT_URL", "https://www.googleapis.com/oauth2/v1/certs").to_s %>
client_x509_cert_url: <%= Decidim::Env.new("GCS_CLIENT_X509_CERT_URL").to_s %>

menu_default: &menu_default
localhost:
- key: somenergia.menu.team_et
url: /assemblies/et
position: 10
if_membership_in: et
prod.participa.somenergia.coop:
- key: somenergia.menu.team_et
url: /assemblies/et
position: 10
if_membership_in: et
staging.participa.somenergia.coop:
- key: somenergia.menu.team_et
url: /assemblies/et
position: 10
if_membership_in: et
participa.somenergia.coop:
- key: somenergia.menu.team_et
url: /assemblies/et
position: 10
if_membership_in: et

default: &default
decidim:
<<: *decidim_default
Expand Down Expand Up @@ -155,26 +177,7 @@ default: &default
url: //matomo.participa.somenergia.coop/
id: <%= ENV["MATOMO_ID"] %>
menu:
localhost:
- key: somenergia.menu.team_et
url: /assemblies/et
position: 10
if_membership_in: et
prod.participa.somenergia.coop:
- key: somenergia.menu.team_et
url: /assemblies/et
position: 10
if_membership_in: et
staging.participa.somenergia.coop:
- key: somenergia.menu.team_et
url: /assemblies/et
position: 10
if_membership_in: et
participa.somenergia.coop:
- key: somenergia.menu.team_et
url: /assemblies/et
position: 10
if_membership_in: et
<<: *menu_default
alternative_assembly_types:
-
key: local_groups # used to search a I18n key and a route path
Expand All @@ -191,11 +194,11 @@ development:
secret_key_base: 90d17c079bb42e0d52d9a33a8e59eacd887ba2b0c0da5e0792354cb82ac9f94fee61c1b503b81211d9b98cd8aa0f292b8bf3c1126773fa17211391ba2af998f5

test:
<<: *default
secret_key_base: 9f93fabe88fd2169da4ad6f3f535c3056260fa95392573312a331134b3c47e5ba3231d0b5a97a17972ca6a03a67af7714ca37cc7b2055b2237a15943d1a86525
decidim:
<<: *decidim_default
available_locales: ["en", "es", "ca"]
default_locale: "en"
secret_key_base: 9f93fabe88fd2169da4ad6f3f535c3056260fa95392573312a331134b3c47e5ba3231d0b5a97a17972ca6a03a67af7714ca37cc7b2055b2237a15943d1a86525
omniauth:
facebook:
enabled: true
Expand All @@ -206,6 +209,18 @@ test:
matomo:
url: https://run.mocky.io/v3/ac05e29c-26b8-424b-af06-2f3c7e1f719b?
id: 123
menu:
<<: *menu_default
alternative_assembly_types:
-
key: local_groups # used to search a I18n key and a route path
position_in_menu: 2.6
assembly_type_ids: [5]
scoped_participatory_process_slug_prefixes:
-
key: general_assemblies # used to search a I18n key and a route path
position_in_menu: 2.1
slug_prefixes: ["SomAG"]

# Do not keep production secrets in the repository,
# instead read values from the environment.
Expand Down
27 changes: 27 additions & 0 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,30 @@
require "decidim/decidim_awesome/test/factories"
require "decidim/consultations/test/factories"
require "decidim/initiatives/test/factories"

shared_examples "a participatory space with extra menu" do |prefix|
let!(:linked_space) { create(:participatory_process, organization: organization) }

before do
allow(ENV).to receive(:fetch).and_call_original
allow(ENV).to receive(:fetch).with("#{prefix}#{participatory_space.slug.upcase}", "").and_return("Decidim::ParticipatoryProcess/#{linked_space.slug}")
visit visit_path
end

it "shows the extra menu" do
within "#process-nav-content" do
expect(page).to have_link(href: "/processes/#{linked_space.slug}")
end
end

context "when visiting another space" do
let!(:another_space) { create(:participatory_process, organization: organization) }
let(:visit_path) { decidim_participatory_processes.participatory_process_path(another_space.slug) }

it "does not show the extra menu" do
within "#process-nav-content" do
expect(page).not_to have_link(href: "/processes/#{linked_space.slug}")
end
end
end
end
6 changes: 4 additions & 2 deletions spec/lib/overrides_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
{
package: "decidim-assemblies",
files: {
"/app/views/decidim/assemblies/_filter_by_type.html.erb" => "c6ddcc8dd42702031f8027bb56b69687"
"/app/views/decidim/assemblies/_filter_by_type.html.erb" => "c6ddcc8dd42702031f8027bb56b69687",
"/app/views/layouts/decidim/_assembly_navigation.html.erb" => "159f168bf1634937183cf5ca56b03a9d"
}
},
{
package: "decidim-participatory_processes",
files: {
"/app/cells/decidim/participatory_processes/process_filters_cell.rb" => "cd83acfcd8865c5fe1dbcf8deb5bf319"
"/app/cells/decidim/participatory_processes/process_filters_cell.rb" => "cd83acfcd8865c5fe1dbcf8deb5bf319",
"/app/views/layouts/decidim/_process_navigation.html.erb" => "e4d2322544d80ef4452aa61425034aa3"
}
},
{
Expand Down
5 changes: 5 additions & 0 deletions spec/system/participatory_processes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,9 @@
expect(page).to have_content("MORE INFO")
end
end

it_behaves_like "a participatory space with extra menu", "EXTRA_PROCESS_MENU_" do
let(:participatory_space) { normal_process }
let(:visit_path) { decidim_participatory_processes.participatory_process_path(normal_process.slug) }
end
end
5 changes: 5 additions & 0 deletions spec/system/tech_assembly_menu_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,9 @@
it_behaves_like "shows menu"
end
end

it_behaves_like "a participatory space with extra menu", "EXTRA_ASSEMBLY_MENU_" do
let(:participatory_space) { assembly }
let(:visit_path) { decidim_assemblies.assembly_path(assembly.slug) }
end
end

0 comments on commit 34fcaba

Please sign in to comment.