Adding total and active count to pod view

The backend adds the total count for all pods, as well as the count for active pods.

In the frontend shows the new counts but without any further user interactions
This commit is contained in:
Thorsten Claus 2022-07-28 23:23:22 +02:00
parent 429a47d64d
commit 416c806012
5 changed files with 39 additions and 3 deletions

View file

@ -29,6 +29,25 @@ app.pages.AdminPods = app.views.Base.extend({
_showMessages: function() { _showMessages: function() {
var msgs = document.createDocumentFragment(); 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 ) { if( gon.uncheckedCount && gon.uncheckedCount > 0 ) {
var unchecked = $("<div class='alert alert-info' role='alert' />") var unchecked = $("<div class='alert alert-info' role='alert' />")
.append(Diaspora.I18n.t("admin.pods.unchecked", {count: gon.uncheckedCount})); .append(Diaspora.I18n.t("admin.pods.unchecked", {count: gon.uncheckedCount}));

View file

@ -14,7 +14,8 @@ module Admin
gon.unchecked_count = Pod.unchecked.count gon.unchecked_count = Pod.unchecked.count
gon.version_failed_count = Pod.version_failed.count gon.version_failed_count = Pod.version_failed.count
gon.error_count = Pod.check_failed.count gon.error_count = Pod.check_failed.count
gon.active_count = Pod.active.count
gon.total_count = Pod.count
render "admins/pods" render "admins/pods"
end end
format.mobile { render "admins/pods" } format.mobile { render "admins/pods" }

View file

@ -1,6 +1,9 @@
# frozen_string_literal: true # frozen_string_literal: true
class Pod < ApplicationRecord 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( enum status: %i(
unchecked unchecked
no_errors 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]) 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 validate :not_own_pod
class << self class << self
@ -73,9 +80,9 @@ class Pod < ApplicationRecord
Pod.offline_statuses.include?(Pod.statuses[status]) Pod.offline_statuses.include?(Pod.statuses[status])
end 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? 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 end
def to_s def to_s

View file

@ -10,6 +10,7 @@ class PodPresenter < BasePresenter
status: status, status: status,
checked_at: checked_at, checked_at: checked_at,
response_time: response_time, response_time: response_time,
active: active?,
offline: offline?, offline: offline?,
offline_since: offline_since, offline_since: offline_since,
created_at: created_at, created_at: created_at,

View file

@ -70,9 +70,17 @@ en:
other: "<%= count %>ms" other: "<%= count %>ms"
unknown: "unknown" unknown: "unknown"
not_available: "not available" not_available: "not available"
total:
one: "There is only one known pod."
other: "There are <%= count %> known pods in total."
unchecked: unchecked:
one: "There is still one pod that hasn't been checked at all." 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." 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: version_failed:
one: "There is one pod that has no version (old pod, no NodeInfo)." 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)." other: "There are <%= count %> pods that have no version (old pods, no NodeInfo)."