diff --git a/lib/mv_web/live/member_live/index.ex b/lib/mv_web/live/member_live/index.ex index 85ee4fb..1f8acb5 100644 --- a/lib/mv_web/live/member_live/index.ex +++ b/lib/mv_web/live/member_live/index.ex @@ -60,6 +60,8 @@ defmodule MvWeb.MemberLive.Index do |> assign_new(:sort_order, fn -> :asc end) |> assign(:selected_members, []) |> assign(:custom_fields_visible, custom_fields_visible) + |> assign(:member_field_configurations, get_member_field_configurations()) + |> assign(:member_fields_visible, get_visible_member_fields()) # We call handle params to use the query from the URL {:ok, socket} @@ -733,4 +735,39 @@ defmodule MvWeb.MemberLive.Index do nil end end + + # Gets the configuration for all member fields with their show_in_overview values. + # + # Reads the visibility configuration from Settings and returns a map with all member fields + # and their show_in_overview values (true or false). Fields not configured in settings + # default to true. + # + # Returns a map: %{field_name => show_in_overview} + # + # This can be used for: + # - Rendering the overview (filtering visible fields) + # - UI configuration dropdowns (showing all fields with their current state) + # - Dynamic field management + # + # Fields are read from the global Constants module. + defp get_member_field_configurations do + # Get all eligible fields from the global constants + all_fields = Mv.Constants.member_fields() + + Enum.reduce(all_fields, %{}, fn field, acc -> + show_in_overview = Mv.Membership.Member.show_in_overview?(field) + Map.put(acc, field, show_in_overview) + end) + end + + # Gets the list of member fields that should be visible in the overview. + # + # Filters the member field configurations to return only fields with show_in_overview: true. + # + # Returns a list of atoms representing visible member field names. + defp get_visible_member_fields do + get_member_field_configurations() + |> Enum.filter(fn {_field, show_in_overview} -> show_in_overview end) + |> Enum.map(fn {field, _show_in_overview} -> field end) + end end diff --git a/lib/mv_web/live/member_live/index.html.heex b/lib/mv_web/live/member_live/index.html.heex index 67fa804..0fa9f05 100644 --- a/lib/mv_web/live/member_live/index.html.heex +++ b/lib/mv_web/live/member_live/index.html.heex @@ -69,9 +69,7 @@ > {member.first_name} {member.last_name} - <:col - :let={member} - label={ + <:col :if={:email in @member_fields_visible} :let={member} label={ ~H""" <.live_component module={MvWeb.Components.SortHeaderComponent} @@ -82,13 +80,10 @@ sort_order={@sort_order} /> """ - } - > + }> {member.email} - <:col - :let={member} - label={ + <:col :if={:street in @member_fields_visible} :let={member} label={ ~H""" <.live_component module={MvWeb.Components.SortHeaderComponent} @@ -99,13 +94,10 @@ sort_order={@sort_order} /> """ - } - > + }> {member.street} - <:col - :let={member} - label={ + <:col :if={:house_number in @member_fields_visible} :let={member} label={ ~H""" <.live_component module={MvWeb.Components.SortHeaderComponent} @@ -116,13 +108,10 @@ sort_order={@sort_order} /> """ - } - > + }> {member.house_number} - <:col - :let={member} - label={ + <:col :if={:postal_code in @member_fields_visible} :let={member} label={ ~H""" <.live_component module={MvWeb.Components.SortHeaderComponent} @@ -133,13 +122,10 @@ sort_order={@sort_order} /> """ - } - > + }> {member.postal_code} - <:col - :let={member} - label={ + <:col :if={:city in @member_fields_visible} :let={member} label={ ~H""" <.live_component module={MvWeb.Components.SortHeaderComponent} @@ -150,13 +136,10 @@ sort_order={@sort_order} /> """ - } - > + }> {member.city} - <:col - :let={member} - label={ + <:col :if={:phone_number in @member_fields_visible} :let={member} label={ ~H""" <.live_component module={MvWeb.Components.SortHeaderComponent} @@ -167,13 +150,10 @@ sort_order={@sort_order} /> """ - } - > + }> {member.phone_number} - <:col - :let={member} - label={ + <:col :if={:join_date in @member_fields_visible} :let={member} label={ ~H""" <.live_component module={MvWeb.Components.SortHeaderComponent} @@ -184,8 +164,7 @@ sort_order={@sort_order} /> """ - } - > + }> {member.join_date} <:action :let={member}>