mirror of
https://github.com/czhu12/canine.git
synced 2025-12-21 10:49:49 -06:00
Dashboard page for statistics
This commit is contained in:
4
app/avo/resource_tools/user.rb
Normal file
4
app/avo/resource_tools/user.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
class Avo::ResourceTools::User < Avo::BaseResourceTool
|
||||
self.name = "User Tool"
|
||||
# self.partial = "avo/resource_tools/post_info"
|
||||
end
|
||||
@@ -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
|
||||
|
||||
6
app/controllers/avo/tools_controller.rb
Normal file
6
app/controllers/avo/tools_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
class Avo::ToolsController < Avo::ApplicationController
|
||||
def dashboard
|
||||
@page_title = "Dashboard"
|
||||
add_breadcrumb "Dashboard"
|
||||
end
|
||||
end
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
5
app/views/avo/custom/statistics/_new_users.html.erb
Normal file
5
app/views/avo/custom/statistics/_new_users.html.erb
Normal 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>
|
||||
@@ -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>
|
||||
37
app/views/avo/resource_tools/_user.html.erb
Normal file
37
app/views/avo/resource_tools/_user.html.erb
Normal 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>
|
||||
|
||||
|
||||
1
app/views/avo/sidebar/items/_dashboard.html.erb
Normal file
1
app/views/avo/sidebar/items/_dashboard.html.erb
Normal file
@@ -0,0 +1 @@
|
||||
<%= render Avo::Sidebar::LinkComponent.new label: 'Dashboard', path: "#{avo.root_path}dashboard" %>
|
||||
20
app/views/avo/tools/dashboard.html.erb
Normal file
20
app/views/avo/tools/dashboard.html.erb
Normal 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>
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user