Commit Graph

1038 Commits

Author SHA1 Message Date
Javi Martín
7f749bb9bb Add and apply Style/CollectionQuerying rubocop rule
This rule was added in rubocop 1.77. We were following it most of the
time. It makes the code more readable in my humble opinion.
2025-11-05 14:27:12 +01:00
dependabot[bot]
1fa3cf8ce7 Bump rubocop from 1.76.1 to 1.81.1
This release includes some updates in the Style/RedundantParentheses and
Naming/PredicateMethod rules. We're changing the code accordingly.

Bumps [rubocop](https://github.com/rubocop/rubocop) from 1.76.1 to 1.81.1.
- [Release notes](https://github.com/rubocop/rubocop/releases)
- [Changelog](https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rubocop/rubocop/compare/v1.76.1...v1.81.1)

---
updated-dependencies:
- dependency-name: rubocop
  dependency-version: 1.81.1
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-11-05 14:27:11 +01:00
taitus
1f97a996f8 Move resource partial to a component
We're renaming it to ActiveResource in order to better differentiate it
from the DefaultResource component.
2025-08-27 17:40:45 +02:00
Javi Martín
34c8559065 Remove helper that returned a polymorphic path
This is similar to what we did in commits 1a902a967 and fa3781059.
2025-08-22 13:38:03 +02:00
Javi Martín
a548c497fc Move recommended index partial to a component
Thanks to it, we can slightly simplify the debates view rendering it.
2025-08-22 13:32:04 +02:00
Javi Martín
909272d879 Move users following partial to a component 2025-08-22 13:25:50 +02:00
Javi Martín
b00ddfc931 Move helper method to the component 2025-08-22 13:12:10 +02:00
taitus
b9bffeb321 Add and apply Naming/PredicateMethod RuboCop 1.76 rule
This rule was introduced in RuboCop 1.76.0 to ensure methods ending
in '?' return boolean.

This commit applies suggested renames and code cleanup:
- Renames 'is_active?' to 'active_class' since it returns a string
- Renames 'parsed_value' to 'in_favor?' and 'is_request_active' to end with '?'
  for boolean semantics
- Skips false positives like 'save', 'auto_labels' or 'save_requiring_finish_signup',
  which are not predicate methods.
2025-06-16 16:07:35 +02:00
Javi Martín
1632990838 Extract component to render officing results form
In a couple of commits we're going to add some styles for this form, and
it's easier to know where to add these styles when there's a component.
2025-04-03 15:00:12 +02:00
Javi Martín
ee03712df0 Move milestones progress bars partial to a component 2025-04-02 14:44:01 +02:00
Javi Martín
932d4cd698 Fix wrong ARIA attribute in dashboard actions form
Using a `data-toggle` attribute, which we do since commit 07fd5084f,
made Foundation generate an `aria-expanded` attribute to a radio button,
but this attribute can't be present in radio buttons. This makes sense,
since the main purpose of a radio button in a form is to choose an
option, not to show/hide content.

This resulted in the following error when checking the page with Axe:

```
Found 1 accessibility violation:

aria-allowed-attr: Elements must only use supported ARIA attributes
(critical)
https://dequeuniversity.com/rules/axe/4.10/aria-allowed-attr?application=axeAPI
The following 2 nodes violate this rule:

  Selector: #dashboard_action_action_type_proposed_action
  HTML: <input data-toggle="request_to_administrators short_description"
               type="radio" value="proposed_action" checked="checked"
               name="dashboard_action[action_type]"
               id="dashboard_action_action_type_proposed_action"
               aria-expanded="true"
               aria-controls="request_to_administrators">
  Fix all of the following:
    - ARIA attribute is not allowed: aria-expanded="true"

  Selector: #dashboard_action_action_type_resource
  HTML: <input data-toggle="request_to_administrators short_description"
               type="radio" value="resource"
               name="dashboard_action[action_type]"
               id="dashboard_action_action_type_resource"
               aria-expanded="true"
               aria-controls="request_to_administrators">
  Fix all of the following:
    - ARIA attribute is not allowed: aria-expanded="true"
```

So we're using custom JavaScript instead. We're also making the
`short_description` field act as intended; since the changes in commit
07fd5084f it was never shown because it had the `hide` HTML class and it
didn't have a `data-toggler` attribute.
2025-04-02 13:43:29 +02:00
Javi Martín
985d3da032 Move officing menu partial to a component
This way we can move some system tests to component tests and stop
creating records after starting the browser with a `visit`.

We could also split the system test in two, but since these tests
aren't checking any user interactions, moving the to component tests we
check the same things while making the tests faster.

Since the partial was using an instance variable, we're passing it to
the component. We're naming it `voter_user` instead of `user` because
passing something named `user` could make us think that we're passing
the `current_user`. I wasn't sure about naming it `voter` because it's a
`User` record and not a `Poll::Voter` record, but naming it `voter`
would definitely be an option.
2025-04-01 15:08:55 +02:00
Javi Martín
d18510e102 Remove unused image_default parameter
This parameter isn't used since commit b4a6f664b.

Note we're changing the tests to use proposals instead of debates
because proposals may have images attached, while debates may not.
2025-03-26 16:42:04 +01:00
Javi Martín
11816f833d Use a flex layout to render participation processes lists
This way we simplify the HTML, which had some `if...else` blocks that
were hard to follow because there were opening tags inside these blocks
while the closing tags were outside these blocks.

We're also making the CSS container-dependent instead of
window-dependent. Since there are between one and three elements inside
the panel, we accomplish this by making the element with the content
take its own line if the width of the panel is smaller than 35rem.

Note we're trying to keep the layout similar to what it was; since we're
no longer using negative margins (like the ones in the `.row` selector),
the votes element now gets a width of 22.5% instead of 25%.

Also note we're using the column-gap property for flexbox because the
`flex-with-gap` mixin doesn't work so well with elements that have
borders. Since the column-gap property for flexbox is now supperted by
more than 98% of the browsers (which wasn't the case when we started
using the `flex-with-gap` mixin), the `flex-with-gap` mixin has become
obsolete.

Finally, note we're removing the `max-width: 12rem` rule in the images.
I'm not sure why we introduced this rule in the first place, and it
didn't play so well to the new layout. I considered using code like
`max-width: min(100%, 12rem)`, but, since I'm not sure why `12rem` was
there in the first place, I'm not sure whether this approach was better,
and it sure made things more complex.
2025-03-06 18:49:39 +01:00
Javi Martín
53ff81dfdf Unify code applying the colors of a process
We had some duplication because the `css_for_process_header` was using
an instance variable, and so it couldn't be called from a partial where
this instance variable wasn't available.

Using a local variable and passing it as a parameter (as we should
always do) solves the issue and lets us simplify the code.
2025-03-06 18:25:45 +01:00
Javi Martín
ee34ead4ee Move poll shifts form partial to a component
Thanks to it, we can move a few helper methods to the component.
2024-11-12 15:17:16 +01:00
Javi Martín
9ab6c15975 Remove unused method in shifts helper
We don't use this method since commit 452723628.
2024-11-12 15:16:23 +01:00
Javi Martín
6af8ddd324 Extract component to render the date of birth
We reduce code duplication thanks to that, and make it easier
to change this field.

Note that there was one place where the "16.years" value was
hardcoded. We're moving the test for this case to the
component and changing it so the test doesn't use the default
age.

We're also removing the redundant helper method that had the
same code as a method in the User class which is called
everywhere else.
2024-11-12 15:15:34 +01:00
Javi Martín
6f81215425 Merge pull request #5786 from consuldemocracy/stats_turbolinks_reload
Include stat graphs JavaScript in all admin stats actions
2024-11-11 15:46:15 +01:00
Javi Martín
c28ff49f10 Move investments search form partial to a component
As a bonus, we now have a few less helper methods :).
2024-11-11 15:04:40 +01:00
Javi Martín
9a4aea9381 Extract method to include stat graphs JavaScript
We're going to use this method everywhere in the admin stats section.
2024-11-08 19:37:09 +01:00
Javi Martín
3931b43b87 Move omniauth form partial to a component
This way we simplify the view a little bit and replace some slow system
tests with faster component tests.
2024-10-28 21:23:56 +01:00
Javi Martín
607dabbc8a Move admin investments partial to a component
This way it'll be easier to organize the code related to it.
2024-10-25 17:24:32 +02:00
Javi Martín
3cebce9a29 Extract link to toggle selection to a component 2024-10-25 16:40:32 +02:00
Javi Martín
1b18151941 Use minimum and maximum in enumerables
While the `minimum` and `maximum` methods have been available for a long
time for ActiveRecord relations, Rails 7.0 has added these methods for
enumerables as well.

This means that the `start_date` and `end_date` methods in the
ShiftsHelper can use `minimum` and `maximum` no matter whether they
receive an ActiveRecord relation or an array of polls (I think the
latter never happens, though, but I'm not 100% sure).
2024-07-22 18:35:35 +02:00
Javi Martín
46dc4a3163 Add and apply Style/MapIntoArray rubocop rule
This rule was added in rubocop 1.63.0.
2024-07-09 11:23:02 +02:00
Javi Martín
8997ed316c Rename variables describing poll options as answers
Since we've renamed the class to `Option`, having variables, methods and
texts refering to it as `answer` was confusing.
2024-06-13 19:13:05 +02:00
Javi Martín
765ab758dc Extract component to render a poll in the poll index
This is consistent with the way we've got partials to render debates,
proposals and legislation processes on their index pages.

Note that, while adding the tests for the status icon, we're keeping one
system test because it also tests the process of voting. We're adding a
new, similar component test, where the voter is created in the database,
so all possible statuses are tested in the component.
2024-06-07 15:52:02 +02:00
Javi Martín
579e332cf8 Extract component to render an embedded video 2024-06-06 17:35:27 +02:00
Javi Martín
236b58ab01 Remove duplication in code to validate video URL
We were using the same code, and the same regular expressions, in two
places. To do so, we were including a helper inside a model, which is
something we don't usually do.
2024-06-06 17:35:27 +02:00
Javi Martín
722e50a669 Simplify code to find a content block
We're only calling the `block_for` method from one place: the
`content_block` helper, and we're never passing the locale parameter to
that helper, which means we're always calling `block_for` using
`I18n.locale`.

So I'm not sure why we were doing the `locale ||=` assignment, since
`I18n.locale` doesn't return nil.

In any case, since this was added in commit c1de2dced, Ruby has added
support for arguments forwarding, so we can use it here to simplify the
code a little bit.
2024-06-05 16:10:56 +02:00
Javi Martín
c11780880c Move form builders to their own folder
We were defining one builder in the `app/lib/` folder and another one
inside a helper module.

So now we're grouping them together. This way we're following the "one
class per file" convention that we follow most of the time. And, by
extracting the `TranslatableFormBuilder` class to its own file, it'll be
easier to add tests for it.

Note that, for consistency, we're renaming the
`TranslationsFieldsBuilder` class so it ends in `FormBuilder`.
2024-06-05 16:10:56 +02:00
Javi Martín
26b48e527a Move information texts form partial to a component
This way it'll be easierto write tests for it when we change it.
2024-06-05 16:10:56 +02:00
Javi Martín
b451a251fc Rename methods that returns an array of locales
Having `_languages` in the method name made it harder to know what that
method was returning.
2024-06-05 16:10:55 +02:00
Javi Martín
5f09718e77 Move globalize locales partial to a component 2024-06-05 16:10:55 +02:00
Javi Martín
9a4a7bd56e Remove obsolete parameter rendering globalize locales
This parameter isn't used since commit b86c0d3c3, which deleted a file
that wasn't used since commit 146c09adb. Further proof that this code
wasn't used is the fact that the `enable_translation_style` method,
which this code called, was removed in commit 5ada97544.
2024-06-05 16:10:55 +02:00
Javi Martín
4855fee3d5 Remove unused code in globalize helper
This code isn't used since commit 041abe904.
2024-06-05 16:10:55 +02:00
Javi Martín
f7e2d724dd Replace ahoy events with real data
We were tracking some events with Ahoy, but in an inconsistent way. For
example, we were tracking when a debate was created, but (probably
accidentally) we were only tracking proposals when they were created
from the management section. For budget investments and their supports,
we weren't using Ahoy events but checking their database tables instead.
And we were only using ahoy events for the charts; for the other stats,
we were using the real data.

While we could actually fix these issues and start tracking events
correctly, existing production data would remain broken because we
didn't track a certain event when it happened. And, besides, why should
we bother, for instance, to track when a debate is created, when we can
instead access that information in the debates table?

There are probably some features related to tracking an event and their
visits, but we weren't using them, and we were storing more user data
than we needed to.

So we're removing the track events, allowing us to simplify the code and
make it more consistent. We aren't removing the `ahoy_events` table in
case existing Consul Democracy installations use it, but we'll remove it
after releasing version 2.2.0 and adding a warning in the release notes.

This change fixes the proposal created chart, since we were only
tracking proposals created in the management section, and opens the
possibility to add more charts in the future using data we didn't track
with Ahoy.

Also note the "Level 2 user Graph" test wasn't testing the graph, so
we're changing it in order to test it. We're also moving it next to the
other graphs test and, since we were tracking the event when we were
confirming the phone, we're renaming to "Level 3 users".

Finally, note that, since we were tracking events when something was
created, we're including the `with_hidden` scope. This is also
consistent with the other stats shown in the admin section as well as
the public stats.
2024-05-09 14:28:32 +02:00
Javi Martín
1edf0d937d Move stats graph partial to a component
Note we're naming it "chart" in order to avoid possible conflicts with
the "graph" view when we move it to a component.
2024-05-09 14:28:31 +02:00
Javi Martín
4e9ed4dfa6 Extract component to render links to event stats 2024-05-09 14:28:31 +02:00
Javi Martín
445b01c280 Move management menu partial to a component
So it's consistent with the `Admin::MenuComponent`.
2024-04-18 15:48:21 +02:00
Javi Martín
1a0f4ec65f Follow Zeitwerk conventions in names with acronyms
We were getting a few errors when trying out Zeitwerk:

```
expected file lib/sms_api.rb to define constant SmsApi

expected file app/components/layout/common_html_attributes_component.rb
to define constant Layout::CommonHtmlAttributesComponent
```

In these cases, we aren't using an inflection because we also define the
`Verification::SmsController` and a few migrations containing `Html` in
their class name, and none of them would work if we defined the
inflection.

We were also getting an error regarding classes containing WYSIWYG in
its name:

```
NameError: uninitialized constant WYSIWYGSanitizer
Did you mean?  WysiwygSanitizer
```

In this case, adding the acronym is easier, since we never use "Wysiwyg"
in the code but we use "WYSIWYG" in many places.
2024-04-11 19:08:01 +02:00
Javi Martín
f8c97b9bb9 Remove monkey-patch of the Numeric class
This monkey-patch doesn't seem to be working with Zeitwerk, and we were
only using it in one place, so the easiest way to solve the problem is
to remove it.

Note that, in the process, we're changing the operation so `* 100`
appears before the division, so it's consistent with other places where
we do similar things (like the `supports_percentage` method in the
proposals helper).
2024-04-11 19:08:01 +02:00
Javi Martín
7828e6d8ee Simplify argument forwarding when possible
IMHO it's now more obvious that these methods only forward their
arguments to other methods.
2024-04-11 17:59:40 +02:00
Javi Martín
fdfdbcbd0d Add and apply Style/ArgumentsForwarding rule
We were using generic names like `args` and `options` which don't really
add anything to `*` or `**` because Ruby required us to.

That's no longer the case in Ruby 3.2, so we can simplify the code a
bit.
2024-04-11 17:59:40 +02:00
taitus
45d82d6e6b Move comments form to component 2024-03-25 07:59:39 +01:00
taitus
260196ca54 Use comments component for legislation annotations and questions 2024-03-22 08:56:13 +01:00
Senén Rodero Rodríguez
0643606dcd Add new setting to enable/disable map marker clustering 2024-01-29 17:56:54 +01:00
Senén Rodero Rodríguez
57c257e91c Extract settings table partial to a component 2024-01-25 18:29:38 +01:00
Javi Martín
0aee568977 Add and apply Rails/RedundantActiveRecordAllMethod
This rule was introduced in rubocop-rails 2.21.0.
2023-11-20 14:22:12 +01:00