Commit 55a93f19 authored by Alex Kalderimis's avatar Alex Kalderimis Committed by Kerri Miller

Move methods from model to presenter

As part of this the 'Wall' return value for 'note_target_type_name' is
removed, since there is no valid note for which this can be the returned
value, due to the validations that ensure that notes always have a
`noteable_type`.
parent 8be28faf
...@@ -106,7 +106,7 @@ class UsersController < ApplicationController ...@@ -106,7 +106,7 @@ class UsersController < ApplicationController
def calendar_activities def calendar_activities
@calendar_date = Date.parse(params[:date]) rescue Date.today @calendar_date = Date.parse(params[:date]) rescue Date.today
@events = contributions_calendar.events_by_date(@calendar_date) @events = contributions_calendar.events_by_date(@calendar_date).map(&:present)
render 'calendar_activities', layout: false render 'calendar_activities', layout: false
end end
......
...@@ -28,19 +28,7 @@ module EventsHelper ...@@ -28,19 +28,7 @@ module EventsHelper
end end
def event_action_name(event) def event_action_name(event)
target = if event.target_type target = event.note_target_type_name || event.target_type_name
if event.design? || event.design_note?
'design'
elsif event.wiki_page?
'wiki page'
elsif event.note?
event.note_target_type
else
event.target_type.titleize.downcase
end
else
'project'
end
[event.action_name, target].join(" ") [event.action_name, target].join(" ")
end end
...@@ -229,7 +217,7 @@ module EventsHelper ...@@ -229,7 +217,7 @@ module EventsHelper
def event_note_title_html(event) def event_note_title_html(event)
if event.note_target if event.note_target
capture do capture do
concat content_tag(:span, event.note_target_type, class: "event-target-type gl-mr-2") concat content_tag(:span, event.note_target_type_name, class: "event-target-type gl-mr-2")
concat link_to(event.note_target_reference, event_note_target_url(event), title: event.target_title, class: 'has-tooltip event-target-link gl-mr-2') concat link_to(event.note_target_reference, event_note_target_url(event), title: event.target_title, class: 'has-tooltip event-target-link gl-mr-2')
end end
else else
......
...@@ -329,14 +329,6 @@ class Event < ApplicationRecord ...@@ -329,14 +329,6 @@ class Event < ApplicationRecord
end end
end end
def note_target_type
if target.noteable_type.present?
target.noteable_type.titleize
else
"Wall"
end.downcase
end
def body? def body?
if push_action? if push_action?
push_with_commits? push_with_commits?
......
...@@ -29,4 +29,26 @@ class EventPresenter < Gitlab::View::Presenter::Delegated ...@@ -29,4 +29,26 @@ class EventPresenter < Gitlab::View::Presenter::Delegated
'' ''
end end
end end
def target_type_name
if design?
'Design'
elsif wiki_page?
'Wiki Page'
elsif target_type.present?
target_type.titleize
else
"Project"
end.downcase
end
def note_target_type_name
return unless note?
if design_note?
'Design'
else
target.noteable_type.titleize
end.downcase
end
end end
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
- if event.target - if event.target
%span.event-type.d-inline-block.gl-mr-2{ class: event.action_name } %span.event-type.d-inline-block.gl-mr-2{ class: event.action_name }
= event.action_name = event.action_name
%span.event-target-type.gl-mr-2= event.target_type.titleize.downcase %span.event-target-type.gl-mr-2= event.target_type_name
= link_to event.target_link_options, class: 'has-tooltip event-target-link gl-mr-2', title: event.target_title do = link_to event.target_link_options, class: 'has-tooltip event-target-link gl-mr-2', title: event.target_title do
= event.target.reference_link_text = event.target.reference_link_text
- unless event.milestone? - unless event.milestone?
......
---
title: Customize value of note_target_type for designs
merge_request: 43727
author:
type: fixed
...@@ -12,7 +12,7 @@ RSpec.describe 'Projects > Activity > User sees design comment', :js do ...@@ -12,7 +12,7 @@ RSpec.describe 'Projects > Activity > User sees design comment', :js do
let_it_be(:design) { create(:design, issue: issue) } let_it_be(:design) { create(:design, issue: issue) }
let(:design_activity) do let(:design_activity) do
"#{commenter.name} #{commenter.to_reference} commented on design" "#{commenter.name} #{commenter.to_reference} commented on design #{design.to_reference}"
end end
let(:issue_activity) do let(:issue_activity) do
......
...@@ -38,4 +38,34 @@ RSpec.describe EventPresenter do ...@@ -38,4 +38,34 @@ RSpec.describe EventPresenter do
it { is_expected.to eq([project, target]) } it { is_expected.to eq([project, target]) }
end end
end end
describe '#target_type_name' do
it 'returns design for a design event' do
expect(build(:design_event).present).to have_attributes(target_type_name: 'design')
end
it 'returns project for a project event' do
expect(build(:project_created_event).present).to have_attributes(target_type_name: 'project')
end
it 'returns milestone for a milestone event' do
expect(group_event.present).to have_attributes(target_type_name: 'milestone')
end
end
describe '#note_target_type_name' do
it 'returns design for an event on a comment on a design' do
expect(build(:event, :commented, :for_design).present)
.to have_attributes(note_target_type_name: 'design')
end
it 'returns nil for an event without a target' do
expect(build(:event).present).to have_attributes(note_target_type_name: be_nil)
end
it 'returns issue for an issue comment event' do
expect(build(:event, :commented, target: build(:note_on_issue)).present)
.to have_attributes(note_target_type_name: 'issue')
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment