Commit Graph

996 Commits

Author SHA1 Message Date
Senén Rodero Rodríguez
ede6a3f73f Disable Turbolinks page loading for language links
Only when the current language has a different text direction
than the localization link to generate.
2022-06-08 07:12:29 +02:00
decabeza
7f0f35a5c0 Add mailer helpers to simplify customization 2022-06-02 17:56:15 +02:00
Javi Martín
7212657c02 Remove Paperclip and use just Active Storage 2022-02-23 18:43:48 +01:00
Javi Martín
8e6df7f5d9 Use Active Storage to render custom images
Just like we did with regular attachments, we're moving the logic to
generate URLs out of the model.

Note we're changing the `image_path_for` helper method in order to
return a `polymorphic_path` because sometimes it's used in combination
with `favicon_link_tag`, and `favicon_link_tag` doesn't automatically
generate a polymorphic URL when given an `ActiveStorage::Attachment`
record.
2022-02-23 18:21:38 +01:00
Javi Martín
091abfc944 Use Active Storage to render attachments
This way we fix a bug we mentioned in commit 930bb753c which caused
links to documents to be broken when editing their title because the
title was used to generate the URL of the document.

Note we're still using Paperclip to render cached attachments because
this is the only case where we store files with just Paperclip and not
Active Storage.

With Active Storage, we render attachments just like any other resource,
using `polymorphic_path`. Paperclip included the `url` method in the
model; since the model doesn't have access to the request parameters
(like the host), this was inconvenient because it wasn't possible to
generate absolute URLs with Paperclip.

In order to simplify the code and make it similar to the way we used
Paperclip, we're adding a `variant` method accepting the name of a
variant and returning the variant.
2022-02-23 18:21:38 +01:00
Javi Martín
86ad2df46d Unify code in debates/legislation vote links
We were using the same code to render links to agree and disagree, so we
can extract a new component for this code.

We're also adding component tests to make it easier to test whether
we're breaking anything while refactoring, although the code is probably
already covered by system tests.

Since the votes mixin was only used in one place, we're removing it and
moving most of its code to a new CSS file for the shared component.
2022-02-21 18:47:13 +01:00
Javi Martín
b98244afd9 Remove votes query optimizations
Just like we did in commit 0214184b2d for investments, we're removing
some possible optimizations (we don't have any benchmarks proving they
affect performance at all) in order to simplify the code.

The investement votes component `delegate` code was accidentally left
but isn't used since commit 0214184b2, so we're removing it now that
we're removing the `voted_for?` helper method.
2022-02-21 18:47:13 +01:00
Javi Martín
231a7aa8ee Remove unused code to track events
We forgot to remove it in commit f28a5cc49.

The generated HTML was invalid, with the error:

> Element meta is missing one or more of the following attributes:
> content, property.
2021-12-30 17:05:07 +01:00
Javi Martín
78e543f6d3 Extract method to get a user segment name
We're going to add geozones as user segments, so it's handy to have the
method in the UserSegments class.

We're also changing the `user_segment_emails` parameter name for
consistency and simplicity.
2021-12-20 15:07:43 +01:00
rgarcia
68a2281203 Refactor segment constant into a class method
We're going to make it dynamic using the geozones. Besides, class
methods can be overwritten using custom models, while constants can't be
overwritten without getting a warning [1].

Makes the definition of segments with geozones a little cleaner. I
think it’s worth it, compared to the slight memory gain of using a
constant [2].

[1] warning: already initialized constant UserSegments::SEGMENTS

[2] https://stackoverflow.com/questions/15903835/class-method-vs-constant-in-ruby-rails#answer-15903970
2021-12-20 15:07:25 +01:00
Javi Martín
519a34b1f8 Use the admin header in the management section
Now that we also have the "go back to CONSUL" link, the layouts are so
similar that it isn't worth it maintaining both of them separately.

With this change, people using small screens also get the "menu" button
in the management section, just like they do everywhere else.

We're adding the `namespace != "management"` condition so the menu still
shows up in the officing namespace.
2021-12-15 13:53:56 +01:00
Javi Martín
735f99f877 Fix comment notifications on legislation proposals
The `commentable_url` method wasn't updated when we added legislation
proposals.

Back when we first created this method, we couldn't pass budget
investments or topics directly to `polymorphic_url` because they are
nested resources. That isn't the case since commit ff93f5a59, so now we
can simplify this method.

We're keeping the `commentable_url` method for now in order to keep
compatibility with custom changes that might use it, although this
method isn't consistent with the `commentable_path` method (which
receives a comment, and not a commentable), and so we might have to
revisit this code in the future.
2021-11-29 16:16:15 +01:00
Javi Martín
756a16f67a Remove investment filters in groups
The interface was a bit confusing, since after clicking on "See
unfeasible investments" (or similar), we were on a page where no
investments were shown.

Besides, since commit 7e3dd47d5, the group page is only linked from the
"my ballot" page, through a link inviting the user to vote in that
group, and it's only possible to vote selected investments (which is the
default filter during the final voting phase).

The only reason we had these links here was these links weren't present
in the investments page. But they're present there since commit
04605d5d5, so we don't need them in the group page anymore.
2021-10-29 15:01:40 +02:00
Javi Martín
4a42804a7d Extract calculate winners button to a component
This way we remove some duplication.
2021-10-19 02:33:53 +02:00
Javi Martín
b35c8bda4b Move form field partial to a component
This way it's easier to test; changing it will also be easier.

During my experiments I made a mistake which wasn't covered by the test
suite. We're adding a test for this case.

Note we're using `i18n_content` in the component instead of `content`
because there's already a `content` method provided by ViewComponent.
2021-10-11 20:03:07 +02:00
Senén Rodero Rodríguez
c115165ef1 Fix social share image URL with external storage
Co-Authored-By: Pierre Mesure <pierre@mesu.re>
2021-09-21 15:09:45 +02:00
Javi Martín
b52ceb2c78 Move attachable methods from helpers to models
We were using helper methods inside the model; we might as well include
them in the model and use them from anywhere else.

Note we're using a different logic for images and documents methods.
That's because for images the logic was defined in the helper methods,
but for documents the logic is defined in the Documentable concern. In
the past, different documentable classes allowed different content
types, while imageable classes have always allowed the same content
types.

I'm not sure which method is better; for now, I'm leaving it the way it
was (except for the fact that we're removing the helper methods).
2021-09-11 17:05:00 +02:00
Javi Martín
d14f6691dc Return document max file size in megabytes
The same way it's done for images.

We were converting the number of megabytes to bytes and then converting
it to megabytes again. Instead, we can leave it as it is and only
convert it to bytes when necessary (only one place).
2021-09-11 17:05:00 +02:00
Javi Martín
720d3530d7 Add and apply Style/HashTransformKeys rubocop rule
The `transform_keys` method is available since Ruby 2.5.
2021-09-03 11:49:53 +02:00
Javi Martín
65c9786db7 Apply Layout/RedundantLineBreak rule to short lines
We're not adding the rule because it would apply the current line length
rule of 110 characters per line. We still haven't decided whether we'll
keep that rule or make lines shorter so they're easier to read,
particularly when vertically splitting the editor window.

So, for now, I'm applying the rule to lines which are about 90
characters long.
2021-09-03 11:49:53 +02:00
Javi Martín
2bc6018465 Add and apply Style/HashConversion rubocop rule
This rule was added in Rubocop 1.10.0. This style is IMHO clearer and
possible since Ruby 2.1.
2021-09-03 11:49:53 +02:00
Javi Martín
0be6eb9512 Add and apply Style/RedundantParentheses rule
Parentheses make the code harder to read in these cases.
2021-09-03 11:49:52 +02:00
Javi Martín
a868a5ff35 Change Foundation text direction in RTL languages
This way, when the language is written form right-to-left, elements
using Foundation mixins/classes will float to the opposite direction as
they do in left-to-right languages. The same will apply to text
alignment.

To offer full support for RTL languages, we need to change every single
reference to `float: left`, `float: right`, `text-align: left`,
`text-align: right`, and possible adjust other properties like `left`,
`margin-left`, `padding-left` or `border-left`. In the meantime, we at
least partially support these languages.

Replacing `float` with `flex` when possible would also improve RTL
support.
2021-08-16 17:47:33 +02:00
Machine Learning
4d27bbebad Add experimental machine learning 2021-08-16 16:31:04 +02:00
Javi Martín
ab9e99f45c Merge pull request #4288 from consul/dependabot/bundler/rubocop-rails-2.9.1
Bump rubocop-rails from 2.6.0 to 2.9.1
2021-08-10 13:23:32 +02:00
Javi Martín
69dda19af7 Add and apply Rails/PluckId rubocop rule 2021-08-09 23:52:47 +02:00
Javi Martín
469b39ffa3 Add and apply Style/RedundantInterpolation rule
Somehow I thought we already had this rule; must have forgotten to
actually add it.
2021-08-09 21:37:04 +02:00
Javi Martín
99bbad9b1e Add and apply Style/RedundantCondition rule
This is a rule we generally follow all the time but accidentally forgot
in one place.
2021-08-09 19:21:31 +02:00
Javi Martín
a102f3f0a7 Add and apply Style/ExplicitBlockArgument rule
We were already applying it in most places.
2021-08-09 19:11:29 +02:00
Javi Martín
930bb753c5 Use a rake task to delete cached attachments
Our previous system to delete cached attachments didn't work for
documents because the `custom_hash_data` is different for files created
from a file and files created from cached attachments.

When creating a document attachment, the name of the file is taken into
account to calculate the hash. Let's say the original file name is
"logo.pdf", and the generated hash is "123456". The cached attachment
will be "123456.pdf", so the generated hash using the cached attachment
will be something different, like "28af3". So the file that will be
removed will be "28af3.pdf", and not "123456.pdf", which will still be
present.

Furthermore, there are times where users choose a file and then they
close the browser or go to a different page. In those cases, we weren't
deleting the cached attachments either.

So we're adding a rake task to delete these files once a day. This way
we can simplify the logic we were using to destroy cached attachments.

Note there's related a bug in documents: when editing a record (for
example, a proposal), if the title of the document changes, its hash
changes, and so it will be impossible to generate a link to that
document. Changing the way this hash is generated is not an option
because it would break links to existing files. We'll try to fix it when
moving to Active Storage.
2021-07-30 17:30:11 +02:00
Javi Martín
a181052f0d Move nested images partial to a component 2021-07-13 16:58:13 +02:00
Javi Martín
c9113041c0 Move nested documents partial to a component 2021-07-13 16:58:13 +02:00
Javi Martín
3073fee4c8 Remove unused documentable class method
It isn't used since commit 6c1d828a6.
2021-07-13 16:58:13 +02:00
Javi Martín
810814486c Move document fields partial to a component 2021-07-13 16:58:13 +02:00
Javi Martín
d58c2f8323 Move image fields partial to a component 2021-07-13 16:58:13 +02:00
Javi Martín
a7ed1f9a37 Remove unused errors on attachment methods
They aren't used since commit f8d78ec4a.
2021-07-13 16:58:13 +02:00
Javi Martín
d0243764a2 Extract component to render a list of links
This way it's easier to refactor it and/or change it.

Back in commit c156621a4 I wrote:

> Generally speaking, I'm not a big fan of helpers, but there are
> methods which IMHO qualify as helpers when (...) many Rails helpers,
> like `tag`, follow these principles.

It's time to modify these criteria a little bit. In some situations,
it's great to have a helper method so it can be easily used in view
(like `link_to`). However, from the maintenance point of view, helper
methods are usually messy because extracting methods requires making
sure there isn't another helper method with that name.

So we can use the best part of these worlds and provide a helper so it
can be easily called from the view, but internally make that helper
render a component and enjoy the advantages associated with using an
isolated Ruby class.
2021-07-05 22:27:39 +02:00
Javi Martín
422404085f Extract poll questions filter to a component 2021-06-30 16:42:23 +02:00
Javi Martín
ccbc708b5b Simplify poll select options helper
The `include_all` parameter was always used, and the option was
redundant because we already had a prompt offering the same
functionality.

I guess one possible reason was users would want to filter by all polls,
and having to click on "select a poll" to do so wasn't that intuitive.
So we're using "All" as the prompt instead.
2021-06-30 16:42:23 +02:00
Javi Martín
d8d5b7f60a Extract budget executions filters to a component 2021-06-29 20:07:55 +02:00
Javi Martín
bf10cf0c18 Simplify calls to content_block helper
All calls were using `I18n.locale` as the second parameter, so we might
as well make it optional.
2021-06-24 13:15:04 +02:00
Javi Martín
d5f4313f59 Simplify getting URL to support an investment
We're also changing the method name to `vote_path` in order to be
consistent with the way Rails uses `_path` for relative URLs.
2021-06-14 14:38:34 +02:00
Javi Martín
57628a78d9 Move investment votes partial to a component
This way changing it will be easier.
2021-06-14 12:51:41 +02:00
Javi Martín
82e8de094b Extract budget form to a component
This way it will be easier to change it and reuse it.
2021-06-08 14:25:43 +02:00
taitus
ea8ce24a2a Only make suggestions for related titles for new records
Avoid show suggestions for :edit and :update actions.
2021-04-12 11:05:51 +02:00
taitus
56d3840c40 Extract to help method to fill in the data for the suggestions 2021-04-12 11:04:32 +02:00
Julian Herrero
7e3dd47d5a Unify budget landing pages
There was a big difference between the current budget and a specific
budget landing page. This didn't really make too much sense. Also, it
was not possible to know how a draft participatory budget will look
before it was published.

By unifying those two views now they will look quite similar and it
will be possible for administrators to preview any draft budget and to
know how the budget will look like before actually publishing it.
2021-03-18 15:03:21 +01:00
Julian Herrero
16c582f282 Extract component for budget groups and headings 2021-03-18 13:59:09 +01:00
decabeza
04605d5d5b Add filters on budget investments index page
Now it's easier to change the investments filter. Previously we had to
go back to the budget index page, change the filter there, and then
select one heading.

Now the links to change the current filter in the budget index page
aren't needed anymore.
2021-03-17 13:44:01 +01:00
Julian Herrero
28caabecdf Refactor participatory budgets in draft mode
Previously the draft mode was a phase of the PB, but that had some
limitations.

Now the phase drafting disappears and therefore the PB can have the
status published or not published (in draft mode).

That will give more flexibility in order to navigate through the
different phases and see how it looks for administrators before
publishing the PB and everybody can see.

By default, the PB is always created in draft mode, so it gives you
the flexibility to adjust and modify anything before publishing it.
2021-02-23 17:05:24 +01:00