Skip to content

Commit

Permalink
[#7] User can view / edit number of arrests on Rebel (#91)
Browse files Browse the repository at this point in the history
* Seed an admin user and five rebels

* Add number of arrests column to rebels

* Add number of arrests to form and show page

* Fix annotate with fresh install

* Add number of arrests to rebels table & export

* Copy tweak

* Narrow the form field

* Remove :number_of_arrests from authorized params for the public form
  • Loading branch information
kvrag authored and mhulet committed Oct 23, 2019
1 parent c85650f commit 07023d2
Show file tree
Hide file tree
Showing 22 changed files with 191 additions and 88 deletions.
29 changes: 15 additions & 14 deletions app/models/rebel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@
# Table name: rebels
#
# id :bigint not null, primary key
# name :string
# availability :string
# consent :boolean
# email :string
# phone :string
# notes :text
# created_at :datetime not null
# updated_at :datetime not null
# interests :string
# internal_notes :text
# irl :boolean
# local_group_id :bigint
# consent :boolean
# tags :text
# language :string
# name :string
# notes :text
# number_of_arrests :integer
# phone :string
# postcode :string
# interests :string
# internal_notes :text
# status :string
# self_updated_at :datetime
# source :string
# willingness_to_be_arrested :boolean
# status :string
# tags :text
# token :string
# self_updated_at :datetime
# availability :string
# willingness_to_be_arrested :boolean
# created_at :datetime not null
# updated_at :datetime not null
# local_group_id :bigint
#

class Rebel < ApplicationRecord
Expand Down
4 changes: 2 additions & 2 deletions app/models/rebel_skill.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# Table name: rebel_skills
#
# id :bigint not null, primary key
# rebel_id :bigint not null
# skill_id :bigint not null
# created_at :datetime not null
# updated_at :datetime not null
# rebel_id :bigint not null
# skill_id :bigint not null
#

class RebelSkill < ApplicationRecord
Expand Down
18 changes: 9 additions & 9 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
# Table name: users
#
# id :bigint not null, primary key
# admin :boolean
# current_sign_in_at :datetime
# current_sign_in_ip :inet
# email :string default(""), not null
# encrypted_password :string default(""), not null
# reset_password_token :string
# reset_password_sent_at :datetime
# remember_created_at :datetime
# sign_in_count :integer default(0), not null
# current_sign_in_at :datetime
# failed_attempts :integer default(0), not null
# last_sign_in_at :datetime
# current_sign_in_ip :inet
# last_sign_in_ip :inet
# failed_attempts :integer default(0), not null
# unlock_token :string
# locked_at :datetime
# remember_created_at :datetime
# reset_password_sent_at :datetime
# reset_password_token :string
# sign_in_count :integer default(0), not null
# unlock_token :string
# created_at :datetime not null
# updated_at :datetime not null
# local_group_id :bigint
# admin :boolean
#

class User < ApplicationRecord
Expand Down
4 changes: 2 additions & 2 deletions app/models/working_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# Table name: working_groups
#
# id :bigint not null, primary key
# local_group_id :bigint not null
# color :string
# name :string
# created_at :datetime not null
# updated_at :datetime not null
# color :string
# local_group_id :bigint not null
#

class WorkingGroup < ApplicationRecord
Expand Down
4 changes: 2 additions & 2 deletions app/models/working_group_enrollment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# Table name: working_group_enrollments
#
# id :bigint not null, primary key
# rebel_id :bigint not null
# working_group_id :bigint not null
# created_at :datetime not null
# updated_at :datetime not null
# rebel_id :bigint not null
# working_group_id :bigint not null
#

class WorkingGroupEnrollment < ApplicationRecord
Expand Down
1 change: 1 addition & 0 deletions app/services/rebels/create_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def rebel_admin_params(params)
:local_group_id,
:name,
:notes,
:number_of_arrests,
:phone,
:postcode,
:status,
Expand Down
1 change: 1 addition & 0 deletions app/services/rebels/update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def rebel_params(params)
:local_group_id,
:name,
:notes,
:number_of_arrests,
:phone,
:postcode,
:status,
Expand Down
7 changes: 7 additions & 0 deletions app/views/rebels/_form.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@
label: "Willingness to be arrested during an action",
required: false

.grid-x
.cell.small-6.medium-4.large-3
= f.input :number_of_arrests,
label: "Number of arrests",
as: :integer,
required: false

= f.input :skill_ids,
as: :check_boxes,
label: "Areas of interest",
Expand Down
12 changes: 9 additions & 3 deletions app/views/rebels/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ div(data-controller="datatable" data-datatable-export-title="#{FFaker::Music.son
th(data-exportable) Joined
th(data-exportable) Status
th(title="Willingness to be arrested") Arrest?
th(title="Number of arrests") #&nbsp;Arrests
th(title="We met in real life") IRL
th(data-exportable) Postcode
th(data-exportable data-sortable="false") WG
th(data-exportable data-sortable="false") Tags
th.hide(data-exportable) Phone
th.hide(data-exportable) IRL
th.hide(data-exportable) Willingness to be arrested
th.hide(data-exportable) Number of arrests
th.hide(data-exportable) Email
th.hide(data-exportable) Secure Email
th.hide(data-exportable) WG
Expand All @@ -42,7 +44,7 @@ div(data-controller="datatable" data-datatable-export-title="#{FFaker::Music.son
tr(id="selected-id-#{rebel.id}" data-object-id="#{rebel.id}" data-rebel-name="#{rebel.name}")
td
td
=> link_to (rebel.name.present? ? rebel.name : "-"),
=> link_to (rebel.name.presence || "-"),
rebel_path(rebel)
- if rebel.notes.present?
small(data-tooltip title="#{rebel.notes}")
Expand All @@ -54,12 +56,14 @@ div(data-controller="datatable" data-datatable-export-title="#{FFaker::Music.son
td(data-sort="#{rebel.created_at.iso8601}" style="width: 8rem")
= l(rebel.created_at.to_date)
td
= rebel.status.present? ? rebel.status : "-"
= rebel.status.presence || "-"
td
- if rebel.willingness_to_be_arrested?
.inline-icon
= render "layouts/icons/check_square"
td(style="width: 10rem")
td
= rebel.number_of_arrests.presence || "-"
td(style="width: 5rem")
- if rebel.irl?
.inline-icon
= render "layouts/icons/like_bubble"
Expand All @@ -85,6 +89,8 @@ div(data-controller="datatable" data-datatable-export-title="#{FFaker::Music.son
= rebel.irl? ? 'yes' : 'unknown'
td.hide
= rebel.willingness_to_be_arrested? ? 'yes' : 'unknown'
td.hide
= rebel.number_of_arrests.presence || 'unknown'
td.hide
= rebel.email
td.hide
Expand Down
8 changes: 7 additions & 1 deletion app/views/rebels/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,18 @@
.cell.small-6.medium-8
= @rebel.willingness_to_be_arrested? ? '✓' : 'NO'

.cell.small-6.medium-4
p
strong Number of arrests
.cell.small-6.medium-8
= @rebel.number_of_arrests.presence || "-"

.grid-x.grid-padding-x
.cell.small-6.medium-4
p
strong Notes added when signing up
.cell.small-6.medium-8
= @rebel.notes.present? ? @rebel.notes : "-"
= @rebel.notes.presence || "-"

.spacer-2

Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20191016200306_add_number_of_arrests_to_rebels.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddNumberOfArrestsToRebels < ActiveRecord::Migration[6.0]
def change
add_column :rebels, :number_of_arrests, :integer
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2019_10_09_104535) do
ActiveRecord::Schema.define(version: 2019_10_16_200306) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -84,6 +84,7 @@
t.string "token"
t.datetime "self_updated_at"
t.string "availability"
t.integer "number_of_arrests"
t.index ["local_group_id"], name: "index_rebels_on_local_group_id"
end

Expand Down
16 changes: 16 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,19 @@
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)

if User.none?
User.create(email: 'admin@example.com', password: 'admin123', admin: true)
end

if Rebel.none?
local_group = LocalGroup.find_or_create_by(name: 'Example Group')

5.times do
Rebel.create(name: FFaker::Name.unique.name,
email: FFaker::Internet.unique.email,
consent: true,
language: 'en',
local_group: local_group)
end
end
57 changes: 57 additions & 0 deletions lib/tasks/auto_annotate_models.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# NOTE: only doing this in development as some production environments (Heroku)
# NOTE: are sensitive to local FS writes, and besides -- it's just not proper
# NOTE: to have a dev-mode tool do its thing in production.
if Rails.env.development?
require 'annotate'
task :set_annotation_options do
# You can override any of these by setting an environment variable of the
# same name.
Annotate.set_defaults(
'additional_file_patterns' => [],
'routes' => 'false',
'models' => 'true',
'position_in_routes' => 'before',
'position_in_class' => 'before',
'position_in_test' => 'before',
'position_in_fixture' => 'before',
'position_in_factory' => 'before',
'position_in_serializer' => 'before',
'show_foreign_keys' => 'false',
'show_complete_foreign_keys' => 'false',
'show_indexes' => 'false',
'simple_indexes' => 'false',
'model_dir' => 'app/models',
'root_dir' => '',
'include_version' => 'false',
'require' => '',
'exclude_tests' => 'false',
'exclude_fixtures' => 'false',
'exclude_factories' => 'false',
'exclude_serializers' => 'false',
'exclude_scaffolds' => 'true',
'exclude_controllers' => 'true',
'exclude_helpers' => 'true',
'exclude_sti_subclasses' => 'false',
'ignore_model_sub_dir' => 'false',
'ignore_columns' => nil,
'ignore_routes' => nil,
'ignore_unknown_models' => 'false',
'hide_limit_column_types' => 'integer,bigint,boolean',
'hide_default_column_types' => 'json,jsonb,hstore',
'skip_on_db_migrate' => 'false',
'format_bare' => 'true',
'format_rdoc' => 'false',
'format_markdown' => 'false',
'sort' => 'false',
'force' => 'false',
'frozen' => 'false',
'classified_sort' => 'true',
'trace' => 'false',
'wrapper_open' => nil,
'wrapper_close' => nil,
'with_comment' => 'true'
)
end

Annotate.load_tasks
end
29 changes: 15 additions & 14 deletions test/fixtures/rebels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@
# Table name: rebels
#
# id :bigint not null, primary key
# name :string
# availability :string
# consent :boolean
# email :string
# phone :string
# notes :text
# created_at :datetime not null
# updated_at :datetime not null
# interests :string
# internal_notes :text
# irl :boolean
# local_group_id :bigint
# consent :boolean
# tags :text
# language :string
# name :string
# notes :text
# number_of_arrests :integer
# phone :string
# postcode :string
# interests :string
# internal_notes :text
# status :string
# self_updated_at :datetime
# source :string
# willingness_to_be_arrested :boolean
# status :string
# tags :text
# token :string
# self_updated_at :datetime
# availability :string
# willingness_to_be_arrested :boolean
# created_at :datetime not null
# updated_at :datetime not null
# local_group_id :bigint
#

# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
Expand Down
18 changes: 9 additions & 9 deletions test/fixtures/users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
# Table name: users
#
# id :bigint not null, primary key
# admin :boolean
# current_sign_in_at :datetime
# current_sign_in_ip :inet
# email :string default(""), not null
# encrypted_password :string default(""), not null
# reset_password_token :string
# reset_password_sent_at :datetime
# remember_created_at :datetime
# sign_in_count :integer default(0), not null
# current_sign_in_at :datetime
# failed_attempts :integer default(0), not null
# last_sign_in_at :datetime
# current_sign_in_ip :inet
# last_sign_in_ip :inet
# failed_attempts :integer default(0), not null
# unlock_token :string
# locked_at :datetime
# remember_created_at :datetime
# reset_password_sent_at :datetime
# reset_password_token :string
# sign_in_count :integer default(0), not null
# unlock_token :string
# created_at :datetime not null
# updated_at :datetime not null
# local_group_id :bigint
# admin :boolean
#

# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
Expand Down
Loading

0 comments on commit 07023d2

Please sign in to comment.