Skip to content

Commit

Permalink
various tweaks to layout
Browse files Browse the repository at this point in the history
  • Loading branch information
dereke committed Aug 20, 2021
1 parent d474eaa commit 7e69ff5
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 22 deletions.
7 changes: 3 additions & 4 deletions app/controllers/initiatives_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,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 @@ -70,8 +70,7 @@ def update
@initiative.assign_attributes initiative_params
@initiative.update_location_from_postcode

@initiative.remove_empty_websites
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 @@ -80,6 +79,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 Expand Up @@ -120,7 +120,6 @@ def update_solutions(initiative)

def set_initiative
@initiative = Initiative.find(params[:id])
@initiative.websites << InitiativeWebsite.new if @initiative.websites.empty?

redirect_to initiatives_url unless can_edit_initiative?(@initiative)
end
Expand Down
23 changes: 12 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 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
7 changes: 5 additions & 2 deletions frontend/styles/components/alert.css
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
.Alert {
margin: 0 auto;
margin-bottom: 10px;
max-width: 800px;
padding: 15px;
text-align: center;
}

.Alert--danger {
background-color: rgb(246, 220, 222);
background-color: rgba(246, 220, 222, 0.6);
color: rgb(146, 40, 48);
}

.Alert--info {
background-color: rgb(156, 209, 255);
background-color: rgba(0, 222, 233, 0.2);
color: rgb(15, 55, 89);
}
5 changes: 3 additions & 2 deletions frontend/styles/components/footer.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
}

.Footer-copyright {
flex: 1;
margin-bottom: 10px;
}

.Footer-contact {
Expand All @@ -28,7 +30,6 @@
flex: 1;
flex-direction: row;
justify-content: space-between;
margin: 24px 0;
}

.Footer-internal_links {
Expand All @@ -40,7 +41,7 @@
margin-left: 10px;
}

@media (--bp-mobile) {
@media (--bp-desktop) {

.Footer-main {
flex-direction: row;
Expand Down
2 changes: 1 addition & 1 deletion frontend/styles/components/sponsors.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
text-align: center;
}

@media (--bp-mobile) {
@media (--bp-desktop) {

.sponsors-logo {
margin: 20px;
Expand Down
13 changes: 13 additions & 0 deletions test/controllers/initiatives_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@ def header_image
assert_equal 'rejected', @initiative.reload.publication_status
end

test 'cannot publish initiative in an invalid state' do
@initiative.update!(publication_status: 'draft')
@initiative.name = ''

sign_in_as :georgie
VCR.use_cassette('valid_postcode') do
patch initiative_url(@initiative),
params: update_params(@initiative, publication_status: 'published')
end

assert_equal 'draft', @initiative.reload.publication_status
end

test 'create initiative and lead group' do
sign_in_as :georgie
lead_group = {
Expand Down

0 comments on commit 7e69ff5

Please sign in to comment.