-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathindex_component.rb
143 lines (121 loc) · 4.15 KB
/
index_component.rb
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# frozen_string_literal: true
# -- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2023 the OpenProject GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See COPYRIGHT and LICENSE files for more details.
# ++
module WorkPackages
module ActivitiesTab
module Journals
class IndexComponent < ApplicationComponent
MAX_RECENT_JOURNALS = 30
include ApplicationHelper
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable
include WorkPackages::ActivitiesTab::SharedHelpers
def initialize(work_package:, filter: :all, deferred: false)
super
@work_package = work_package
@filter = filter
@deferred = deferred
end
private
attr_reader :work_package, :filter, :deferred
def insert_target_modified?
true
end
def insert_target_modifier_id
"work-package-journal-days"
end
def journal_sorting_desc?
journal_sorting == "desc"
end
def base_journals
combine_and_sort_records(fetch_journals, fetch_revisions)
end
def fetch_journals
API::V3::Activities::ActivityEagerLoadingWrapper.wrap(
work_package
.journals
.includes(:user, :customizable_journals, :attachable_journals, :storable_journals, :notifications)
.reorder(version: journal_sorting)
.with_sequence_version
)
end
def fetch_revisions
work_package.changesets.includes(:user, :repository)
end
def combine_and_sort_records(journals, revisions)
(journals + revisions).sort_by do |record|
timestamp = record_timestamp(record)
journal_sorting_desc? ? [-timestamp, -record.id] : [timestamp, record.id]
end
end
def record_timestamp(record)
if record.is_a?(API::V3::Activities::ActivityEagerLoadingWrapper)
record.created_at&.to_i
elsif record.is_a?(Changeset)
record.committed_on.to_i
end
end
def journals
base_journals
end
def recent_journals
if journal_sorting_desc?
base_journals.first(MAX_RECENT_JOURNALS)
else
base_journals.last(MAX_RECENT_JOURNALS)
end
end
def older_journals
if journal_sorting_desc?
base_journals.drop(MAX_RECENT_JOURNALS)
else
base_journals.take(base_journals.size - MAX_RECENT_JOURNALS)
end
end
def journal_with_notes
work_package
.journals
.where.not(notes: "")
end
def wp_journals_grouped_emoji_reactions
@wp_journals_grouped_emoji_reactions ||= Journal.grouped_work_package_journals_emoji_reactions(work_package)
end
def empty_state?
filter == :only_comments && journal_with_notes.empty?
end
def inner_container_margin_bottom
if journal_sorting_desc?
3
else
0
end
end
end
end
end
end