debian-mirror-gitlab/lib/gitlab/alert_management/alert_status_counts.rb

50 lines
1.1 KiB
Ruby
Raw Normal View History

2020-05-24 23:13:21 +05:30
# frozen_string_literal: true
module Gitlab
module AlertManagement
# Represents counts of each status or category of statuses
class AlertStatusCounts
include Gitlab::Utils::StrongMemoize
attr_reader :project
def self.declarative_policy_class
'AlertManagement::AlertPolicy'
end
def initialize(current_user, project, params)
@project = project
@current_user = current_user
@params = params
end
# Define method for each status
2021-01-03 14:25:43 +05:30
::AlertManagement::Alert.status_names.each do |status|
2020-05-24 23:13:21 +05:30
define_method(status) { counts[status] }
end
def open
counts[:triggered] + counts[:acknowledged]
end
def all
2021-01-03 14:25:43 +05:30
counts.values.sum
2020-05-24 23:13:21 +05:30
end
private
attr_reader :current_user, :params
def counts
strong_memoize(:counts) do
Hash.new(0).merge(counts_by_status)
end
end
def counts_by_status
2021-01-03 14:25:43 +05:30
::AlertManagement::AlertsFinder.counts_by_status(current_user, project, params)
2020-05-24 23:13:21 +05:30
end
end
end
end