Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/redesign' into redesign
Browse files Browse the repository at this point in the history
  • Loading branch information
dereke committed Sep 1, 2021
2 parents 65959d3 + 7e69ff5 commit 0395de8
Show file tree
Hide file tree
Showing 25 changed files with 210 additions and 104 deletions.
30 changes: 25 additions & 5 deletions .exrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
let g:vigun_extra_keywords = ['test']
let g:vigun_test_keywords = ['test', 'it', 'context', 'describe']
let g:vjs_tags_enabled = 0

let g:vigun_commands = [
fun! s:watch(cmd)
return "rg --files | entr -r -c sh -c 'echo ".escape('"'.a:cmd.'"', '"')." && ".a:cmd."'"
endf

let g:vigun_mappings = [
\ {
\ 'pattern': 'test/.*_test.rb$',
\ 'all': 'rails test #{file}',
\ 'nearest': 'rails test #{file}:#{line}',
\ 'watch-all': s:watch('rails test #{file}'),
\ 'watch-nearest': s:watch('rails test #{file}:#{line}'),
\ },
\ {
\ 'pattern': 'test/.*_test.rb$',
\ 'normal': 'rails test',
\ 'debug': 'BACKTRACE=1 rails test',
\ 'pattern': 'test/javascript/.*_test.js$',
\ 'all': 'yarn test #{file}',
\ 'nearest': 'yarn test --fgrep #{nearest_test} #{file}',
\ 'debug-all': 'yarn test --interactive #{file}',
\ 'debug-nearest': 'yarn test --interactive --fgrep #{nearest_test} #{file}',
\ }
\]

command! -nargs=0 Fixturex :cexpr system('./bin/fixturex.rb '. expand('%:t:r') .' '.shellescape(expand('<cword>'))) | copen

" open report fixture in a split to the right
" nnoremap gj :exec "botright vnew
" test/fixtures/reports/".expand('<cword>').".json"<cr>
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# Ignore bundler config.
/.bundle
vendor/bundle/**/*.*

# Ignore the default SQLite database.
/db/*.sqlite3*
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,4 @@ RUBY VERSION
ruby 2.6.5p114

BUNDLED WITH
2.1.4
2.2.5
7 changes: 5 additions & 2 deletions app/controllers/initiatives_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# rubocop:disable Metrics/ClassLength
class InitiativesController < ApplicationController
include ApplicationHelper

before_action :set_initiative, only: %i[edit update]
before_action :set_edit_data, only: %i[edit new create update]
skip_before_action :authenticate_user!, only: %i[index show]
Expand Down Expand Up @@ -36,14 +38,14 @@ def new

def edit
@current_initiative_step = (params[:step] || 1).to_i
@initiative.websites << InitiativeWebsite.new if @initiative.websites.empty?
end

# rubocop:disable Metrics/MethodLength
def create
@initiative = Initiative.new(initiative_params.merge(owner: current_user))
add_solutions(@initiative)
find_or_create_group
@initiative.update_location_from_postcode

if @initiative.save(validate: @initiative.publication_status != 'draft')
redirect_to edit_initiative_step_path(@initiative, step: 2)
Expand All @@ -69,7 +71,7 @@ def update
@initiative.assign_attributes initiative_params
@initiative.update_location_from_postcode

if @initiative.save(validate: publication_status != 'draft')
if @initiative.save(validate: @initiative.publication_status != 'draft')
@initiative.images.attach images if images
if (params[:step] || '').empty?
redirect_to initiative_path(@initiative),
Expand All @@ -78,6 +80,7 @@ def update
redirect_to edit_initiative_step_path(@initiative, step: params[:step])
end
else
@current_initiative_step = params[:step].blank? ? 1 : params[:step].to_i - 1
render :edit
end
end
Expand Down
12 changes: 6 additions & 6 deletions app/helpers/suit_form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ def form_field(field, options = {}, &block)
css_classes << 'FormField--required' if required
css_classes << 'is-error' if field_errors.any?
css_classes << options[:class_names]
# rubocop:disable HelperInstanceVariable
@template.content_tag :div, class: css_classes, &block
# rubocop:enable HelperInstanceVariable
# rubocop:disable Rails/HelperInstanceVariable
@template.tag.div(class: css_classes, &block)
# rubocop:enable Rails/HelperInstanceVariable
end

def label(method, text = nil, options = {})
Expand Down Expand Up @@ -41,9 +41,9 @@ def check_box(attribute, options = {}, checked_value = '1', unchecked_value = '0
end
label(attribute, class: 'FormField-check FormField-check--checkbox') do
super(attribute, options.reverse_merge(class: 'FormField-checkInput'), checked_value, unchecked_value) +
# rubocop:disable HelperInstanceVariable
@template.content_tag(:span, label_text, class: 'FormField-checkLabel')
# rubocop:enable HelperInstanceVariable
# rubocop:disable Rails/HelperInstanceVariable
@template.tag.span(label_text, class: 'FormField-checkLabel')
# rubocop:enable Rails/HelperInstanceVariable
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/group_website.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class GroupWebsite < ApplicationRecord
belongs_to :group
validates :url, format: URI.regexp(%w[http https])
validates :url, format: URI::DEFAULT_PARSER.make_regexp(%w[http https])
include Website
delegate :name, prefix: true, to: :group
end
27 changes: 16 additions & 11 deletions app/models/initiative.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@
class Initiative < ApplicationRecord
after_initialize :set_default_location
after_initialize :set_default_publication_status
before_save :remove_empty_websites

belongs_to :owner, class_name: 'User'
belongs_to :lead_group, class_name: 'Group'
belongs_to :status, class_name: 'InitiativeStatus'
belongs_to :parish

delegate :name, prefix: true, to: :status
delegate :name, prefix: true, to: :lead_group
delegate :ward, to: :parish
delegate :district, to: :ward
delegate :county, to: :district
delegate :region, to: :county
delegate :name, prefix: true, to: :status, allow_nil: true
delegate :name, prefix: true, to: :lead_group, allow_nil: true
delegate :ward, to: :parish, allow_nil: true
delegate :district, to: :ward, allow_nil: true
delegate :county, to: :district, allow_nil: true
delegate :region, to: :county, allow_nil: true

has_many :solutions, class_name: 'InitiativeSolution', dependent: :destroy
has_many :themes, class_name: 'InitiativeTheme', dependent: :destroy
Expand Down Expand Up @@ -111,11 +112,11 @@ def location
# rubocop:disable Metrics/MethodLength
def location_attributes
{
parish: parish.name,
ward: ward.name,
district: district.name,
county: county.name,
region: region.name,
parish: parish&.name,
ward: ward&.name,
district: district&.name,
county: county&.name,
region: region&.name,
postcode: postcode,
latlng: {
# "Down to Earth Stroud, PO Box 427, Stonehouse, Gloucestershire, GL6 1JG",
Expand All @@ -130,6 +131,10 @@ def carbon_saving_quantified?
carbon_saving_amount&.positive?
end

def remove_empty_websites
websites.delete(websites.select { |website| website.url.blank? })
end

private

def set_default_location
Expand Down
2 changes: 1 addition & 1 deletion app/models/initiative_website.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class InitiativeWebsite < ApplicationRecord
validates :url, format: URI.regexp(%w[http https])
validates :url, format: URI::DEFAULT_PARSER.make_regexp(%w[http https])
include Website

belongs_to :initiative
Expand Down
6 changes: 4 additions & 2 deletions app/models/public_initiative.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# The publicly available data of an initiative
class PublicInitiative
include ActionView::Helpers::DateHelper
delegate :name,
delegate :id,
:name,
:description_what,
:description_how,
:description_further_information,
Expand Down Expand Up @@ -70,7 +71,7 @@ def websites
end

def last_updated
time_ago_in_words(timestamp) + ' ago'
"#{time_ago_in_words(timestamp)} ago"
end

def href
Expand All @@ -81,6 +82,7 @@ def href
# rubocop:disable Metrics/AbcSize
def as_json(_options = {})
{
'id': id,
'name': name,
'description_what': description_what,
'description_how': description_how,
Expand Down
10 changes: 3 additions & 7 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= javascript_packs_with_chunks_tag 'explore_tabs', 'data-turbolinks-track': 'reload' %>
<%= javascript_packs_with_chunks_tag 'home', 'data-turbolinks-track': 'reload' %>
<div class="Home-strapline">
<p class="u-mb">We share community-based projects that work towards a Carbon Neutral Stroud District by 2030 and connect groups organising them.</p>
<p class="u-mb">Share knowledge. Enable Change</p>
Expand All @@ -16,13 +16,9 @@
<span class="Home-search_or">Or</span>

<span class="Home-search">
<form action="/search" method="GET">
<form id="search">
<div class="ButtonInput">
<input type="search" name="q" placeholder="Search for a project" />
<button type="submit" class="Button">
<span class="u-mr">Go</span>
<img src="<%=asset_pack_path("media/icons/right_arrow.svg")%>">
</button>
</div>
</form>
</span>
Expand Down Expand Up @@ -75,7 +71,7 @@

<tbody>
<% @initiatives.each do |initiative| %>
<tr class="Initiative Initiative-<%=initiative.publication_status%>">
<tr class="Initiative Initiative-<%=initiative.publication_status%>" data-content="initiative_<%=initiative.id %>">
<td><%= link_to initiative.name, initiative_path(initiative) %></td>
<td><%= initiative.location %></td>
<td><%= initiative.status_name %></td>
Expand Down
29 changes: 10 additions & 19 deletions app/views/initiatives/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@

<%= f.form_field :contact_email, required: true do %>
<%= f.label :contact_email, 'Email address to contact about this project' %>
<div class="Hint">Find out <%= link_to 'how we use your email address', :privacy%></div>
<%= f.text_field :contact_email, placeholder: 'Email address' %>
<% end %>

Expand All @@ -119,28 +120,18 @@
<%= f.check_box :consent_to_share_phone, 'Make this phone number public. (Please ensure you have permission to share it first)' %>
<% end %>

<h2 class="u-mb">Website & Social Media</h2>
<%= f.label :website, 'Website(s) or social media links for further project info' %>
<div id="initiative_websites" class="CollectionItem-container">
<table>
<thead>
<tr>
<th>Website</th>
<th>Delete?</th>
</tr>
</thead>

<tbody>
<%= f.fields_for :websites do |website_form| %>
<%= render 'partials/website_fields_row', f: website_form %>
<% end %>
</tbody>
</table>
</div>
<div class="FormField">
<%= f.fields_for :websites, InitiativeWebsite.new do |website_form| %>
<%= add_object_link 'Add website', 'initiative_websites', :partial => 'partials/website_fields_row', :locals => { :f => website_form } %>
<%= f.fields_for :websites do |website_form| %>
<%= website_form.form_field :url do %>
<%= website_form.text_field :url, placeholder: 'eg: https://twitter.com/carbon-map' %>
<% end %>
<% end %>
<%= javascript_packs_with_chunks_tag 'initiative_websites', 'data-turbolinks-track': 'reload' %>
</div>
<a href="#" data-content="add_initiative_website">
<span>Add another</span><img src="<%=asset_pack_path("media/icons/right_arrow.svg")%>">
</a>
<% end %>

<%= initiative_step 5, @current_initiative_step, title: 'Help us understand how you got going', next_text: 'Next: project sector and notes' do %>
Expand Down
3 changes: 1 addition & 2 deletions app/views/layouts/_base.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,8 @@ set_meta_tags og: {
<div class="Footer-contact">
<p>Carbon Neutral Map</p>
<a href="mailto:[email protected]">[email protected]</a>
<div class="Footer-copyright">&copy; Transition Stroud <time datetime="<%= Date.current.year %>"><%= Date.current.year %></time></div>
</div>

<div class="Footer-copyright">&copy; Transition Stroud <time datetime="<%= Date.current.year %>"><%= Date.current.year %></time></div>
<div class="Footer-links">
<div class="Footer-internal_links">
<%= link_to 'Privacy policy', '/privacy' %>
Expand Down
9 changes: 0 additions & 9 deletions app/views/partials/_initiative_website.html.erb

This file was deleted.

8 changes: 4 additions & 4 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@
config.i18n.fallbacks = true

ActionMailer::Base.smtp_settings = {
address: 'smtp.sendgrid.net',
address: ENV['SMTP_SERVER'],
port: 587,
user_name: ENV['SENDGRID_USERNAME'],
password: ENV['SENDGRID_PASSWORD'],
user_name: ENV['SMTP_USERNAME'],
password: ENV['SMTP_PASSWORD'],
domain: 'carbonneutralmap.org.uk',
authentication: :plain,
enable_starttls_auto: true
Expand All @@ -97,7 +97,7 @@
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')

if ENV['RAILS_LOG_TO_STDOUT'].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger = ActiveSupport::Logger.new($stdout)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
Expand Down
10 changes: 5 additions & 5 deletions config/puma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches the default thread size of Active Record.
#
max_threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 }
min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count }
max_threads_count = ENV.fetch('RAILS_MAX_THREADS', 5)
min_threads_count = ENV.fetch('RAILS_MIN_THREADS', max_threads_count)
threads min_threads_count, max_threads_count

# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
port ENV.fetch('PORT') { 3_000 }
port ENV.fetch('PORT', 3_000)

# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch('RAILS_ENV') { 'development' }
environment ENV.fetch('RAILS_ENV', 'development')

# Specifies the `pidfile` that Puma will use.
pidfile ENV.fetch('PIDFILE') { 'tmp/pids/server.pid' }
pidfile ENV.fetch('PIDFILE', 'tmp/pids/server.pid')

# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked web server processes. If using threads and workers together
Expand Down
23 changes: 0 additions & 23 deletions frontend/packs/explore_tabs.js

This file was deleted.

Loading

0 comments on commit 0395de8

Please sign in to comment.