Skip to content

Commit

Permalink
Merge pull request #2444 from geeksforsocialchange/main
Browse files Browse the repository at this point in the history
v0.23.0
  • Loading branch information
r-ferrier committed Apr 29, 2024
2 parents 51fe369 + b81c410 commit 34dc2a5
Show file tree
Hide file tree
Showing 91 changed files with 1,185 additions and 824 deletions.
7 changes: 7 additions & 0 deletions .rubocop.yml
Expand Up @@ -61,8 +61,15 @@ Rails/ActionOrder:
Metrics/ClassLength:
Exclude:
- "test/**/*.rb"
- "app/models/partner.rb"

Metrics/CyclomaticComplexity:
Exclude:
- app/controllers/application_controller.rb

Metrics/PerceivedComplexity:
Exclude:
- app/controllers/application_controller.rb

Rails/RootPathnameMethods:
Enabled: false
Expand Down
2 changes: 2 additions & 0 deletions .rubocop_todo.yml
Expand Up @@ -372,6 +372,8 @@ Rails/SkipsModelValidations:
Exclude:
- 'lib/tasks/fixes/users.rake'
- 'db/migrate/20240125175508_partner_hidden_attribute_set_value.rb'
- 'db/migrate/20240411200641_partner_can_be_assigned_events_set_value.rb'
- 'db/migrate/20240422092628_set_calendar_checksum_date.rb'

# Offense count: 22
# This cop supports unsafe autocorrection (--autocorrect-all).
Expand Down
98 changes: 29 additions & 69 deletions README.md
@@ -1,40 +1,24 @@
# PlaceCal

## Introduction / Warning
## Introduction

PlaceCal is a large and very complicated app for collating organisation and event information from a large variety of sources. In the words of one developer: "I'm not sure where the interface between the app and the real world is here".
PlaceCal is an online calendar which lists events and activities by and for members of local communities, curated around interests and locality.

The codebase doesn't currently have enough seeds to create a dev environment suitable for developing from scratch. If you're interested in contributing to PlaceCal please get in touch at support@placecal.org

To get an idea of the project and what we're about, check out [the handbook](https://handbook.placecal.org/).

## Requirements

To run PlaceCal locally you will need:

- A Mac or a Linux machine (we don't support Windows at present)
- GNU Compiler Collection (gcc) (for compiling ruby and gems)
- Docker (optional) (for isolating and automating postgres management)
- Postgres relational database. We are currently using v14.
- Server
- either installed for your distribution or as a docker image (with the correct open port -- see below)
- Client
- you will still need the local developer libraries for postgres
- these are distribution specific so you need to find out what they are called to install them
- `libpq-dev` (debian)
- `postgresql-libs` (arch)
- `dev-db/postgresql` (gentoo)
- Ruby 3.1.2 - We recommend using a version manager for this such as `rvm` or `rbenv`. Current version we are using is in `.ruby-version`.
- [rvm](https://rvm.io/)
- [rbenv](https://github.com/rbenv/rbenv)
- [ruby-build](https://github.com/rbenv/ruby-build)
- [rbenv-gemset](https://github.com/jf/rbenv-gemset) (optional)
- Node.js 16.x. We recommend using a version manager for this such as `nvm` or `nodenv`. Current version we are using is in `.node-version`.
- [nvm](https://github.com/nvm-sh/nvm)
- [nodenv](https://github.com/nodenv/nodenv)
- Yarn 1.x
- [yarn](https://classic.yarnpkg.com/en/docs/install)
- ImageMagick for image manipulation
To run PlaceCal locally you will need to install the following dependencies:

- [Docker](https://docs.docker.com/get-docker/)
- [Ruby 3.1.2](https://www.ruby-lang.org/en/news/2022/04/12/ruby-3-1-2-released/)
- [Node.js](https://nodejs.org/en/download) 16.x & (optional) [nvm](https://github.com/nvm-sh/nvm) to manage it
- [Yarn 1.x](https://classic.yarnpkg.com/lang/en/)
- [ImageMagick](https://imagemagick.org/index.php) for image manipulation
- [Graphviz](https://voormedia.github.io/rails-erd/install.html) for documentation diagrams
- Chrome/Chromium for system tests along with a matching version of [Chromedriver](https://chromedriver.chromium.org/)
- [Chrome/Chromium](https://www.chromium.org/chromium-projects/) for system tests along with a matching version of [Chromedriver](https://chromedriver.chromium.org/)

## Quickstart with docker for GFSC devs

Expand All @@ -50,6 +34,15 @@ Local site is now running at `lvh.me:3000`

Some other useful commands for developing can be found in the makefile.

## Troubleshooting

If the make command fails and you can't work out why, here are some suggestions:

- Do you have an older version of the database hanging around? Try running `rails db:drop:all`
- Is the docker daemon running?
- Is the port in use by another application or docker container? Try stopping or removing any conflicting containers
- Are you using the correct node version? Try running `nvm use`

## Quickstart for everyone else

### Set up Postgresql locally with docker
Expand All @@ -74,61 +67,28 @@ Amongst other things, this will create an admin user for you:
- The admin interface is at `admin.lvh.me:3000`
- Access code docs through your local filesystem and update them with `bin/rails yard`

## Testing
## Testing, linting and formatting

PlaceCal tests are written in minitest.
PlaceCal tests are written in minitest. We use Rubocop to lint our Ruby code.

Before running the tests please make sure your development environment is up to date (you can run `bin/update` to quickly do that).
We use [Prettier](https://prettier.io/) to format everything it's able to parse. We run this automatically as part of a pre-commit hook.

You can run the tests with:
You can run the tests & rubocop with:

```sh
make # will run all unit and system tests then lint check all code
rails test # will run all unit tests
rails test:system # will run system tests
make test
```

Note that the system tests can take a while to run and are quite resource-intensive. To perform more advanced usage like executing only a specific test or test file, see the [Rails documentation on testing](https://guides.rubyonrails.org/testing.html).

## Documentation for Developers

The documentation for PlaceCal currently stored in notion and can be read [here](https://www.notion.so/gfsc/PlaceCal-developer-handbook-01649b69009340e3ae3035e9cf346f27). There is also a small amount of documentation sprinkled throughout the code itself and can be turned into HTML by running `rails yard`. If you are working with the code and are completely lost you can also try the GFSC discord server where you can prod a human for answers. Good Luck!
The documentation for PlaceCal is currently stored in notion and can be read [here](https://handbook.placecal.org/placecal-developer-handbook). There is also a small amount of documentation sprinkled throughout the code itself and can be turned into HTML by running `rails yard`. If you are working with the code and are completely lost you can also try the [GFSC discord server](http://discord.gfsc.studio) where you can prod a human for answers. Good Luck!

### Generating new components

We use view_component to make components, and you can create a new one by running `rails g component <Name> <args>`
Previously this system used mountain view, and some of the components are still generated using this.
More info here: https://viewcomponent.org/guide/generators.html

## Formatting

We use [Prettier](https://prettier.io/) to format everything it's able to parse. It will run as a pre-commit hook and format your changes as you make commits so you shouldn't have to think about it much.

If you do want to run it manually, you can:

```sh
bin/yarn run format
```

It's also run for you by the test runner.

Note that we use tabs over spaces because [tabs are more accessible to people using braille displays](https://twitter.com/Rich_Harris/status/1541761871585464323).

## Linting

We use Rubocop to lint our Ruby code. Because of the time it can take to run, this is a manual step:

```sh
bin/bundle exec rubocop --autocorrect
```

It's also run for you by the test runner.

## Contributing

We welcome new contributors but strongly recommend you have a chat with us in [Geeks for Social Change's Discord server](http://discord.gfsc.studio) and say hi before you do. We will be happy to onboard you properly before you get stuck in.

## Donations

If you'd like to support development, please consider sending us a one-off or regular donation on Ko-fi.

[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/M4M43THUM)
If you'd like to support development, please consider sending us a one-off or regular donation on Ko-fi. You can do this through the "support" button in GitHub at the top of this repo.
34 changes: 34 additions & 0 deletions app/assets/stylesheets/base/grid.scss
Expand Up @@ -116,6 +116,24 @@ $column: 17.38317%;
}
}

.three-col {
-moz-column-count: 3;
-webkit-column-count: 3;
column-count: 3;
-webkit-column-width: 20rem;
-moz-column-width: 20rem;
column-width: 20rem;
margin-top: 1.35rem !important;

li:first-of-type {
margin-top: -1.35rem;
}

a {
display: inline-block;
}
}

@supports (display: grid) {
.two-col {
display: grid;
Expand All @@ -133,6 +151,22 @@ $column: 17.38317%;
}
}

.three-col {
display: grid;
grid-template-columns: 1fr;

@include for-tablet-landscape-up {
grid-template-columns: 1fr 1fr 1fr;
}

grid-gap: 1rem;
align-items: start;

li:first-of-type {
margin-top: 0;
}
}

.g--partner {
display: grid;
grid-template-columns: 1fr;
Expand Down
4 changes: 4 additions & 0 deletions app/components/address/address_component.rb
Expand Up @@ -12,6 +12,10 @@ def formatted_address
return address_lines.join(', <br>').html_safe
end

uri = URI.parse(raw_location)
"<a href='#{uri}'>#{uri.hostname}</a>".html_safe

rescue URI::InvalidURIError
raw_location
end
end
6 changes: 3 additions & 3 deletions app/components/event/_event.html.erb
Expand Up @@ -34,11 +34,11 @@
Online
</div>
<% end %>
<% if place || first_address_line %>
<% if partner_at_location || first_address_line %>
<div class="event__detail event__location">
<span class="icon-font--place"></span>
<% if place %>
<%= link_to place, partner_path(place) %>
<% if partner_at_location %>
<%= link_to partner_at_location, partner_path(partner_at_location) %>
<% elsif first_address_line %>
<%= first_address_line %>
<% end %>
Expand Down
3 changes: 1 addition & 2 deletions app/components/event/event_component.rb
Expand Up @@ -8,8 +8,7 @@ class EventComponent < MountainView::Presenter
include ActionView::Helpers::DateHelper

delegate :id, to: :event

delegate :place, to: :event
delegate :partner_at_location, to: :event

def time
if event.dtend
Expand Down
2 changes: 1 addition & 1 deletion app/components/event_list/_event_list.html.erb
Expand Up @@ -24,5 +24,5 @@
</ol>
<% end %>
<% else %>
<p>No events with this selection.</p>
<p>No events with this selection.<%= link_to 'skip to next date with events.', next_url(@next) if @next.present? %></p>
<% end %>
24 changes: 15 additions & 9 deletions app/components/paginator/_paginator.html.erb
Expand Up @@ -23,13 +23,17 @@
<!-- Day or week view -->
<div class="filters__group">
<div class="filters__option">
<%= radio_button_tag(:period, "day", period == 1.day) %>
<%= radio_button_tag(:period, "day", period == 'day') %>
<%= label_tag(:period_day, "Daily view") %>
</div>
<div class="filters__option">
<%= radio_button_tag(:period, "week", period == 1.week) %>
<%= radio_button_tag(:period, "week", period == 'week') %>
<%= label_tag(:period_week, "Weekly view") %>
</div>
<div class="filters__option">
<%= radio_button_tag(:period, "future" , period == 'future') %>
<%= label_tag(:period_future, "Show all") %>
</div>
</div>
<hr>
<!-- Show or hide repeating events -->
Expand All @@ -54,13 +58,15 @@
<% end %>
</div>

<ol class="paginator__buttons paginator__buttons--day">
<% paginator.each do |page| %>
<li class="<%= page[:css] %>">
<%= link_to page[:text], page[:link] %>
</li>
<% end %>
</ol>
<% if @period == 'day' || @period == 'week' %>
<ol class="paginator__buttons paginator__buttons--day">
<% paginator.each do |page| %>
<li class="<%= page[:css] %>">
<%= link_to page[:text], page[:link] %>
</li>
<% end %>
</ol>
<% end %>

<hr>
</div>
20 changes: 10 additions & 10 deletions app/components/paginator/paginator_component.rb
Expand Up @@ -13,33 +13,33 @@ def paginator
pages = []
# Create backward arrow link
pages << { text: back_arrow,
link: create_event_url(pointer - period),
link: create_event_url(pointer - step),
css: 'paginator__arrow paginator__arrow--back js-back' }
# Create in-between links according to steps requested
(0..steps).each do |i|
day = pointer + (period * i)
day = pointer + (step * i)
css = active?(day) ? 'active js-button' : 'js-button'
pages << { text: format_date(day),
link: create_event_url(day),
css: css }
end
# Create forwards arrow link
pages << { text: forward_arrow,
link: create_event_url(pointer + period),
link: create_event_url(pointer + step),
css: 'paginator__arrow paginator__arrow--forwards js-forwards' }
end

# Paginator title
def title
if period <= 1.day
if step <= 1.day
# Thursday 14 September, 2017
pointer.strftime('%A %e %B, %Y')
else
# Thursday 14 September - 21 September 2017
t = pointer.strftime('%A %e %B')
t += ' - '
# FIXME: 1.day needs sorting when we add in month views
t + (pointer + period - 1.day).strftime('%A %e %B %Y')
t + (pointer + step - 1.day).strftime('%A %e %B %Y')
end
end

Expand All @@ -49,7 +49,7 @@ def sort
end

# How far does each step take us?
def period
def step
properties[:period] == 'week' ? 1.week : 1.day
end

Expand All @@ -67,7 +67,7 @@ def steps

# Which day are we doing our calculations based on?
def pointer
if period == 1.week
if step == 1.week
# This should be set by the model, but just to be sure
properties[:pointer].beginning_of_week
else
Expand All @@ -77,7 +77,7 @@ def pointer

# Format date according to context
def format_date(date)
if period <= 1.day
if step <= 1.day
todayify(date)
else
weekify(date)
Expand All @@ -101,7 +101,7 @@ def todayify(date)
# Format the button for a week of events
def weekify(date)
today = Date.today
end_date = date + period - 1.day
end_date = date + step - 1.day
date_fmt = if date.month == end_date.month
"#{date.strftime('%e')} - #{end_date.strftime('%e %b')}"
else
Expand All @@ -124,7 +124,7 @@ def create_event_url(dt)
# URL params to add back in
def url_suffix
str = []
str << 'period=week' if period == 1.week
str << "period=#{period}"
str << "sort=#{sort}" if sort
str << "repeating=#{repeating}" if repeating
"?#{str.join('&')}" if str.any?
Expand Down

0 comments on commit 34dc2a5

Please sign in to comment.