Commit Graph

75 Commits

Author SHA1 Message Date
Javi Martín
b9e137619a Simplify the way we provide the title in most cases
This is consistent with the way we're providing the main class.

Note we're still setting the title using a block in more complex cases.
2024-03-23 00:35:47 +01:00
Javi Martín
2b962f2789 Use a <main> tag on every page
Many pages had this tag, but many other didn't, which made navigation
inconsistent for people using screen readers.

Note that there are slight changes in two pages:

* The homepage now includes the banner and the content of the
  `shared/header` element inside the <main> tag
* The budgets index now includes the banner inside the <main> tag

I see both potential advantages and disadvantages of this approach,
since banners aren't necessarily related to the main content of a page
but on the other hand they aren't the same across pages and people using
screen readers might accidentally skip them if they jump to the <main>
tag.

So I'm choosing the option that is easier to implement.

Note we're adding a `public-content` class to the <main> element in the
application layout. This might be redundat because the element could
already be accessed through the `.public main` selector, but this is
consistent with the `admin-content` class used in the admin section, and
without it the <main> element would sometimes have an empty class
attribute and we'd have to use `if content_for?(:main_class)` or
`tag.main` which IMHO makes the code less consistent.

The Capybara::DSL monkey-patch is only done on the `visit` method
because it's the only reliable one. Other methods like `click_link`
generate AJAX requests, so `expect(page).to have_css "main", count: 1`
might be executed before the AJAX request is finished, meaning it
wouldn't properly test anything.
2024-03-23 00:35:43 +01:00
taitus
f795c18bec Allow sorting widget_cards on sdg section 2024-03-21 18:27:49 +01:00
Javi Martín
1d955b7a20 Simplify using helper methods in components
The `use_helpers` method was added in ViewComponent 3.8.0, and it's
included by default in all components since version 3.11.0.

Note we sometimes delegated the `can?` method to the controller instead
of the helpers, for no particularly reason. We're unifying that code as
well.
2024-03-02 17:34:25 +01:00
Javi Martín
c2710de5fc Extract method to open links in a new window
This way we can slightly simplify the code.
2023-10-23 18:19:48 +02:00
Javi Martín
a1439d0790 Apply Layout/LineLength rubocop rule
Note we're excluding a few files:

* Configuration files that weren't generated by us
* Migration files that weren't generated by us
* The Gemfile, since it includes an important comment that must be on
  the same line as the gem declaration
* The Budget::Stats class, since the heading statistics are a mess and
  having shorter lines would require a lot of refactoring
2023-08-30 14:46:35 +02:00
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
adaa9c021f Merge pull request #4683 from consul/empty_sdg_tags
Don't render empty SDG tag list div
2021-10-04 16:07:28 +02:00
Javi Martín
b2dd6bcc16 Remove placeholder in SDG related list
Its value is difficult to read due to the low contrast between the color
of the field and the color of the placeholder text, and we already have
the same information in the hint above it.
2021-10-01 16:19:21 +02:00
Javi Martín
c025fef50b Add short titles to SDG targets
Since targets didn't have a title but only a long description, every
form allowing to select targets was pretty much unusable: we either
displayed just the code or the whole description.

Now, with a concise title, it's easier to find and select the desired
target.

The titles have been copied from The Global Goals page [1].

Note we're using the `short_title` I18n key for the `title` method and
the `long_title` I18n key for the `long_title` method. We can't use
`title` as I18n key instead of `short_title` because it would affect
existing translations.

[1] https://www.globalgoals.org/
2021-10-01 16:19:10 +02:00
Javi Martín
391d1083e4 Don't render empty SDG tag list div
The same way we don't render empty regular tags since commit 4d27bbeba.

This way we avoid adding an empty `<div class="sdg-tag-list">` tag,
which might have associated styles (in custom CONSUL installation
styles, for instance) and thus break the layout
2021-10-01 13:54:30 +02:00
Javi Martín
7f9a05d052 Extract method to get SDG code with title 2021-09-30 16:05:57 +02:00
Javi Martín
78811f5f4d Load SDG icons in SVG when available
SVG files are smaller than PNG files, can be compressed, and are
scalable.

We're choosing to render SVG files as images instead of inline because
inline SVGs aren't cached nor compressed, and they might appear several
times on the same page, making the generated HTML much larger.

We could also load them with an SVG sprite, using `<use>`, which would
reduce the number of HTTP requests when several icons are present on the
page (like in the index of most sections). However, using SVG inside an
`<img>` tag is universally supported, while the `<use>` tag doesn't
work in Internet Explorer when using an external URI and support in
Opera Mini and UC Browser is unknown.
2021-09-30 15:06:50 +02:00
Javi Martín
5de90547a7 Rename folder method in SDG icon component
The method name was a bit confusing because it returned a locale.
2021-09-30 15:06:50 +02:00
Javi Martín
c4542457ac Group styles setting padding to the main content
So we don't add the same lines to pretty much every stylesheet we
create.

Eventually we'll remove this code and add a padding to every <main>
element, or (even better) to the <body> element itself.
2021-07-13 15:27:14 +02:00
Javi Martín
8a3b9f6abf Remove no longer necessary row classes
These element had no columns inside and the row classes had only been
added to give them a maximum width. That's no longer necessary since now
the body has that maximum width.
2021-07-07 23:03:58 +02:00
Javi Martín
7024f1edf5 Extract class to find assets
So its methods can be used in other places.
2021-05-29 14:34:46 +02:00
Javi Martín
6ea9383743 Allow toggling elements with the keyboard
Using `<a>` tags with no `href` means these elements cannot be activated
by keyboard users, so we're replacing them with buttons.

In the future we probably want to add more consistency so all toggle
buttons use the same code. We might also add styles depending on the
`aria-expanded` property.
2021-03-31 13:38:38 +02:00
Javi Martín
d1675750b8 Fix a chrome bug in versions lower than 86
https://bugs.chromium.org/p/chromium/issues/detail?id=375693
2021-03-08 10:51:22 +01:00
Senén Rodero Rodríguez
37faaa9b94 Add canonical link
As we do at other help pages.
2021-03-02 14:45:20 +01:00
taitus
90f014f639 Allow open link on new window
While trying to add the target="_blank" to this link I noticed that this attribute
no longer works in some places in the application, such as the terms and
conditions  link in the sign_up page.

For the time being I think we can resolve it this way in this case and deal with
this issue in a separate PR.
2021-03-02 14:45:19 +01:00
taitus
e91b52ffe0 Add link to help page to related list selector component 2021-03-02 14:45:18 +01:00
taitus
d26607183e Add sdg help page
In this page we will render a list of clickable Goals icons that will show their
targets and related local targets

Co-authored-by: Senen <senenrodero@gmail.com>
2021-03-02 14:45:18 +01:00
taitus
522684cd2f Adapt targets component to render on sdg help page
This component was rendered on different pages so there were no conflicts
with static id's.
Now in the SDG help page we are going to render them all at once, so we
convert the static identifiers to dynamic.
2021-02-26 16:36:40 +01:00
taitus
4a880fc1c5 Render header on sdg index page
We no longer show the static header when we have created a
custom header.
2021-02-26 16:20:57 +01:00
Javi Martín
45517f659e Add SDG goals/targets to legislation proposals 2021-02-24 20:42:53 +01:00
Javi Martín
ab2b3a2671 Improve help messages in SDG selector
Hopefully now it's a bit more obvious that SDGs can be selected by
clicking on them and that the field to select goals and the field to
select targets/goals are related (since they're now part of the same
fieldset).
2021-02-15 15:48:25 +01:00
Javi Martín
6ecb6757a6 Use real check boxes to select goals
We were using list items with the checkbox role. This is probably
confusing since list items have a listitem role, and so we were
basically using a list with no listitem.

We could add a `<span role="checkbox">` tag inside the list item, but
using real checkboxes is probably easier. We're also adding a test to
verify the checkboxes native behavior is compatible with our code.

Note we're using the "enter" key to toggle the "checked" status of the
SDG. This is probably not intuitive for screen reader users who might
try to submit the form using the "enter" key after selecting a goal.

However, the alternative would be even less intuitive for sighted
keyboard users, since for them these icons look like links or buttons
and they would accidentally submit the form when trying to select a
goal.

Since we haven't come up with a better interface yet, for now we're
following the principle of least damage; we consider submitting the form
against a user's will is less annoying than forcing users to move to a
different field before being able to submit the form.

Also note we can't write `check` in the tests because Capybara will try
to click the checkbox, which is hidden by the image in the label.
2021-02-15 15:48:25 +01:00
Javi Martín
7d4e49a090 Reorganize SDG tag list components
So now we've got a component receiving records (goals or targets) and a
related model (Debate, Proposal, ...), with optionally a link to see
more tags.

This way we simplify some logic since the `TagList` classes were dealing
with too many cases (a record is passed, a class name is passed, a limit
is passed), ... Now `TagList` only deal with the natural `TagList` case,
which is listing the tags for a record. The case where a class name is
passed is used in the `TagCloud` class.
2021-02-02 22:22:40 +01:00
Javi Martín
a78663120a Extract component to render a goal/target tag 2021-02-02 22:22:40 +01:00
Javi Martín
999d1a2cfd Rename goals FilterLinks component to TagCloud
This is more consistent with the "tag_cloud" partial name.
2021-02-02 22:22:39 +01:00
Javi Martín
ad56b01a9a Extract component to render "see more" link 2021-02-02 22:22:37 +01:00
Javi Martín
7c4515d6ce Simplify code to generate "See more" link
We can skip the `link_to(*options) if options` part if we accept anchor
tags in the `link_list` helper.
2021-02-02 20:05:40 +01:00
Senén Rodero Rodríguez
bb1315def1 Prepare SDG tag list component to render list with or without links
Now the tag list can render tags with or without links, so we need
to adapt the styles slightly.

We want to use the same text color for tags without links.

The hover style is only needed when using tags with links.
2021-01-31 13:33:26 +01:00
Senén Rodero Rodríguez
cc2ce38d13 Create SDG target component to render plain tags 2021-01-31 13:33:25 +01:00
Senén Rodero Rodríguez
54843c1e53 Create SDG goal component to render plain tags 2021-01-31 13:33:25 +01:00
taitus
1d151b7b6f Add empty message when there are not local targets 2021-01-29 14:15:58 +01:00
taitus
f45bbb316c Add Targets component to Show component 2021-01-29 14:15:58 +01:00
taitus
857a6aa228 Add targets component to render all targets in tabs section 2021-01-29 14:15:58 +01:00
taitus
7a02ce9c08 Add sdg section header on SDG IndexComponent
Co-Authored-By: Javi Martín <javim@elretirao.net>
2021-01-28 20:02:46 +01:00
Javi Martín
e0b6b83b11 Use <main> in SDG index
Just like we do in the other sections.

We're also moving the banner inside the <main> element because we do it
the same way in other sections.
2021-01-28 19:49:31 +01:00
Javi Martín
3018de2847 Merge pull request #4324 from consul/sdg_target_filter
Add SDG target tags and filter
2021-01-27 16:48:12 +01:00
Javi Martín
1fefc910d6 Add list of targets to SDG tag list
Co-authored-by: Senén Rodero Rodríguez <senenrodero@gmail.com>
2021-01-27 16:21:40 +01:00
Javi Martín
7b3fcf6cb5 Split goal tag list component
This way we'll be able to add targets as well. Besides, having two
classes in the CSS selector will allows to overwrite styles such as
`.debate-show ul li`.

On the other hand, we need to add a stylesheet for the filters as well.
2021-01-27 16:21:40 +01:00
taitus
6c7a8d31b1 Add read more and real less on long description
In the spec we added in system/sdg/goals_spec.rb we couldn't use
either click_link or find_link, because the link to show/hide the
long description doesn't have the href attribute.
2021-01-27 15:56:08 +01:00
Javi Martín
b0a6c20bc0 Add long description to goals 2021-01-27 15:49:46 +01:00
taitus
7fa594e3e3 Rename sdg_related_list to related_sdg_list
To maintain consistency with the current names in the database with fields:
:related_sdg_type and :related_sdg_id
2021-01-26 19:18:11 +01:00
taitus
41ead2b37c Allow add local targets to RelatedListSelectorComponent 2021-01-26 19:16:57 +01:00
Javi Martín
e96f45ba39 Merge pull request #4325 from consul/add_related_list_selector
Add related list selector component to forms
2021-01-22 16:34:10 +01:00
taitus
189c299a6e Do not render component when the feature is disabled 2021-01-22 16:03:53 +01:00