Dashboard page for statistics

This commit is contained in:
Chris Zhu
2025-02-18 17:29:01 -08:00
parent 7d86b29f32
commit 8d71e89e37
11 changed files with 96 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
class Avo::ResourceTools::User < Avo::BaseResourceTool
self.name = "User Tool"
# self.partial = "avo/resource_tools/post_info"
end

View File

@@ -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

View File

@@ -0,0 +1,6 @@
class Avo::ToolsController < Avo::ApplicationController
def dashboard
@page_title = "Dashboard"
add_breadcrumb "Dashboard"
end
end

View File

@@ -0,0 +1,6 @@
<div class="px-4" style="border-right: 1px solid #e0e0e0;">
<% @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 %>
<p class="text-sm text-gray-500 mb-2">Deployment success rate</p>
<p class="text-2xl font-bold"><%= @deployment_success_rate %>%</p>
</div>

View File

@@ -0,0 +1,5 @@
<div class="px-4" style="border-right: 1px solid #e0e0e0;">
<% @hanging_builds_count = Build.where(updated_at: 20.minutes.ago..).where(status: :in_progress).count %>
<p class="text-sm text-gray-500 mb-2">Hanging builds</p>
<p class="text-2xl font-bold"><%= @hanging_builds_count %></p>
</div>

View File

@@ -0,0 +1,5 @@
<div class="px-4" style="border-right: 1px solid #e0e0e0;">
<% @new_users_count = User.where(created_at: 1.day.ago..).count %>
<p class="text-sm text-gray-500 mb-2">New users</p>
<p class="text-2xl font-bold"><%= @new_users_count %></p>
</div>

View File

@@ -0,0 +1,6 @@
<div class="px-4">
<% @projects_count = Project.count %>
<% @clusters_count = Cluster.count %>
<p class="text-sm text-gray-500 mb-2">Projects / Clusters</p>
<p class="text-2xl font-bold"><%= @projects_count %> / <%= @clusters_count %></p>
</div>

View File

@@ -0,0 +1,37 @@
<div class="flex flex-col">
<%= 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 %>
<div class="flex flex-col p-4 min-h-24">
<div class="space-y-4">
<h3>Manage User</h3>
<p>
You can edit this file here <code class='p-1 rounded bg-gray-500 text-white text-sm'>app/views/avo/resource_tools/_user.html.erb</code>.
</p>
<p>
The resource tool configuration file should be here <code class='p-1 rounded bg-gray-500 text-white text-sm'>app/avo/resource_tools/user.rb</code>.
</p>
<%
# In this partial you have access to the following variables:
# tool
# @resource
# @resource.record
# params
# Avo::Current.context
# current_user
%>
</div>
</div>
<% end %>
<% end %>
</div>

View File

@@ -0,0 +1 @@
<%= render Avo::Sidebar::LinkComponent.new label: 'Dashboard', path: "#{avo.root_path}dashboard" %>

View File

@@ -0,0 +1,20 @@
<div class="flex flex-col">
<%= render Avo::PanelComponent.new(name: 'Dashboard', display_breadcrumbs: true) do |c| %>
<% c.with_tools do %>
<div class="text-sm italic">This is the panels tools section.</div>
<% end %>
<% c.with_body do %>
<div class="flex flex-col justify-between py-6 min-h-24">
<div class="px-6 space-y-4">
<div class="grid grid-cols-4 gap-4">
<%= 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' %>
</div>
</div>
</div>
<% end %>
<% end %>
</div>

View File

@@ -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