From c6821bbca97166fcb70063ba195dd8c26308e97a Mon Sep 17 00:00:00 2001 From: Max Wofford Date: Sun, 16 Feb 2025 12:31:43 -0500 Subject: [PATCH] Add Avo for admin dashboards --- Gemfile | 2 + Gemfile.lock | 35 +++++ app/avo/resources/user.rb | 17 +++ app/controllers/avo/users_controller.rb | 4 + config/initializers/avo.rb | 164 ++++++++++++++++++++++++ config/routes.rb | 1 + 6 files changed, 223 insertions(+) create mode 100644 app/avo/resources/user.rb create mode 100644 app/controllers/avo/users_controller.rb create mode 100644 config/initializers/avo.rb diff --git a/Gemfile b/Gemfile index bcd56e6..317fabd 100644 --- a/Gemfile +++ b/Gemfile @@ -18,6 +18,8 @@ gem "turbo-rails" gem "stimulus-rails" # Build JSON APIs with ease [https://github.com/rails/jbuilder] gem "jbuilder" +# Avo Community +gem "avo", ">= 3.2.1" # Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] # gem "bcrypt", "~> 3.1.7" diff --git a/Gemfile.lock b/Gemfile.lock index a6c71d0..e08becb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -44,6 +44,9 @@ GEM erubi (~> 1.11) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) + active_link_to (1.0.5) + actionpack + addressable activejob (8.0.1) activesupport (= 8.0.1) globalid (>= 0.3.6) @@ -75,6 +78,21 @@ GEM addressable (2.8.7) public_suffix (>= 2.0.2, < 7.0) ast (2.4.2) + avo (3.17.6) + actionview (>= 6.1) + active_link_to + activerecord (>= 6.1) + activesupport (>= 6.1) + addressable + docile + inline_svg + meta-tags + pagy (>= 7.0.0) + prop_initializer (>= 0.2.0) + turbo-rails (>= 2.0.0) + turbo_power (>= 0.6.0) + view_component (>= 3.7.0) + zeitwerk (>= 2.6.12) base64 (0.2.0) bcrypt_pbkdf (1.1.1) benchmark (0.4.0) @@ -101,6 +119,7 @@ GEM debug (1.10.0) irb (~> 1.10) reline (>= 0.3.8) + docile (1.4.1) domain_name (0.6.20240107) dotenv (3.1.7) dotenv-rails (3.1.7) @@ -141,6 +160,9 @@ GEM actionpack (>= 6.0.0) activesupport (>= 6.0.0) railties (>= 6.0.0) + inline_svg (1.10.0) + activesupport (>= 3.0) + nokogiri (>= 1.6) io-console (0.8.0) irb (1.15.1) pp (>= 0.6.0) @@ -177,6 +199,9 @@ GEM net-smtp marcel (1.0.4) matrix (0.4.2) + meta-tags (2.22.1) + actionpack (>= 6.0.0, < 8.1) + method_source (1.1.0) mini_mime (1.1.5) minitest (5.25.4) msgpack (1.8.0) @@ -210,6 +235,7 @@ GEM nokogiri (1.18.2-x86_64-linux-musl) racc (~> 1.4) ostruct (0.6.1) + pagy (9.3.3) parallel (1.26.3) parser (3.3.7.1) ast (~> 2.4.1) @@ -218,6 +244,8 @@ GEM pp (0.6.2) prettyprint prettyprint (0.2.0) + prop_initializer (0.2.0) + zeitwerk (>= 2.6.18) propshaft (1.1.0) actionpack (>= 7.0.0) activesupport (>= 7.0.0) @@ -359,6 +387,8 @@ GEM turbo-rails (2.0.11) actionpack (>= 6.0.0) railties (>= 6.0.0) + turbo_power (0.7.0) + turbo-rails (>= 1.3.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) unicode-display_width (3.1.4) @@ -366,6 +396,10 @@ GEM unicode-emoji (4.0.4) uri (1.0.2) useragent (0.16.11) + view_component (3.21.0) + activesupport (>= 5.2.0, < 8.1) + concurrent-ruby (~> 1.0) + method_source (~> 1.0) web-console (4.2.1) actionview (>= 6.0.0) activemodel (>= 6.0.0) @@ -393,6 +427,7 @@ PLATFORMS x86_64-linux-musl DEPENDENCIES + avo (>= 3.2.1) bootsnap brakeman capybara diff --git a/app/avo/resources/user.rb b/app/avo/resources/user.rb new file mode 100644 index 0000000..1037574 --- /dev/null +++ b/app/avo/resources/user.rb @@ -0,0 +1,17 @@ +class Avo::Resources::User < Avo::BaseResource + # self.includes = [] + # self.attachments = [] + # self.search = { + # query: -> { query.ransack(id_eq: params[:q], m: "or").result(distinct: false) } + # } + + def fields + field :id, as: :id + field :slack_uid, as: :text + field :email, as: :text + field :username, as: :text + field :avatar_url, as: :text + end +end + + diff --git a/app/controllers/avo/users_controller.rb b/app/controllers/avo/users_controller.rb new file mode 100644 index 0000000..a9987c6 --- /dev/null +++ b/app/controllers/avo/users_controller.rb @@ -0,0 +1,4 @@ +# This controller has been generated to enable Rails' resource routes. +# More information on https://docs.avohq.io/3.0/controllers.html +class Avo::UsersController < Avo::ResourcesController +end diff --git a/config/initializers/avo.rb b/config/initializers/avo.rb new file mode 100644 index 0000000..81710ba --- /dev/null +++ b/config/initializers/avo.rb @@ -0,0 +1,164 @@ +# For more information regarding these settings check out our docs https://docs.avohq.io +# The values disaplayed here are the default ones. Uncomment and change them to fit your needs. +Avo.configure do |config| + ## == Routing == + config.root_path = '/avo' + # used only when you have custom `map` configuration in your config.ru + # config.prefix_path = "/internal" + + # Sometimes you might want to mount Avo's engines yourself. + # https://docs.avohq.io/3.0/routing.html + # config.mount_avo_engines = true + + # Where should the user be redirected when visiting the `/avo` url + # config.home_path = nil + + ## == Licensing == + # config.license_key = ENV['AVO_LICENSE_KEY'] + + ## == Set the context == + config.set_context do + # Return a context object that gets evaluated within Avo::ApplicationController + end + + ## == Authentication == + # config.current_user_method = :current_user + # config.authenticate_with do + # end + + ## == Authorization == + # config.is_admin_method = :is_admin + # config.is_developer_method = :is_developer + # config.authorization_methods = { + # index: 'index?', + # show: 'show?', + # edit: 'edit?', + # new: 'new?', + # update: 'update?', + # create: 'create?', + # destroy: 'destroy?', + # search: 'search?', + # } + # config.raise_error_on_missing_policy = false + config.authorization_client = nil + config.explicit_authorization = true + + ## == Localization == + # config.locale = 'en-US' + + ## == Resource options == + # config.resource_row_controls_config = { + # placement: :right, + # float: false, + # show_on_hover: false + # }.freeze + # config.model_resource_mapping = {} + # config.default_view_type = :table + # config.per_page = 24 + # config.per_page_steps = [12, 24, 48, 72] + # config.via_per_page = 8 + # config.id_links_to_resource = false + # config.pagination = -> do + # { + # type: :default, + # size: 9, # `[1, 2, 2, 1]` for pagy < 9.0 + # } + # end + + ## == Response messages dismiss time == + # config.alert_dismiss_time = 5000 + + + ## == Number of search results to display == + # config.search_results_count = 8 + + ## == Associations lookup list limit == + # config.associations_lookup_list_limit = 1000 + + ## == Cache options == + ## Provide a lambda to customize the cache store used by Avo. + ## We compute the cache store by default, this is NOT the default, just an example. + # config.cache_store = -> { + # ActiveSupport::Cache.lookup_store(:solid_cache_store) + # } + # config.cache_resources_on_index_view = true + + ## == Turbo options == + # config.turbo = -> do + # { + # instant_click: true + # } + # end + + ## == Logger == + # config.logger = -> { + # file_logger = ActiveSupport::Logger.new(Rails.root.join("log", "avo.log")) + # + # file_logger.datetime_format = "%Y-%m-%d %H:%M:%S" + # file_logger.formatter = proc do |severity, time, progname, msg| + # "[Avo] #{time}: #{msg}\n".tap do |i| + # puts i + # end + # end + # + # file_logger + # } + + ## == Customization == + config.click_row_to_view_record = true + # config.app_name = 'Avocadelicious' + # config.timezone = 'UTC' + # config.currency = 'USD' + # config.hide_layout_when_printing = false + # config.full_width_container = false + # config.full_width_index_view = false + # config.search_debounce = 300 + # config.view_component_path = "app/components" + # config.display_license_request_timeout_error = true + # config.disabled_features = [] + # config.buttons_on_form_footers = true + # config.field_wrapper_layout = true + # config.resource_parent_controller = "Avo::ResourcesController" + # config.first_sorting_option = :desc # :desc or :asc + # config.exclude_from_status = [] + + ## == Branding == + # config.branding = { + # colors: { + # background: "248 246 242", + # 100 => "#CEE7F8", + # 400 => "#399EE5", + # 500 => "#0886DE", + # 600 => "#066BB2", + # }, + # chart_colors: ["#0B8AE2", "#34C683", "#2AB1EE", "#34C6A8"], + # logo: "/avo-assets/logo.png", + # logomark: "/avo-assets/logomark.png", + # placeholder: "/avo-assets/placeholder.svg", + # favicon: "/avo-assets/favicon.ico" + # } + + ## == Breadcrumbs == + # config.display_breadcrumbs = true + # config.set_initial_breadcrumbs do + # add_breadcrumb "Home", '/avo' + # end + + ## == Menus == + # config.main_menu = -> { + # section "Dashboards", icon: "avo/dashboards" do + # all_dashboards + # end + + # section "Resources", icon: "avo/resources" do + # all_resources + # end + + # section "Tools", icon: "avo/tools" do + # all_tools + # end + # } + # config.profile_menu = -> { + # link "Profile", path: "/avo/profile", icon: "heroicons/outline/user-circle" + # } +end diff --git a/config/routes.rb b/config/routes.rb index 0629d66..3c6d041 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + mount Avo::Engine, at: Avo.configuration.root_path # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.