A user has many profiles now
Still need to change controllers quite a lot.
This commit is contained in:
parent
b0a978975c
commit
454f18dd2f
6
TODO
6
TODO
|
@ -15,9 +15,11 @@
|
||||||
|
|
||||||
- users:
|
- users:
|
||||||
- # edit profile: image upload and stuff
|
- # edit profile: image upload and stuff
|
||||||
- show profile
|
- # show profile
|
||||||
|
- Edit profiles instead
|
||||||
|
|
||||||
|
- Home-area user CRUD
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
- .row > .col-lg-12 -> put that outside of the "yield"?
|
- .row > .col-lg-12 -> put that outside of the "yield"?
|
||||||
- human_attribute_name -> create a short alias?
|
- human_attribute_name -> create a short alias?
|
||||||
- NullPersonalProfile with placeholders?
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
|
# TODO Needs to work with profiles, not with users
|
||||||
module Management
|
module Management
|
||||||
class UsersController < ManagementController
|
class UsersController < ManagementController
|
||||||
def index
|
def index
|
||||||
@users = User.includes(:personal_profile)
|
@profiles = current_conference.participant_profiles
|
||||||
end
|
end
|
||||||
|
|
||||||
def toggle_admin
|
def toggle_admin
|
||||||
|
@ -12,12 +13,12 @@ module Management
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@user = find_user
|
@user = find_user
|
||||||
@profile = @user.personal_profile
|
@profile = @user.personal_profile(current_conference)
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@user = find_user
|
@user = find_user
|
||||||
@user.personal_profile if @user.personal_profile.blank?
|
@profile = @user.personal_profile(current_conference)
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
|
|
@ -12,6 +12,7 @@ class Conference < ActiveRecord::Base
|
||||||
has_many :halls
|
has_many :halls
|
||||||
has_many :events, through: :tracks
|
has_many :events, through: :tracks
|
||||||
has_one :call_for_participation, dependent: :destroy
|
has_one :call_for_participation, dependent: :destroy
|
||||||
|
has_many :participant_profiles, class_name: 'PersonalProfile'
|
||||||
|
|
||||||
accepts_nested_attributes_for :tracks, :halls, reject_if: :all_blank, allow_destroy: true
|
accepts_nested_attributes_for :tracks, :halls, reject_if: :all_blank, allow_destroy: true
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
class PersonalProfile < ActiveRecord::Base
|
class PersonalProfile < ActiveRecord::Base
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
belongs_to :conference
|
||||||
|
|
||||||
validates :first_name, presence: true
|
validates :first_name, presence: true
|
||||||
validates :last_name, presence: true
|
validates :last_name, presence: true
|
||||||
|
|
|
@ -4,28 +4,20 @@ class User < ActiveRecord::Base
|
||||||
devise :database_authenticatable, :registerable, :confirmable,
|
devise :database_authenticatable, :registerable, :confirmable,
|
||||||
:recoverable, :rememberable, :trackable, :validatable
|
:recoverable, :rememberable, :trackable, :validatable
|
||||||
|
|
||||||
has_one :personal_profile
|
has_many :personal_profiles, dependent: :destroy
|
||||||
has_many :lectures
|
has_many :lectures
|
||||||
has_many :workshops
|
has_many :workshops
|
||||||
has_many :events
|
has_many :events
|
||||||
|
|
||||||
accepts_nested_attributes_for :personal_profile, update_only: true
|
accepts_nested_attributes_for :personal_profiles, update_only: true
|
||||||
|
|
||||||
default_scope { order id: :desc }
|
default_scope { order id: :desc }
|
||||||
|
|
||||||
def name
|
def personal_profile(conference)
|
||||||
personal_profile.try(:name) || email
|
personal_profiles.find_by!(conference_id: conference.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def toggle_admin!
|
def toggle_admin!
|
||||||
update admin: !admin
|
update admin: !admin
|
||||||
end
|
end
|
||||||
|
|
||||||
def profile_picture
|
|
||||||
if personal_profile.present?
|
|
||||||
personal_profile.picture
|
|
||||||
else
|
|
||||||
PictureUploader.new
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
- content_for :title
|
- content_for :title
|
||||||
=> t 'actions.edit.title', model: User.model_name.human
|
=> t 'actions.edit.title', model: User.model_name.human
|
||||||
= @user.name
|
= @profile.name
|
||||||
|
|
||||||
.row
|
.row
|
||||||
.col-lg-12
|
.col-lg-12
|
||||||
|
@ -18,12 +18,11 @@
|
||||||
hr
|
hr
|
||||||
.row
|
.row
|
||||||
.col-lg-12
|
.col-lg-12
|
||||||
- personal_profile = @user.personal_profile
|
-# TODO we have many personal_profiles now
|
||||||
|
|
||||||
= f.simple_fields_for :personal_profile do |ff|
|
= f.simple_fields_for :personal_profile do |ff|
|
||||||
- if personal_profile.picture.present?
|
- if @profile.picture.present?
|
||||||
.col-sm-offset-3.col-sm-9
|
.col-sm-offset-3.col-sm-9
|
||||||
= image_tag personal_profile.picture.medium.url, class: 'img-thumbnail'
|
= image_tag @profile.picture.medium.url, class: 'img-thumbnail'
|
||||||
|
|
||||||
= ff.input :picture, wrapper: :horizontal_file_input
|
= ff.input :picture, wrapper: :horizontal_file_input
|
||||||
|
|
||||||
|
|
|
@ -12,10 +12,12 @@
|
||||||
th = User.human_attribute_name :admin
|
th = User.human_attribute_name :admin
|
||||||
th.actions
|
th.actions
|
||||||
tbody
|
tbody
|
||||||
- @users.each do |user|
|
- @profiles.each do |profile|
|
||||||
|
- user = profile.user
|
||||||
|
|
||||||
tr
|
tr
|
||||||
td= image_tag(user.profile_picture.thumb.url)
|
td= image_tag(profile.picture.thumb.url)
|
||||||
td= user.name
|
td= profile.name
|
||||||
td.boolean-col
|
td.boolean-col
|
||||||
= link_to toggle_admin_management_user_path(user), method: :put do
|
= link_to toggle_admin_management_user_path(user), method: :put do
|
||||||
- if user.admin?
|
- if user.admin?
|
||||||
|
|
|
@ -1,39 +1,39 @@
|
||||||
- content_for :title
|
- content_for :title
|
||||||
= @user.name
|
= @profile.name
|
||||||
|
|
||||||
.row
|
.row
|
||||||
.speaker-profile
|
.speaker-profile
|
||||||
.panel.panel-default
|
.panel.panel-default
|
||||||
.panel-heading
|
.panel-heading
|
||||||
h1.panel-title
|
h1.panel-title
|
||||||
= @user.name
|
= @profile.name
|
||||||
= link_to icon(:edit), edit_management_user_path(@user), class: 'btn btn-xs btn-danger pull-right'
|
= link_to icon(:edit), edit_management_user_path(@user), class: 'btn btn-xs btn-danger pull-right'
|
||||||
.panel-body
|
.panel-body
|
||||||
.center
|
.center
|
||||||
= image_tag @user.personal_profile.picture.medium.url, class: "profile-image"
|
= image_tag @profile.picture.medium.url, class: "profile-image"
|
||||||
- if @user.personal_profile.organisation.present?
|
- if @profile.organisation.present?
|
||||||
div
|
div
|
||||||
=> icon :briefcase
|
=> icon :briefcase
|
||||||
= @user.personal_profile.organisation
|
= @profile.organisation
|
||||||
div.social
|
div.social
|
||||||
= link_to "mailto://#{@user.email}"
|
= link_to "mailto://#{@user.email}"
|
||||||
= icon :envelope
|
= icon :envelope
|
||||||
- if @user.personal_profile.github.present?
|
- if @profile.github.present?
|
||||||
= link_to "https://github.com/#{@user.personal_profile.github}"
|
= link_to "https://github.com/#{@profile.github}"
|
||||||
= icon :github
|
= icon :github
|
||||||
- if @user.personal_profile.twitter.present?
|
- if @profile.twitter.present?
|
||||||
= link_to "https://twitter.com/#{@user.personal_profile.twitter}"
|
= link_to "https://twitter.com/#{@profile.twitter}"
|
||||||
= icon :twitter
|
= icon :twitter
|
||||||
|
|
||||||
hr
|
hr
|
||||||
|
|
||||||
h4 = PersonalProfile.human_attribute_name(:biography)
|
h4 = PersonalProfile.human_attribute_name(:biography)
|
||||||
= simple_format @user.personal_profile.biography
|
= simple_format @profile.biography
|
||||||
|
|
||||||
h4 = t :contacts
|
h4 = t :contacts
|
||||||
- if @user.personal_profile.twitter.present?
|
- if @profile.twitter.present?
|
||||||
p #{icon :twitter} @#{@user.personal_profile.twitter}
|
p #{icon :twitter} @#{@profile.twitter}
|
||||||
- if @user.personal_profile.public_email.present?
|
- if @profile.public_email.present?
|
||||||
p #{icon :envelope} #{@user.personal_profile.public_email} (#{t(:public)})
|
p #{icon :envelope} #{@profile.public_email} (#{t(:public)})
|
||||||
p #{icon :envelope} #{@user.email} (#{t(:private)})
|
p #{icon :envelope} #{@user.email} (#{t(:private)})
|
||||||
p #{glyph :phone} #{Phony.format(@user.personal_profile.mobile_phone, format: :international)}
|
p #{glyph :phone} #{Phony.format(@profile.mobile_phone, format: :international)}
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
class AddConferenceIdToPersonalProfiles < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :personal_profiles, :conference_id, :integer
|
||||||
|
add_index :personal_profiles, :conference_id
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,12 @@
|
||||||
|
class Conference < ActiveRecord::Base
|
||||||
|
end
|
||||||
|
|
||||||
|
class PersonalProfile < ActiveRecord::Base
|
||||||
|
end
|
||||||
|
|
||||||
|
class PopulateConferenceIdInPersonalProfiles < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
conference = Conference.first!
|
||||||
|
PersonalProfile.where(conference_id: nil).update_all(conference_id: conference.id)
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue