diff --git a/TODO b/TODO index f6f8b4d..ed078e9 100644 --- a/TODO +++ b/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? diff --git a/app/controllers/management/users_controller.rb b/app/controllers/management/users_controller.rb index 428b28f..653a688 100644 --- a/app/controllers/management/users_controller.rb +++ b/app/controllers/management/users_controller.rb @@ -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 diff --git a/app/models/conference.rb b/app/models/conference.rb index d45f920..af860bd 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -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 diff --git a/app/models/personal_profile.rb b/app/models/personal_profile.rb index bce6222..afebe25 100644 --- a/app/models/personal_profile.rb +++ b/app/models/personal_profile.rb @@ -1,5 +1,6 @@ class PersonalProfile < ActiveRecord::Base belongs_to :user + belongs_to :conference validates :first_name, presence: true validates :last_name, presence: true diff --git a/app/models/user.rb b/app/models/user.rb index 6c4452f..613b481 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/management/users/edit.html.slim b/app/views/management/users/edit.html.slim index 238c336..79abe42 100644 --- a/app/views/management/users/edit.html.slim +++ b/app/views/management/users/edit.html.slim @@ -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 diff --git a/app/views/management/users/index.html.slim b/app/views/management/users/index.html.slim index 228b1df..3229a06 100644 --- a/app/views/management/users/index.html.slim +++ b/app/views/management/users/index.html.slim @@ -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? diff --git a/app/views/management/users/show.html.slim b/app/views/management/users/show.html.slim index 394a77d..0ec415e 100644 --- a/app/views/management/users/show.html.slim +++ b/app/views/management/users/show.html.slim @@ -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)} diff --git a/db/migrate/20150530182514_add_conference_id_to_personal_profiles.rb b/db/migrate/20150530182514_add_conference_id_to_personal_profiles.rb new file mode 100644 index 0000000..50ca38a --- /dev/null +++ b/db/migrate/20150530182514_add_conference_id_to_personal_profiles.rb @@ -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 diff --git a/db/migrate/20150530182857_populate_conference_id_in_personal_profiles.rb b/db/migrate/20150530182857_populate_conference_id_in_personal_profiles.rb new file mode 100644 index 0000000..ff151ea --- /dev/null +++ b/db/migrate/20150530182857_populate_conference_id_in_personal_profiles.rb @@ -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