Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
1 change: 0 additions & 1 deletion .erb_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ linters:
- author-data__extra
- author-data__main
- author__avatar--small
- author__badge
- author__date
- author__name--container
- author__nickname
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
DECIDIM_SPAM_DETECTION_BACKEND_USER: "memory"
services:
validator:
image: ghcr.io/validator/validator@sha256:28bd490412bb5abf1cf23eae0e3c197e9fbbda43cb9d23239b9ce859dc585db0
image: ghcr.io/validator/validator:latest
ports: ["8888:8888"]
postgres:
image: postgres:14
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ResultsController < Decidim::Accountability::ApplicationController
helper Decidim::TraceabilityHelper
helper Decidim::Accountability::BreadcrumbHelper

helper_method :results, :result, :first_class_taxonomies, :count_calculator
helper_method :results, :result, :count_calculator, :selected_root_taxonomy, :selected_taxonomy_children, :selected_taxonomy_grandchildren?

before_action :set_controller_breadcrumb

Expand Down Expand Up @@ -46,8 +46,24 @@ def default_filter_params
}
end

def first_class_taxonomies
@first_class_taxonomies ||= current_organization.taxonomies.where(parent_id: current_component.available_root_taxonomies, id: current_component.available_taxonomy_ids)
def selected_taxonomy_grandchildren?
@selected_taxonomy_grandchildren ||= selected_root_taxonomy.all_children.count > selected_taxonomy_children.count
end

def selected_taxonomy_children
return [] if selected_root_taxonomy.blank?

@selected_taxonomy_children ||= current_organization.taxonomies.where(parent_id: selected_root_taxonomy.id, id: current_component.available_taxonomy_ids)
end

def selected_root_taxonomy
@selected_root_taxonomy ||= if params[:root_taxonomy_id] == "list"
nil
elsif params[:root_taxonomy_id].blank?
current_component.available_root_taxonomies.find_by(id: component_settings.default_taxonomy)
else
current_component.available_root_taxonomies.find_by(id: params[:root_taxonomy_id])
end
end

def count_calculator(taxonomy_id)
Expand Down
36 changes: 33 additions & 3 deletions decidim-accountability/app/packs/stylesheets/accountability.scss
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,16 @@
}

&__grid {
@apply grid md:grid-cols-3 items-start gap-x-10 gap-y-8 md:gap-y-16;
@apply grid md:grid-cols-3 items-start gap-x-6 gap-y-6;

& > :nth-child(even) {
@apply grid md:col-span-2;
&--one-level {
@apply grid;
}

&--two-levels {
& > :nth-child(even) {
@apply grid md:col-span-2;
}
}

/* display the titles only for the first two rows in desktop */
Expand Down Expand Up @@ -171,4 +177,28 @@
&__filters {
@apply w-full space-y-10;
}

&__taxonomies {
@apply w-full;

ul {
@apply flex flex-wrap gap-4 mt-4;

li {
@apply bg-white py-1 px-4 rounded;

a {
@apply text-secondary font-semibold text-sm;
}

&.active {
@apply bg-secondary text-white;

a {
@apply text-white;
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="accountability__filters">
<%= render partial: "search" %>
<%= render partial: "root_taxonomies_selector" %>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<h1 class="title-decorator"><%= component_name %></h1>

<% if component_settings.display_progress_enabled? %>
<%= cell(
"decidim/accountability/status",
nil,
title: t("decidim.accountability.results.home_header.global_status"),
progress: progress_calculator(nil).presence,
extra_classes: "accountability__status__home"
) %>
<% end %>
<%= render partial: "filters" %>
Original file line number Diff line number Diff line change
@@ -1,32 +1,9 @@
<div class="accountability__grid">
<% first_class_taxonomies.each do |taxonomy| %>
<% subelements = cell(
"decidim/accountability/status",
taxonomy,
extra_classes: "accountability__status__background",
url: results_path(filter: { taxonomies_part_of_contains: taxonomy }),
render_blank: true
) %>
<h3 class="mb-8 font-semibold text-xl">
<%= translated_attribute(selected_root_taxonomy.name) %>
</h3>

<div>
<%= subelements.call %>
</div>

<div>
<% if subelements.has_results? %>
<div class="accountability__subgrid">
<% taxonomy.children.where(id: current_component.available_taxonomy_ids).each do |sub_taxonomy| %>
<%= cell(
"decidim/accountability/status",
sub_taxonomy,
extra_classes: "accountability__status__border",
url: results_path(filter: { taxonomies_part_of_contains: sub_taxonomy })
) %>
<% end %>
</div>
<% else %>
<%= cell("decidim/announcement", t("no_results", scope: "decidim.accountability.results")) %>
<% end %>
</div>
<% end %>
</div>
<% if selected_taxonomy_grandchildren? %>
<%= render "two_levels_taxonomies" %>
<% else %>
<%= render "one_level_taxonomies" %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div class="accountability__grid accountability__grid--one-level">
<% selected_taxonomy_children.each do |taxonomy| %>
<% subelements = cell(
"decidim/accountability/status",
taxonomy,
extra_classes: "accountability__status__background",
url: results_path(filter: { taxonomies_part_of_contains: taxonomy }),
render_blank: true
) %>

<% if subelements.has_results? %>
<div>
<%= subelements.call %>
</div>
<% end %>
<% end %>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,4 @@
<% end %>
</div>

<div class="accountability__filters">
<%= render partial: "search" %>
</div>
<%= render partial: "filters" %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div class="accountability__taxonomies">
<h2 class="accountability__taxonomies__title">
<%= t("decidim.accountability.results.root_taxonomies.title") %>
</h2>
<ul>
<% current_component.available_root_taxonomies.each do |taxonomy| %>
<% is_selected = selected_root_taxonomy&.id == taxonomy.id %>
<li class="<%= "active" if is_selected && action_name == "home" %>">
<% if is_selected %>
<%= link_to translated_attribute(taxonomy.name), home_results_path(root_taxonomy_id: "list") %>
<% else %>
<%= link_to translated_attribute(taxonomy.name), home_results_path(root_taxonomy_id: taxonomy.id) %>
<% end %>
</li>
<% end %>
</ul>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<div class="accountability__grid accountability__grid--two-levels">
<% selected_taxonomy_children.each do |taxonomy| %>
<% subelements = cell(
"decidim/accountability/status",
taxonomy,
extra_classes: "accountability__status__background",
url: results_path(filter: { taxonomies_part_of_contains: taxonomy }),
render_blank: true
) %>

<% if subelements.has_results? %>
<div>
<%= subelements.call %>
</div>

<div>
<div class="accountability__subgrid">
<% taxonomy.children.where(id: current_component.available_taxonomy_ids).each do |sub_taxonomy| %>
<%= cell(
"decidim/accountability/status",
sub_taxonomy,
extra_classes: "accountability__status__border",
url: results_path(filter: { taxonomies_part_of_contains: sub_taxonomy })
) %>
<% end %>
</div>
</div>
<% end %>
<% end %>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,10 @@
<%= append_stylesheet_pack_tag "decidim_accountability" %>

<% content_for :aside do %>
<h1 class="title-decorator"><%= component_name %></h1>

<% if component_settings.display_progress_enabled? %>
<%= cell(
"decidim/accountability/status",
nil,
title: t("decidim.accountability.results.home_header.global_status"),
progress: progress_calculator(nil).presence,
extra_classes: "accountability__status__home"
) %>
<% end %>
<div class="accountability__filters">
<%= render partial: "search" %>
</div>
<%= render partial: "home_aside" %>
<% end %>

<%= render layout: "layouts/decidim/shared/layout_two_col" do %>

<% if Decidim::Map.available?(:geocoding, :dynamic) && component_settings.geocoding_enabled? %>
<div class="accountability__map">
<%= cell "decidim/map", @all_geocoded_results, metadata_card: "decidim/accountability/result_metadata" %>
Expand All @@ -36,14 +22,14 @@
<div class="editor-content"><%= decidim_sanitize_admin translated_attribute(component_settings.intro) %></div>
</section>

<section class="layout-main__section">
<% if first_class_taxonomies.empty? %>
<%= cell("decidim/announcement",
params[:filter].present? ?
t("empty_filters", scope: "decidim.accountability.results.home") :
t("empty", scope: "decidim.accountability.results.home")) %>
<% end %>
<%= render partial: "home_taxonomies" %>
</section>

<% if selected_root_taxonomy.present? %>
<section class="layout-main__section">
<%= render partial: "home_taxonomies" %>
</section>
<% else %>
<section id="results" class="layout-main__section">
<%= cell "decidim/accountability/results", results %>
<%= decidim_paginate results, order_start_time: params[:order_start_time] %>
</section>
<% end %>
<% end %>
8 changes: 5 additions & 3 deletions decidim-accountability/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,11 @@ en:
results_count:
one: 1 result
other: "%{count} results"
home:
empty: There are no results yet.
empty_filters: There are no results with this criteria.
home_header:
global_status: Global execution status
no_results: There are no projects
root_taxonomies:
title: 'View by:'
search:
search: Search for actions
show:
Expand All @@ -304,6 +303,8 @@ en:
clear_all: Clear all
comments_enabled: Comments enabled
comments_max_length: Comments max length (Leave 0 for default value)
default_taxonomy: Default taxonomy
default_taxonomy_help: Select which taxonomy you want to show by default. If no taxonomy is selected, the results will be shown in a list format.
define_taxonomy_filters: Please define some filters for this participatory space before using this setting.
display_progress_enabled: Display progress
geocoding_enabled: Maps enabled
Expand All @@ -313,6 +314,7 @@ en:
taxonomy_filters_add: Add filter
step:
comments_blocked: Comments blocked
visualization: Visualization
download_your_data:
show:
result_comments: Result comments export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
settings.attribute :intro, type: :text, translated: true, editor: true
settings.attribute :display_progress_enabled, type: :boolean, default: true
settings.attribute :geocoding_enabled, type: :boolean, default: false
settings.attribute :default_taxonomy, type: :select, include_blank: true, raw_choices: true, choices: lambda { |context|
context[:component].available_root_taxonomies.map { |taxonomy| [taxonomy.name["en"], taxonomy.id] }
}
end

component.register_stat :results_count, primary: true, priority: Decidim::StatsRegistry::HIGH_PRIORITY do |components, _start_at, _end_at|
Expand Down
4 changes: 4 additions & 0 deletions decidim-accountability/lib/decidim/accountability/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class Engine < ::Rails::Engine
routes do
resources :results, only: [:index, :show] do
resources :versions, only: [:show]

collection do
get :home
end
end
root to: "results#home"
end
Expand Down
13 changes: 4 additions & 9 deletions decidim-accountability/spec/system/explore_results_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@
let(:taxonomy_filter_ids) { [] }

it "shows an empty page with a message" do
expect(page).to have_content "There are no results yet"
expect(page).to have_content "There are no projects"
end
end

context "with a taxonomy" do
it "shows an empty page with a message" do
within "main" do
expect(page).to have_i18n_content(taxonomy.name)
expect(page).to have_content "There are no projects"
end
end
Expand Down Expand Up @@ -85,14 +84,10 @@
expect(page).to have_css(".accountability__map")
end

it "shows taxonomies and sub_taxonomies with results for enabled filters" do
[taxonomy, sub_taxonomy].each do |item|
taxonomy_count = Decidim::Accountability::ResultsCalculator.new(component, item.id).count
expect(page).to have_content(translated(item.name)) if taxonomy_count.positive?
it "shows root taxonomies filters" do
within("aside") do
expect(page).to have_content(translated(taxonomy.parent.name))
end

expect(page).to have_no_content(translated(other_taxonomy.name))
expect(page).to have_no_content(translated(other_sub_taxonomy.name))
end

it "shows progress" do
Expand Down
Loading
Loading