blob: e55e0016599dee71bb23bf4a88e9e7f3515d75dc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# 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
::AlertManagement::Alert.status_names.each do |status|
define_method(status) { counts[status] }
end
def open
counts[:triggered] + counts[:acknowledged]
end
def all
counts.values.sum
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
::AlertManagement::AlertsFinder.counts_by_status(current_user, project, params)
end
end
end
end
|