Commit Graph

18194 Commits

Author SHA1 Message Date
Javi Martín
45b9eccfd8 Show valuator group investments to their valuators
When accessing the valuation area, we were only displaying the
investments directly assigned to the current valuator, but we weren't
displaying the investments assigned to that valuator's group.

Using the `assigned_investments_ids` method, which takes the valuator
group into account, solves the issue.

We've also found an issue on our development machines: since we don't
have a unique index per `investment_id` and `valuator_id` in the
`budget_valuator_assignments` table, we've found duplicate records on
this table. When that happened, we were displaying the same investment
several times.

Since now we no longer join this table in the query returning the
investment, this issue is also solved, and we're adding a test for it.
We can now remove the call to the `distinct` method when calculating the
number of investments per heading.
2023-02-20 14:59:31 +01:00
Javi Martín
f7dfe30675 Merge pull request #5078 from consul/link_to_evaluate
Show link to evaluate investments with valuation finished
2023-02-20 14:42:58 +01:00
Javi Martín
1b61effa43 Merge pull request #4985 from consul/fix_budget_stats
Show admin heading stats for the current budget
2023-02-20 14:38:59 +01:00
Javi Martín
e51e034468 Use budget stats model to calculate admin stats
This way we reduce duplication.
2023-02-20 14:21:22 +01:00
Javi Martín
b536a7cb77 Extract component for supporting budget admin stats
This is consistent with the component for balloting stats. We're about
to change both components, and the changes are easier to follow if
they're similar.

We're also using consistent names in methods.
2023-02-20 14:21:22 +01:00
Javi Martín
dd28163be7 Show admin heading stats for the current budget
To get the heading where a user voted, we were relying on the
`balloted_heading_id` field.

Our guess is this was done so the total number of users is the same as
the sum of users who voted on a heading. That is, if 2000 people voted
just on the "All city" heading, 1000 voted just on the "North district"
heading, and 500 people voted on both, instead of showing "3500 people
voted in total, 2500 voted in all city, 1500 voted in north district",
we show something like "3500 people voted in total, 2250 voted in all
city, and 1250 voted in north district".

However, this approach has some disadvantages.

The first disadvantage is, the stats aren't correct. In the case above,
2500 voted on the "All city heading", so the statistics for this heading
don't show reality.

The second one is we weren't considering the last heading where users
voted inside the budget being displayed, but the last heading where
users voted, period. That means that, if all the people above voted on a
later budget, the stats for the budget above would become "3500 people
voted in total, 0 voted in all city, and 0 voted in north district".
That also means we were including headings from previous budgets in the
statistics for more recent budgets when people hadn't voted on the
recent ones.

So we're removing the `balloted_heading_id` since its data is lost once
people vote on a new budget. And, in order to show the right stats and
simplify the code, we're no longer trying to add votes just to one
heading when users vote on several headings.

Co-Authored-By: Julian Nicolas Herrero <microweb10@gmail.com>
2023-02-20 14:21:03 +01:00
Javi Martín
698fc753ba Fix invalid HTML in budget stats tables
The <th> elements should be inside <tr> elements.

Since we're changing this code, we're also adding <thead> and <tbody>
tags because that's what we usually do and it makes it easier to select
<tr> tags from either the table head or the table body using CSS or
JavaScript.
2023-02-20 14:20:50 +01:00
Javi Martín
44451193f6 Use consistent method names in admin stats component
We had one method called `vote_count_by_heading` and another one called
`user_count_by_district`, when here districts refer to headings.
2023-02-20 14:20:50 +01:00
Javi Martín
76b08398cf Extract component for balloting budget admin stats
We're also moving the tests, but we're keeping one system test in order
to test the controller and the navigation to get to this page.

Note we're slightly changing the order of the methods in the component;
the order of the instance variables was `user_`, `vote_`, `vote_`,
`user_`, which was hard to follow.
2023-02-20 14:20:50 +01:00
Javi Martín
915999db4a Simplify data in budget admin stats tests
We don't need groups to create headings since commit 20b1085dc, and
`let!` was used as a substitute for instance variables in commit
91c21b098, but it isn't necessary in this case.
2023-02-20 14:20:50 +01:00
Javi Martín
d1edccebef Merge pull request #5077 from consul/investment_cache
Don't cache related actions in investments view
2023-02-20 14:10:52 +01:00
Javi Martín
54fbdf4372 Remove unnecessary condition in valuation investments
The budget is loaded using a method which raises an exception if it
isn't found, so `@budget.present?` will always return true.
2023-02-17 15:27:53 +01:00
Javi Martín
b6ed11471e Simplify investment params filters in valuation
We weren't allowing the `budget_id` parameter and then we were adding it
manually. We were also allowing other parameters that aren't used in the
valuation section.

So we're allowing budget and heading, which are the only parameter we're
offering filters for in the user interface. Note the `budget_id`
parameter doesn't seem to make sense because we're already inside a
`@budget.investments` statement, but the `budget_id` parameter is
required by the `scoped_filter` method.
2023-02-17 15:27:53 +01:00
Javi Martín
1649b9125e Add scope to get investments visible to a valuator
Using this method makes it more obvious that we're loading the same
investments in the budgets index as in the investments index.
2023-02-17 15:27:53 +01:00
Javi Martín
ed4b03c3ed Show link to evaluate after evaluation has finished
This way it's still possible to access the "evaluation finished" filter
in the valuation investments index.
2023-02-17 15:26:49 +01:00
Javi Martín
d5cb01bf98 Split test in budget valuation component
We're going to add more cases and the test for the link to the evaluate
would become too big, so we're splitting it.
2023-02-17 15:25:25 +01:00
Javi Martín
02e8ffca36 Don't cache related actions in investments view
We've experienced some caching issues with this code for years. We've
fixed some of them in commits 9979b5399 and 3645c333a, but we're still
running into other issues. In order to really cache this section, we'd
need to cache:

* Whether or not the investment should show the aside and vote/support
  buttons (we could do it by caching its budget)
* Whether its budget is balloting or finished (we could do it by caching
  its budget)
* Whether the current user is following the investment
* Whether the `remove_investments_supports` feature is enabled
* Whether the `community` feature is enabled
* The value of the `org_name` setting
* The value of the `twitter_handle` setting

We weren't caching all these elements, meaning that (for instance), we
didn't display the button to vote when a budget moved into the voting
phase if we had already cached this section without the button.

And chances are the list is incomplete. So, instead of trying to take
into account every single possible factor that should make us expire the
cache, we're restricting the cache so it only affects the content of the
investment. This is similar to what we do in the investments index,
where we cache the content of the investment but we don't cache the
vote/support buttons.
2023-02-17 14:56:13 +01:00
Javi Martín
4debff754c Merge pull request #5024 from consul/poll_officer_menu
Always show poll officer menu to officers
2023-02-17 14:33:51 +01:00
decabeza
1ff2144830 Show always poll officer menu to officers
Since the change on commit cbbe188d6 we added a Poll.current.any?
condition to show the officing link on admin menu to officers.

That condition doesn't have much sense since Poll results only can be
added after a poll has ended, and there may be only one active poll.
2023-02-17 14:07:02 +01:00
Javi Martín
2e9c4de061 Unify specs testing access to admin menu items
In most sections, we had two specs testing what happens after accessing
one of the privileged areas. We're grouping the expectations and so
we've only got one test per area, making these tests faster.
2023-02-17 14:07:02 +01:00
Javi Martín
465d2d604d Move login items tests to the component
This way we reduce the number of system tests or, in some cases,
requests during system tests, making the tests faster.

We're still testing the interaction with the menu when users have the
right permissions.
2023-02-17 14:07:02 +01:00
Javi Martín
169b1b191a Merge pull request #5073 from consul/remote_translations_crash
Fix crash translating an already translated text
2023-02-17 14:05:23 +01:00
Javi Martín
0448280fd3 Merge pull request #5072 from consul/top_bar_adjustments
Fix menu on "wide" small screens
2023-02-17 14:03:57 +01:00
Javi Martín
2b9f9ed557 Fix crash translating an already translated text
The page was crashing when at least part of the content of the page had
been translated between the request showing the remote translations
button and the moment people pressed the button.
2023-02-16 17:52:17 +01:00
Javi Martín
fe3c9d47fa Make the translation button condition more readable
I was finding this part hard to follow, but after changing the name of
the condition suddenly I understood what was going on.
2023-02-16 17:52:17 +01:00
Javi Martín
2f0327acf8 Use remote translations objects instead of hashes
This way we can simplify the code dealing with the translatable
association.
2023-02-16 17:52:17 +01:00
Javi Martín
26cc75a891 Move remote translations controller methods to the model
Now that all the code related to this model is in the same place,
changing it will be easier.
2023-02-16 17:52:17 +01:00
Javi Martín
d09a47a023 Move remote translations concern methods to the model
This way it'll be easier to change the code.
2023-02-16 17:52:17 +01:00
Javi Martín
f8df90010e Unify spacing styles in public and admin top bars
The top bar padding was different on small screens when we were in the
admin section, so we're now applying the same padding everywhere.

Note we're still applying extra padding on medium/large screens because
in the public section we display our logo image, which has some blank
space. In the admin section we're emulating this blank space with
padding; we might change it in the future if we change our logo.

Also note we're using `0.8rem` instead of `$line-height / 2`. The reason
is tricky: there's a spec testing the reorder feature with drag and drop
in the poll questions answers administration, and that test fails when
the drop space is right at the bottom of the screen, which is what
happens when we use the `$line-height / 2` padding. A proper solution
would be to remove the inaccessible drag and drop feature and use a
different method to reorder the answers.
2023-02-16 17:51:09 +01:00
Javi Martín
27d9859674 Remove unnecessary styles in top bar
Not sure why these properties were added, but they no longer seem to be
necessary.
2023-02-16 17:24:34 +01:00
Javi Martín
3b125d9cfc Simplify styles for the remote translations button
We can use the `link` mixin. Note this mixin uses anchor-color instead
of brand-color; by default, they're both the same, so we probably meant
anchor-color here.
2023-02-16 17:24:34 +01:00
Javi Martín
fb2b88b10a Simplify styles for the remote translations message
Instead of adding all the styles of a callout and then overwriting half
of them, we can simply add the half we need.
2023-02-16 17:24:34 +01:00
Javi Martín
9bca73bc8b Fix background width in remote translations message
The `overflow: hidden` applied to the `.callout` selector made the full
width background invisible, meaning this section hasn't looked properly
on very large screens since  commit 701378d02.
2023-02-16 17:24:34 +01:00
Javi Martín
1778a7563b Use CSS to define alignment in translations message
That way it's possible to override the style without changing the HTML,
which is the hardest code to customize and maintain.
2023-02-16 17:24:34 +01:00
Javi Martín
efc69e8663 Extract component for remote translations button
So we're consistent with the rest of the code in the header, which
renders components and not partials.
2023-02-16 17:24:34 +01:00
Javi Martín
bbd4d3e62d Render components instead of partials in headers
We were using partials to render components in order to ease the
transition of custom code from earlier versions of Consul. However,
that was back in Consul 1.4, and now these views looked a bit messy
since they sometimes rendered components and sometimes they
rendered partials.
2023-02-16 17:24:34 +01:00
Javi Martín
2ac338f51a Remove redundant admin-top-bar element
We weren't using the `admin-top-bar` class since commit e6c1cf774, and
we can always use the `.admin .top-bar` selector if we need to. And the
`row expanded` classes basically give an element a width of 100%, which
is already the default width for block elements.
2023-02-16 17:24:34 +01:00
Javi Martín
49cb6e010b Extract component to render the responsive menu
We were using the same code for the button in both the public and admin
headers, so we're removing the duplication.

Since the menu and the button must go together, and the contents of the
menu are different for different layouts, we're passing these contents
using a block.

Note the ID of the menu was `responsive-menu` in the public section but
`responsive_menu` in the admin section. Since we usually use underscores
for IDs and dashes for classes, we're keeping the one with the
underscore.
2023-02-16 17:24:34 +01:00
Javi Martín
b489923f66 Move menu button to the left in the admin section
So now it uses the same interface and styles as the main layout. On
small screens, it's easier to play with the menu when the button is on
the left because the menu it opens is aligned to the left.

Note that now we can get rid of the title-bar class; we didn't use the
styles in the public area since commit dcec003d0, and we were overriding
all the Foundation styles in the admin area with the exception of the
padding, which we no longer need.
2023-02-16 17:24:34 +01:00
Javi Martín
b50b7ad64a Adjust order of elements on small screens
We're changing the order of the elements in the HTML so the menu button
appears next to the menu it opens, with no logo between them, which IMHO
makes sense and makes it easier to understand the layout for people
using screen readers.

A small advantage of this approach is that on very narrow screens or
Consul applications having a very long word for "Menu", the menu button
appeared on top, the logo appeared below it, and the contents of the
menu appeared below the logo. Now the logo appears on top, the menu
button appears below it, and the contents of the menu appear below the
menu button.
2023-02-16 17:24:34 +01:00
Javi Martín
045ac648d7 Fix menu on "wide" small screens
The menu didn't look properly on these screens since commit dcec003d0.

On small screens with enough horizontal space to show the menu button,
the logo, and the contents of the menu, all three elements were shown on
the same row, which looked broken.

Now the contents of the menu are shown below the menu button.

Note that, to force this, we're making the contents of the menu 100%
wide. That means links would take the 100% of the space, which would
make it easy to click on a link while trying to scroll when using
touchscreens. So we're making the links as wide as their text, which
also has a disadvantage: it's harder to click on narrow links like
"SDG".
2023-02-16 17:24:34 +01:00
Javi Martín
86dd34d32e Don't load Foundation styles for the top-bar
We're going to change these styles in order to fix a bug, and the
Foundation styles were getting in the way. Besides, we were overwriting
some rules and so now we're removing 6 properties while we're also
adding 6, so it isn't like the Foundation styles were helping us.
2023-02-16 17:24:24 +01:00
Javi Martín
c553e15a90 Remove usage of top-bar-left class
We don't need it since it's only used for flexbox styles, and we
already have a `flex-grow` rule for the `h1` element which does the
same thing.
2023-02-16 17:07:20 +01:00
Javi Martín
6b01dc53da Remove unused style inside top-bar-left
There isn't a `ul` element here, so this rule doesn't apply.
2023-02-16 17:07:20 +01:00
Javi Martín
70161720a0 Remove usages of the top-bar-right class
This is one of Foundation's classes that only applies when its
parent element is a flex container, which isn't the case here since
commit dcec003d0.
2023-02-16 17:07:20 +01:00
Javi Martín
3e5039d72c Remove usage of the top-bar-title class
This class was only there in order to use Foundation's styles, but
the amount of styles we were using was equal to the amount of
styles we were overwriting.
2023-02-16 17:07:20 +01:00
Javi Martín
d0fcc9022f Move menu and navigation styles to their own files
This way we follow the convention of one stylesheet per component.
Note that we depend on Foundation's `menu` class for some of the
styles and JavaScript behavior, so we're keeping both the `menu` and
`account-menu` classes.
2023-02-16 17:07:20 +01:00
Senén Rodero
3e8c4c4e61 Merge pull request #4937 from consul/dependabot/bundler/master/airbrake-13.0.2
Bump airbrake from 11.0.3 to 13.0.2
2023-02-03 19:01:06 +01:00
Javi Martín
76b47c3e42 Merge pull request #4992 from consul/proposal_image
Fix image size on proposals list
2023-02-03 18:06:32 +01:00
dependabot[bot]
b6e9a3c2f9 Bump airbrake from 11.0.3 to 13.0.2
Bumps [airbrake](https://github.com/airbrake/airbrake) from 11.0.3 to 13.0.2.
- [Release notes](https://github.com/airbrake/airbrake/releases)
- [Changelog](https://github.com/airbrake/airbrake/blob/master/CHANGELOG.md)
- [Commits](https://github.com/airbrake/airbrake/compare/v11.0.3...v13.0.2)

---
updated-dependencies:
- dependency-name: airbrake
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-03 17:53:54 +01:00