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:
|
||||
- # edit profile: image upload and stuff
|
||||
- show profile
|
||||
- # show profile
|
||||
- Edit profiles instead
|
||||
|
||||
- Home-area user CRUD
|
||||
|
||||
Notes:
|
||||
- .row > .col-lg-12 -> put that outside of the "yield"?
|
||||
- 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
|
||||
class UsersController < ManagementController
|
||||
def index
|
||||
@users = User.includes(:personal_profile)
|
||||
@profiles = current_conference.participant_profiles
|
||||
end
|
||||
|
||||
def toggle_admin
|
||||
|
@ -12,12 +13,12 @@ module Management
|
|||
|
||||
def show
|
||||
@user = find_user
|
||||
@profile = @user.personal_profile
|
||||
@profile = @user.personal_profile(current_conference)
|
||||
end
|
||||
|
||||
def edit
|
||||
@user = find_user
|
||||
@user.personal_profile if @user.personal_profile.blank?
|
||||
@profile = @user.personal_profile(current_conference)
|
||||
end
|
||||
|
||||
def update
|
||||
|
|
|
@ -12,6 +12,7 @@ class Conference < ActiveRecord::Base
|
|||
has_many :halls
|
||||
has_many :events, through: :tracks
|
||||
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
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
class PersonalProfile < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
belongs_to :conference
|
||||
|
||||
validates :first_name, presence: true
|
||||
validates :last_name, presence: true
|
||||
|
|
|
@ -4,28 +4,20 @@ class User < ActiveRecord::Base
|
|||
devise :database_authenticatable, :registerable, :confirmable,
|
||||
:recoverable, :rememberable, :trackable, :validatable
|
||||
|
||||
has_one :personal_profile
|
||||
has_many :personal_profiles, dependent: :destroy
|
||||
has_many :lectures
|
||||
has_many :workshops
|
||||
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 }
|
||||
|
||||
def name
|
||||
personal_profile.try(:name) || email
|
||||
def personal_profile(conference)
|
||||
personal_profiles.find_by!(conference_id: conference.id)
|
||||
end
|
||||
|
||||
def toggle_admin!
|
||||
update admin: !admin
|
||||
end
|
||||
|
||||
def profile_picture
|
||||
if personal_profile.present?
|
||||
personal_profile.picture
|
||||
else
|
||||
PictureUploader.new
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
- content_for :title
|
||||
=> t 'actions.edit.title', model: User.model_name.human
|
||||
= @user.name
|
||||
= @profile.name
|
||||
|
||||
.row
|
||||
.col-lg-12
|
||||
|
@ -18,12 +18,11 @@
|
|||
hr
|
||||
.row
|
||||
.col-lg-12
|
||||
- personal_profile = @user.personal_profile
|
||||
|
||||
-# TODO we have many personal_profiles now
|
||||
= f.simple_fields_for :personal_profile do |ff|
|
||||
- if personal_profile.picture.present?
|
||||
- if @profile.picture.present?
|
||||
.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
|
||||
|
||||
|
|
|
@ -12,10 +12,12 @@
|
|||
th = User.human_attribute_name :admin
|
||||
th.actions
|
||||
tbody
|
||||
- @users.each do |user|
|
||||
- @profiles.each do |profile|
|
||||
- user = profile.user
|
||||
|
||||
tr
|
||||
td= image_tag(user.profile_picture.thumb.url)
|
||||
td= user.name
|
||||
td= image_tag(profile.picture.thumb.url)
|
||||
td= profile.name
|
||||
td.boolean-col
|
||||
= link_to toggle_admin_management_user_path(user), method: :put do
|
||||
- if user.admin?
|
||||
|
|
|
@ -1,39 +1,39 @@
|
|||
- content_for :title
|
||||
= @user.name
|
||||
= @profile.name
|
||||
|
||||
.row
|
||||
.speaker-profile
|
||||
.panel.panel-default
|
||||
.panel-heading
|
||||
h1.panel-title
|
||||
= @user.name
|
||||
= @profile.name
|
||||
= link_to icon(:edit), edit_management_user_path(@user), class: 'btn btn-xs btn-danger pull-right'
|
||||
.panel-body
|
||||
.center
|
||||
= image_tag @user.personal_profile.picture.medium.url, class: "profile-image"
|
||||
- if @user.personal_profile.organisation.present?
|
||||
= image_tag @profile.picture.medium.url, class: "profile-image"
|
||||
- if @profile.organisation.present?
|
||||
div
|
||||
=> icon :briefcase
|
||||
= @user.personal_profile.organisation
|
||||
= @profile.organisation
|
||||
div.social
|
||||
= link_to "mailto://#{@user.email}"
|
||||
= icon :envelope
|
||||
- if @user.personal_profile.github.present?
|
||||
= link_to "https://github.com/#{@user.personal_profile.github}"
|
||||
- if @profile.github.present?
|
||||
= link_to "https://github.com/#{@profile.github}"
|
||||
= icon :github
|
||||
- if @user.personal_profile.twitter.present?
|
||||
= link_to "https://twitter.com/#{@user.personal_profile.twitter}"
|
||||
- if @profile.twitter.present?
|
||||
= link_to "https://twitter.com/#{@profile.twitter}"
|
||||
= icon :twitter
|
||||
|
||||
hr
|
||||
|
||||
h4 = PersonalProfile.human_attribute_name(:biography)
|
||||
= simple_format @user.personal_profile.biography
|
||||
= simple_format @profile.biography
|
||||
|
||||
h4 = t :contacts
|
||||
- if @user.personal_profile.twitter.present?
|
||||
p #{icon :twitter} @#{@user.personal_profile.twitter}
|
||||
- if @user.personal_profile.public_email.present?
|
||||
p #{icon :envelope} #{@user.personal_profile.public_email} (#{t(:public)})
|
||||
- if @profile.twitter.present?
|
||||
p #{icon :twitter} @#{@profile.twitter}
|
||||
- if @profile.public_email.present?
|
||||
p #{icon :envelope} #{@profile.public_email} (#{t(:public)})
|
||||
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