From 2354b10eb5e9c7382726bc5e6e041ea30a903c90 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 16 Jul 2018 01:11:53 +0200 Subject: Add admin dashboard (#8029) --- app/views/admin/dashboard/index.html.haml | 140 ++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 app/views/admin/dashboard/index.html.haml (limited to 'app/views') diff --git a/app/views/admin/dashboard/index.html.haml b/app/views/admin/dashboard/index.html.haml new file mode 100644 index 000000000..50004de33 --- /dev/null +++ b/app/views/admin/dashboard/index.html.haml @@ -0,0 +1,140 @@ +- content_for :page_title do + = t('admin.dashboard.title') + +.dashboard__counters + %div + = link_to admin_accounts_url(local: 1, recent: 1) do + .dashboard__counters__num= number_with_delimiter @users_count + .dashboard__counters__label= t 'admin.dashboard.total_users' + %div + %div + .dashboard__counters__num= number_with_delimiter @registrations_week + .dashboard__counters__label= t 'admin.dashboard.week_users_new' + %div + %div + .dashboard__counters__num= number_with_delimiter @logins_week + .dashboard__counters__label= t 'admin.dashboard.week_users_active' + %div + %div + .dashboard__counters__num= number_with_delimiter @interactions_week + .dashboard__counters__label= t 'admin.dashboard.week_interactions' + %div + = link_to admin_reports_url do + .dashboard__counters__num= number_with_delimiter @reports_count + .dashboard__counters__label= t 'admin.dashboard.open_reports' + %div + = link_to sidekiq_url do + .dashboard__counters__num= number_with_delimiter @queue_backlog + .dashboard__counters__label= t 'admin.dashboard.backlog' + +.dashboard__widgets + .dashboard__widgets__users + %div + %h4= t 'admin.dashboard.recent_users' + %ul + - @recent_users.each do |user| + %li= admin_account_link_to(user.account) + + .dashboard__widgets__features + %div + %h4= t 'admin.dashboard.features' + %ul + %li + = link_to t('admin.dashboard.feature_registrations'), edit_admin_settings_path + - if @registrations_enabled + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + %li + = link_to t('admin.dashboard.feature_invites'), edit_admin_settings_path + - if @invites_enabled + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + %li + = link_to t('admin.dashboard.feature_deletions'), edit_admin_settings_path + - if @deletions_enabled + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + %li + = link_to t('admin.dashboard.feature_relay'), admin_relays_path + - if @relay_enabled + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + + .dashboard__widgets__versions + %div + %h4= t 'admin.dashboard.software' + %ul + %li + Mastodon + %span.pull-right= @version + %li + Ruby + %span.pull-right= "#{RUBY_VERSION}p#{RUBY_PATCHLEVEL}" + %li + PostgreSQL + %span.pull-right= @database_version + %li + Redis + %span.pull-right= @redis_version + + .dashboard__widgets__space + %div + %h4= t 'admin.dashboard.space' + %ul + %li + PostgreSQL + %span.pull-right= number_to_human_size @database_size + %li + Redis + %span.pull-right= number_to_human_size @redis_size + + .dashboard__widgets__config + %div + %h4= t 'admin.dashboard.config' + %ul + %li + = t('admin.dashboard.search') + - if @search_enabled + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + %li + = t('admin.dashboard.single_user_mode') + - if @single_user_mode + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + %li + LDAP + - if @ldap_enabled + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + %li + CAS + - if @cas_enabled + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + %li + SAML + - if @saml_enabled + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + %li + PAM + - if @pam_enabled + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + %li + = t 'admin.dashboard.hidden_service' + - if @hidden_service + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' -- cgit From 0d13e30ad2579a9fc55f1b57c80cf9a9a89b1491 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 16 Jul 2018 19:21:27 +0200 Subject: Display trending hashtags on admin dashboard (#8038) --- app/controllers/admin/dashboard_controller.rb | 1 + app/models/trending_tags.rb | 27 +++++++++++++++++++++++++++ app/views/admin/dashboard/index.html.haml | 9 +++++++++ 3 files changed, 37 insertions(+) (limited to 'app/views') diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb index af1ac7b5e..7be753c9b 100644 --- a/app/controllers/admin/dashboard_controller.rb +++ b/app/controllers/admin/dashboard_controller.rb @@ -27,6 +27,7 @@ module Admin @saml_enabled = ENV['SAML_ENABLED'] == 'true' @pam_enabled = ENV['PAM_ENABLED'] == 'true' @hidden_service = ENV['ALLOW_ACCESS_TO_HIDDEN_SERVICE'] == 'true' + @trending_hashtags = TrendingTags.get(7) end private diff --git a/app/models/trending_tags.rb b/app/models/trending_tags.rb index c3641d7fd..b11f35292 100644 --- a/app/models/trending_tags.rb +++ b/app/models/trending_tags.rb @@ -1,7 +1,10 @@ # frozen_string_literal: true class TrendingTags + KEY = 'trending_tags' EXPIRE_HISTORY_AFTER = 7.days.seconds + EXPIRE_TRENDS_AFTER = 1.day.seconds + THRESHOLD = 5 class << self def record_use!(tag, account, at_time = Time.now.utc) @@ -9,6 +12,14 @@ class TrendingTags increment_historical_use!(tag.id, at_time) increment_unique_use!(tag.id, account.id, at_time) + increment_vote!(tag.id, at_time) + end + + def get(limit) + key = "#{KEY}:#{Time.now.utc.beginning_of_day.to_i}" + tag_ids = redis.zrevrange(key, 0, limit).map(&:to_i) + tags = Tag.where(id: tag_ids).to_a.map { |tag| [tag.id, tag] }.to_h + tag_ids.map { |tag_id| tags[tag_id] }.compact end private @@ -25,6 +36,22 @@ class TrendingTags redis.expire(key, EXPIRE_HISTORY_AFTER) end + def increment_vote!(tag_id, at_time) + key = "#{KEY}:#{at_time.beginning_of_day.to_i}" + expected = redis.pfcount("activity:tags:#{tag_id}:#{(at_time - 1.day).beginning_of_day.to_i}:accounts").to_f + expected = 1.0 if expected.zero? + observed = redis.pfcount("activity:tags:#{tag_id}:#{at_time.beginning_of_day.to_i}:accounts").to_f + + if expected > observed || observed < THRESHOLD + redis.zrem(key, tag_id.to_s) + else + score = ((observed - expected)**2) / expected + redis.zadd(key, score, tag_id.to_s) + end + + redis.expire(key, EXPIRE_TRENDS_AFTER) + end + def disallowed_hashtags return @disallowed_hashtags if defined?(@disallowed_hashtags) diff --git a/app/views/admin/dashboard/index.html.haml b/app/views/admin/dashboard/index.html.haml index 50004de33..41a0ee5a1 100644 --- a/app/views/admin/dashboard/index.html.haml +++ b/app/views/admin/dashboard/index.html.haml @@ -138,3 +138,12 @@ %span.pull-right.positive-hint= fa_icon 'check fw' - else %span.pull-right.negative-hint= fa_icon 'times fw' + + .dashboard__widgets__trends + %div + %h4= t 'admin.dashboard.trends' + %ul + - @trending_hashtags.each do |tag| + %li + = link_to "##{tag.name}", web_url("timelines/tag/#{tag.name}") + %span.pull-right= number_with_delimiter(tag.history[0]['accounts'].to_i) -- cgit From 8241f162dfa4f7c2cfe79d6f18ddcbd2de4def0c Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 16 Jul 2018 19:51:16 +0200 Subject: Fix tag usage display on admin dashboard --- app/views/admin/dashboard/index.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/views') diff --git a/app/views/admin/dashboard/index.html.haml b/app/views/admin/dashboard/index.html.haml index 41a0ee5a1..1996eef4d 100644 --- a/app/views/admin/dashboard/index.html.haml +++ b/app/views/admin/dashboard/index.html.haml @@ -146,4 +146,4 @@ - @trending_hashtags.each do |tag| %li = link_to "##{tag.name}", web_url("timelines/tag/#{tag.name}") - %span.pull-right= number_with_delimiter(tag.history[0]['accounts'].to_i) + %span.pull-right= number_with_delimiter(tag.history[0][:accounts].to_i) -- cgit