From d777bb98540783870471e6bb2c165cc264b35d47 Mon Sep 17 00:00:00 2001 From: Tomas Goncalves <43731728+Runner-dev@users.noreply.github.com> Date: Mon, 7 Oct 2024 19:16:08 -0400 Subject: [PATCH 1/5] feat: Add profile option to always view full names in event view Created migration to add :prefers_full_name to member. Added the option to edit it. Made it change the way names are displayed by event_role. --- app/helpers/events_helper.rb | 2 +- app/models/event_role.rb | 6 +++++- app/views/members/_form.html.erb | 7 ++++++- app/views/members/show.html.erb | 6 ++++++ .../20241007223900_add_profile_option_view_full_name.rb | 6 ++++++ db/schema.rb | 3 ++- 6 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20241007223900_add_profile_option_view_full_name.rb diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb index 0331cb2d..bf8f2c28 100644 --- a/app/helpers/events_helper.rb +++ b/app/helpers/events_helper.rb @@ -150,7 +150,7 @@ def show_run_position(er, hover) return link_to("you?", new_application_url(er.event, event_role_id: er.id, format: :js), :remote => true) unless hover "you?" if hover elsif !hover and current_member - er.assigned_to use_display_name: true + er.assigned_to use_display_name: true, use_both_names: current_member.prefers_full_name else er.assigned_to end diff --git a/app/models/event_role.rb b/app/models/event_role.rb index 9d8e039a..ae9ed96b 100644 --- a/app/models/event_role.rb +++ b/app/models/event_role.rb @@ -115,7 +115,11 @@ def to_s def assigned_to(options = {}) if assigned? if options[:use_display_name] - member.display_name + if options[:use_both_names] + "#{member.display_name} (#{member.fullname})" + else + member.display_name + end else member.fullname end diff --git a/app/views/members/_form.html.erb b/app/views/members/_form.html.erb index 08de230a..8e7bafec 100755 --- a/app/views/members/_form.html.erb +++ b/app/views/members/_form.html.erb @@ -98,11 +98,16 @@
<%= f.text_field :interests, class: "wide-input" %>
+
+
<%= f.label :prefers_full_name, "Prefer full name:" %>
+
<%= f.check_box :prefers_full_name %>
+
+
Notifications - +
<%= f.check_box :receives_comment_emails %>
<%= f.label :receives_comment_emails, "Email me when comments are posted on events I have run positions for" %>
diff --git a/app/views/members/show.html.erb b/app/views/members/show.html.erb index a41f256c..d430d936 100755 --- a/app/views/members/show.html.erb +++ b/app/views/members/show.html.erb @@ -111,6 +111,12 @@ Interests <%= @member.interests %> + <% if @member == current_member %> + + Prefers Full Name + <%= @member.prefers_full_name ? "YES" : "NO" %> + + <% end %> <% if can? :read, Timecard %> diff --git a/db/migrate/20241007223900_add_profile_option_view_full_name.rb b/db/migrate/20241007223900_add_profile_option_view_full_name.rb new file mode 100644 index 00000000..51ccefe2 --- /dev/null +++ b/db/migrate/20241007223900_add_profile_option_view_full_name.rb @@ -0,0 +1,6 @@ +class AddProfileOptionViewFullName < ActiveRecord::Migration[6.1] + def change + # Change members table; Add column prefers_full_name + add_column :members, :prefers_full_name, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 4f300bfb..c5c31508 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2023_08_01_123836) do +ActiveRecord::Schema.define(version: 2024_10_07_223900) do create_table "accounts", charset: "utf8mb4", collation: "utf8mb4_bin", force: :cascade do |t| t.string "name", limit: 255, null: false @@ -324,6 +324,7 @@ t.string "grad_year" t.string "interests" t.string "officer_position" + t.boolean "prefers_full_name", default: false t.index ["email"], name: "members_kerbid_index" end From a4b84d8d49df219060f3501caa72262ac0fc53c6 Mon Sep 17 00:00:00 2001 From: Tomas Goncalves <43731728+Runner-dev@users.noreply.github.com> Date: Mon, 7 Oct 2024 23:40:50 -0400 Subject: [PATCH 2/5] Changed wording to show real names of members --- app/views/members/_form.html.erb | 2 +- app/views/members/show.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/members/_form.html.erb b/app/views/members/_form.html.erb index 8e7bafec..e7ae7745 100755 --- a/app/views/members/_form.html.erb +++ b/app/views/members/_form.html.erb @@ -99,7 +99,7 @@
-
<%= f.label :prefers_full_name, "Prefer full name:" %>
+
<%= f.label :prefers_full_name, "Show full names of members:" %>
<%= f.check_box :prefers_full_name %>
diff --git a/app/views/members/show.html.erb b/app/views/members/show.html.erb index d430d936..90261a08 100755 --- a/app/views/members/show.html.erb +++ b/app/views/members/show.html.erb @@ -113,7 +113,7 @@ <% if @member == current_member %> - Prefers Full Name + Show real names of members <%= @member.prefers_full_name ? "YES" : "NO" %> <% end %> From 2f7311a9d2563d472b8747f8317563abafc727e3 Mon Sep 17 00:00:00 2001 From: Tomas Goncalves <43731728+Runner-dev@users.noreply.github.com> Date: Mon, 7 Oct 2024 23:42:26 -0400 Subject: [PATCH 3/5] Save option on profile updates. Make functions more elegant --- app/controllers/members_controller.rb | 2 +- app/helpers/events_helper.rb | 11 ++++++++++- app/models/event_role.rb | 16 ++++++++-------- app/views/events/_event_role_fields.html.erb | 6 +++--- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 7ff8761f..995a75be 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -239,7 +239,7 @@ def member_params params.require(:member).permit( :password, :password_confirmation, :email, :namefirst, :namelast, :namenick, :title, :callsign, :shirt_size, :phone, :payrate, :role, :tracker_dev, :receives_comment_emails, - :on_payroll, :pronouns, :favorite_entropy_drink, :major, :grad_year, :interests, :officer_position, + :on_payroll, :pronouns, :favorite_entropy_drink, :prefers_full_name, :major, :grad_year, :interests, :officer_position, :super_tics_attributes => [:id, :_destroy, :day] ) end diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb index bf8f2c28..ca7efd2a 100644 --- a/app/helpers/events_helper.rb +++ b/app/helpers/events_helper.rb @@ -149,8 +149,10 @@ def show_run_position(er, hover) elsif er.appliable and not er.assigned? and can? :create, er.applications.build(member: current_member) return link_to("you?", new_application_url(er.event, event_role_id: er.id, format: :js), :remote => true) unless hover "you?" if hover + elsif !hover and current_member and current_member.prefers_full_name + return er.assigned_to :both_names elsif !hover and current_member - er.assigned_to use_display_name: true, use_both_names: current_member.prefers_full_name + return er.assigned_to else er.assigned_to end @@ -166,4 +168,11 @@ def weeks_from_now(weeks) end end + def run_position_name_preference(member) + if member.prefers_full_name + return :both_names + else + return :display_name + end + end end diff --git a/app/models/event_role.rb b/app/models/event_role.rb index ae9ed96b..8efee2f4 100644 --- a/app/models/event_role.rb +++ b/app/models/event_role.rb @@ -112,16 +112,16 @@ def to_s role + ": " + assigned_to end - def assigned_to(options = {}) + def assigned_to(mode = :full_name) + # Logger if assigned? - if options[:use_display_name] - if options[:use_both_names] - "#{member.display_name} (#{member.fullname})" - else - member.display_name - end - else + case mode + when :full_name member.fullname + when :display_name + member.display_name + when :both_names + "#{member.display_name} (#{member.fullname})" end else "(unassigned)" diff --git a/app/views/events/_event_role_fields.html.erb b/app/views/events/_event_role_fields.html.erb index 71fb6a50..84d50242 100644 --- a/app/views/events/_event_role_fields.html.erb +++ b/app/views/events/_event_role_fields.html.erb @@ -11,11 +11,11 @@ <%= link_to_remove_fields image_tag("cross.png"), f, f.object.new_record? %> <% elsif f.object.member == current_member %> <%= f.object.role %> - <%= f.object.assigned_to use_display_name: true %> + <%= f.object.assigned_to(run_position_name_preference(current_member)) %> <%= link_to_remove_fields image_tag("cross.png"), f %> <% else %> <%= f.object.role %> - <%= f.object.assigned_to use_display_name: true %> + <%= f.object.assigned_to(run_position_name_preference(current_member)) %> <% end %> - \ No newline at end of file + From 250c88fa94adf2cc73a84e183493a1efd5542fb8 Mon Sep 17 00:00:00 2001 From: Tomas Goncalves <43731728+Runner-dev@users.noreply.github.com> Date: Mon, 7 Oct 2024 23:49:47 -0400 Subject: [PATCH 4/5] Re add display name after refactor (missed this) --- app/helpers/events_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb index ca7efd2a..c32e1f74 100644 --- a/app/helpers/events_helper.rb +++ b/app/helpers/events_helper.rb @@ -152,7 +152,7 @@ def show_run_position(er, hover) elsif !hover and current_member and current_member.prefers_full_name return er.assigned_to :both_names elsif !hover and current_member - return er.assigned_to + return er.assigned_to :display_name else er.assigned_to end From 686930fd888b15618839c197b840800807701d30 Mon Sep 17 00:00:00 2001 From: Tomas Goncalves <43731728+Runner-dev@users.noreply.github.com> Date: Tue, 8 Oct 2024 14:58:28 -0400 Subject: [PATCH 5/5] Prevent errors when getting run position name preference for unathenticated users. --- app/helpers/events_helper.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb index c32e1f74..e3de07d8 100644 --- a/app/helpers/events_helper.rb +++ b/app/helpers/events_helper.rb @@ -169,7 +169,9 @@ def weeks_from_now(weeks) end def run_position_name_preference(member) - if member.prefers_full_name + if !member + return :full_name + elsif member.prefers_full_name return :both_names else return :display_name