Files
fizzy/app/helpers/accesses_helper.rb
T
2025-09-12 14:46:05 +02:00

75 lines
2.4 KiB
Ruby

module AccessesHelper
def access_menu_tag(collection, **options, &)
tag.menu class: [ options[:class], { "toggler--toggled": collection.all_access? } ], data: {
controller: "filter toggle-class navigable-list",
action: "keydown->navigable-list#navigate filter:changed->navigable-list#reset",
navigable_list_focus_on_selection_value: true,
navigable_list_actionable_items_value: true,
toggle_class_toggle_class: "toggler--toggled" }, &
end
def access_toggles_for(users, selected:)
render partial: "collections/access_toggle",
collection: users, as: :user,
locals: { selected: selected },
cached: ->(user) { [ user, selected ] }
end
def access_involvement_advance_button(collection, user, show_watchers: true)
access = collection.access_for(user)
turbo_frame_tag dom_id(collection, :involvement_button) do
concat collection_watchers_list(collection) if show_watchers
concat involvement_button(collection, access, show_watchers)
end
end
def collection_watchers_list(collection)
tag.div(class: "flex flex-wrap gap-half justify-center") do
safe_join(
collection.users
.without(User.system)
.where(accesses: { involvement: :watching })
.distinct
.map { |watcher| avatar_tag(watcher) }
)
end
end
def involvement_button(collection, access, show_watchers)
involvement_label_id = dom_id(collection, :involvement_label)
button_to(
collection_involvement_path(collection),
method: :put,
aria: { labelledby: involvement_label_id },
class: "btn",
params: { show_watchers: show_watchers, involvement: next_involvement(access.involvement) }
) do
safe_join([
icon_tag("notification-bell-#{access.involvement.dasherize}"),
tag.span(
involvement_access_label(collection, access.involvement),
class: "txt-nowrap txt-uppercase",
id: involvement_label_id
)
])
end
end
private
def next_involvement(involvement)
order = %w[ watching access_only ]
order[(order.index(involvement.to_s) + 1) % order.size]
end
def involvement_access_label(collection, involvement)
case involvement
when "access_only"
"Watch this"
when "watching"
"Stop Watching"
end
end
end