-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1208 from hisayohorie/person_contributes_councill…
…or_info Add form for a person to contribute suggested councillor info Yay! Well done @hisayohorie 🎆
- Loading branch information
Showing
28 changed files
with
507 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
ActiveAdmin.register SuggestedCouncillor do | ||
actions :index | ||
index do | ||
column :authority | ||
column :name | ||
column :email | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
app/assets/stylesheets/partials/special_forms/_councillor_contribution_form.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// TODO: These forms styles are very repetitive with #new_add_comment and .formtastic child styles | ||
// They just don't have the .formatastic overrides. | ||
// There is probably a refactor to make these the base/raw form styles | ||
// and to move them into _form.scss | ||
.councillor-contribution-form { | ||
.councillor-contribution-label { | ||
display: block; | ||
margin: .75em 0 .25em; | ||
padding: 0; | ||
font-size: 1em; | ||
font-weight: 500; | ||
} | ||
|
||
input { | ||
display: block; | ||
padding: .25em; | ||
font-family: $blueprint-font-family; | ||
font-size: 100%; | ||
} | ||
|
||
fieldset { | ||
margin-bottom: 1em; | ||
} | ||
|
||
ul { | ||
list-style: none; | ||
padding: 0; | ||
margin: 0; | ||
} | ||
} | ||
|
||
.councillor-contribution-councillors { | ||
padding-bottom: 2em; | ||
|
||
input, | ||
dd { | ||
font-size: 1.2em; | ||
} | ||
|
||
dt { | ||
color: $cool-highlight; | ||
} | ||
} | ||
|
||
.councillor-contribution-actions { | ||
text-align: right; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
class ContributorsController < ApplicationController | ||
before_action :check_if_feature_flag_is_on | ||
|
||
def new | ||
@contributor = Contributor.new | ||
end | ||
|
||
def create | ||
@contributor = Contributor.new(contributor_params) | ||
@councillor_contribution = CouncillorContribution.find(params[:contributor][:councillor_contribution_id]) | ||
if @contributor.save | ||
@councillor_contribution.update(contributor: @contributor) | ||
flash[:notice] = "Thank you" | ||
redirect_to root_url | ||
end | ||
end | ||
|
||
def no_contributor_info | ||
flash[:notice] = "Thank you" | ||
redirect_to root_url | ||
end | ||
|
||
private | ||
|
||
def contributor_params | ||
params.require(:contributor).permit(:name, :email) | ||
end | ||
|
||
def check_if_feature_flag_is_on | ||
unless ENV["CONTRIBUTE_COUNCILLORS_ENABLED"] == "true" | ||
render "static/error_404", status: 404 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
class CouncillorContributionsController < ApplicationController | ||
before_action :check_if_feature_flag_is_on | ||
|
||
def new | ||
@authority = Authority.find_by_short_name_encoded!(params[:authority_id]) | ||
|
||
if params["councillor_contribution"] | ||
@councillor_contribution = @authority.councillor_contributions.build(councillor_contribution_params) | ||
else | ||
@councillor_contribution = CouncillorContribution.new | ||
end | ||
|
||
@councillor_contribution.suggested_councillors.build({email: nil, name: nil}) | ||
end | ||
|
||
def create | ||
@authority = Authority.find_by_short_name_encoded!(params[:authority_id]) | ||
@councillor_contribution = @authority.councillor_contributions.build(councillor_contribution_params) | ||
|
||
if @councillor_contribution.save | ||
redirect_to new_contributor_url(councillor_contribution_id: @councillor_contribution.id) | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
private | ||
|
||
def councillor_contribution_params | ||
params.require(:councillor_contribution).permit(suggested_councillors_attributes: [:name, :email]) | ||
end | ||
|
||
def check_if_feature_flag_is_on | ||
unless ENV["CONTRIBUTE_COUNCILLORS_ENABLED"].present? | ||
render "static/error_404", status: 404 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Contributor < ActiveRecord::Base | ||
has_many :councillor_contributions | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class CouncillorContribution < ActiveRecord::Base | ||
belongs_to :contributor | ||
belongs_to :authority | ||
has_many :suggested_councillors, inverse_of: :councillor_contribution | ||
accepts_nested_attributes_for :suggested_councillors, reject_if: :all_blank | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class SuggestedCouncillor < ActiveRecord::Base | ||
has_one :authority, through: :councillor_contribution | ||
belongs_to :councillor_contribution | ||
validates :councillor_contribution, :name, :email, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
%h1 Thank you! | ||
%p | ||
This data you contributed will be reviewed | ||
by an administrator, and go live shortly. | ||
= form_for @contributor do |f| | ||
= f.hidden_field :councillor_contribution_id, value: params[:councillor_contribution_id] | ||
%fieldset | ||
%legend | ||
Please tell us about yourself, so we can send you a little note of appreciation | ||
and updates about your contribution when it goes live. | ||
%p This field is optional. | ||
%p | ||
= f.label :name | ||
= f.text_field :name | ||
%p | ||
= f.label :email | ||
= f.text_field :email | ||
%p.button | ||
= f.submit "Submit" | ||
= link_to "I prefer not to", contributors_no_info_path |
9 changes: 9 additions & 0 deletions
9
app/views/councillor_contributions/_contribution_form_input.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
%fieldset | ||
.suggested-councillor-input-wrapper | ||
= f.fields_for :suggested_councillors, @councillor_contribution.suggested_councillors.last do |suggested_councillor_field| | ||
.suggested-councillor-input-group | ||
= suggested_councillor_field.label :name, "Full name", class: "councillor-contribution-label" | ||
= suggested_councillor_field.text_field :name | ||
.suggested-councillor-input-group | ||
= suggested_councillor_field.label :email, class: "councillor-contribution-label" | ||
= suggested_councillor_field.text_field :email |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.councillor-contributions | ||
%h1.page-title Add a new councillor for #{@authority.full_name} | ||
= form_for [@authority, @councillor_contribution], url: authority_councillor_contributions_path, html: { class: "councillor-contribution-form" } do |f| | ||
- @councillor_contribution.suggested_councillors[0...-1].each do |s| | ||
= f.fields_for :suggested_councillors, @councillor_contribution.suggested_councillors.last do |suggested_councillor_field| | ||
= suggested_councillor_field.hidden_field :name, value: s.name | ||
= suggested_councillor_field.hidden_field :email, value: s.email | ||
.councillor-contribution-councillors | ||
- if @councillor_contribution.suggested_councillors.many? | ||
%ul | ||
- @councillor_contribution.suggested_councillors[0...-1].each do |s| | ||
%li | ||
%dl.suggested-councillor-input-wrapper | ||
.suggested-councillor-input-group | ||
%dt.councillor-contribution-label Full name | ||
%dd= s.name | ||
.suggested-councillor-input-group | ||
%dt.councillor-contribution-label Email | ||
%dd= s.email | ||
= render 'contribution_form_input', f: f | ||
%button{formaction: new_authority_councillor_contribution_path, class: "button"} Add another councillor | ||
.councillor-contribution-actions | ||
= f.submit "Submit #{pluralize(@councillor_contribution.suggested_councillors.length, "new councillor")}", class: "button-action" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CreateSuggestedCouncillors < ActiveRecord::Migration | ||
def change | ||
create_table :suggested_councillors do |t| | ||
t.string :name | ||
t.string :email | ||
t.integer :authority_id | ||
|
||
t.timestamps null: false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CreateContributors < ActiveRecord::Migration | ||
def change | ||
create_table :contributors do |t| | ||
t.string :name | ||
t.string :email | ||
|
||
t.timestamps null: false | ||
end | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
db/migrate/20170623024916_add_contributor_id_to_suggested_councillors.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddContributorIdToSuggestedCouncillors < ActiveRecord::Migration | ||
def change | ||
add_column :suggested_councillors, :contributor_id, :integer | ||
end | ||
end |
10 changes: 10 additions & 0 deletions
10
db/migrate/20170704043739_create_councillor_contributions.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CreateCouncillorContributions < ActiveRecord::Migration | ||
def change | ||
create_table :councillor_contributions do |t| | ||
t.integer :contributor_id | ||
t.integer :authority_id | ||
|
||
t.timestamps null: false | ||
end | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
db/migrate/20170704164758_add_councillor_contribution_id_in_suggested_councillors.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddCouncillorContributionIdInSuggestedCouncillors < ActiveRecord::Migration | ||
def change | ||
add_column :suggested_councillors, :councillor_contribution_id, :integer | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
db/migrate/20170704165154_remove_authority_id_from_suggested_councillors.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class RemoveAuthorityIdFromSuggestedCouncillors < ActiveRecord::Migration | ||
def change | ||
remove_column :suggested_councillors, :authority_id | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
db/migrate/20170704165351_remove_contributor_id_from_suggested_councillors.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class RemoveContributorIdFromSuggestedCouncillors < ActiveRecord::Migration | ||
def change | ||
remove_column :suggested_councillors, :contributor_id | ||
end | ||
end |
Oops, something went wrong.