diff --git a/app/components/avo/sidebar_component.html.erb b/app/components/avo/sidebar_component.html.erb deleted file mode 100644 index 8f3d8663f9fd48352d5b0ee537f67f0980f917ff..0000000000000000000000000000000000000000 --- a/app/components/avo/sidebar_component.html.erb +++ /dev/null @@ -1,53 +0,0 @@ -<div - class="avo-sidebar fixed z-[60] t-0 application-sidebar w-64 flex-1 border-r lg:border-none bg-none h-[calc(100dvh-4rem)] bg-application lg:bg-transparent <%= 'print:hidden' if Avo.configuration.hide_layout_when_printing %> <%= 'hidden' unless @sidebar_open %>" - data-sidebar-target="<%= stimulus_target %>" -> - <div class="flex flex-col w-full h-full"> - <div class="flex-1 flex flex-col justify-between overflow-auto h-full pt-3 mac-styled-scrollbar"> - <%= render Avo::Sidebar::LinkComponent.new label: 'Get started', path: helpers.avo.root_path, active: :exclusive if Rails.env.development? && Avo.configuration.home_path.nil? %> - - <% if Avo.plugin_manager.installed?(:avo_menu) && Avo.has_main_menu? %> - <% Avo.main_menu.items.each do |item| %> - <%= render Avo::Sidebar::ItemSwitcherComponent.new item: item %> - <% end %> - <% else %> - - <% if dashboards.present? %> - <div> - <%= render Avo::Sidebar::HeadingComponent.new label: t('avo.dashboards'), icon: helpers.svg("avo/dashboards", class: 'h-4') %> - - <div class="w-full space-y-1"> - <% dashboards.sort_by { |r| r.navigation_label }.each do |dashboard| %> - <%= render Avo::Sidebar::LinkComponent.new label: dashboard.navigation_label, path: helpers.avo_dashboards.dashboard_path(dashboard) %> - <% end %> - </div> - </div> - <% end %> - - <div> - <%= render Avo::Sidebar::HeadingComponent.new label: t('avo.resources'), icon: helpers.svg("avo/resources", class: 'h-4') %> - - <div class="w-full space-y-1"> - <% resources.sort_by { |r| r.navigation_label }.each do |resource| %> - <%= render Avo::Sidebar::LinkComponent.new label: resource.navigation_label, path: helpers.resources_path(resource: resource) %> - <% end %> - </div> - </div> - - <% if tools.present? %> - <div> - <%= render Avo::Sidebar::HeadingComponent.new label: t('avo.tools'), icon: helpers.svg("avo/tools", class: 'h-4') %> - - <div class="w-full space-y-1"> - <% tools.each do |partial| %> - <%= render partial: "/avo/sidebar/items/#{partial}" %> - <% end %> - </div> - </div> - <% end %> - <% end %> - - <%= render partial: "/avo/partials/sidebar_extra" %> - </div> - </div> -</div> diff --git a/app/components/avo/sidebar_component.rb b/app/components/avo/sidebar_component.rb deleted file mode 100644 index 39310097a8a8c3d93570605099089b6c544bf95d..0000000000000000000000000000000000000000 --- a/app/components/avo/sidebar_component.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -class Avo::SidebarComponent < Avo::BaseComponent - prop :sidebar_open, default: false - prop :for_mobile, default: false - - def dashboards - return [] unless Avo.plugin_manager.installed?(:avo_dashboards) - - Avo::Dashboards.dashboard_manager.dashboards_for_navigation - end - - def resources - Avo.resource_manager.resources_for_navigation helpers._current_user - end - - def tools - Avo.tool_manager.tools_for_navigation - end - - def stimulus_target - @for_mobile ? "mobileSidebar" : "sidebar" - end -end diff --git a/app/components/avo/sidebar_profile_component.html.erb b/app/components/avo/sidebar_profile_component.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/components/avo/sidebar_profile_component.rb b/app/components/avo/sidebar_profile_component.rb new file mode 100644 index 0000000000000000000000000000000000000000..177e8fa687240b90aa21b1cb844f43c19d1bb905 --- /dev/null +++ b/app/components/avo/sidebar_profile_component.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +class Avo::SidebarProfileComponent < Avo::BaseComponent + prop :user + + delegate :main_app, to: :helpers + + def avatar + if @user.respond_to?(:avatar) && @user.avatar.present? + @user.avatar + else + "" + end + end + + def name + if @user.respond_to?(:name) && @user.name.present? + @user.name + elsif @user.respond_to?(:email) && @user.email.present? + @user.email + elsif @user.respond_to?(:email_address) && @user.email_address.present? + @user.email_address + else + "Avo user" + end + end + + def title + if @user.respond_to?(:avo_title) && @user.avo_title.present? + @user.avo_title + else + "" + end + end + + def sign_out_method + :delete + end + + def sign_out_path + return Avo.configuration.sign_out_path_name if Avo.configuration.sign_out_path_name.present? + return :session_path if helpers.possibly_rails_authentication? + + default_sign_out_path + end + + def default_sign_out_path + default_path = :"destroy_#{Avo.configuration.current_user_resource_name}_session_path" + + default_path if main_app.respond_to?(default_path) + end + + def can_sign_out_user? + sign_out_path.present? && main_app.respond_to?(sign_out_path&.to_sym) + end +end