From b1c4ac7edef74df9a8f89feb3dba6b4ff150548f Mon Sep 17 00:00:00 2001 From: Pranav Date: Fri, 19 Dec 2025 12:14:23 -0800 Subject: [PATCH] Update dashboard icons --- .../super_admin/dashboard_controller.rb | 40 ++++- app/dashboards/account_dashboard.rb | 9 +- app/fields/locale_field.rb | 12 ++ app/fields/status_field.rb | 15 ++ .../views/dashboard/Index.vue | 72 +++++++-- app/views/fields/avatar_field/_index.html.erb | 2 +- app/views/fields/locale_field/_form.html.erb | 9 ++ app/views/fields/locale_field/_index.html.erb | 3 + app/views/fields/locale_field/_show.html.erb | 1 + app/views/fields/status_field/_form.html.erb | 9 ++ app/views/fields/status_field/_index.html.erb | 3 + app/views/fields/status_field/_show.html.erb | 3 + app/views/super_admin/accounts/show.html.erb | 28 ++-- .../super_admin/app_configs/show.html.erb | 4 +- .../application/_collection.html.erb | 144 +++++++++--------- .../super_admin/application/_icons.html.erb | 61 ++++++++ .../application/_nav_item.html.erb | 6 +- .../application/_navigation.html.erb | 22 +-- .../application/_settings_menu.html.erb | 16 +- .../super_admin/application/index.html.erb | 2 +- .../super_admin/application/show.html.erb | 2 +- .../super_admin/dashboard/index.html.erb | 3 +- .../instance_statuses/show.html.erb | 14 +- app/views/super_admin/settings/show.html.erb | 4 +- .../super_admin/users/_collection.html.erb | 143 +++++++++-------- app/views/super_admin/users/show.html.erb | 28 ++-- 26 files changed, 421 insertions(+), 234 deletions(-) create mode 100644 app/fields/locale_field.rb create mode 100644 app/fields/status_field.rb create mode 100644 app/views/fields/locale_field/_form.html.erb create mode 100644 app/views/fields/locale_field/_index.html.erb create mode 100644 app/views/fields/locale_field/_show.html.erb create mode 100644 app/views/fields/status_field/_form.html.erb create mode 100644 app/views/fields/status_field/_index.html.erb create mode 100644 app/views/fields/status_field/_show.html.erb diff --git a/app/controllers/super_admin/dashboard_controller.rb b/app/controllers/super_admin/dashboard_controller.rb index 56d19d563..db38d033b 100644 --- a/app/controllers/super_admin/dashboard_controller.rb +++ b/app/controllers/super_admin/dashboard_controller.rb @@ -1,11 +1,41 @@ class SuperAdmin::DashboardController < SuperAdmin::ApplicationController include ActionView::Helpers::NumberHelper + ALLOWED_CHART_DAYS = [7, 30].freeze + def index - @data = Conversation.unscoped.group_by_day(:created_at, range: 30.days.ago..2.seconds.ago).count.to_a - @accounts_count = number_with_delimiter(Account.count) - @users_count = number_with_delimiter(User.count) - @inboxes_count = number_with_delimiter(Inbox.count) - @conversations_count = number_with_delimiter(Conversation.count) + @chart_days = parse_chart_days + @data = conversations_by_day + @accounts_count = format_count(Account.count) + @users_count = format_count(User.count) + @inboxes_count = format_count(Inbox.count) + @conversations_count = format_count(recent_conversations.count) + end + + private + + def parse_chart_days + days = params[:chart_period].to_i + ALLOWED_CHART_DAYS.include?(days) ? days : 7 + end + + def chart_date_range + (@chart_days - 1).days.ago.beginning_of_day..Time.current + end + + def last_30_days + 29.days.ago.beginning_of_day..Time.current + end + + def recent_conversations + Conversation.unscoped.where(created_at: last_30_days) + end + + def conversations_by_day + Conversation.unscoped.group_by_day(:created_at, range: chart_date_range, default_value: 0).count.to_a + end + + def format_count(count) + number_with_delimiter(count) end end diff --git a/app/dashboards/account_dashboard.rb b/app/dashboards/account_dashboard.rb index 9be674f11..dd7236692 100644 --- a/app/dashboards/account_dashboard.rb +++ b/app/dashboards/account_dashboard.rb @@ -31,8 +31,8 @@ class AccountDashboard < Administrate::BaseDashboard updated_at: Field::DateTime, users: CountField, conversations: CountField, - locale: Field::Select.with_options(collection: LANGUAGES_CONFIG.map { |_x, y| y[:iso_639_1_code] }), - status: Field::Select.with_options(collection: [%w[Active active], %w[Suspended suspended]]), + locale: LocaleField, + status: StatusField, account_users: Field::HasMany, custom_attributes: Field::String }.merge(enterprise_attribute_types).freeze @@ -45,10 +45,9 @@ class AccountDashboard < Administrate::BaseDashboard COLLECTION_ATTRIBUTES = %i[ id name - locale - users - conversations status + users + locale ].freeze # SHOW_PAGE_ATTRIBUTES diff --git a/app/fields/locale_field.rb b/app/fields/locale_field.rb new file mode 100644 index 000000000..60dd28289 --- /dev/null +++ b/app/fields/locale_field.rb @@ -0,0 +1,12 @@ +require 'administrate/field/base' + +class LocaleField < Administrate::Field::Base + def to_s + language = LANGUAGES_CONFIG.find { |_key, val| val[:iso_639_1_code] == data } + language ? language[1][:name] : data + end + + def selectable_options + LANGUAGES_CONFIG.map { |_key, val| [val[:name], val[:iso_639_1_code]] } + end +end diff --git a/app/fields/status_field.rb b/app/fields/status_field.rb new file mode 100644 index 000000000..e06df55fc --- /dev/null +++ b/app/fields/status_field.rb @@ -0,0 +1,15 @@ +require 'administrate/field/base' + +class StatusField < Administrate::Field::Base + def to_s + data.to_s.capitalize + end + + def active? + data.to_s == 'active' + end + + def selectable_options + [%w[Active active], %w[Suspended suspended]] + end +end diff --git a/app/javascript/superadmin_pages/views/dashboard/Index.vue b/app/javascript/superadmin_pages/views/dashboard/Index.vue index 0c03a846c..579aff64f 100644 --- a/app/javascript/superadmin_pages/views/dashboard/Index.vue +++ b/app/javascript/superadmin_pages/views/dashboard/Index.vue @@ -1,6 +1,8 @@