From 8d71e89e378b9ae2a4320d1b5429ad0b7506c3ab Mon Sep 17 00:00:00 2001 From: Chris Zhu Date: Tue, 18 Feb 2025 17:29:01 -0800 Subject: [PATCH] Dashboard page for statistics --- app/avo/resource_tools/user.rb | 4 ++ app/avo/resources/user.rb | 2 + app/controllers/avo/tools_controller.rb | 6 +++ .../_deployment_success_rate.html.erb | 6 +++ .../statistics/_hanging_builds_count.html.erb | 5 +++ .../avo/custom/statistics/_new_users.html.erb | 5 +++ .../_projects_and_clusters.html.erb | 6 +++ app/views/avo/resource_tools/_user.html.erb | 37 +++++++++++++++++++ .../avo/sidebar/items/_dashboard.html.erb | 1 + app/views/avo/tools/dashboard.html.erb | 20 ++++++++++ config/routes.rb | 4 ++ 11 files changed, 96 insertions(+) create mode 100644 app/avo/resource_tools/user.rb create mode 100644 app/controllers/avo/tools_controller.rb create mode 100644 app/views/avo/custom/statistics/_deployment_success_rate.html.erb create mode 100644 app/views/avo/custom/statistics/_hanging_builds_count.html.erb create mode 100644 app/views/avo/custom/statistics/_new_users.html.erb create mode 100644 app/views/avo/custom/statistics/_projects_and_clusters.html.erb create mode 100644 app/views/avo/resource_tools/_user.html.erb create mode 100644 app/views/avo/sidebar/items/_dashboard.html.erb create mode 100644 app/views/avo/tools/dashboard.html.erb diff --git a/app/avo/resource_tools/user.rb b/app/avo/resource_tools/user.rb new file mode 100644 index 00000000..4e21d138 --- /dev/null +++ b/app/avo/resource_tools/user.rb @@ -0,0 +1,4 @@ +class Avo::ResourceTools::User < Avo::BaseResourceTool + self.name = "User Tool" + # self.partial = "avo/resource_tools/post_info" +end diff --git a/app/avo/resources/user.rb b/app/avo/resources/user.rb index 7e52618e..f240de99 100644 --- a/app/avo/resources/user.rb +++ b/app/avo/resources/user.rb @@ -6,6 +6,8 @@ class Avo::Resources::User < Avo::BaseResource # } def fields + tool Avo::ResourceTools::User, show_on: :index + field :id, as: :id field :email, as: :text field :first_name, as: :text diff --git a/app/controllers/avo/tools_controller.rb b/app/controllers/avo/tools_controller.rb new file mode 100644 index 00000000..a3c4cd6f --- /dev/null +++ b/app/controllers/avo/tools_controller.rb @@ -0,0 +1,6 @@ +class Avo::ToolsController < Avo::ApplicationController + def dashboard + @page_title = "Dashboard" + add_breadcrumb "Dashboard" + end +end diff --git a/app/views/avo/custom/statistics/_deployment_success_rate.html.erb b/app/views/avo/custom/statistics/_deployment_success_rate.html.erb new file mode 100644 index 00000000..8111b9ba --- /dev/null +++ b/app/views/avo/custom/statistics/_deployment_success_rate.html.erb @@ -0,0 +1,6 @@ +
+ <% @builds_count = Build.where(updated_at: 1.day.ago.., status: :completed).count.to_f %> + <% @deployment_success_rate = @builds_count > 0 ? Deployment.where(updated_at: 1.day.ago.., status: :success).count / @builds_count * 100 : 0 %> +

Deployment success rate

+

<%= @deployment_success_rate %>%

+
\ No newline at end of file diff --git a/app/views/avo/custom/statistics/_hanging_builds_count.html.erb b/app/views/avo/custom/statistics/_hanging_builds_count.html.erb new file mode 100644 index 00000000..5df0365c --- /dev/null +++ b/app/views/avo/custom/statistics/_hanging_builds_count.html.erb @@ -0,0 +1,5 @@ +
+ <% @hanging_builds_count = Build.where(updated_at: 20.minutes.ago..).where(status: :in_progress).count %> +

Hanging builds

+

<%= @hanging_builds_count %>

+
\ No newline at end of file diff --git a/app/views/avo/custom/statistics/_new_users.html.erb b/app/views/avo/custom/statistics/_new_users.html.erb new file mode 100644 index 00000000..a039b397 --- /dev/null +++ b/app/views/avo/custom/statistics/_new_users.html.erb @@ -0,0 +1,5 @@ +
+ <% @new_users_count = User.where(created_at: 1.day.ago..).count %> +

New users

+

<%= @new_users_count %>

+
\ No newline at end of file diff --git a/app/views/avo/custom/statistics/_projects_and_clusters.html.erb b/app/views/avo/custom/statistics/_projects_and_clusters.html.erb new file mode 100644 index 00000000..95d2818a --- /dev/null +++ b/app/views/avo/custom/statistics/_projects_and_clusters.html.erb @@ -0,0 +1,6 @@ +
+ <% @projects_count = Project.count %> + <% @clusters_count = Cluster.count %> +

Projects / Clusters

+

<%= @projects_count %> / <%= @clusters_count %>

+
\ No newline at end of file diff --git a/app/views/avo/resource_tools/_user.html.erb b/app/views/avo/resource_tools/_user.html.erb new file mode 100644 index 00000000..547a0671 --- /dev/null +++ b/app/views/avo/resource_tools/_user.html.erb @@ -0,0 +1,37 @@ +
+ <%= render Avo::PanelComponent.new(name: "User") do |c| %> + <% c.with_tools do %> + <%= a_link('/avo', icon: 'heroicons/solid/academic-cap', color: :primary, style: :primary) do %> + Login As + <% end %> + <% end %> + + <% c.with_body do %> +
+
+

Manage User

+ +

+ You can edit this file here app/views/avo/resource_tools/_user.html.erb. +

+ +

+ The resource tool configuration file should be here app/avo/resource_tools/user.rb. +

+ + <% + # In this partial you have access to the following variables: + # tool + # @resource + # @resource.record + # params + # Avo::Current.context + # current_user + %> +
+
+ <% end %> + <% end %> +
+ + diff --git a/app/views/avo/sidebar/items/_dashboard.html.erb b/app/views/avo/sidebar/items/_dashboard.html.erb new file mode 100644 index 00000000..96f6c6f9 --- /dev/null +++ b/app/views/avo/sidebar/items/_dashboard.html.erb @@ -0,0 +1 @@ +<%= render Avo::Sidebar::LinkComponent.new label: 'Dashboard', path: "#{avo.root_path}dashboard" %> diff --git a/app/views/avo/tools/dashboard.html.erb b/app/views/avo/tools/dashboard.html.erb new file mode 100644 index 00000000..b7cc90c9 --- /dev/null +++ b/app/views/avo/tools/dashboard.html.erb @@ -0,0 +1,20 @@ +
+ <%= render Avo::PanelComponent.new(name: 'Dashboard', display_breadcrumbs: true) do |c| %> + <% c.with_tools do %> +
This is the panels tools section.
+ <% end %> + + <% c.with_body do %> +
+
+
+ <%= render 'avo/custom/statistics/hanging_builds_count' %> + <%= render 'avo/custom/statistics/deployment_success_rate' %> + <%= render 'avo/custom/statistics/new_users' %> + <%= render 'avo/custom/statistics/projects_and_clusters' %> +
+
+
+ <% end %> + <% end %> +
diff --git a/config/routes.rb b/config/routes.rb index 96354f38..eeacec9c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,6 +3,10 @@ require "sidekiq/web" Rails.application.routes.draw do authenticate :user, ->(user) { user.admin? } do mount Avo::Engine, at: Avo.configuration.root_path + Avo::Engine.routes.draw do + # This route is not protected, secure it with authentication if needed. + get "dashboard", to: "tools#dashboard", as: :dashboard + end end resources :accounts, only: [ :create ] do resources :account_users, only: %i[create index destroy], module: :accounts