diff options
author | Benjamin Neff <benjamin@coding4coffee.ch> | 2022-07-31 05:10:26 +0300 |
---|---|---|
committer | Benjamin Neff <benjamin@coding4coffee.ch> | 2022-07-31 05:12:02 +0300 |
commit | 77af1b9942a04e533783246c51fe7d1de54dcab9 (patch) | |
tree | bdf9d3c005ee62f718312057a08c94ffb9206919 | |
parent | 496ec4b059649a4576eb33a43cbb6cbf39c25c84 (diff) | |
parent | 416c806012502bd3fdbdaf21edc190f06deb23ff (diff) |
Merge pull request #8383 from tclaus/show_available_pods
Prepare the backend for generating a list of active pods
-rw-r--r-- | Changelog.md | 1 | ||||
-rw-r--r-- | app/assets/javascripts/app/pages/admin_pods.js | 19 | ||||
-rw-r--r-- | app/controllers/admin/pods_controller.rb | 3 | ||||
-rw-r--r-- | app/models/pod.rb | 11 | ||||
-rw-r--r-- | app/presenters/pod_presenter.rb | 1 | ||||
-rw-r--r-- | config/locales/javascript/javascript.en.yml | 8 |
6 files changed, 40 insertions, 3 deletions
diff --git a/Changelog.md b/Changelog.md index 5b8a54165..4e055e849 100644 --- a/Changelog.md +++ b/Changelog.md @@ -43,6 +43,7 @@ We use yarn to install the frontend dependencies now, so you need to have that i * Allow podmins/moderators to see all local public posts to improve moderation [#8232](https://github.com/diaspora/diaspora/pull/8232) [#8320](https://github.com/diaspora/diaspora/pull/8320) * Add support for directly paste images to upload them [#8237](https://github.com/diaspora/diaspora/pull/8237) * Add support for webp images and convert new png/jpg to webp to save space and bandwidth [#8358](https://github.com/diaspora/diaspora/pull/8358) +* Show total and active pods count in the pods list for podmins [#8383](https://github.com/diaspora/diaspora/pull/8383) # 0.7.18.0 diff --git a/app/assets/javascripts/app/pages/admin_pods.js b/app/assets/javascripts/app/pages/admin_pods.js index 27fb1979e..8c0ae6d39 100644 --- a/app/assets/javascripts/app/pages/admin_pods.js +++ b/app/assets/javascripts/app/pages/admin_pods.js @@ -29,6 +29,25 @@ app.pages.AdminPods = app.views.Base.extend({ _showMessages: function() { var msgs = document.createDocumentFragment(); + if (gon.totalCount && gon.totalCount > 0) { + let totalPods = $("<div class='alert alert-info' role='alert' />") + .append(Diaspora.I18n.t("admin.pods.total", {count: gon.totalCount})); + if (gon.activeCount) { + if (gon.activeCount === 0) { + totalPods + .append(" " + Diaspora.I18n.t("admin.pods.none_active")); + } + if (gon.activeCount === gon.totalCount) { + totalPods + .append(" " + Diaspora.I18n.t("admin.pods.all_active")); + } else { + totalPods + .append(" " + Diaspora.I18n.t("admin.pods.active", {count: gon.activeCount})); + } + } + msgs.appendChild(totalPods[0]); + } + if( gon.uncheckedCount && gon.uncheckedCount > 0 ) { var unchecked = $("<div class='alert alert-info' role='alert' />") .append(Diaspora.I18n.t("admin.pods.unchecked", {count: gon.uncheckedCount})); diff --git a/app/controllers/admin/pods_controller.rb b/app/controllers/admin/pods_controller.rb index ed41d0669..f39d37ac8 100644 --- a/app/controllers/admin/pods_controller.rb +++ b/app/controllers/admin/pods_controller.rb @@ -14,7 +14,8 @@ module Admin gon.unchecked_count = Pod.unchecked.count gon.version_failed_count = Pod.version_failed.count gon.error_count = Pod.check_failed.count - + gon.active_count = Pod.active.count + gon.total_count = Pod.count render "admins/pods" end format.mobile { render "admins/pods" } diff --git a/app/models/pod.rb b/app/models/pod.rb index 08692f280..1edc4e899 100644 --- a/app/models/pod.rb +++ b/app/models/pod.rb @@ -1,6 +1,9 @@ # frozen_string_literal: true class Pod < ApplicationRecord + # a pod is active if it is online or was online less than 14 days ago + ACTIVE_DAYS = 14.days + enum status: %i( unchecked no_errors @@ -39,6 +42,10 @@ class Pod < ApplicationRecord where(arel_table[:status].gt(Pod.statuses[:no_errors])).where.not(status: Pod.statuses[:version_failed]) } + scope :active, -> { + where(["offline_since is null or offline_since > ?", DateTime.now.utc - ACTIVE_DAYS]) + } + validate :not_own_pod class << self @@ -73,9 +80,9 @@ class Pod < ApplicationRecord Pod.offline_statuses.include?(Pod.statuses[status]) end - # a pod is active if it is online or was online less than 14 days ago + # a pod is active if it is online or was online recently def active? - !offline? || offline_since.try {|date| date > DateTime.now.utc - 14.days } + !offline? || offline_since.try {|date| date > DateTime.now.utc - ACTIVE_DAYS } end def to_s diff --git a/app/presenters/pod_presenter.rb b/app/presenters/pod_presenter.rb index a29859dc7..df8226a76 100644 --- a/app/presenters/pod_presenter.rb +++ b/app/presenters/pod_presenter.rb @@ -10,6 +10,7 @@ class PodPresenter < BasePresenter status: status, checked_at: checked_at, response_time: response_time, + active: active?, offline: offline?, offline_since: offline_since, created_at: created_at, diff --git a/config/locales/javascript/javascript.en.yml b/config/locales/javascript/javascript.en.yml index ed0e12931..32b1ff996 100644 --- a/config/locales/javascript/javascript.en.yml +++ b/config/locales/javascript/javascript.en.yml @@ -70,9 +70,17 @@ en: other: "<%= count %>ms" unknown: "unknown" not_available: "not available" + total: + one: "There is only one known pod." + other: "There are <%= count %> known pods in total." unchecked: one: "There is still one pod that hasn't been checked at all." other: "There are still <%= count %> pods that haven't been checked at all." + active: + one: "One pod was active recently." + other: "<%= count %> pods were active recently." + none_active: "None of them were active recently." + all_active: "All of them were active recently." version_failed: one: "There is one pod that has no version (old pod, no NodeInfo)." other: "There are <%= count %> pods that have no version (old pods, no NodeInfo)." |