Commit Graph

2216 Commits

Author SHA1 Message Date
Javi Martín
a75e470c7d Fix SDG section header and banner background
They weren't taking the full width because in the SDG index the `main`
element has a padding.
2021-10-28 21:23:07 +02:00
Javi Martín
8eb1a64996 Fix overlapping banner in budgets index
This bug was introduced in commit 3cd252979.
2021-10-28 21:23:07 +02:00
Javi Martín
6856a18736 Fix banner width in admin section
The banner background was extending outside the table where its preview
was rendered.
2021-10-28 21:23:07 +02:00
Sebastia
64c98cbda4 Merge pull request #4722 from consul/improve-investment-list-img
Fix investments list images width in Chrome 93+
2021-10-28 11:58:37 +02:00
taitus
e6ef9bc976 Improve width imageon investments list 2021-10-27 16:32:18 +02:00
Javi Martín
2ecc98dc41 Fix Sass deprecation warning
When running `scss-lint`, we were getting the following message:

DEPRECATION WARNING: #{} interpolation near operators will be simplified
in a future version of Sass. To preserve the current behavior, use
quotes:

  unquote("#{$global-width / 2} - 50vw")
2021-10-26 21:30:41 +02:00
Javi Martín
d702fbbfc7 Add a caption to headings table in budgets admin
Captions benefit blind screen reader users who navigate through tables,
particularly in this case because we potentially have several tables
with headings (one table per group), so when navigating through tables
it might be hard to know which group the headings belong to.

In this case they also benefit sighted users. Usability tests have shown
the "Groups and headings" section is a bit confusing, so adding a
caption like "Headings in Districts" helps clarifying Districts is a
group and the table refers to headings in that group.

The very same table is rendered in the "headings" step of the budget
creation wizard. However, in that case the information of the caption is
redundant because the page is specific for headings belonging to a
certain group. We're making the element invisible but still keeping it
for screen reader users in order to ease their navigation through
tables.
2021-10-25 18:34:19 +02:00
Javi Martín
7c7cf2b043 Move budget group actions to their own line
The problem of having actions next to the title is that, when there are
titles of very different lenghts, at certain resolutions some actions
will be next to their titles (because there'll be space for everything)
but some actions will be below their titles. This makes it hard for
people to follow where the actions are.
2021-10-25 18:34:19 +02:00
Javi Martín
1b407b0702 Move budget ballot actions to admin budget page
The buttons to create polls associated with a budget were too prominent,
appearing on the table as if they were as used as the link to manage
investments. Most CONSUL installations don't use physical booths, and
would probably wonder what that button is about.

We're moving it to a more discrete place, at the bottom of the budget
page. This way we can also split the action in two: on budgets not
having a poll, we display the button in a not-so-accessible position (at
the bottom of the page), since this button will only be used once per
budget at most. Once the poll has been created, it means this feature is
going to be used, so we display a link to manage ballots more
prominently at the top of the page. If the budget has finished the final
voting stage without creating a poll, we don't show either the link or
the button because this feature can no longer be used.

We're also adding some texts indicating what this feature is about,
since it's probably one of the least understood features in CONSUL
(probably because the interface is very confusing... but that's a
different story).

Since now from the budget page we can access every feature related to
the budget, we can remove the "preview" action from the budgets index
table, since this feature isn't that useful for budgets once they're
published.

Now the budgets table doesn't take as much space as it used to, although
it's still too wide to be handled properly on devices with a small
screen.
2021-10-25 18:34:19 +02:00
Javi Martín
8bb55f0d45 Add link to investments from the admin budget page
Since managing investments is a very common action, with this link
administrators won't have to go back to the index page to manage
investments; they can access it from either the budgets index page or
the budget page.

Since now the links we've got on the budget page are similar to the ones
we've got in the index page table, we're styling them in a similar way.

We're also fixing a small typo en the investments path; it works exactly
the same way as it used to, but passing `budget` instead of `budget_id:
budget.id` is shorter and more consistent with what we do in other
places.
2021-10-25 18:34:19 +02:00
Javi Martín
51a0bce58c Add information about budget actions
Both the calculate winners and delete actions benefit from some kind of
hint.

The "calculate winners" hint informs administrators that results won't
be publicly available unless the "show results" option is enabled.

The delete action was redirecting with an error message when the budget
couldn't be deleted; IMHO it's better to disable it and inform
administrators why it's disabled. Alternatively we could remove the
button completely; however, users might be looking for a way to delete a
budget and wouldn't find any hint about it.

We're now removing the "Delete" action from the budgets index table,
since most of the time it isn't possible to delete a budget and so the
action takes up space and we get little gain in return. We could keep
the "Delete" icon just for budgets which can be deleted; however, the
alignment of the table rows would suffer, making it harder to find the
intended action.
2021-10-25 18:34:17 +02:00
Julian Herrero
2b709f1a36 Groups and headings CRUD from budget view
Before, users needed to navigate to the list of groups in order to
add, edit or delete a group.

Also, they need to navigate to the list of groups first, and then to
the list of headings for that group in order to add, edit or delete a
heading.

Now, it's possible to do all these actions for any group or heading
from the participatory budget view to bring simplicity and to reduce
the number of clicks from a user perspective.

Co-Authored-By: Javi Martín <javim@elretirao.net>
2021-10-25 18:01:47 +02:00
Javi Martín
46d8bc4f0e Use a switch to enable/disable budget phases
In the past it would have been confusing to add a way to directly
enable/disable a phase in the phases table because it was in the middle
of the form. So we would have had next to each other controls that don't
do anything until the form is sent and controls which modify the
database immediately. That's why we couldn't add the checkboxes we used
when using the wizard.

Now the phases aren't on the same page as the budget form, so we can
edit them independently. We're using a switch, so it's consistent with
the way we enable/disable features. We could have used checkboxes, but
with checkboxes, users expect they aren't changing anything until they
click on a button to send the form, so we'd have to add a button, and it
might be missed since we're going to add "buttons" for headings and
groups to this page which won't send a form but will be links.

Since we're changing the element with JavaScript after an AJAX call, we
need a way to find the button we're changing. The easiest way is adding
an ID attribute to all admin actions buttons/links.
2021-10-25 18:01:47 +02:00
Javi Martín
349dbb74d7 Move phases and actions out of the budget form
Having links in the middle of a form distracts users from the task of
filling in the form, and following a link before submitting the form
will mean whatever has been filled in is lost.

And the budgets form is already very long and hard to fill in. Having
the phases table in the middle of it made it even harder. And, since
we're planning to add the option to manage groups and headings from the
same page, it's better to have a dedicated page for the form.
2021-10-25 18:01:47 +02:00
Javi Martín
8aa6f29d6b Use buttons for budgets actions
Using buttons for non-GET actions is better for accessibility, as
mentioned in commit 5311daadf.
2021-10-25 18:01:45 +02:00
Javi Martín
b81bdc778b Move budget actions out of the form
Since we aren't very consistent in the styles for submit buttons in the
admin section, it was possible to accidentally press the "Calculate
Winner Investments" link after filling in the form. This wouldn't submit
the form and so the changes wouldn't be saved.

It's also a bit confusing for users. After filling in a form, users
expect a submit button. When finding two buttons, they've got to stop to
think which one is the one they've got to press.

Furthermore, the "Calculate Winner Investments" link would work better
as a button instead of a link, for the reasons mentioned in commit
5311daadf. Since HTML forms can't be nested, that would mean treating
this button in a different way than the rest of the buttons in the
application.

Moving the link before the form solves the issue.

Since now we've got the budget actions before the budget form, we're
grouping these actions together with the "Preview" action. We're not
adding the "Publish budget" button as well to this group because it's
got an associated message.
2021-10-22 15:16:09 +02:00
Javi Martín
7cf8469fac Improve RTL text support in flex-with-gap mixin
Even if it was looking OK using `margin-left`, there were probably edge
cases where it wouldn't behave as we expected.

As mentioned in the previous commit, this won't be necessary once
everyone uses browsers supporting the `gap` property in flexbox layouts,
but this won't happen for a few years.

In a few months we might also consider using the `margin-inline-start`
property, which is currently supported by about 97% of the browsers [1].

[1] https://caniuse.com/css-logical-props
2021-10-19 02:33:53 +02:00
Javi Martín
4fea839c54 Extract mixin to add a gap to a flexbox layout
This way we remove duplication and it'll be easier to add better support
for RTL languages.

In a few years this might not be necessary since support for the `gap`
property in a flexbox layout will improve. At the time of writing,
however, only 86.5% of the browsers support it [1].

[1] https://caniuse.com/flexbox-gap
2021-10-19 02:33:53 +02:00
Javi Martín
b1c07862b4 Merge pull request #4689 from consul/ie_heading_mode
Fix budget mode selection in Internet Explorer 11
2021-10-06 15:59:16 +02:00
Javi Martín
0652d3f52d Fix budget mode selection in Internet Explorer 11
As mentioned in commit b7f6c4c43:

> [In Internet Explorer] the `flex: 1` property doesn't work so well
> when `flex-direction` is set to `column`. We're replacing it with
> `flex-grow: 1`. No need to set other `flex-basis` nor `flex-shrink`
> since in this case the default values will work just fine.
2021-10-06 14:46:08 +02:00
Javi Martín
081b524e03 Fix .keep file in custom stylesheets.
It was accidentally named `.gitkeep` in commit b549eb444. We use `.keep`
everywhere else.
2021-10-06 14:45:51 +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
e20e468c0f Use sans-serif fonts as fallbacks for SDG titles
This way titles look a little less broken during the time the font is
downloaded.
2021-09-30 15:06:50 +02:00
Javi Martín
c42c8e3c7a Increase minimum size for SDG icons
The icons were a bit hard to click on small screens, even for people
without any motion disabilities.

We might increase the size or the space between icons again in the
future; right now it's hard for users with certain motion disabilities
to click on the right icon.

Coincidentally, the minimum size of the icon is now barely over the 44px
established as minimum required size by the WCAG guideline 2.5.5 (level
AAA) [1].

Also coincidentally, at a screen 320px wide (the minimum screen size we
support), six icons appear on each row, just like in the UN logo.

[1] https://www.w3.org/TR/WCAG21/#target-size
2021-09-30 15:06:50 +02:00
Javi Martín
d232e8cdf9 Reduce width of the admin menu on large screens
On very large screens, the admin menu had a lot of blank space for
languages where all sections had short names (like English). This was
inconvenient because the icon to open a submenu was far from its
associated menu item.

Using the `max-content` value for the `max-width` property, we reduce
the amount of blank space in these cases.
2021-09-30 13:35:13 +02:00
Javi Martín
e241bab130 Fix accordion icon overlap in admin menu
Since the icon was absolutely positioned, in some languages it
overlapped with the text.

Using a flex layout solves this issue. It also improves the appearance
of elements whose text spans over multiple lines; previously the second
line would go under their section icon.

We're also using the `$global-left` variable so the icon is properly
displayed in languages written from right to left. We could use the
`margin-inline-start` property instead, but it isn't universally
supported in every browser yet.

Since the layout is now incompatible with the old (and obsolete) way to
add icons to the menu (using classes which would use the
`[class^="icon-"]` selector), we're removing this code.
2021-09-30 13:35:10 +02:00
Javi Martín
d3a4a7bca3 Fix line-height in admin menu items
When items went over multiple lines, the distance between their lines
was the same as the distance between one element and another one. This
made it hard to differentiate how many elements there were.

Using a padding to separate the contents of one element and the contents
of the next one solves the issue.
2021-09-28 15:16:47 +02:00
Javi Martín
fabe97e506 Use a switch control to enable/disable features
We were using buttons with the "Enable" and "Disable" texts to
enable/disable settings. However, when machine learning settings were
introduced in commit 4d27bbeba, a switch control was introduced to
enable/disable them.

In order to keep the interface consistent, we're now using switch
controls in other sections where settings are enabled/disabled. We can
even use the same code in the machine learning settings as well.

We're also removing the confirmation dialog to enable/disable a setting,
since the dialog is really annoying when changing several settings and
this action can be undone immediately. The only setting which might need
a confirmation is the "Skip user verification" one; we might add it in
the future. Removing the confirmation here doesn't make things worse,
though; the "Are you sure?" confirmation dialog was also pretty useless
and users would most likely blindly accept it.

Note Capybara doesn't support finding a button by its `aria-labelledby`
atrribute. Ideally we'd write `click_button "Participatory budgeting"`
instead of `click_button "Yes"`, since from the user's point of view the
"Yes" or "No" texts aren't button labels but indicators of the status of
the setting. This makes the code a little brittle since tests would pass
even if the element referenced by `aria-labelledby` didn't exist.
2021-09-23 13:25:20 +02:00
Javi Martín
f638e50174 Wait for suggestions to finish loading in tests
Sometimes tests were hanging indefinitely. Debugging shows that in some
cases it's due to submitting a form before the AJAX request to get
proposals, debates or investments suggestions is finished, since having
an AJAX and a non-AJAX request at the same time when running the test
sometimes leads to unexpected results.

In our case, we were having many timeouts in Github Actions in the
branches where we use both ActiveStorage and Paperclip to store files
(based on pull request 4598). I can reproduce it in those branches
running the following test ("Should show new image after successful
creation with one uploaded file"), although only when my laptop isn't
plugged (!!):

```
rspec './spec/system/proposals_spec.rb[1:33:1:14]'
```

Since we didn't have a proper way to know the AJAX request had finished,
we're adding a `suggest-success` class to the element showing the
suggestions when that happens. Then in the tests we can look for that
class after filling in the title of a proposal, debate or investments.
Just for clarity's sake, we're also adding the `suggest-loading` class
when the suggestions are loading.

In order not to have expectations everywhere about the suggestions,
we're extracting methods to fill in those titles in the tests. Note we
aren't using these methods in the "edit" actions (suggestions are not
showing when editing) or in tests with the `no_js` tag (since
suggestions only work with JavaScript).
2021-09-22 18:29:23 +02:00
Javi Martín
2c5f151d0e Remove no longer needed table action style
It isn't used since commit 25e906591.
2021-09-20 20:27:37 +02:00
Javi Martín
66320c3eca Fix clickable blank space in admin table actions
There were times when some actions had text expanding over two lines
while other actions had text on just one line.

Since all the items in a row had the same height, the elements with just
one line added a blank second line. This was obvious when hovering with
the mouse or focusing on the element with the keyboard. It looked weird
when the element received focused, and it could also lead to
unintentional clicks when clicking on the blank space below the element.
2021-09-20 20:27:37 +02:00
Javi Martín
475b18d171 Adjust hover styles in table actions
The underline text decoration looked a bit strange with the icon on top
of it, and we had an inconsistency since links had a text decoration but
buttons didn't. I think we can remove it since both the color of the
icon and the cursor change on hover and that's enough feedback.

And we were accidentally overwriting the color of the investments link
on hover and focus.
2021-09-20 20:27:37 +02:00
Javi Martín
aaa5f6c285 Disable buttons in table actions when pressed
By default, Rails disables submit inputs (<input type="submit">) when
they're pressed so we avoid a double-submission when users click the
button twice.

However, Rails does not disable submit buttons (<button type="submit">)
when they're pressed. This means there's a chance users might press the
button several times. Even if most our table actions are idempotent, it
might cause certain issues. For instance, pressing the "Delete" button
twice means the second request might raise an
`ActiveRecord::RecordNotFound` exception.

Disabling the button also gives feedback to users, letting them know
they've correctly clicked the button.
2021-09-20 20:27:37 +02:00
Javi Martín
5311daadfe Use a button for non-GET table actions
Links acting like buttons have a few disadvantages.

First, screen readers will announce them as "links". Screen reader users
usually associate links with "things that get you somewhere" and buttons
with "things that perform an action". So when something like "Delete,
link" is announced, they'll probably think this is a link which will
take them to another page where they can delete a record.

Furthermore, the URL of the link for the "destroy" action might be the
same as the URL for the "show" action (only one is accessed with a
DELETE request and the other one with a GET request). That means screen
readers could announce the link like "Delete, visited link", which is
very confusing.

They also won't work when opening links in a new tab, since opening
links in a new tab always results in a GET request to the URL the link
points to.

Finally, submit buttons work without JavaScript enabled, so they'll work
even if the JavaScript in the page hasn't loaded (for whatever reason).

For all these reasons (and probably many more), using a button to send
forms is IMHO superior to using links.

There's one disadvantage, though. Using `button_to` we create a <form>
tag, which means we'll generate invalid HTML if the table is inside
another form. If we run into this issue, we need to use `button_tag`
with a `form` attribute and then generate a form somewhere else inside
the HTML (with `content_for`).

Note we're using `button_to` with a block so it generates a <button>
tag. Using it in a different way the text would result in an <input />
tag, and input elements can't have pseudocontent added via CSS.

The following code could be a starting point to use the `button_tag`
with a `form` attribute. One advantage of this approach is screen
readers wouldn't announce "leaving form" while navigating through these
buttons. However, it doesn't work in Internet Explorer.

```
ERB:

<% content_for(:hidden_content, form_tag(path, form_options) {}) %>
<%= button_tag text, button_options %>

Ruby:

def form_id
  path.gsub("/", "_")
end

def form_options
  { id: form_id, method: options[:method] }
end

def button_options
  html_options.except(:method).merge(form: form_id)
end

Layout:

<%= content_for :hidden_content %> # Right before the `</body>`
```
2021-09-20 20:27:37 +02:00
Javi Martín
7254ca333e Merge pull request #4680 from consul/small_menu_links
Increase login links touch area on small screens
2021-09-15 17:30:33 +02:00
Javi Martín
bd135966ca Use :focus-visible to define styles on focus
Styles on keyboard focus are essential for keyboard navigation; without
them, keyboard users wouldn't see which element they're currently
interacting with. That's why we use an `outline` on elements having the
current keyboard focus.

However, this is sometimes annoying for mouse/touchscreen users, since
clicking/touching an element also gives it keyboard focus.

When clicking on a button performing some kind of action through
JavaScript, keeping the outline on the button after clicking it is
distracting.

Even after clicking a link, for some users having the outline present
while they wait for the next page to load is annoying.

That's why modern browsers (at the time of writing, 74%) implement the
`:focus-visible` pseudoclass, which selects elements which have received
focus using the keyboard, but not elements which have been
clicked/tapped on. We can use it to provide focus styles for keyboard
users without getting in the way of mouse/touchscreen users.

Usually we wouldn't use a feature which isn't supported in more than 96%
of the browsers out there. However, in this case we've got a solid
fallback: we just use the `:focus` pseudoclass. Since the `@support` CSS
condition doesn't accept pseudoclasses as parameters, we're disabling
`:focus` styles only on browsers supporting the `:focus-visible`
pseudoclass using the `:focus:not(:focus-visible)` selector, which will
be ignored by browsers without support for `:focus-visible`.

Since now users receive less feedback when clicking/touching a link or a
button, we're adding styles for the `:active` pseudoclass. This way
users will know which item they're clicking/tapping on. I'm not sure the
outline is a good option for this case, though; I think for touchscreen
users a better solution would be to apply the styles we apply on hover.
We might change it in the future.

Note grouping styles together like this would *not* work:

```
&:focus,
&:focus-visible {
  // Styles here
}
```

Browsers not supporting the `:focus-visible` pseudoclass would ignore
this statement completely, meaning they wouldn't apply the styles on
`:focus` either.
2021-09-15 13:38:36 +02:00
Javi Martín
cd45607ce2 Fix focus styles in admin form controls
We lost focus styles on certain controls in commit 4dad04ae3, since we
were applying a border with a rule which had more precedence than the
rule of border on focus.
2021-09-15 13:38:36 +02:00
Javi Martín
35a45837ff Add default focus outline to buttons
We were using a focus outline on links, but weren't doing the same for
buttons. Since sometimes browsers use a default outline which is barely
visible, this was very disorienting when browsing using the keyboard; we
were navigating through links that clearly indicated where the keyboard
focus was, and when reaching a button suddenly we had this almost
imperceptible feedback. Even if I'm used to it, my first reaction is
always "where did the focus go?" until I realize it's now on a button.

This is even more confusing because we've got buttons looking like links
and links looking like buttons.

Note that in the rules for the `:focus` styles we're including buttons
and the `[type="button"]` attribute. This seems redundant since those
styles are already covered by the `button` selector. However, Foundation
adds styles to buttons with the `[type]` attribute. Since the attribute
selector has precedence over the tag selector, we need to use the
attribute selector as well in order to override Foundation's styles.
2021-09-15 13:38:36 +02:00
Javi Martín
b24994abf7 Fix styles in draft version body
There were no elements matching this selector since commit d679c1eb7 and
these styles were completely ignored. I'm re-adding the ones with make
sense in my humble opinion. I'm not adding top and bottom paddings since
they affect the way the height of the element is calculated, and am not
sure about the intention behind setting the height property.
2021-09-15 13:38:34 +02:00
Javi Martín
288ae13958 Merge pull request #4687 from consul/phases_image_button
Fix "Add image" button styles in budget phases
2021-09-14 13:19:30 +02:00
Javi Martín
e2d680947a Add separator in small screen navigation
The "Sign in" or "My account" links and the main navigation are
different elements, and they're in different places on medium and large
screens. Now we're also separating them on small screens.

Since the `.vertical` class in the menu added quite a few styles and it
was difficult to overwrite them, we're simply removing this class from
this element. This way we're also removing the huge space between the
menu button and the first element of the navigation.
2021-09-12 14:20:53 +02:00
Javi Martín
00565bba6a Increase login links touch area on small screens
On small screens, the "Sign in", "Register", "My content", "My account"
and "Sign out" links didn't have much padding nor space between them,
and it was easy to accidentally click the wrong link.

This change also positively affects the menu on medium and large
screens. When one of the options (like "SDG content") had a text
spanning over two lines (like it happens in Swedish), there was barely
any space between those two lines. So we're using `line-height: inherit`
instead and adjusting the padding accordingly.
2021-09-12 14:00:42 +02:00
Javi Martín
4fbe2d99d5 Simplify small screen styles in admin submenu
Some of these styles were redundant and so we can remove them.
2021-09-12 14:00:42 +02:00
Javi Martín
877eb44bd4 Simplify logo layout in admin header
Having the logo inside a list of one item wasn't needed and its classes
conflicted with other elements with the `.menu` class.
2021-09-12 14:00:40 +02:00
Javi Martín
59da7d0af4 Fix "Add image" button styles in budget phases
It was broken since we fixed issues with other image fields in commit
394a94cbf, because there we added a fieldset for the image fields, and
so they inherited the styles in budget phases fields (these styles were
added before it was possible to attach an image to a phase).
2021-09-12 13:47:15 +02:00
Javi Martín
4ea30da299 Fix line height in subnavigation items
When, on small screens, a navigation element had a very long text
causing it to span over multiple lines, the space between each line was
the same as the space between elements. This made it hard to see where
elements started and ended.

Using a padding to separate the contents of one element and the contents
of the next one solves the issue.
2021-09-12 01:25:10 +02:00
Javi Martín
9f1f912d84 Remove official level filter from advanced search
User testing has shown this filter isn't really useful and sometimes
makes users wonder what it's about. This is particularly true in CONSUL
installations which don't change the default values (most of them),
since users will see a filter with options like "Official position 1".
2021-09-11 17:28:38 +02:00
Javi Martín
a868a5ff35 Change Foundation text direction in RTL languages
This way, when the language is written form right-to-left, elements
using Foundation mixins/classes will float to the opposite direction as
they do in left-to-right languages. The same will apply to text
alignment.

To offer full support for RTL languages, we need to change every single
reference to `float: left`, `float: right`, `text-align: left`,
`text-align: right`, and possible adjust other properties like `left`,
`margin-left`, `padding-left` or `border-left`. In the meantime, we at
least partially support these languages.

Replacing `float` with `flex` when possible would also improve RTL
support.
2021-08-16 17:47:33 +02:00
Machine Learning
4d27bbebad Add experimental machine learning 2021-08-16 16:31:04 +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