Skip to content
Draft
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
6 changes: 3 additions & 3 deletions app/controllers/admin/analytics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def index
@most_viewed_tutorials = decorate_with_counts(most_viewed_for_model(Tutorial, time_scope), :view_count)
@most_viewed_projects = decorate_with_counts(most_viewed_for_model(Project, time_scope), :view_count)
@most_viewed_events = decorate_with_counts(most_viewed_for_model(Event, time_scope), :view_count)
@most_viewed_facilitators = decorate_with_counts(most_viewed_for_model(Facilitator, time_scope), :view_count)
@most_viewed_people = decorate_with_counts(most_viewed_for_model(Person, time_scope), :view_count)

@most_printed_workshops = decorate_with_counts(most_printed_for_model(Workshop, time_scope), :print_count)
@most_printed_resources = decorate_with_counts(most_printed_for_model(Resource, time_scope), :print_count)
Expand Down Expand Up @@ -71,8 +71,8 @@ def index
views: view_count_for_model(Project, time_scope),
prints: print_count_for_model(Project, time_scope)
},
facilitators: {
views: view_count_for_model(Facilitator, time_scope)
people: {
views: view_count_for_model(Person, time_scope)
}
}
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/community_news_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def index
per_page = params[:number_of_items_per_page].presence || 12
unfiltered = current_user.super_user? ? CommunityNews.all : CommunityNews.published
filtered = unfiltered.search_by_params(params)
@community_news = filtered&.includes([ :bookmarks, :primary_asset, :author, :project, author: :facilitator ])
@community_news = filtered&.includes([ :bookmarks, :primary_asset, :author, :project, author: :person ])
&.paginate(page: params[:page], per_page: per_page)&.decorate

@count_display = if filtered.count == unfiltered.count
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
class FacilitatorsController < ApplicationController
class PeopleController < ApplicationController
include AhoyTracking
before_action :set_facilitator, only: %i[ show edit update destroy ]
before_action :set_person, only: %i[ show edit update destroy ]

def index
per_page = params[:number_of_items_per_page].presence || 25
facilitators = Facilitator
people = Person
.searchable
.search_by_params(params.to_unsafe_h)
.includes(:user, :avatar_attachment, :sectorable_items, user: [ :avatar_attachment, :projects ]).references(:user)
.order(:first_name, :last_name)
@count_display = facilitators.size
@facilitators = facilitators.paginate(page: params[:page], per_page: per_page)
@count_display = people.size
@people = people.paginate(page: params[:page], per_page: per_page)
end

def show
@facilitator = Facilitator.find(params[:id]).decorate
track_view(@facilitator)
@person = Person.find(params[:id]).decorate
track_view(@person)
end

def new
set_user
@facilitator = @user ? FacilitatorFromUserService.new(user: @user).call : Facilitator.new
@person = @user ? PersonFromUserService.new(user: @user).call : Person.new
set_form_variables
end

Expand All @@ -29,12 +29,12 @@ def edit
end

def create
@facilitator = Facilitator.new(facilitator_params.except(:user_attributes))
@facilitator.user ||= (User.find(params[:facilitator][:user_attributes][:id]) if params[:facilitator][:user_attributes])
@person = Person.new(person_params.except(:user_attributes))
@person.user ||= (User.find(params[:person][:user_attributes][:id]) if params[:person][:user_attributes])

respond_to do |format|
if @facilitator.save
format.html { redirect_to @facilitator, notice: "Facilitator was successfully created." }
if @person.save
format.html { redirect_to @person, notice: "Person was successfully created." }
else
set_form_variables
format.html { render :new, status: :unprocessable_content }
Expand All @@ -44,8 +44,8 @@ def create

def update
respond_to do |format|
if @facilitator.update(facilitator_params)
format.html { redirect_to @facilitator, notice: "Facilitator was successfully updated." }
if @person.update(person_params)
format.html { redirect_to @person, notice: "Person was successfully updated." }
else
set_form_variables
format.html { render :edit, status: :unprocessable_content }
Expand All @@ -54,35 +54,35 @@ def update
end

def destroy
@facilitator.destroy
@person.destroy

respond_to do |format|
format.html { redirect_to facilitators_path, status: :see_other, notice: "Facilitator was successfully destroyed." }
format.html { redirect_to people_path, status: :see_other, notice: "Person was successfully destroyed." }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_facilitator
@facilitator = Facilitator.find(params[:id])
def set_person
@person = Person.find(params[:id])
end

def set_user
if params[:user_id].present?
@user ||= User.find_by(id: params[:user_id])
if @user
@facilitator&.user ||= @user
@user.facilitator ||= @facilitator
@person&.user ||= @user
@user.person ||= @person
end
end
end

def set_form_variables
set_user
# @facilitator.build_user if @facilitator.user.blank? # Build a fresh one if missing
# @person.build_user if @person.user.blank? # Build a fresh one if missing

if @facilitator.user
@facilitator.user.project_users.first || @facilitator.user.project_users.build
if @person.user
@person.user.project_users.first || @person.user.project_users.build
end
projects = if current_user.super_user?
Project.active
Expand All @@ -94,8 +94,8 @@ def set_form_variables


# Only allow a list of trusted parameters through.
def facilitator_params
params.require(:facilitator).permit(
def person_params
params.require(:person).permit(
:avatar,
:first_name, :last_name,
:email, :email_type,
Expand Down Expand Up @@ -157,7 +157,7 @@ def facilitator_params
:_destroy
],
user_attributes: [
:id, :facilitator_id,
:id, :person_id,
:first_name,
:last_name,
:email,
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/project_users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ def destroy
else
flash[:alert] = "Unable to delete project user. Please contact AWBW."
end
redirect_to generate_facilitator_user_path(user)
redirect_to generate_person_user_path(user)
end
end
6 changes: 3 additions & 3 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def show
.references(:windows_type)
.order("workshops.title ASC, windows_types.name ASC")

@facilitators = User.active
@people = User.active
.or(User.where(id: user_ids))
.distinct
.order(:last_name, :first_name)
Expand Down Expand Up @@ -78,13 +78,13 @@ def destroy
# Optional hooks for setting variables for forms or index
def set_form_variables
@project_statuses = ProjectStatus.all
@facilitators_array = Facilitator.includes(:user)
@people_array = Person.includes(:user)
.joins(:user)
.order(:first_name, :last_name)
.map { |f| [ f.name, f.user.id ] }
@project.project_users = @project.project_users
.includes(:project)
.sort_by { |pu| pu.user.facilitator&.name.to_s.downcase }
.sort_by { |pu| pu.user.person&.name.to_s.downcase }
end

def set_index_variables
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/resources_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def new
end

def edit
@resource = Resource.includes(user: :facilitator).find(resource_id_param).decorate
@resource = Resource.includes(user: :person).find(resource_id_param).decorate
set_form_variables

if turbo_frame_request?
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/stories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def story_params
params.require(:story).permit(
:title, :rhino_body, :featured, :published, :public, :public_featued, :youtube_url, :website_url,
:windows_type_id, :project_id, :workshop_id, :external_workshop_title,
:created_by_id, :updated_by_id, :story_idea_id, :spotlighted_facilitator_id
:created_by_id, :updated_by_id, :story_idea_id, :spotlighted_person_id
)
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/taggings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def index
stories: params[:stories_page],
community_news: params[:community_news_page],
events: params[:events_page],
facilitators: params[:facilitators_page],
people: params[:people_page],
projects: params[:projects_page],
quotes: params[:quotes_page]
}
Expand Down
32 changes: 16 additions & 16 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class UsersController < ApplicationController
before_action :set_user, only: [ :show, :edit, :update, :destroy, :generate_facilitator, :toggle_lock_status, :confirm_email, :send_reset_password_instructions ]
before_action :set_user, only: [ :show, :edit, :update, :destroy, :generate_person, :toggle_lock_status, :confirm_email, :send_reset_password_instructions ]

def index
return redirect_to root_path unless current_user.super_user?
Expand Down Expand Up @@ -30,9 +30,9 @@ def create
@user.password ||= SecureRandom.hex(8)
@user.password_confirmation ||= @user.password

# assign facilitator
facilitator_id = params[:facilitator_id].presence || params.dig(:user, :facilitator_id).presence
@user.facilitator = Facilitator.find(facilitator_id) if facilitator_id
# assign person
person_id = params[:person_id].presence || params.dig(:user, :person_id).presence
@user.person = Person.find(person_id) if person_id

if @user.save
# @user.notifications.create(notification_type: 0)
Expand Down Expand Up @@ -87,15 +87,15 @@ def update_password
end
end

def generate_facilitator
if @user.facilitator.present?
redirect_to @user.facilitator and return
def generate_person
if @user.person.present?
redirect_to @user.person and return
else
@facilitator = FacilitatorFromUserService.new(user: @user).call
if @facilitator.save
redirect_to @facilitator, notice: "Facilitator was successfully created for this user." and return
@person = PersonFromUserService.new(user: @user).call
if @person.save
redirect_to @person, notice: "Person was successfully created for this user." and return
else
redirect_to @user, alert: "Unable to create facilitator: #{@facilitator.errors.full_messages.join(", ")}" and return
redirect_to @user, alert: "Unable to create person: #{@person.errors.full_messages.join(", ")}" and return
end
end
end
Expand Down Expand Up @@ -146,13 +146,13 @@ def set_user
@user = User.find(params[:id])
end

def set_facilitator
@facilitator = @user.facilitator ||
(Facilitator.where(id: params[:facilitator_id]).first if params[:facilitator_id].present?)
def set_person
@person = @user.person ||
(Person.where(id: params[:person_id]).first if params[:person_id].present?)
end

def set_form_variables
set_facilitator
set_person
@user.project_users.first || @user.project_users.build
projects = if current_user.super_user?
Project.active
Expand All @@ -176,7 +176,7 @@ def user_params
:address, :address2, :city, :city2, :state, :state2, :zip, :zip2,
:phone, :phone2, :phone3, :birthday, :best_time_to_call, :comment,
:notes, :primary_address, :avatar, :subscribecode,
:agency_id, :facilitator_id, :created_by_id, :updated_by_id,
:agency_id, :person_id, :created_by_id, :updated_by_id,
:confirmed, :inactive, :super_user, :legacy, :legacy_id,
project_users_attributes: [ :id, :project_id, :position, :title, :inactive, :_destroy ]
)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/workshop_logs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def set_index_variables # needs to not be private
@year_options = WorkshopLog.pluck(
Arel.sql("DISTINCT EXTRACT(YEAR FROM COALESCE(date, created_at, NOW()))")
).sort.reverse
@facilitators = User.active.or(User.where(id: @workshop_logs_unpaginated.pluck(:user_id)))
@people = User.active.or(User.where(id: @workshop_logs_unpaginated.pluck(:user_id)))
.includes(:workshop_logs)
.joins(:workshop_logs)
.distinct
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/workshops_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def index

@workshops = search_service.workshops
.includes(:categories, :windows_type, :user, :images, :bookmarks, :age_ranges,
user: [ :facilitator ], primary_asset: [ :file_attachment ])
user: [ :person ], primary_asset: [ :file_attachment ])
.paginate(page: params[:page], per_page: params[:per_page] || 12)

@workshops_count = search_service.workshops.size
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class FacilitatorDecorator < ApplicationDecorator
class PersonDecorator < ApplicationDecorator
def title
"#{first_name} #{last_name}"
end
Expand Down Expand Up @@ -37,9 +37,9 @@ def badges
years = member_since ? (Time.zone.now.year - member_since.year) : 0
badges = []
badges << [ "Legacy Facilitator (10+ years)", "yellow" ] if years >= 10
badges << [ "Seasoned Facilitator (3-10 years)", DomainTheme.bg_class_for(:facilitators) ] if member_since.present? && years >= 3
badges << [ "Seasoned Facilitator (3-10 years)", DomainTheme.bg_class_for(:people) ] if member_since.present? && years >= 3
badges << [ "New Facilitator (<3 years)", "green" ] if member_since.present? && years < 3
badges << [ "Spotlighted Facilitator", "gray" ] if stories_as_spotlighted_facilitator
badges << [ "Featured in Stories", "gray" ] if stories_as_spotlighted_person
badges << [ "Events Attended", DomainTheme.bg_class_for(:events) ] if user && user.events.any?
badges << [ "Workshop Author", DomainTheme.bg_class_for(:workshops) ] if user && user.workshops.any? # indigo
badges << [ "Story Author", DomainTheme.bg_class_for(:stories) ] if user && user.stories_as_creator.any? # pink
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/admin_cards_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module AdminCardsHelper
def system_cards
[
model_card(:banners, icon: "📣"),
model_card(:facilitators, icon: "🧑‍🎨"),
model_card(:people, icon: "🧑‍🎨"),
model_card(:faqs, icon: "❔", title: "FAQs"),
model_card(:community_news, icon: "📰"),
model_card(:events, icon: "📆"),
Expand Down
24 changes: 12 additions & 12 deletions app/helpers/facilitator_helper.rb → app/helpers/person_helper.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
module FacilitatorHelper
def facilitator_profile_button(facilitator, size: 10)
link_to facilitator_path(facilitator),
module PersonHelper
def person_profile_button(person, size: 10)
link_to person_path(person),
class: "group inline-flex items-center gap-2 px-4 py-2
border border-primary text-primary rounded-lg
hover:bg-primary hover:text-white transition-colors duration-200
font-medium shadow-sm leading-none whitespace-nowrap" do
facilitator = facilitator.decorate
person = person.decorate

# --- Avatar ---
avatar = if facilitator.avatar.present?
image_tag url_for(facilitator.avatar),
avatar = if person.avatar.present?
image_tag url_for(person.avatar),
class: "w-10 h-10 rounded-full object-cover border border-gray-300 shadow-sm flex-shrink-0"
elsif facilitator.user&.avatar.present?
image_tag url_for(facilitator.user.avatar),
elsif person.user&.avatar.present?
image_tag url_for(person.user.avatar),
class: "w-10 h-10 rounded-full object-cover border border-gray-300 shadow-sm flex-shrink-0"
else
image_tag "missing.png",
Expand All @@ -22,16 +22,16 @@ def facilitator_profile_button(facilitator, size: 10)
# --- Name: stays one line & turns white on hover ---
name = content_tag(
:span,
facilitator.name.to_s.truncate(21),
title: facilitator.name.to_s,
person.name.to_s.truncate(21),
title: person.name.to_s,
class: "font-semibold text-gray-900 group-hover:text-white"
)

# --- Pronouns ---
pronouns = if facilitator.pronouns_display.present?
pronouns = if person.pronouns_display.present?
content_tag(
:span,
facilitator.pronouns_display,
person.pronouns_display,
class: "text-xs text-gray-500 italic group-hover:text-white"
)
end
Expand Down
4 changes: 2 additions & 2 deletions app/mailers/notification_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def event_registration_confirmation_fyi(notification)
@event_registration = notification.noticeable
@event = @event_registration.event.decorate
@user = @event_registration.registrant
@facilitator = @user.facilitator
@person = @user.person
@notification_type = "Event registration"

# Send email to the admin
Expand Down Expand Up @@ -58,7 +58,7 @@ def report_submitted_fyi(notification)

def reset_password_fyi(notification)
@user = notification.noticeable
@facilitator = @user.facilitator
@person = @user.person
@notification_type = "Password reset"

# Send email to the admin
Expand Down
Loading