Commit Graph

7679 Commits

Author SHA1 Message Date
Javi Martín
334b57501b Simplify uses of polymorphic admin nested routes 2020-06-11 18:39:57 +02:00
Javier Martín
f929108870 Merge pull request #4023 from consul/homepage_confirm_dialog
Don't use confirm dialog in admin homepage form
2020-05-26 18:14:58 +02:00
Senén Rodero Rodríguez
31c0b4360d Improve the way to toggle comment responses
Co-Authored-By: Javi Martín <javim@elretirao.net>
2020-05-26 13:20:26 +02:00
Senén Rodero Rodríguez
dcff7e8a33 Show parent comment responses when a new reply is added
When a user replies to a comment whose responses was hidden at the
moment of reply form submission and although the reply were correctly
added to the DOM it was hidden because was added to a collapsed list.

This solution is about showing all responses of parent comment after adding
the new comment to the DOM so the user can see new reply into the screen.
(This is not applicable to root comments which cannot be collapsed)
2020-05-26 13:20:26 +02:00
Senén Rodero Rodríguez
014fa6eb1c Add mutations observer to initialize user initials added through ajax 2020-05-26 13:20:26 +02:00
Senén Rodero Rodríguez
956f002738 Update parent comment responses count when a new reply is created
Extract the needed portion of code to a new partial to be able to update
only the elements needed when a new comment is added keeping UI properly
updated.
2020-05-26 13:20:26 +02:00
Javi Martín
5bf968d2b2 Don't use confirm dialog in admin homepage form
In this case the confirmation dialog isn't really necessary since the
action to enable/disable the setting can easily be undone.

Furthermore, these tests were failing with Chrome 83, probably because
we use `confirm_dialog` and then we use `visit` without checking the
page in between.

In theory we shouldn't need to check the page in between because the
request generated by `confirm_dialog` is a synchronous one and so
`visit` isn't executed after the previous request has finished, but
apparently this behavior has changed in Chrome 83.

We could add an expectation before executing the `visit` method, but
that wouldn't improve the usability of the application.
2020-05-25 19:28:16 +02:00
Javi Martín
1e883af9cd Don't count errors for the same field twice
The number of errors in a form includes several errors for the same
field. For example, if a title is mandatory and has to have at least 5
characters, leaving the title blank will result in two errors. So users
will be invited to look for two errors, but they'll only find one field
with errors.

So it's a bit more intuitive to show as many errors as fields having
errors.

Note we're excluding errors on `:base`, which is a bit of a hack for
errors in association fields. For example, if the title of one
translation is not present, `resource.errors.messages` will contain two
elements: one for the translation's title, and one for the `base` field.
This resulted in the count of errors being 2 when there was only one.

Also note I haven't found a way to count errors on all `has_many`
relations. That is, if two translations have a missing title field, only
one error will be mentioned in the message (as it did before this
commit).
2020-05-18 17:57:06 +02:00
Javier Martín
d9d18f0d15 Merge pull request #3995 from rockandror/fix_map_zoom_js_error
Do not update form location fields when marker is not defined
2020-05-14 19:36:26 +02:00
Javier Martín
8c9264f24e Merge pull request #3992 from consul/remote_translations_runtime
Check remote translations locales at runtime
2020-05-13 18:04:51 +02:00
Javi Martín
ae41becd3a Use CSS to hide reply forms
We were using inline styles and passing local variables around, while
the rule we were following is very simple: it's only hidden if it's a
form to reply to a comment.
2020-05-12 23:57:57 +02:00
Javi Martín
5d362ced1f Fix duplicate HTML IDs in comment forms
Since there were many on the page, the resulting HTML was invalid.
2020-05-12 23:57:57 +02:00
Javi Martín
faefb52972 Use the same code to add comments and replies 2020-05-12 23:57:57 +02:00
Javi Martín
4627372a62 Use a <ul> tag for a list of comments
We were using a <ul> tag for a single comment, where the first element
of the list was the comment itself and the second element was the list
of replies.

IMHO it makes more sense to have a list of all comments, where every
element is a comment and inside it there's a list of replies.

We're also rendering the list even if it has no children so it's easier
to add comments through JavaScript. Then we use the :empty CSS selector
to hide the list if it's empty. However, since ERB adds whitespace if we
structure our code the usual way and current browsers don't recognize
elements with whitespace as empty, we have to use the `tag` helper so no
whitespace is added.
2020-05-12 23:57:16 +02:00
Javi Martín
bedd879025 Remove redundant show/hide screen reader texts
These texts are redundant since we added the same texts for everyone in
commit 6b85ed87.
2020-05-12 23:23:01 +02:00
Javi Martín
41b9d2ba01 Simplify code to show/collapse comment replies
Tests are also a bit easier to read, even though we need to use the
`text:` option to find links because otherwise the text in the hidden
`<span>` tags will cause `click_link` to miss the link we want to click.

Here's an explanation by one of Capybara's authors:
https://github.com/teamcapybara/capybara/issues/2347#issuecomment-626373440
2020-05-12 23:23:01 +02:00
Javi Martín
255e56c0f2 Simplify toggleClass call
This method accepts several classes as arguments, so there's no need to
call it twice.
2020-05-11 16:09:23 +02:00
Javi Martín
06b7c6dbd3 Simplify comment partial variables
We were passing around many variables to condition the way we display
the comment. However, in the end we only had one place where these
variables were used: valuation. So we can make everything depend on the
valuation variable.
2020-05-11 16:09:23 +02:00
Javi Martín
573f861ad1 Don't use comment_flags to cache comments
Flagging a comment automatically updates the comment, so the cache
expires anyway, making the `comment_flags` variable redundant.
2020-05-11 16:09:23 +02:00
Javi Martín
fbaa5c2388 Remove unused commentable tree partial
It was created in commit 83d254ad, but it was never used, since the
commit creating it removed the code rendering the
`budgets/investments/comments` partial, which this partial was supposed
to replace.
2020-05-11 16:09:23 +02:00
Javier Martín
2fee7099ae Merge pull request #3998 from rockandror/ckeditor-browser-history-back
Destroy and intialize ckeditor on browser history back
2020-05-11 14:29:39 +02:00
Senén Rodero Rodríguez
3d0ce57f03 Destroy and intialize ckeditor on browser history back
When a page with ckeditor is restored from browser cache by using browser
history back feature application was trying to re-initialize it but this was
throwing some javascript errors that left ckeditor useless. The ckeditor user
interface seemed to be loaded correctly but editor contents was not shown
and ckeditor locked.

This solution is about destroying all ckeditor instances on page before
leaving it and force the reinitialization after Turbolinks restored the cache.
Inspiration here [1].

There is a similar patch to make it work with Turbolinks 5.x versions [2].

  [1] https://github.com/galetahub/ckeditor/issues/575#issuecomment-132757961
  [2] https://github.com/galetahub/ckeditor/issues/575#issuecomment-241185136
2020-05-11 11:15:45 +02:00
Javier Martín
4b9a05d4d8 Merge pull request #3997 from rockandror/remove_ajax_complete
Do not run all javascript after every ajax call
2020-05-09 13:43:08 +02:00
Senén Rodero Rodríguez
c2b9377055 Extract duplicated code to method 2020-05-09 08:17:56 +02:00
Senén Rodero Rodríguez
70a9fb7355 Do not call initialize_modules after every ajax call
We were calling initialize_modules after every ajax call only to apply the
application javascript to new elements added though ajax calls, this is not
always needed because some ajax calls do not add new elements to the user
interface so there is no new elements to initialize. This technique was working
fine in most cases but was causing different kind of problems at some pages where
some elements where being unnecessarily reinitiliazed causing the execution of the
element associated scripts as many times as the element was initialized. This fix
should relief a little bit of work to users browsers.

After this change we had to fix some pieces of javascript:

Regarding LegistationAnnotatable module, since we are not re-initializing Annotator
app we cannot destroy it so now we only need to insert the new annotation into annotator
interface to keep it properly updated.

Regarding Comments module, we do not need anymore the initialization check because this
code only will be fired once now we do not launch application initialization after ajax
calls. Also, when a new comment is created its added to the DOM through AJAX and include
some elements that needs javascript initialization to work. By using
"Delegated event handlers" [1] new comments will be initialized automatically when added.

[1] https://api.jquery.com/on/#direct-and-delegated-events
2020-05-09 08:17:55 +02:00
Senén Rodero Rodríguez
0ec1f6a4f8 Do not update form location fields when marker is not defined 2020-04-30 19:44:23 +02:00
Javi Martín
e7fcca9b47 Check remote translations locales at runtime
We were evaluating its value when the server starts. On production
enviroments, that could mean weeks or months before the available
locales are checked again, and so it would be possible to use a list
which is no longer in sync with the list provided by microsoft.
2020-04-28 15:45:32 +02:00
Javi Martín
f2cdc31786 Use ActiveRecord::Relation#count with a block
This method used to ignore the block but in Rails 5.1 it uses
Enumerable#count.

See https://github.com/rails/rails/pull/24203/commits/58772397
2020-04-27 19:26:37 +02:00
Javi Martín
08679bc9cc Use link_to instead of content_tag :a 2020-04-27 19:26:37 +02: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
fa070f326e Remove unnecessary content_tag calls
We're usually using HTML tags in views instead.
2020-04-27 19:26:37 +02:00
Javi Martín
3ba8b05cbb Use Date#all_day in DirectMessage.today
The method `Date#all_day` was added in Rails 5.1, and returns the same
interval we were using while it makes the code simple.
2020-04-27 19:26:37 +02:00
Javi Martín
4e76f90afd Simplify LEFT JOIN using ActiveRecord#left_joins
This method is available since Rails 5.0.
2020-04-27 19:26:37 +02:00
Javi Martín
37361a6f3d Replace render :nothing with head :ok
Using `render :nothing` was deprecated, but we never noticed it because
we didn't have a test for the action using it. In Rails 5.1, it raises
an exception.

Using `head :ok` and adding a test for this scenario solves the issue.
2020-04-24 15:43:54 +02:00
Javi Martín
12774c7484 Replace attribute_changed? in after callbacks
This method is deprecated in Rails 5.1 because its behavior will be
different in `before` and `after` callbacks.

We're replacing the deprecated `attribute_changed?` and `attribute_was`
methods with `saved_change_to_attribute?` and
`attribute_before_last_save` during `after_save` callbacks.

https://github.com/rails/rails/pull/32835/
2020-04-24 15:43:54 +02:00
Javi Martín
c6a8aa1301 Replace attribute_changed? in before callbacks
This method is deprecated in Rails 5.1 because its behavior will be
different in `before` and `after` callbacks.

Here we're replacing the deprecated `attribute_changed?` and
`attribute_was` with `will_save_change_to_attribute?` and
`attribute_in_database` during `before_save` callbacks.

https://github.com/rails/rails/pull/32835/
2020-04-24 15:43:54 +02:00
Javier Martín
082fc1a1b6 Merge pull request #3981 from rockandror/disable-ckeditor-unused-plugins
Disable ckeditor unused plugins
2020-04-23 13:06:50 +02:00
Javier Martín
2e4ff552c6 Merge pull request #3977 from consul/fix_ckeditor_drag_drop
Fix attaching images in CKEditor via drag and drop
2020-04-23 13:03:48 +02:00
Senén Rodero Rodríguez
9fd9ef8a54 Explicitly disable not used ckeditor plugins
All of these plugins are not used anywhere.

Change introduced at ckeditor initializer will ommit unneeded
precompilation of plugins assets on production environments.

Change introduced at ckeditor config file adresses the problem with assets
pipeline fallback on testing environments described here: #2711. Now plugins
that are explicitly disabled will not be precomiled when running ckeditor
javascript enabled feature specs.
2020-04-23 10:37:26 +02:00
Javier Martín
b2d64b20ed Merge pull request #3979 from rockandror/ckeditor-recover-copy-paste
Allow to paste formatted content into ckeditors
2020-04-22 14:57:12 +02:00
Javier Martín
5a80548fc8 Merge pull request #3973 from consul/cards-height
Replace equalizer to display flex on cards
2020-04-21 14:00:02 +02:00
decabeza
caedd21da8 Move cards to shared partials 2020-04-21 12:54:16 +02:00
Senén Rodero Rodríguez
1e3f7e0062 Allow to paste formatted content into ckeditors 2020-04-20 20:27:00 +02:00
Javi Martín
8e4f9d5173 Fix attaching images in CKEditor via drag and drop
The URL used for the generated request was
`/ckeditor/pictures&responseType=json`. This is a known issue in the
ckeditor gem, and it's suggested to add a `?` at the end of the URL in
order to fix it.

I haven't added a test for this case since simulating dropping a file in
the browser with Selenium/Capybara seems to be quite tricky and I
haven't found a solution guaranteed to correctly emulate what users do.
2020-04-18 12:39:30 +02:00
Javier Martín
56bc0c6e41 Merge pull request #3976 from rockandror/deactivate-ckeditor-file-attachment
Deactivate ckeditor file attachments feature
2020-04-18 12:38:31 +02:00
Senén Rodero Rodríguez
7466148408 Deactivate ckeditor file uploads feature
This feature was not working so its better to disable it completely.

By removing attachment_files endpoints related buttons and tabs from ckeditor UI are not shown to users anymore.
2020-04-18 09:21:25 +02:00
Javier Martín
87e6ed5bfb Merge pull request #3972 from consul/icon-comments
Replaces icons of expand/collapse comments
2020-04-17 19:44:43 +02:00
decabeza
111e3d3083 Replaces icons of expand/collapse comments 2020-04-16 23:22:14 +02:00
Javi Martín
95a90b1895 Simplify method to calculate document max size
Since we're only doing the convertion from bytes to megabytes in one
place, IMHO adding an extra method makes the code harder to read.

This way we don't have do include the DocumentsHelper in the specs
anymore, reducing the risk of possible method naming collisions.
2020-04-16 12:08:09 +02:00
Javi Martín
ca2dc10ee9 Simplify method to check an image max size
We were converting megabytes to bytes with the `megabytes` method and
then adding a `bytes_to_megabytes` method to convert it back to bytes,
which is the same as not doing anything at all :).
2020-04-16 12:08:09 +02:00