From 7a33d2c2253ef8409b8b0229647265ff94f0606a Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 18 Nov 2024 13:22:14 +0100 Subject: [PATCH] boundary ux --- lib/web/boundaries_live_handler.ex | 2 +- lib/web/components/acls/acl_live.ex | 3 +- lib/web/components/acls/acl_live.sface | 183 +++++++++--------- .../display/yes_maybe_false_live.ex | 3 +- .../display/yes_maybe_false_live.sface | 77 ++++---- .../roles/roles_dropdown_live.sface | 8 +- .../roles/tabled_roles/tabled_roles_live.ex | 107 +++++----- .../tabled_roles/tabled_roles_live.sface | 24 ++- .../set/boundaries_general_access_live.sface | 2 +- .../components/set/boundary_items_live.sface | 2 +- .../set/set_boundaries_button_live.sface | 6 +- .../components/set/set_boundaries_live.sface | 2 +- 12 files changed, 224 insertions(+), 195 deletions(-) diff --git a/lib/web/boundaries_live_handler.ex b/lib/web/boundaries_live_handler.ex index 60827de..fec1892 100644 --- a/lib/web/boundaries_live_handler.ex +++ b/lib/web/boundaries_live_handler.ex @@ -753,7 +753,7 @@ defmodule Bonfire.Boundaries.LiveHandler do (circles || []) |> Enum.map(fn {circle, roles} -> - Enum.map(roles, &{e(known_circles, id(circle), nil) || circle, &1}) + Enum.map(roles, &{ed(known_circles, id(circle), nil) || circle, &1}) end) |> List.flatten() |> debug("computed") diff --git a/lib/web/components/acls/acl_live.ex b/lib/web/components/acls/acl_live.ex index 87f55ce..300a889 100644 --- a/lib/web/components/acls/acl_live.ex +++ b/lib/web/components/acls/acl_live.ex @@ -218,8 +218,7 @@ defmodule Bonfire.UI.Boundaries.Web.AclLive do end end - def handle_event("edit_grant_role", %{"to_circles" => subjects} = _attrs, socket) do - # debug(attrs) + def handle_event("edit_grant_role", %{"to_circles" => subjects} = attrs, socket) do current_user = current_user_required!(socket) acl = e(assigns(socket), :acl, nil) scope = e(assigns(socket), :scope, nil) diff --git a/lib/web/components/acls/acl_live.sface b/lib/web/components/acls/acl_live.sface index d6b2f67..9bdf77a 100644 --- a/lib/web/components/acls/acl_live.sface +++ b/lib/web/components/acls/acl_live.sface @@ -21,7 +21,10 @@ {#match nil}
-
+
{e(@acl, :extra_info, :summary, "No description provided for this boundary preset.")} @@ -76,87 +79,102 @@
  • - {#if e(subject, :profile, :id, nil)} - - {#else} -
    - - <#Icon iconify="pajamas:group" class="inline-block w-5 h-5 text-base-content" /> - -
    -
    {LiveHandler.subject_name(subject)}
    - -
    -
    - {/if} - -
    - {#if !@read_only} - debug("the role")} - extra_roles={[{:custom, l("Custom")}]} - no_actions +
    + {#if e(subject, :profile, :id, nil)} + - - -
    - {l("Are you sure to remove %{subject_name} from '%{boundary_name}' boundary preset?", - subject_name: LiveHandler.subject_name(subject), - boundary_name: e(@acl, :named, :name, nil) || e(@acl, :stereotyped, :named, :name, nil) - )} -
    - - <:open_btn> - - -
    {#else} - - {/if} + {#if !@read_only} + + +
    + {l("Are you sure to remove %{subject_name} from '%{boundary_name}' boundary preset?", + subject_name: LiveHandler.subject_name(subject), + boundary_name: e(@acl, :named, :name, nil) || e(@acl, :stereotyped, :named, :name, nil) + )} +
    + + <:open_btn> + + +
    +
    + {/if} +
    +
    +
    +
    {l("Assign a role to %{subject_name}", subject_name: LiveHandler.subject_name(subject))}
    + debug("the role")} + roles={Bonfire.Boundaries.Roles.roles_for_dropdown(@usage, scope: @scope, context: @__context__)} + /> +
@@ -164,21 +182,6 @@ {/if}
- {/if}
diff --git a/lib/web/components/display/yes_maybe_false_live.ex b/lib/web/components/display/yes_maybe_false_live.ex index dbf87f1..9b94981 100644 --- a/lib/web/components/display/yes_maybe_false_live.ex +++ b/lib/web/components/display/yes_maybe_false_live.ex @@ -3,7 +3,8 @@ defmodule Bonfire.UI.Boundaries.Web.YesMaybeFalseLive do prop id, :any, default: nil prop field_name, :any, default: nil - + prop role, :any, default: nil + prop verb, :any, default: nil prop value, :any, default: nil prop read_only, :boolean, default: false prop event_target, :any, default: nil diff --git a/lib/web/components/display/yes_maybe_false_live.sface b/lib/web/components/display/yes_maybe_false_live.sface index 2f1c823..157d130 100644 --- a/lib/web/components/display/yes_maybe_false_live.sface +++ b/lib/web/components/display/yes_maybe_false_live.sface @@ -14,55 +14,54 @@ <#Icon solid="Minus" class="w-4 h-4 text-gray-400" /> {/case} {#else} -
- - {!-- +
+ --} + <#Icon solid="X" class="w-4 h-4" /> + +
+
{/if} \ No newline at end of file diff --git a/lib/web/components/roles/roles_dropdown_live.sface b/lib/web/components/roles/roles_dropdown_live.sface index 6a8eb27..1426b89 100644 --- a/lib/web/components/roles/roles_dropdown_live.sface +++ b/lib/web/components/roles/roles_dropdown_live.sface @@ -1,4 +1,8 @@ - + >{Recase.to_title(to_string(id))} diff --git a/lib/web/components/roles/tabled_roles/tabled_roles_live.ex b/lib/web/components/roles/tabled_roles/tabled_roles_live.ex index 04606e0..4413067 100644 --- a/lib/web/components/roles/tabled_roles/tabled_roles_live.ex +++ b/lib/web/components/roles/tabled_roles/tabled_roles_live.ex @@ -4,6 +4,12 @@ defmodule Bonfire.UI.Boundaries.Web.TabledRolesLive do prop scope, :any, default: nil prop read_only, :boolean, default: false + prop selectable, :boolean, default: false + prop role, :any, default: nil + prop field, :atom, default: :to_circles + prop circle_id, :string, default: nil + prop roles, :map, default: nil + prop event_target, :any, default: nil #  FIXME: this should be in config where the verbs are defined @verb_order [ @@ -40,14 +46,26 @@ defmodule Bonfire.UI.Boundaries.Web.TabledRolesLive do (e(assigns, :scope, nil) || e(assigns(socket), :scope, nil)) |> debug("role_scope") + roles_with_verbs = + e( + assigns, + :roles, + Bonfire.Boundaries.Roles.role_verbs(:all, + one_scope_only: true, + scope: scope, + current_user: current_user(socket) + ) + ) + |> get_roles_with_verbs(scope) + |> debug("roles_with_verbs") + {:ok, socket |> assign(assigns) |> assign( scope: scope, verb_order: verb_order(), - roles_with_verbs: - get_roles_with_verbs(scope, current_user(socket)) |> debug("roles_with_verbs") + roles_with_verbs: roles_with_verbs )} end @@ -79,14 +97,8 @@ defmodule Bonfire.UI.Boundaries.Web.TabledRolesLive do sorted according to @verb_order. Returns a list of tuples: [{role, verbs_with_statuses}]. """ - def get_roles_with_verbs(scope, current_user) do - Bonfire.Boundaries.Roles.role_verbs(:all, - one_scope_only: true, - scope: scope, - current_user: current_user - ) - |> debug("got") - # |> List.wrap() + def get_roles_with_verbs(roles, scope) do + roles |> Enum.map(fn {role_name, role_data} when is_map(role_data) -> can_verbs = Map.get(role_data, :can_verbs, []) @@ -102,50 +114,45 @@ defmodule Bonfire.UI.Boundaries.Web.TabledRolesLive do end) end - def handle_event("edit_verb_value", %{"role" => roles} = attrs, socket) do + def handle_event( + "edit_verb_value", + %{"role" => role, "verb" => verb, "status" => value} = attrs, + socket + ) do debug(attrs) current_user = current_user_required!(socket) scope = e(assigns(socket), :scope, nil) - # verb_value = List.first(Map.values(roles)) - - with [ok: edited] <- - Enum.flat_map(roles, fn {role_name, verb_value} -> - Enum.flat_map(verb_value, fn {verb, value} -> - case Types.maybe_to_atom!(verb) do - nil -> - [{:error, "Invalid verb"}] - - verb -> - debug(scope, "edit #{role_name} -- #{verb} = #{value} - scope:") - - [ - Roles.edit_verb_permission(role_name, verb, value, - scope: scope, - current_user: current_user - ) - ] - end - end) - end) do - { - :noreply, - socket - |> assign_flash(:info, l("Permission edited!")) - |> maybe_assign_settings(edited) - |> assign( - :role_verbs, - Bonfire.Boundaries.Roles.role_verbs(:all, - one_scope_only: assigns(socket)[:scope_type] not in [:smart_input], - scope: scope, - current_user: current_user(edited) + + role = Bonfire.Common.Types.maybe_to_atom(role) + verb = Bonfire.Common.Types.maybe_to_atom(verb) + debug(scope, "edit #{role} -- #{verb} = #{value} - scope:") + + case Roles.edit_verb_permission(role, verb, value, + scope: scope, + current_user: current_user + ) do + {:ok, edited} -> + debug(edited, "edited") + + { + :noreply, + socket + |> assign_flash(:info, l("Permission edited!")) + |> maybe_assign_settings(edited) + |> assign( + :roles_with_verbs, + Bonfire.Boundaries.Roles.role_verbs(:all, + one_scope_only: assigns(socket)[:scope_type] not in [:smart_input], + scope: scope, + current_user: current_user(edited) + ) + |> get_roles_with_verbs(scope) ) - ) - } - else - other -> - error(other) + } + error -> + error(error) {:noreply, assign_error(socket, l("Could not edit permission"))} end end @@ -160,11 +167,11 @@ defmodule Bonfire.UI.Boundaries.Web.TabledRolesLive do # socket # |> assign_global(instance_settings: settings) - # end + # end defp maybe_assign_settings(socket, %{id: _, data: data} = _scope) do socket - |> assign(role_verbs: data[:bonfire][:role_verbs]) + |> assign(roles: data[:bonfire][:role_verbs]) end defp maybe_assign_settings(socket, ret) do diff --git a/lib/web/components/roles/tabled_roles/tabled_roles_live.sface b/lib/web/components/roles/tabled_roles/tabled_roles_live.sface index 868a972..76de067 100644 --- a/lib/web/components/roles/tabled_roles/tabled_roles_live.sface +++ b/lib/web/components/roles/tabled_roles/tabled_roles_live.sface @@ -4,24 +4,40 @@ Role - {verb} + {verb} - + + {Recase.to_title(to_string(role))} {#if e(assigns, :read_only, nil) != true} - + + {#else} diff --git a/lib/web/components/set/boundaries_general_access_live.sface b/lib/web/components/set/boundaries_general_access_live.sface index 7450a98..d7ce7f7 100644 --- a/lib/web/components/set/boundaries_general_access_live.sface +++ b/lib/web/components/set/boundaries_general_access_live.sface @@ -25,7 +25,7 @@ hide_custom={@hide_custom} /> <:open_btn> - diff --git a/lib/web/components/set/boundary_items_live.sface b/lib/web/components/set/boundary_items_live.sface index 25e14c3..5547cb7 100644 --- a/lib/web/components/set/boundary_items_live.sface +++ b/lib/web/components/set/boundary_items_live.sface @@ -81,7 +81,7 @@ }, target: "#smart_input" )} - class="btn btn-sm btn-circle btn-ghost" + class="btn btn-xs btn-circle btn-ghost" > <#Icon iconify="ic:baseline-minus" class="w-4 h-4" /> diff --git a/lib/web/components/set/set_boundaries_button_live.sface b/lib/web/components/set/set_boundaries_button_live.sface index 2d50c2d..48a3822 100644 --- a/lib/web/components/set/set_boundaries_button_live.sface +++ b/lib/web/components/set/set_boundaries_button_live.sface @@ -51,11 +51,11 @@ {#match boundary_name} -
+
{boundary_name}
{/case} - + \ No newline at end of file diff --git a/lib/web/components/set/set_boundaries_live.sface b/lib/web/components/set/set_boundaries_live.sface index 5a72688..995a9b8 100644 --- a/lib/web/components/set/set_boundaries_live.sface +++ b/lib/web/components/set/set_boundaries_live.sface @@ -66,7 +66,7 @@ /> {#if e(assigns, :exclude_circles, []) && e(assigns, :exclude_circles, []) != []} -
+