From ff545a1bb9f26fc3afbd4cda2fa5bef98667a9ad Mon Sep 17 00:00:00 2001 From: wimsy113 Date: Wed, 18 May 2016 15:01:41 -0400 Subject: [PATCH] WIP: User may choose time check in reminder email time --- .../account/registrations_controller.rb | 7 ++++++- app/models/account.rb | 4 ++++ app/models/settings.rb | 17 ++++++++++++++++ app/views/devise/registrations/edit.html.erb | 7 +++++++ .../20160518181634_add_settings_to_account.rb | 6 ++++++ db/schema.rb | 20 ++++++++++--------- 6 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 app/models/settings.rb create mode 100644 db/migrate/20160518181634_add_settings_to_account.rb diff --git a/app/controllers/account/registrations_controller.rb b/app/controllers/account/registrations_controller.rb index 9a7cdaf..7ad34e0 100644 --- a/app/controllers/account/registrations_controller.rb +++ b/app/controllers/account/registrations_controller.rb @@ -21,6 +21,11 @@ def create end end + def update + byebug + super + end + # GET /resource/edit # def edit # super @@ -54,7 +59,7 @@ def configure_sign_up_params # You can put the params you want to permit in the empty array. def configure_account_update_params - devise_parameter_sanitizer.for(:account_update) << [:name, :time_zone] + devise_parameter_sanitizer.for(:account_update) << [:name, :time_zone, settings_attributes: [:check_in_reminder_time] ] end # The path used after sign up. diff --git a/app/models/account.rb b/app/models/account.rb index 8800c80..9db1448 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -19,6 +19,7 @@ class Account < ActiveRecord::Base validates :name, presence: true serialize :features, Features + serialize :settings, Settings def enable_feature(feature) features.send(:"#{feature}=", true) @@ -45,4 +46,7 @@ def remaining_recent_capacity def remaining_weekly_capacity weekly_expected_capacity - total_weekly_capacity end + + def settings_attributes=(attributes) + end end diff --git a/app/models/settings.rb b/app/models/settings.rb new file mode 100644 index 0000000..050289a --- /dev/null +++ b/app/models/settings.rb @@ -0,0 +1,17 @@ +class Settings + include Virtus.model + + attribute :check_in_reminder_time, Integer, default: 6 + + def self.dump(settings) + settings.to_hash + end + + def self.load(settings) + new(settings) + end + + def persisted? + false + end +end diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index 953a2ab..94ff03a 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -21,6 +21,13 @@ <%= f.label :time_zone %> <%= f.time_zone_select :time_zone, ActiveSupport::TimeZone.all.sort %> +
+ <%= f.fields_for :settings do |settings_fields| %> + <%= settings_fields.label :check_in_reminder_time %> + <%= settings_fields.time_select(:check_in_reminder_time, ampm: true, discard_minute: true) %> + <% end %> +
+
<%= f.label :password %> (leave blank if you don't want to change it) <%= f.password_field :password, autocomplete: "off" %> diff --git a/db/migrate/20160518181634_add_settings_to_account.rb b/db/migrate/20160518181634_add_settings_to_account.rb new file mode 100644 index 0000000..4d88e0a --- /dev/null +++ b/db/migrate/20160518181634_add_settings_to_account.rb @@ -0,0 +1,6 @@ +class AddSettingsToAccount < ActiveRecord::Migration + def change + enable_extension "citext" + add_column :accounts, :settings, :jsonb, null: false, default: "{}" + end +end diff --git a/db/schema.rb b/db/schema.rb index bb7ae21..dde0df6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,30 +11,32 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160511170833) do +ActiveRecord::Schema.define(version: 20160518181634) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" enable_extension "uuid-ossp" enable_extension "hstore" + enable_extension "citext" create_table "accounts", id: :uuid, default: "uuid_generate_v4()", force: :cascade do |t| - t.string "name", default: "", null: false - t.string "email", default: "", null: false - t.string "encrypted_password", null: false + t.string "name", default: "", null: false + t.string "email", default: "", null: false + t.string "encrypted_password", null: false t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" t.inet "current_sign_in_ip" t.inet "last_sign_in_ip" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "weekly_expected_capacity", default: 0, null: false - t.string "time_zone", default: "Central Time (US & Canada)", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "weekly_expected_capacity", default: 0, null: false + t.string "time_zone", limit: 255, default: "UTC", null: false t.hstore "features" + t.jsonb "settings", default: {}, null: false end add_index "accounts", ["created_at"], name: "index_accounts_on_created_at", using: :btree