Skip to content

Commit

Permalink
Merge branch 'develop' into feature/main_ctas_sticky_buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
ElviaBth committed Jun 10, 2024
2 parents 977b434 + 0376e6d commit 4cd0f0c
Show file tree
Hide file tree
Showing 27 changed files with 370 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Individual workflows with changes:
- `ci_javascript.yml`: Runs tests for the JS files. Tests must run from the project root folder. You will need to install NodeJS and the JS dependencies:

```yml
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- run: npm ci
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/brakeman.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
if: "!startsWith(github.head_ref, 'chore/l10n')"
timeout-minutes: 60
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: ruby/setup-ruby@v1
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build_app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ jobs:
env:
POSTGRES_PASSWORD: postgres
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ inputs.ruby_version }}
bundler-cache: true
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node_version }}
cache: 'npm'
cache-dependency-path: ./package-lock.json
- uses: actions/cache@v3
- uses: actions/cache@v4
id: app-cache
with:
path: ./spec/decidim_dummy_app/
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/ci_generators.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,27 @@ jobs:
DATABASE_HOST: localhost
RUBYOPT: '-W:no-deprecated'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ env.RUBY_VERSION }}
bundler-cache: true
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Get npm cache directory path
id: npm-cache-dir-path
run: echo "dir=$(npm get cache)-${{ env.DECIDIM_MODULE }}" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
- uses: actions/cache@v4
id: npm-cache
with:
path: ${{ steps.npm-cache-dir-path.outputs.dir }}
key: npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
npm-
- uses: actions/cache@v3
- uses: actions/cache@v4
id: app-cache
with:
path: ./Gemfile.lock
Expand All @@ -106,7 +106,7 @@ jobs:
working-directory: ${{ env.DECIDIM_MODULE }}
env:
SIMPLECOV: "true"
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
name: Upload coverage
with:
token: ${{ env.CODECOV_TOKEN }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci_javascript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ jobs:
if: "!startsWith(github.head_ref, 'chore/l10n')"
timeout-minutes: 60
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Get npm cache directory path
id: npm-cache-dir-path
run: echo "dir=$(npm get cache)-javascript" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
- uses: actions/cache@v4
id: npm-cache
with:
path: ${{ steps.npm-cache-dir-path.outputs.dir }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ env.RUBY_VERSION }}
bundler-cache: true
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Get npm cache directory path
id: npm-cache-dir-path
run: echo "dir=$(npm get cache)-main" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
- uses: actions/cache@v4
id: npm-cache
with:
path: ${{ steps.npm-cache-dir-path.outputs.dir }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci_performance_metrics_monitoring.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@ jobs:
DATABASE_HOST: localhost
RUBYOPT: '-W:no-deprecated'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ env.RUBY_VERSION }}
bundler-cache: true
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Get npm cache directory path
id: npm-cache-dir-path
run: echo "dir=$(npm get cache)-${{ env.DECIDIM_MODULE }}" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
- uses: actions/cache@v4
id: npm-cache
with:
path: ${{ steps.npm-cache-dir-path.outputs.dir }}
Expand All @@ -90,7 +90,7 @@ jobs:
name: Warmup the cache at the configured lighthouse urls
working-directory: ./development_app/
- name: Audit URLs using Lighthouse
uses: treosh/lighthouse-ci-action@v10
uses: treosh/lighthouse-ci-action@v11
with:
runs: 3 # run more than once to warm up the application
uploadArtifacts: true
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci_production_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,20 @@ jobs:
DATABASE_HOST: localhost
RUBYOPT: '-W:no-deprecated'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ env.RUBY_VERSION }}
bundler-cache: true
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Get npm cache directory path
id: npm-cache-dir-path
run: echo "dir=$(npm get cache)-${{ env.DECIDIM_MODULE }}" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
- uses: actions/cache@v4
id: npm-cache
with:
path: ${{ steps.npm-cache-dir-path.outputs.dir }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/lint_code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@ jobs:
if: "!startsWith(github.head_ref, 'chore/l10n')"
timeout-minutes: 60
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ env.RUBY_VERSION }}
bundler-cache: true
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Get npm cache directory path
id: npm-cache-dir-path
run: echo "dir=$(npm get cache)-lint" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
- uses: actions/cache@v4
id: npm-cache
with:
path: ${{ steps.npm-cache-dir-path.outputs.dir }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test_app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ jobs:
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ inputs.ruby_version }}
- uses: nanasess/setup-chromedriver@v2
- uses: actions/cache@v3
- uses: actions/cache@v4
id: app-cache
with:
path: ./spec/decidim_dummy_app/
Expand Down Expand Up @@ -110,13 +110,13 @@ jobs:
SIMPLECOV: "true"
SHAKAPACKER_RUNTIME_COMPILE: "false"
NODE_ENV: "test"
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
name: Upload coverage
with:
token: ${{ inputs.codecov_token }}
name: ${{ inputs.working-directory }}
flags: ${{ inputs.working-directory }}
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
if: always()
with:
name: screenshots
Expand Down
1 change: 1 addition & 0 deletions config/i18n-tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ ignore_unused:
- decidim.admin.participatory_process_steps.default_title
- decidim.authorization_handlers.{direct,multistep}
- decidim.admin.models.assembly_member.positions.*
- decidim.application.documents.component_documents.*
- decidim.statistics.*
- decidim.components.*
- decidim.filters.linked_classes.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
<h2 class="h2 decorator"><%= t("decidim.application.documents.related_documents") %></h2>
</div>

<%= cell "decidim/documents_panel", resource %>
<%= cell "decidim/documents_panel", resource, components_collections: %>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

module Decidim
module ContentBlocks
class ParticipatorySpaceDocumentsCell < BaseCell; end
class ParticipatorySpaceDocumentsCell < BaseCell
COMPONENTS_WITH_DOCUMENTS_COLLECTIONS = [:meetings].freeze

def components_collections
components = resource.try(:components)

return [] if components.blank?

components = components.where(manifest_name: COMPONENTS_WITH_DOCUMENTS_COLLECTIONS).published

include_component_name = components.count > 1

components.map do |component|
Decidim::ComponentAttachmentCollectionPresenter.new(component, include_component_name:)
end
end
end
end
end
4 changes: 4 additions & 0 deletions decidim-core/app/cells/decidim/documents_panel/show.erb
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
<%= render partial: "decidim/application/documents", formats: [:html], locals: { documents: } %>
<% components_collections.each do |collection| %>
<%= render partial: "decidim/application/component_documents", formats: [:html], locals: { collection: } %>
<% end %>
10 changes: 9 additions & 1 deletion decidim-core/app/cells/decidim/documents_panel_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,21 @@ class DocumentsPanelCell < Decidim::ViewModel
alias resource model

def show
return if documents.blank?
return if blank?

render
end

def documents
@documents ||= resource.try(:documents)
end

def components_collections
@components_collections ||= options[:components_collections] || []
end

def blank?
documents.blank? && components_collections.blank?
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# frozen_string_literal: true

module Decidim
#
# Decorator attachments of a component acting as an attachment collection
#
class ComponentAttachmentCollectionPresenter < SimpleDelegator
include Decidim::TranslatableAttributes

def initialize(resource, opts = {})
super(resource)

@include_component_name = opts[:include_component_name]
end

def attachments
@attachments ||= if [resource_model_name, resource_table_name].all?(&:present?)
base_query = Decidim::Attachment.joins(resource_join.join_sources)
.where(resource_table_name => { decidim_component_id: __getobj__.id })
if resource_model&.include?(Decidim::Publicable)
base_query.where.not(resource_table_name => { published_at: nil })
else
base_query
end
else
Decidim::Attachment.none
end
end

def documents
@documents ||= attachments.with_attached_file.order(:weight).select(&:document?)
end

def documents_visible_for(user)
return documents unless resource_model.respond_to?(:visible_for)

attachments.merge(resource_model.visible_for(user)).with_attached_file.order(:weight).select(&:document?)
end

def unused?
documents.blank?
end

def id
"component-#{__getobj__.id}"
end

def name
base_name = I18n.t(manifest_name, scope: "decidim.application.documents.component_documents")

return base_name unless @include_component_name

"#{base_name} - #{translated_attribute(__getobj__.name)}"
end

def description; end

private

def resource_join
resource_table = Arel::Table.new(resource_table_name)
attachments_table = Decidim::Attachment.arel_table
attachments_table.join(resource_table).on(
resource_table[:id].eq(attachments_table[:attached_to_id]),
attachments_table[:attached_to_type].eq(resource_model_name)
)
end

def resource_model_name
@resource_model_name ||= Decidim.resource_registry.find(manifest_name)&.model_class_name
end

def resource_model
@resource_model ||= resource_model_name&.safe_constantize
end

def resource_table_name
@resource_table_name ||= resource_model&.table_name
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
</button>

<div id="dropdown-menu-documents-<%= attachment_collection.id %>" class="documents__collection-content" aria-hidden="true">
<p><%= decidim_escape_translated(attachment_collection.description) %></p>
<% if (description = attachment_collection.description).present? %>
<p><%= decidim_escape_translated(description) %></p>
<% end %>

<div class="documents__container">
<% documents.each do |document| %>
Expand Down
Loading

0 comments on commit 4cd0f0c

Please sign in to comment.