2021-05-14 18:10:34 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Analytics
|
|
|
|
module CycleAnalytics
|
|
|
|
class StageEntity < Grape::Entity
|
2021-11-30 15:14:19 +00:00
|
|
|
include ActionView::Context
|
|
|
|
include LabelsHelper
|
|
|
|
include ActionView::Helpers::TagHelper
|
|
|
|
|
2021-05-14 18:10:34 +00:00
|
|
|
expose :title
|
|
|
|
expose :hidden
|
|
|
|
expose :legend
|
|
|
|
expose :description
|
|
|
|
expose :id
|
|
|
|
expose :custom
|
2021-07-07 18:08:30 +00:00
|
|
|
|
|
|
|
# new API
|
|
|
|
expose :start_event do
|
|
|
|
expose :start_event_identifier, as: :identifier, if: -> (s) { s.custom? }
|
|
|
|
expose :start_event_label, as: :label, using: LabelEntity, if: -> (s) { s.start_event_label_based? }
|
|
|
|
expose :start_event_html_description, as: :html_description
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :end_event do
|
|
|
|
expose :end_event_identifier, as: :identifier, if: -> (s) { s.custom? }
|
|
|
|
expose :end_event_label, as: :label, using: LabelEntity, if: -> (s) { s.end_event_label_based? }
|
|
|
|
expose :end_event_html_description, as: :html_description
|
|
|
|
end
|
|
|
|
|
|
|
|
# old API
|
2021-05-14 18:10:34 +00:00
|
|
|
expose :start_event_identifier, if: -> (s) { s.custom? }
|
|
|
|
expose :end_event_identifier, if: -> (s) { s.custom? }
|
|
|
|
expose :start_event_label, using: LabelEntity, if: -> (s) { s.start_event_label_based? }
|
|
|
|
expose :end_event_label, using: LabelEntity, if: -> (s) { s.end_event_label_based? }
|
|
|
|
expose :start_event_html_description
|
|
|
|
expose :end_event_html_description
|
|
|
|
|
|
|
|
def id
|
|
|
|
object.id || object.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def start_event_html_description
|
|
|
|
html_description(object.start_event)
|
|
|
|
end
|
|
|
|
|
|
|
|
def end_event_html_description
|
|
|
|
html_description(object.end_event)
|
|
|
|
end
|
|
|
|
|
2021-11-30 15:14:19 +00:00
|
|
|
# Avoid including ActionView::Helpers::UrlHelper
|
|
|
|
def link_to(*args)
|
|
|
|
ActionController::Base.helpers.link_to(*args)
|
|
|
|
end
|
|
|
|
|
2021-05-14 18:10:34 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def html_description(event)
|
2021-11-30 15:14:19 +00:00
|
|
|
options = {}
|
|
|
|
if event.label_based?
|
2022-03-03 15:16:42 +00:00
|
|
|
label = event.label.present(issuable_subject: event.label.subject)
|
2022-03-03 00:20:18 +00:00
|
|
|
options[:label_html] = render_label(label, link: '', small: true, tooltip: true)
|
2021-11-30 15:14:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
content_tag(:p) { event.html_description(options).html_safe }
|
2021-05-14 18:10:34 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|