Commit Graph

56 Commits

Author SHA1 Message Date
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
584176adfa Add and apply Style/ArrayIntersect rubocop rule
The `intersect?` method has been added in Ruby 3.1, and it's more
readable than `(a & b).any?`.
2023-09-12 15:19:04 +02:00
Javi Martín
f87d4b589d Add and apply Naming/BlockForwarding rubocop rule
This syntax has been added in Ruby 3.1.

Not using a variable name might not be very descriptive, but it's just
as descriptive as using "block" as a variable name. Using just `&` we
get the same amount of information than using `&block`: that we're
passing a block.

We're still using `&action` in `around_action` methods because here we
aren't using a generic name for the variable, so (at least for now) we
aren't running this cop on controllers using `around_action`.
2023-09-12 15:17:28 +02:00
Javi Martín
8b13daad95 Add and apply rules for multi-line hashes
For the HashAlignment rule, we're using the default `key` style (keys
are aligned and values aren't) instead of the `table` style (both keys
and values are aligned) because, even if we used both in the
application, we used the `key` style a lot more. Furthermore, the
`table` style looks strange in places where there are both very long and
very short keys and sometimes we weren't even consistent with the
`table` style, aligning some keys without aligning other keys.

Ideally we could align hashes to "either key or table", so developers
can decide whether keeping the symmetry of the code is worth it in a
case-per-case basis, but Rubocop doesn't allow this option.
2023-08-18 14:56:16 +02:00
Javi Martín
790170a27c Use keyword arguments in tag methods
The interface of this method has changed and uses keyword arguments
instead of a hash of options. This change will be particularly
significant when upgrading to Ruby 3.
2022-08-24 15:10:36 +02:00
Javi Martín
7c8e3788ec Use new module_parent and module_parents methods
We were getting some deprecation warnings:

DEPRECATION WARNING: `Module#parent` has been renamed to
`module_parent`. `parent` is deprecated and will be removed in Rails
6.1.

DEPRECATION WARNING: `Module#parents` has been renamed to
`module_parents`. `parents` is deprecated and will be removed in Rails
6.1.
2022-08-24 14:36:49 +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
taitus
9ac6511d96 Render interface translation by default on SDGManagement 2020-12-21 17:08:39 +01:00
Javi Martín
749428d93f Replace content_tag with new tag builder syntax
One of the main advantages of this syntax is we can now omit the content
parameter when it's empty.
2020-04-27 19:26:37 +02:00
Javi Martín
ac6d50e06b Remove tracker role
The current tracking section had a few issues:

* When browsing as an admin, this section becomes useless since no
investments are shown
* Browsing investments in the admin section, you're suddenly redirected
to the tracking section, making navigation confusing
* One test related to the officing dashboard failed due to these changes
and had been commented
* Several views and controller methods were copied from other sections,
leading to duplication and making the code harder to maintain
* Tracking routes were defined for proposals and legislation processes,
but in the tracking section only investments were shown
* Probably many more things, since these issues were detected after only
an hour reviewing and testing the code

So we're removing this untested section before releasing version 1.1. We
might add it back afterwards.
2019-11-01 20:08:46 +01:00
Javi Martín
8ed3595b70 Revert local variable extraction
It doesn't seem very useful.

This commit reverts part of commit 74083df1.
2019-11-01 16:49:14 +01:00
Javi Martín
a727dcc031 Apply Style/SymbolProc rubocop rule
This style is much more concise.
2019-10-26 20:10:32 +02:00
Javi Martín
eafb4018bf Apply Style/CollectionMethods rubocop rule
We were already using `map` and `reduce` almost everywhere.
2019-10-26 13:03:49 +02:00
Javi Martín
db1ccb18c7 Use safe_join instead of html_safe
The name `html_safe` is very confusing, and many developers (including
me a few years ago) think what that method does is convert the HTML
contents to safe content. It's actually quite the opposite: it marks the
string as safe, so the HTML inside it isn't stripped out by Rails.

In some cases we were marking strings as safe because we wanted to add
some HTML. However, it meant the whole string was considered safe, and
not just the contents which were under our control.

In particular, some translations added by admins to the database or
through crowding were marked as safe, when it wasn't necessarily the
case.

Although AFAIK crowdin checks for potential cross-site scripting
attacks, it's a good practice to sanitize parts of a string potentially
out of our control before marking the string as HTML safe.
2019-10-08 18:46:20 +02:00
Javi Martín
4a19bb6b77 Simplify generating fields with hints
We were already using this code in translatable forms. Using it on every
form means we can reduce the code we need to generate a field with a
hint.
2019-10-06 18:03:38 +02:00
Javi Martín
ae6fab9f5e Inherit from builder instead of monkey patching it
We were monkey-patching FoundationRailsHelper::Formbuilder, which made
form customization difficult. We can inherit from it, which is the
standard way of extending what an existing class does, and make our form
the default one.
2019-10-05 16:01:58 +02:00
Javi Martín
9c3686a6d8 Remove unused block parameters
We're using `yield` in the method body.
2019-10-05 15:03:25 +02:00
Senén Rodero Rodríguez
907fc18ff7 Override translations _destroy value depending of our translations managment logic
During any translatable resource edit, if you remove all translations
you will be redirected to same form with errors showing you one of
persisted but marked to destroy translations, without this patch
_destroy field value wil be true and you will no able to persist without
re-addding the same language through translation interface.
2019-07-02 17:15:39 +02:00
Senén Rodero Rodríguez
966b5b19ba Mark all translations that do not exist for destruction
When a translation not exists yet we can mark them all for destruction
by default. They already should be initialized correctly from database
or via nested attributes.
2019-07-02 17:15:34 +02:00
taitus
a5a62b7471 Add Tracking to backend_translations_enabled? 2019-07-01 15:03:48 +02:00
Senén Rodero Rodríguez
a6e8fecc16 Highlight translation interface and translatable form fields
Only when translations interface is enabled.

Co-Authored-By: alessandro <agileontheweb@gmail.com>
2019-07-01 14:49:43 +02:00
Senén Rodero Rodríguez
73563e5d86 Display needed translations when translation interface is disabled
Display only current locale translation when translation interface is disabled.

Co-Authored-By: javierm <javim@elretirao.net>
2019-06-27 09:20:25 +02:00
Senén Rodero Rodríguez
7e3f0b5c18 Add translation interface feature setting
Allow to enable/disable translation interface at frontend
2019-06-27 09:20:25 +02:00
German Galia
74083df10f Add historic fields to participatory budget 2019-06-12 18:03:53 +02:00
Senén Rodero Rodríguez
f87804aa90 Update helpers after globalize gem version update
Globalize has fixed new translations globalized_model initialization
so we have to adapt existing code.
2019-04-17 17:40:55 +02:00
Javi Martín
2a1b50beba Extract method to render form fields for a locale 2018-10-22 16:36:18 +02:00
Javi Martín
361a15640f Use detect instead of select.first 2018-10-22 16:36:18 +02:00
Javi Martín
1895e2dd2f Make it easier to know destroy_field is an input
By using the input and finding it by its name, it's easier to see the
difference between this input and the delete-language link.
2018-10-22 16:36:18 +02:00
Javi Martín
dbea577062 Follow naming conventions for HTML classes and IDs
We use underscores for IDs and hyphens for classes.
2018-10-22 16:36:18 +02:00
Javi Martín
0505028d77 Extract method in translatable builder
This way we fix the rubocop warning for line too long and make the code
a bit easier to read.
2018-10-22 16:36:17 +02:00
Javi Martín
34b5a88564 Fix updating translatables without current locale
The current locale wasn't being marked for destruction and so saving
the record tried to create a new translation for the current locale.
2018-10-22 16:36:17 +02:00
Javi Martín
6d6eb1f849 Fix ambiguous field in test 2018-10-22 16:36:17 +02:00
Javi Martín
1255aa5032 Make private methods private 2018-10-22 16:36:17 +02:00
Javi Martín
7479223d59 Wrap translation fields in a div
This way we can show/hide that div when displaying translations, and we
can remove the duplication applying the same logic to the label, the
input, the error and the CKEditor.

This way we also solve the problem of the textarea of the CKEditor
taking space when we switch locales, as well as CKEditor itself taking
space even when not displayed.
2018-10-22 16:36:17 +02:00
Javi Martín
ffb8207f84 Show error message for just the displayed locale
Unfortunately the builder didn't offer any options for the error message
and we just had to overwrite the `error_for` methods.
2018-10-22 16:36:17 +02:00
Javi Martín
3b5a12b0ab Don't force translations for the current locale
Globalize creates a translation for the current locale, and the only way
I've found to change this behaviour is to monkey-patch it.

The original code uses `translation.locale` instead of
`Globalize.locale`. Since `translation.locale` loads the translation
with empty attributes. It both makes the record invalid if there are
validations and it makes it almost impossible to create a record with
translations which don't include the current locale.

See also the following convertations:

https://github.com/globalize/globalize/pull/328
https://github.com/globalize/globalize/issues/468
https://github.com/globalize/globalize/pull/578
https://github.com/shioyama/mobility/wiki/Migrating-from-Globalize#blank-translations
2018-10-22 16:28:53 +02:00
Javi Martín
124b8496de Simplify methods defining translation styles
This refactor is going to be useful when we change these rules within
the next few commits.
2018-10-22 16:28:53 +02:00
Javi Martín
e0b9c1bfdd Update poll question answers translatable fields
We needed to bring back support for CKEditor in our translatable form,
which we had temporarily remove.

And now we support CKEditor in our translatable specs, and so we can
remove the duplicated specs for poll question answers.
2018-10-22 16:13:48 +02:00
Javi Martín
6278175f57 Update legislation drafts translatable fields
Updating it required reorganizing the form so translatable fields are
together.

We also needed to add a `hint` option to the form label and input
methods so the hint wouldn't show up for every language.

Finally, the markdown editor needed to use the same globalize attributes
as inputs, labels and hints, which adds a bit of duplication.
2018-10-22 15:44:14 +02:00
Javi Martín
7deb857357 Don't disable new invalid translations
After adding a new translation with invalid data and sending the form,
we were disabling the new translation when displaying the form again to
the user, which was confusing.
2018-10-22 15:43:28 +02:00
Javi Martín
1d2979cd57 Keep invalid translation params through requests
We were reloading the values from the database and ignoring the
parameters sent by the browser.
2018-10-22 15:43:28 +02:00
Javi Martín
5cdda12902 Simplify passing the locale to translatable fields
Creating a new form builder might be too much. My idea was so the view
uses more or less the same syntax it would use with Rails' default
builder, and so we can use `text_field` instead of
`translatable_text_field`.
2018-10-22 15:43:28 +02:00
Javi Martín
71601bd3f8 Validate translations in banners
This change forces us to use nested attributes for translations, instead
of using the more convenient `:"title_#{locale}"` methods.

On the other hand, we can use Rails' native `_destroy` attribute to
remove existing translations, so we don't have to use our custom
`delete_translations`, which was a bit buggy since it didn't consider
failed updates.
2018-10-22 15:43:28 +02:00
Julian Herrero
4344165bce change translatable form helper for cktext_area 2018-09-24 19:40:51 +02:00
Julian Herrero
e6762d6bca handle non-underscored locale names for cktext_area 2018-09-21 20:50:23 +02:00
Marko Lovic
c7fcdd9b0e Use standard locale names for Globalize
It turns out it is not necessary to downcase and underscore
locale names to use the globalize-accessor gem. The gem
will automatically underscore the locale name when defining and
calling the accessor methods.
2018-09-11 18:48:14 +02:00
Marko Lovic
6fe7dc22bc Fix translatable field labels to not include locale
Label for field :title should be "Title", not "Title en"
2018-09-11 18:48:09 +02:00
Marko Lovic
ca5f8719a8 Fix helper to merge style option correctly 2018-09-11 18:48:05 +02:00
Marko Lovic
1fb1437886 Fix merging_translatable_field_options helper 2018-09-11 18:48:01 +02:00
Marko Lovic
5ad3bf03cd Nest TranslatableFormBuilder in helper module
To avoid having multiple top-level classes per file
2018-09-11 18:47:57 +02:00