Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
a52dbbbc
Commit
a52dbbbc
authored
Sep 10, 2019
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'event-presenter' into 'master'
[CE] Add event presenter See merge request gitlab-org/gitlab-ce!32750
parents
6d486fde
f4945879
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
83 additions
and
15 deletions
+83
-15
app/helpers/events_helper.rb
app/helpers/events_helper.rb
+3
-1
app/models/event.rb
app/models/event.rb
+8
-6
app/presenters/event_presenter.rb
app/presenters/event_presenter.rb
+20
-0
app/views/events/_event.atom.builder
app/views/events/_event.atom.builder
+2
-0
app/views/events/_event.html.haml
app/views/events/_event.html.haml
+2
-0
app/views/events/_event_scope.html.haml
app/views/events/_event_scope.html.haml
+2
-3
app/views/events/event/_common.html.haml
app/views/events/event/_common.html.haml
+2
-2
app/views/events/event/_created_project.html.haml
app/views/events/event/_created_project.html.haml
+1
-1
app/views/users/calendar_activities.html.haml
app/views/users/calendar_activities.html.haml
+1
-1
spec/helpers/events_helper_spec.rb
spec/helpers/events_helper_spec.rb
+1
-1
spec/presenters/event_presenter_spec.rb
spec/presenters/event_presenter_spec.rb
+41
-0
No files found.
app/helpers/events_helper.rb
View file @
a52dbbbc
...
...
@@ -103,7 +103,7 @@ module EventsHelper
words
<<
"at"
end
words
<<
event
.
projec
t_name
words
<<
event
.
resource_paren
t_name
words
.
join
(
" "
)
end
...
...
@@ -223,3 +223,5 @@ module EventsHelper
end
end
end
EventsHelper
.
prepend_if_ee
(
'EE::EventsHelper'
)
app/models/event.rb
View file @
a52dbbbc
...
...
@@ -3,6 +3,8 @@
class
Event
<
ApplicationRecord
include
Sortable
include
FromUnion
include
Presentable
default_scope
{
reorder
(
nil
)
}
CREATED
=
1
...
...
@@ -135,6 +137,10 @@ class Event < ApplicationRecord
end
end
def
present
super
(
presenter_class:
::
EventPresenter
)
end
# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
def
visible_to_user?
(
user
=
nil
)
...
...
@@ -161,12 +167,8 @@ class Event < ApplicationRecord
# rubocop:enable Metrics/PerceivedComplexity
# rubocop:enable Metrics/CyclomaticComplexity
def
project_name
if
project
project
.
full_name
else
"(deleted project)"
end
def
resource_parent
project
||
group
end
def
target_title
...
...
app/presenters/event_presenter.rb
0 → 100644
View file @
a52dbbbc
# frozen_string_literal: true
class
EventPresenter
<
Gitlab
::
View
::
Presenter
::
Delegated
presents
:event
def
resource_parent_name
resource_parent
&
.
full_name
||
''
end
def
target_link_options
case
resource_parent
when
Group
[
event
.
group
,
event
.
target
]
when
Project
[
event
.
project
.
namespace
.
becomes
(
Namespace
),
event
.
project
,
event
.
target
]
else
''
end
end
end
app/views/events/_event.atom.builder
View file @
a52dbbbc
return unless event.visible_to_user?(current_user)
event = event.present
xml.entry do
xml.id "tag:#{request.host},#{event.created_at.strftime("%Y-%m-%d")}:#{event.id}"
xml.link href: event_feed_url(event)
...
...
app/views/events/_event.html.haml
View file @
a52dbbbc
-
event
=
event
.
present
-
if
event
.
visible_to_user?
(
current_user
)
.event-item
.event-item-timestamp
...
...
app/views/events/_event_scope.html.haml
View file @
a52dbbbc
...
...
@@ -2,6 +2,5 @@
=
event_preposition
(
event
)
-
if
event
.
project
=
link_to_project
(
event
.
project
)
-
else
=
event
.
project_name
-
elsif
event
.
group
=
link_to
event
.
resource_parent_name
,
group_path
(
event
.
group
)
app/views/events/event/_common.html.haml
View file @
a52dbbbc
...
...
@@ -8,7 +8,7 @@
%span
.event-type.d-inline-block.append-right-4
{
class:
event
.
action_name
}
=
event
.
action_name
%span
.event-target-type.append-right-4
=
event
.
target_type
.
titleize
.
downcase
=
link_to
[
event
.
project
.
namespace
.
becomes
(
Namespace
),
event
.
project
,
event
.
target
]
,
class:
'has-tooltip event-target-link append-right-4'
,
title:
event
.
target_title
do
=
link_to
event
.
target_link_options
,
class:
'has-tooltip event-target-link append-right-4'
,
title:
event
.
target_title
do
=
event
.
target
.
reference_link_text
-
unless
event
.
milestone?
%span
.event-target-title.append-right-4
{
dir:
"auto"
}
...
...
@@ -17,4 +17,4 @@
%span
.event-type.d-inline-block.append-right-4
{
class:
event
.
action_name
}
=
event_action_name
(
event
)
=
render
"events/event_scope"
,
event:
event
=
render
"events/event_scope"
,
event:
event
if
event
.
resource_parent
.
present?
app/views/events/event/_created_project.html.haml
View file @
a52dbbbc
...
...
@@ -10,4 +10,4 @@
-
if
event
.
project
=
link_to_project
(
event
.
project
)
-
else
=
event
.
projec
t_name
=
event
.
resource_paren
t_name
app/views/users/calendar_activities.html.haml
View file @
a52dbbbc
...
...
@@ -27,7 +27,7 @@
-
if
event
.
project
=
link_to_project
(
event
.
project
)
-
else
=
event
.
projec
t_name
=
event
.
resource_paren
t_name
-
else
made a private contribution
-
else
...
...
spec/helpers/events_helper_spec.rb
View file @
a52dbbbc
...
...
@@ -27,7 +27,7 @@ describe EventsHelper do
end
describe
'#event_feed_url'
do
let
(
:event
)
{
create
(
:event
)
}
let
(
:event
)
{
create
(
:event
)
.
present
}
let
(
:project
)
{
create
(
:project
,
:public
,
:repository
)
}
context
'issue'
do
...
...
spec/presenters/event_presenter_spec.rb
0 → 100644
View file @
a52dbbbc
# frozen_string_literal: true
require
'spec_helper'
describe
EventPresenter
do
include
Gitlab
::
Routing
.
url_helpers
set
(
:group
)
{
create
(
:group
)
}
set
(
:project
)
{
create
(
:project
,
group:
group
)
}
set
(
:target
)
{
create
(
:milestone
,
project:
project
)
}
set
(
:group_event
)
{
create
(
:event
,
:created
,
project:
nil
,
group:
group
,
target:
target
)
}
set
(
:project_event
)
{
create
(
:event
,
:created
,
project:
project
,
target:
target
)
}
describe
'#resource_parent_name'
do
context
'with group event'
do
subject
{
group_event
.
present
.
resource_parent_name
}
it
{
is_expected
.
to
eq
(
group
.
full_name
)
}
end
context
'with project label'
do
subject
{
project_event
.
present
.
resource_parent_name
}
it
{
is_expected
.
to
eq
(
project
.
full_name
)
}
end
end
describe
'#target_link_options'
do
context
'with group event'
do
subject
{
group_event
.
present
.
target_link_options
}
it
{
is_expected
.
to
eq
([
group
,
target
])
}
end
context
'with project label'
do
subject
{
project_event
.
present
.
target_link_options
}
it
{
is_expected
.
to
eq
([
group
.
becomes
(
Namespace
),
project
,
target
])
}
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment