Skip to content

Commit

Permalink
fix: Add DB size in system view
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentinchampenois committed Dec 18, 2024
1 parent 9652f6b commit c5471ac
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
28 changes: 28 additions & 0 deletions app/controllers/decidim/system/dashboard_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

module Decidim
module System
class DashboardController < Decidim::System::ApplicationController
before_action :check_organizations_presence

def show
@organizations = Organization.all
@db_size = db_size
end

def check_organizations_presence
return if Organization.exists?

redirect_to new_organization_path
end

private

def db_size
dbname = ActiveRecord::Base.connection.current_database
sql = "SELECT pg_size_pretty(pg_database_size('#{dbname}'));"
ActiveRecord::Base.connection.execute(sql)[0]["pg_size_pretty"]
end
end
end
end
11 changes: 11 additions & 0 deletions app/views/decidim/system/dashboard/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<% provide :title do %>
<h2><%= t("decidim.system.titles.dashboard.title") %></h2>
<h3><%= t ".current_organizations" %></h3>
<%= render partial: "decidim/system/shared/organizations_list", locals: { organizations: @organizations } %>
<div class="header">
<h3><%= I18n.t("decidim.system.titles.dashboard.info.title") %></h3>
<div>
<p><%= I18n.t("decidim.system.titles.dashboard.info.db_size", db_size: @db_size) %></p>
</div>
</div>
<% end %>
6 changes: 6 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ en:
client_id: Client ID
client_secret: Client secret
site_url: Site URL
titles:
dashboard: Dashboard
info:
db_size: 'Database size: %{db_size}'
title: General informations
title:
verifications:
authorizations:
create:
Expand Down
6 changes: 6 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ fr:
client_id: Client ID
client_secret: Client secret
site_url: Site URL
titles:
dashboard:
info:
db_size: 'Poids base de données: %{db_size}'
title: Informations générales
title: Tableau de bord système
verifications:
authorizations:
create:
Expand Down

0 comments on commit c5471ac

Please sign in to comment.