From e9995cbc0b05a6afb3a8b46db6f3cc5db4ba31fd Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Sat, 8 Oct 2016 22:40:56 +0300 Subject: [PATCH] Fix personal profile creation --- app/helpers/events_helper.rb | 16 +++++++++++----- app/models/conference.rb | 5 +---- app/models/event.rb | 6 ++++++ app/views/management/events/_event.slim | 6 +++--- config/locales/bg.yml | 2 ++ 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb index 45f9d7e..5d717b9 100644 --- a/app/helpers/events_helper.rb +++ b/app/helpers/events_helper.rb @@ -1,9 +1,15 @@ module EventsHelper - def participant_names_or_emails(event) + def links_to_event_participants_for(event) event.participants.map do |participant| - participant.try(:personal_profile, current_conference).try(:name) || - participant.personal_profiles.last.try(:name) || - participant.email - end + if participant.personal_profile(event.conference).present? + profile = participant.personal_profile(event.conference) + link_to icon(:user, profile.name), management_conference_personal_profile_path(profile, conference_id: event.conference.id) + else + link_to icon('user-plus', participant.email), + new_management_conference_personal_profile_path(conference_id: event.conference.id, + user_id: participant.id), + title: t('.create_profile'), class: 'bg-danger' + end + end.join(', ').html_safe end end diff --git a/app/models/conference.rb b/app/models/conference.rb index 3d816f6..fb37fa9 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -18,6 +18,7 @@ class Conference < ActiveRecord::Base has_many :volunteers has_one :call_for_participation, dependent: :destroy has_many :participants, class_name: 'User', through: :events + has_many :participant_profiles, class_name: 'PersonalProfile' has_many :slots, through: :halls accepts_nested_attributes_for :tracks, :halls, :event_types, :volunteer_teams, @@ -25,10 +26,6 @@ class Conference < ActiveRecord::Base after_create :create_call_for_participation - def participants - events.where(conference_id: id).map(&:user) - end - def submissions_grouped_by_day submissions = events.group('date(events.created_at)').select('date(events.created_at) as created_at, count(events.id) as number') submissions.group_by { |s| s.created_at.to_date } diff --git a/app/models/event.rb b/app/models/event.rb index 35e2f61..3ea1076 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -26,6 +26,12 @@ class Event < ActiveRecord::Base delegate :status, to: :proposition + def all_participants_have_profiles? + participants.all? do |participant| + participant.personal_profile(conference).present? + end + end + def proposer_profile proposer.personal_profile(conference) end diff --git a/app/views/management/events/_event.slim b/app/views/management/events/_event.slim index 643c197..2303a2e 100644 --- a/app/views/management/events/_event.slim +++ b/app/views/management/events/_event.slim @@ -1,4 +1,4 @@ -tr += content_tag :tr, class: event.all_participants_have_profiles? ? nil : 'warning' td dl.dl-horizontal dt = Event.human_attribute_name :title @@ -7,7 +7,7 @@ tr dt = Event.human_attribute_name :subtitle dd = event.subtitle dt.visible-sm.visible-xs = Event.human_attribute_name :participants - dd.visible-sm.visible-xs = participant_names_or_emails(event).join(', ') + dd.visible-sm.visible-xs = links_to_event_participants_for(event) dt = EventType.model_name.human.mb_chars.titleize dd = event.event_type.name dt = Event.human_attribute_name :track @@ -16,7 +16,7 @@ tr dd = t("locales.#{event.language}") td.visible-md.visible-lg.visible-xl - = participant_names_or_emails(event).join(', ') + = links_to_event_participants_for(event) td.action .dropdown button class="btn btn-sm dropdown-toggle btn-#{proposition_status_class(event.status)}" type="button" data-toggle="dropdown" title="#{t "status.#{event.status}"}" diff --git a/config/locales/bg.yml b/config/locales/bg.yml index a57ff5f..dc4ed06 100644 --- a/config/locales/bg.yml +++ b/config/locales/bg.yml @@ -6,6 +6,8 @@ bg: events: index: all: "Всички" + event: + create_profile: "Създай профил" no_records: no_records_found: 'Не бяха открити записи, които да отговарят на изискванията' abstract: "Резюме"