diff --git a/app/models/rebel.rb b/app/models/rebel.rb index 14396898..5d6b4be8 100644 --- a/app/models/rebel.rb +++ b/app/models/rebel.rb @@ -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 diff --git a/app/models/rebel_skill.rb b/app/models/rebel_skill.rb index 21aae44f..56fb8d95 100644 --- a/app/models/rebel_skill.rb +++ b/app/models/rebel_skill.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 5ec870b1..7ad55b76 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/models/working_group.rb b/app/models/working_group.rb index 89884e1b..54430141 100644 --- a/app/models/working_group.rb +++ b/app/models/working_group.rb @@ -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 diff --git a/app/models/working_group_enrollment.rb b/app/models/working_group_enrollment.rb index 7206d26a..b67b3dea 100644 --- a/app/models/working_group_enrollment.rb +++ b/app/models/working_group_enrollment.rb @@ -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 diff --git a/app/services/rebels/create_service.rb b/app/services/rebels/create_service.rb index 53addab8..9a909b74 100644 --- a/app/services/rebels/create_service.rb +++ b/app/services/rebels/create_service.rb @@ -79,6 +79,7 @@ def rebel_admin_params(params) :local_group_id, :name, :notes, + :number_of_arrests, :phone, :postcode, :status, diff --git a/app/services/rebels/update_service.rb b/app/services/rebels/update_service.rb index e0729578..6bc5a9d5 100644 --- a/app/services/rebels/update_service.rb +++ b/app/services/rebels/update_service.rb @@ -85,6 +85,7 @@ def rebel_params(params) :local_group_id, :name, :notes, + :number_of_arrests, :phone, :postcode, :status, diff --git a/app/views/rebels/_form.html.slim b/app/views/rebels/_form.html.slim index 60290723..558303e1 100644 --- a/app/views/rebels/_form.html.slim +++ b/app/views/rebels/_form.html.slim @@ -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", diff --git a/app/views/rebels/index.html.slim b/app/views/rebels/index.html.slim index d6211d81..b7380808 100644 --- a/app/views/rebels/index.html.slim +++ b/app/views/rebels/index.html.slim @@ -26,6 +26,7 @@ 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") # Arrests th(title="We met in real life") IRL th(data-exportable) Postcode th(data-exportable data-sortable="false") WG @@ -33,6 +34,7 @@ div(data-controller="datatable" data-datatable-export-title="#{FFaker::Music.son 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 @@ -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}") @@ -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" @@ -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 diff --git a/app/views/rebels/show.html.slim b/app/views/rebels/show.html.slim index 207c2415..087586e8 100644 --- a/app/views/rebels/show.html.slim +++ b/app/views/rebels/show.html.slim @@ -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 diff --git a/db/migrate/20191016200306_add_number_of_arrests_to_rebels.rb b/db/migrate/20191016200306_add_number_of_arrests_to_rebels.rb new file mode 100644 index 00000000..a5c93e15 --- /dev/null +++ b/db/migrate/20191016200306_add_number_of_arrests_to_rebels.rb @@ -0,0 +1,5 @@ +class AddNumberOfArrestsToRebels < ActiveRecord::Migration[6.0] + def change + add_column :rebels, :number_of_arrests, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index ab21ba80..fd26ebf0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" @@ -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 diff --git a/db/seeds.rb b/db/seeds.rb index 1beea2ac..e26e67e7 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -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 diff --git a/lib/tasks/auto_annotate_models.rake b/lib/tasks/auto_annotate_models.rake new file mode 100644 index 00000000..e5f0b6a7 --- /dev/null +++ b/lib/tasks/auto_annotate_models.rake @@ -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 diff --git a/test/fixtures/rebels.yml b/test/fixtures/rebels.yml index 7d80f438..f60ed69f 100644 --- a/test/fixtures/rebels.yml +++ b/test/fixtures/rebels.yml @@ -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 diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 7fc8382e..3f261319 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -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 diff --git a/test/fixtures/working_group_enrollments.yml b/test/fixtures/working_group_enrollments.yml index 4dd13490..cc3738dc 100644 --- a/test/fixtures/working_group_enrollments.yml +++ b/test/fixtures/working_group_enrollments.yml @@ -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 # # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html diff --git a/test/fixtures/working_groups.yml b/test/fixtures/working_groups.yml index 1859cd6c..821e8747 100644 --- a/test/fixtures/working_groups.yml +++ b/test/fixtures/working_groups.yml @@ -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 # # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html diff --git a/test/models/rebel_test.rb b/test/models/rebel_test.rb index 1c1b9d5f..bcefd9bd 100644 --- a/test/models/rebel_test.rb +++ b/test/models/rebel_test.rb @@ -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 # require 'test_helper' diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 5ac220f8..e9d3838c 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -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 # require 'test_helper' diff --git a/test/models/working_group_enrollment_test.rb b/test/models/working_group_enrollment_test.rb index 597b6873..f20436db 100644 --- a/test/models/working_group_enrollment_test.rb +++ b/test/models/working_group_enrollment_test.rb @@ -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 # require 'test_helper' diff --git a/test/models/working_group_test.rb b/test/models/working_group_test.rb index 613d8642..8964a570 100644 --- a/test/models/working_group_test.rb +++ b/test/models/working_group_test.rb @@ -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 # require 'test_helper'