Commit Graph

32 Commits

Author SHA1 Message Date
Javi Martín
629e208e9d Add and apply ArgumentAlignment rubocop rule
We're choosing the default `with_first_argument` style because it's the
one we use the most.
2023-08-18 14:56:16 +02:00
Javi Martín
adfb141d1b Simplify URL validation in related content
We were using `Setting["url"]` to verify the content belonged to the
application URL, but we can use `root_url` instead.

Note that means we need to include the port when filling in forms in the
tests, since in tests URL helpers like `polymorphic_url` don't include
the port, but a port is automatically added when actually making the
request.
2022-10-02 16:54:06 +02:00
Javi Martín
c8d8fae98d Move related list partial to a component
This way the code is easier to follow; the code checking whether the
list has contents is in the partial rendering the list.

We also remove some duplication setting up related content in the
controllers.

For some reason, we have to manually ignore i18n keys which were
automatically ignored when the code was in the view.
2021-08-16 16:30:13 +02:00
Javi Martín
14e9b71766 Show score actions after their related content
"Is it related content? Yes (link) No (link)".

After reading that, you probably haven't decided whether to click the
"Yes" link or the "No" link or neither of them. You probably have to
read the content it's related to, and then go back to these links.

That's the reason we style them so they're on the right of the screen on
languages which are read from left to right, so first we read the
content and then we read the links to mark it as related or unrelated.

So it makes sense to put these links after the content they refer to.
This way users with small screens as well as screen reader users will
also see/hear these links after they get the proper context. It will
also be more intuitive for keyboard users, who saw the focus on the
links before focusing on the title of the related content, when they
probably expected the opposite.

Since we're now using a flexbox layout instead of a right float, this
also means the content will automatically be shown on the left when
switching the content direction to "right to left".
2021-06-23 23:06:24 +02:00
Javi Martín
a5a0977f36 Reuse related content variable
We were defining a variable and then using it in some places while
calculating it again in some other places.
2021-06-23 23:06:24 +02:00
Javi Martín
f298a308c2 Show actions to score related content to everyone
We were only showing these actions to users with small screens and to
mouse users on hover. Keyboard users or users with a touch screen of a
medium or large size could never find out the actions were there.
2021-06-23 23:06:24 +02:00
Javi Martín
49e0138cd1 Fix label in related content form
It didn't have a `for` attribute and so it wasn't correctly associated
with its input. That means clicking on / touching the label didn't have
the effect of focusing on the field, and screen readers wouldn't
announce the label.
2021-06-23 23:06:24 +02:00
Javi Martín
85215e7e97 Fix aria-expanded value in related content button
The button was announced as expanded when the form was hidden and as
collapsed when the form was shown.

This is because Foundation sets the expanded attribute based on whether
the class to toggle already exists. Since initially the form had the
"hide" class and the button toggled that class, Foundation checked that
the class was already present and so set the button as expanded.

So we're changing the toggler class for a class we don't use at all,
just so Foundation initiall sets `aria-expanded=false` and then changes
it to `aria-expanded=true` after the button is clicked. Then we're
ignoring this class completely and are styling this form with CSS
instead.

We could also use a toggler class like "visible" and write something
like:

```
.add-related-content + form:not(.visible) {
  display: none;
}
```

However, using ARIA attributes is more robust as it guarantees the
styles will always be in sync with what screen reader users experience.

And we could also remove all the Foundation toggler functionality and
use our own JavaScript to handle the button state. We might do so in the
future.
2021-06-23 23:06:24 +02:00
Javi Martín
f910b326ea Fix indentation in related content form code 2021-06-23 23:06:24 +02:00
Javi Martín
089fe3cd1f Put button to add content next to its related form
This way the relationship between the two elements is more obvious. And
since now the button and the form are siblings, it's easier to find one
based on the other using CSS or JavaScript.
2021-06-23 23:06:18 +02:00
Javi Martín
767b65e7d6 Remove unused related content button ID attribute 2021-06-22 22:33:02 +02:00
Javi Martín
ea2a613359 Render related content form just to signed in users
It doesn't make much sense to render a hidden form to users who will not
be able to use it.
2021-06-22 22:33:02 +02:00
Javi Martín
8a697216d1 Fix invalid HTML in related content button
A button cannot be inside an anchor tag, and it might confuse some
browsers or screen readers.

We're also making it clear in the tests that the intention is to use a
button there by using `click_button` instead of `click_on` since the
latter also clicks on links.
2021-06-22 22:32:08 +02:00
Javi Martín
f9ed186909 Add rubocop spacing rules
We were following these rules in most places; we just didn't define them
anywhere.
2019-09-10 21:04:56 +02:00
Javi Martín
c62da726b8 Apply SpaceAroundErbTag ERB Lint rule 2019-09-10 20:02:15 +02:00
Julian Herrero
f6489bc604 Use double quotes in app/views 2019-03-19 12:33:07 +01:00
María Checa
a1f840e8fd Added improvements to related contents 2018-01-12 18:35:15 +01:00
Bertocq
46dc559301 Filter out nil related contents while listing them 2017-12-31 20:30:45 +01:00
Bertocq
3eecabe9a8 Prevent authors or users that already scored from scoring related content 2017-12-20 03:06:41 +01:00
Bertocq
2e0dd9caea Relationable find_related_content should not be used to find, refactored to have a single purpose 2017-12-20 02:36:13 +01:00
María Checa
b99a2eac6f Fixed tests 2017-12-19 19:10:43 +01:00
decabeza
44b34eb2ac shows add related content link if user is logged 2017-12-19 18:51:46 +01:00
decabeza
f03d922124 fixes styles for mobile size 2017-12-19 18:51:28 +01:00
decabeza
bf073d8535 adds styles to related content score 2017-12-19 17:52:43 +01:00
María Checa
fcb6c7a19d Added related contents score views 2017-12-19 13:20:30 +01:00
María Checa
4b181ead28 Added related content report views 2017-12-18 21:29:38 +01:00
María Checa
067945518e Added check for related_contents 2017-12-15 17:22:27 +01:00
Raimond Garcia
cd89cb801c Merge pull request #2190 from consul/related-content-form
Related content form
2017-12-15 09:59:56 +01:00
María Checa
1830a7bb04 Added pagination for relationed content list 2017-12-14 20:54:35 +01:00
María Checa
88fc740863 Moved RELATIONABLE_MODELS from controller to model 2017-12-14 20:48:32 +01:00
María Checa
586b1ae201 Added related content form 2017-12-14 14:50:47 +01:00
María Checa
4f442792cc Added working related contents list
Also separated related contents into partials.
2017-12-13 13:32:00 +01:00