Commit Graph

11379 Commits

Author SHA1 Message Date
Javi Martín
44f71b24db Fix rubocop line too long warning 2018-11-05 18:20:50 +01:00
Javi Martín
9fc235727e 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-11-05 18:20:50 +01:00
Javi Martín
b024363fae Fix removing an option for legislation questions
We were allowing the `_destroy` field for translations, but not for the
options themselves.
2018-11-05 18:20:50 +01:00
Javi Martín
3165b9b9f4 Fix legislation options not being updated
We broke this behaviour by introducing translations and not allowing the
`id` parameter anymore.
2018-11-05 18:20:50 +01:00
Javi Martín
015cdcc557 Simplify creating a process in questions specs 2018-11-05 18:20:50 +01:00
Javi Martín
1c75df92d7 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-11-05 18:20:50 +01:00
Javi Martín
01ed66e9bb Fix alignment in last translatable fields
When we grouped the fields together, the last one turned into a
`last-child`, which foundation automatically aligns to the right.

The markdown editor also needed to be tweaked a little bit.
2018-11-05 18:20:50 +01:00
Javi Martín
7b9b65043f Fix ambiguous field in test 2018-11-05 18:20:50 +01:00
Javi Martín
28ed6aa136 Make private methods private 2018-11-05 18:20:50 +01:00
Javi Martín
2658bb55f6 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-11-05 18:20:50 +01:00
Javi Martín
a48db19c05 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-11-05 18:20:50 +01:00
Javi Martín
87484015da Update information texts translatable fields
This part used the code we deleted in order to make it easier to
refactor the rest of the translatable models. Now we add the code back.
2018-11-05 18:20:50 +01:00
Javi Martín
1f033383e5 Refactor globalize_locales partials to increase DRYness 2018-11-05 18:20:50 +01:00
Angel Perez
4af5e1d46d Improve I18nContent#flat_hash readability using concise variable names 2018-11-05 18:20:50 +01:00
Angel Perez
ae9cad3c5b Avoid ternary operator usage when appending/creating I18n keys
When using the OR operator, if the left side of the expression evaluates
to false, its right side is taken into consideration. Since in Ruby nil
is false, we can avoid using conditionals for this particular scenario
2018-11-05 18:20:50 +01:00
Angel Perez
3c033d0ac3 Improve readability for I18nContent#begins_with_key spec
In order to be consistent with similar specs, the I18nContent#begins_with_key
spec was improved by explicitly specifying an I18n key for one (1) factory
that relied on its default value
2018-11-05 18:20:50 +01:00
Angel Perez
64dbf55d55 Fix Rubocop warnings [ci skip] 2018-11-05 18:20:50 +01:00
Raúl Fuentes
ff6e8c9bcb Move flat_hash to I18nContent model
also add unit tests for this function and a description
into the model of the behaviour of the function
2018-11-05 18:20:50 +01:00
Angel Perez
9b19a4e956 Extract translation logic to helper method 2018-11-05 18:20:50 +01:00
Angel Perez
362157d56e Add I18nContent model specs 2018-11-05 18:20:50 +01:00
Javi Martín
937cf0bdd3 Validate both the model and its translations
This way we guarantee there will be at least one translation for a model
and we keep compatibility with the rest of the application, which
ideally isn't aware of globalize.
2018-11-05 18:20:50 +01:00
Javi Martín
a38eac02df Refactor globalize models code using a concern
I've chosen the name "Globalizable" because "Translatable" already
existed.
2018-11-05 18:20:50 +01:00
Javi Martín
1ab3b7f42d 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-11-05 18:20:50 +01:00
Javi Martín
f2d64833f0 Simplify methods defining translation styles
This refactor is going to be useful when we change these rules within
the next few commits.
2018-11-05 18:20:50 +01:00
Javi Martín
981b13ac9b Update widget cards translatable fields 2018-11-05 18:20:50 +01:00
Javi Martín
e400cb8eae Update site customization pages translatable fields 2018-11-05 18:20:50 +01:00
Javi Martín
e9a5f03089 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-11-05 18:20:50 +01:00
Javi Martín
292609e7ac Update poll questions translatable fields
We need to replace ".title=" by ".title_#{locale}=" in one place because
for some reason globalize builds a new translation record when using the
latter but it doesn't build one when using the former.
2018-11-05 18:20:25 +01:00
Javi Martín
6478bb70c2 Update polls translatable fields
The `:name` attribute is still allowed in the controller because some
forks use it when creating a poll from a budget.
2018-11-05 18:20:25 +01:00
Javi Martín
601fe666d9 Fix question options translations not being saved
If we enabled the locale and then added an option, the "add option" link
added the partial which was generated before enabling the translation,
and so it generated a field where the translation was disabled.

Enabling the translation after inserting each field solves the issue.
2018-11-05 18:20:25 +01:00
Javi Martín
7cd06bd51d Update legislation questions translatable fields 2018-11-05 18:20:25 +01:00
Javi Martín
9c5a7c58a7 Update legislation process translatable fields 2018-11-05 18:20:25 +01:00
Javi Martín
968a5b11d3 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-11-05 18:20:25 +01:00
Javi Martín
d5bd481f7f Update milestones translatable fields
Note the title field was hidden since commit 01b9aa8, even though it was
required and translatable. I've removed the required validation rule,
since it doesn't seem to make much sense and made the translatable
tests harder to write.

Also note the method `I18n.localize`, which is used to set the
milestone's title, uses `I18n.locale` even if it's inside a
`Globalize.with_locale` block, and so the same format is generated for
every locale.
2018-11-05 18:19:50 +01:00
Javi Martín
d40cd3995d Update admin notifications translatable fields
The same way we did for banners.

We needed to add new translation keys so the labels are displayed in the
correct language. I've kept the original `title` and `body` attributes
so they can be used in other places.

While backporting, we also added the original translations because they
hadn't been backported yet.
2018-11-05 18:19:50 +01:00
Javi Martín
5e6dfe6ed8 Disable removed translations
After removing a translation while editing another one with invalid data
and sending the form, we were displaying the removed translation to the
user.

We now remove that translation from the form, but we don't remove it
from the database until the form has been sent without errors.
2018-11-05 18:19:50 +01:00
Javi Martín
a8f8a7bc4f 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-11-05 18:19:50 +01:00
Javi Martín
6fc3389587 Keep invalid translation params through requests
We were reloading the values from the database and ignoring the
parameters sent by the browser.
2018-11-05 18:19:50 +01:00
Javi Martín
1874480ff0 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-11-05 18:19:50 +01:00
Javi Martín
009cea29bf 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-11-05 18:19:50 +01:00
decabeza
68b83f3a2b Removes unnecessary style to orbit slide 2018-11-05 18:19:50 +01:00
decabeza
c30c94f878 Removes condition to allow images and data equalizer on proposals
The proposal image only can be present if feature :allow_images is enabled, so there is no need to include both conditions. The data-equalizer also is unnecessary because the :thumb image already has an fix height.
2018-11-05 18:19:50 +01:00
decabeza
ebca4bca9b Removes styles to fix logo size on devise views 2018-11-05 18:19:50 +01:00
decabeza
22d8a26b33 Removes unnecessary styles for admin budgets groups 2018-11-05 18:19:50 +01:00
decabeza
d5aa4f7807 Fixes color of datepicker calendar 2018-11-05 18:19:50 +01:00
decabeza
889311853e Updates is-active class for view mode 2018-11-05 18:19:50 +01:00
Javi Martín
8cd6253426 Ease customization in processes controller
By extracting a method just for the allowed parameters, forks can
customize this method by reopening the class.
2018-11-05 18:19:50 +01:00
Javi Martín
55a32d8579 Bring back CKEditor images button
It was accidentally deleted in commit 914bfa6.

Note the following spec passes on my machine if we add a `sleep 0.1`
call in the `:wait_readable` part of ruby's `Net::Protocol#rbuf_fill`.
Otherwise, it hangs forever after clicking the `.fileupload-file` div,
which closes its window. It might be solved when upgrading rails,
capybara, selenium or chromedriver.

scenario "Allows images in CKEditor", :js do
  visit edit_admin_site_customization_page_path(custom_page)

  within(".ckeditor") do
    within_frame(0) { expect(page).not_to have_css("img") }

    expect(page).to have_css(".cke_toolbar .cke_button__image_icon")
    find(".cke_toolbar .cke_button__image_icon").click
  end

  within_window(window_opened_by { click_link "Browse Server" }) do
    attach_file :file,
                Rails.root.join('spec/fixtures/files/clippy.jpg'),
                visible: false
    find(".fileupload-file").click
  end

  click_link "OK"

  within(".ckeditor") do
    within_frame(0) { expect(page).to have_css("img") }
  end
end
2018-11-05 18:19:50 +01:00
Javi Martín
5e95339e51 Fix flaky legislation question spec
The test was failing sometimes because of the sequence:

within('#side_menu') do
  click_link "Collaborative Legislation"
end

click_link "All"
expect(page).to have_content 'An example legislation process'
click_link 'An example legislation process'

Right after clicking the "Collaborative Legislation" link, the link 'An
example legislation process' is already available. So sometimes Capybara
might click the links "All" and 'An example legislation process' at more
or less the same time, causing the second link not to be correctly
clicked.

Making sure the "All" link doesn't exist anymore we guarantee Capybara
will wait for the previous AJAX request to finish before clicking the
next link.

Note the test to "Create Valid legislation question" is almost identical
but it doesn't fail because it doesn't use Capybara's JavaScript driver.
2018-11-05 18:19:50 +01:00
decabeza
c80e436614 Removes guide feature 2018-11-05 18:19:50 +01:00