Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorThorsten Claus <thorstenclaus@web.de>2022-07-29 00:23:22 +0300
committerThorsten Claus <thorstenclaus@web.de>2022-07-31 01:19:41 +0300
commit416c806012502bd3fdbdaf21edc190f06deb23ff (patch)
tree8c32e487bf1ecb5721f3c428596b8f696a40af26 /app
parent429a47d64d7753f14be454a519d198ca53ee7c7a (diff)
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
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/app/pages/admin_pods.js19
-rw-r--r--app/controllers/admin/pods_controller.rb3
-rw-r--r--app/models/pod.rb11
-rw-r--r--app/presenters/pod_presenter.rb1
4 files changed, 31 insertions, 3 deletions
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 c64bf4ce2..6c0deb522 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,