Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

92 automatic profile creation for new user #111

Merged
merged 13 commits into from
Mar 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -362,5 +362,8 @@ DEPENDENCIES
web-console
webmock

RUBY VERSION
ruby 2.3.0p0

BUNDLED WITH
1.12.5
1.13.3
5 changes: 3 additions & 2 deletions app/dashboards/user_dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class UserDashboard < Administrate::BaseDashboard
# on pages throughout the dashboard.
ATTRIBUTE_TYPES = {
entries: Field::HasMany,
profile: Field::HasOne,
cohort_id: CohortField,
permissions: Field::HasMany,
job_applications: Field::HasMany,
id: Field::Number,
Expand All @@ -34,7 +34,7 @@ class UserDashboard < Administrate::BaseDashboard
# SHOW_PAGE_ATTRIBUTES
# an array of attributes that will be displayed on the model's show page.
SHOW_PAGE_ATTRIBUTES = [
:profile,
:cohort_id,
:name,
:github_username,
:email,
Expand All @@ -47,6 +47,7 @@ class UserDashboard < Administrate::BaseDashboard
:name,
:github_username,
:email,
:cohort_id
].freeze

# Overwrite this method to customize how users are displayed
Expand Down
7 changes: 7 additions & 0 deletions app/fields/cohort_field.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "administrate/field/base"

class CohortField < Administrate::Field::Base
def to_s
Cohort.find(data).name
end
end
7 changes: 7 additions & 0 deletions app/models/cohort.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
class Cohort < ActiveRecord::Base
has_many :profiles
has_many :users, through: :profiles

scope :upcoming, -> {where("start_date > ?", Date.today).order(start_date: :asc)}

def self.next
(upcoming.length > 0) ? upcoming[0] : nil
end

end
16 changes: 14 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
class User < ActiveRecord::Base
has_many :entries
has_one :profile
has_one :cohort, through: :profile
has_many :permissions
has_many :events

accepts_nested_attributes_for :profile
has_many :hidings

# accepts_nested_attributes_for :permissions

has_many :job_applications, through: :entries
Expand All @@ -19,6 +19,18 @@ class User < ActiveRecord::Base
delegate :twitter, to: :profile
# delegate :name, :to => :profile

def cohort_id
@cohort_id ||= self.profile.try(:cohort_id)
end

# For every param key passed to User.new, Rails runs a
# setter method named after that key. Most of these are
# default AR setter methods but it will also run this:

def cohort_id=(input)
self.build_profile(cohort_id: input)
end

# Public: Checks if a User's candidate Profile is blank
#
# Returns True if one of the required Profile fields is blank
Expand Down
6 changes: 6 additions & 0 deletions app/views/fields/cohort_field/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="field-unit__label">
<%= f.label field.attribute %>
</div>
<div class="field-unit__field">
<%= f.collection_select(field.attribute, Cohort.all, :id, :name, prompt: true, selected: Cohort.try(:next).id) %>
</div>
1 change: 1 addition & 0 deletions app/views/fields/cohort_field/_index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= field.to_s %>
1 change: 1 addition & 0 deletions app/views/fields/cohort_field/_show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= field.to_s %>
18 changes: 17 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20160914203736) do
ActiveRecord::Schema.define(version: 20161027233611) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -141,6 +141,13 @@

add_index "profiles", ["user_id"], name: "index_profiles_on_user_id", unique: true, using: :btree

create_table "projects", force: :cascade do |t|
t.datetime "created_at"
t.datetime "updated_at"
t.string "name", null: false
t.integer "cohort_id"
end

create_table "salaries", force: :cascade do |t|
t.integer "amount"
t.integer "rate"
Expand All @@ -158,6 +165,15 @@
t.datetime "updated_at", null: false
end

create_table "translations", force: :cascade do |t|
t.integer "user_id"
t.string "input_text", null: false
t.string "output_text", limit: 106
t.datetime "created_at"
t.datetime "updated_at"
t.integer "project_id", null: false
end

create_table "users", force: :cascade do |t|
t.string "name", null: false
t.string "github_username", null: false
Expand Down