diff options
Diffstat (limited to 'app/helpers/issuables_helper.rb')
-rw-r--r-- | app/helpers/issuables_helper.rb | 237 |
1 files changed, 80 insertions, 157 deletions
diff --git a/app/helpers/issuables_helper.rb b/app/helpers/issuables_helper.rb index c83545fa7a7..7f948db2f71 100644 --- a/app/helpers/issuables_helper.rb +++ b/app/helpers/issuables_helper.rb @@ -33,22 +33,6 @@ module IssuablesHelper end end - def sidebar_milestone_tooltip_label(milestone) - return _('Milestone') unless milestone.present? - - [escape_once(milestone[:title]), sidebar_milestone_remaining_days(milestone) || _('Milestone')].join('<br/>') - end - - def sidebar_milestone_remaining_days(milestone) - due_date_with_remaining_days(milestone[:due_date], milestone[:start_date]) - end - - def due_date_with_remaining_days(due_date, start_date = nil) - return unless due_date - - "#{due_date.to_fs(:medium)} (#{remaining_days_in_words(due_date, start_date)})" - end - def multi_label_name(current_labels, default_label) return default_label if current_labels.blank? @@ -131,46 +115,6 @@ module IssuablesHelper end # rubocop: enable CodeReuse/ActiveRecord - def issuable_meta_author_status(author) - return "" unless author&.status&.customized? && status = user_status(author) - - status.to_s.html_safe - end - - def issuable_meta(issuable, project) - output = [] - - if issuable.respond_to?(:work_item_type) && WorkItems::Type::WI_TYPES_WITH_CREATED_HEADER.include?(issuable.issue_type) - output << content_tag(:span, sprite_icon(issuable.work_item_type.icon_name.to_s, css_class: 'gl-icon gl-vertical-align-middle gl-text-gray-500'), class: 'gl-mr-2', aria: { hidden: 'true' }) - output << content_tag(:span, s_('IssuableStatus|%{wi_type} created %{created_at} by ').html_safe % { wi_type: IntegrationsHelper.integration_issue_type(issuable.issue_type), created_at: time_ago_with_tooltip(issuable.created_at) }, class: 'gl-mr-2') - else - output << content_tag(:span, s_('IssuableStatus|Created %{created_at} by').html_safe % { created_at: time_ago_with_tooltip(issuable.created_at) }, class: 'gl-mr-2') - end - - if issuable.is_a?(Issue) && issuable.service_desk_reply_to - output << "#{html_escape(issuable.present(current_user: current_user).service_desk_reply_to)} via " - end - - output << content_tag(:strong) do - author_output = link_to_member(project, issuable.author, size: 24, mobile_classes: "d-none d-sm-inline-block") - author_output << link_to_member(project, issuable.author, size: 24, by_username: true, avatar: false, mobile_classes: "d-inline d-sm-none") - - author_output << issuable_meta_author_status(issuable.author) - - author_output - end - - if access = project.team.human_max_access(issuable.author_id) - output << content_tag(:span, access, class: "user-access-role has-tooltip d-none d-xl-inline-block gl-ml-3 ", title: _("This user has the %{access} role in the %{name} project.") % { access: access.downcase, name: project.name }) - elsif project.team.contributor?(issuable.author_id) - output << content_tag(:span, _("Contributor"), class: "user-access-role has-tooltip d-none d-xl-inline-block gl-ml-3", title: _("This user has previously committed to the %{name} project.") % { name: project.name }) - end - - output << content_tag(:span, (sprite_icon('first-contribution', css_class: 'gl-icon gl-vertical-align-middle') if issuable.first_contribution?), class: 'has-tooltip gl-ml-2', title: _('1st contribution!')) - - output.join.html_safe - end - def issuables_state_counter_text(issuable_type, state, display_count) titles = { opened: _("Open"), @@ -248,71 +192,6 @@ module IssuablesHelper data end - def issue_only_initial_data(issuable) - return {} unless issuable.is_a?(Issue) - - data = { - authorId: issuable.author.id, - authorName: issuable.author.name, - authorUsername: issuable.author.username, - authorWebUrl: url_for(user_path(issuable.author)), - createdAt: issuable.created_at.to_time.iso8601, - hasClosingMergeRequest: issuable.merge_requests_count(current_user) != 0, - isFirstContribution: issuable.first_contribution?, - issueType: issuable.issue_type, - serviceDeskReplyTo: issuable.present(current_user: current_user).service_desk_reply_to, - zoomMeetingUrl: ZoomMeeting.canonical_meeting_url(issuable), - sentryIssueIdentifier: SentryIssue.find_by(issue: issuable)&.sentry_issue_identifier, # rubocop:disable CodeReuse/ActiveRecord - iid: issuable.iid.to_s, - isHidden: issue_hidden?(issuable), - canCreateIncident: create_issue_type_allowed?(issuable.project, :incident), - **incident_only_initial_data(issuable) - } - - data.tap do |d| - if issuable.duplicated? && can?(current_user, :read_issue, issuable.duplicated_to) - d[:duplicatedToIssueUrl] = url_for([issuable.duplicated_to.project, issuable.duplicated_to, { only_path: false }]) - end - - if issuable.moved? && can?(current_user, :read_issue, issuable.moved_to) - d[:movedToIssueUrl] = url_for([issuable.moved_to.project, issuable.moved_to, { only_path: false }]) - end - end - end - - def incident_only_initial_data(issue) - return {} unless issue.incident_type_issue? - - { - hasLinkedAlerts: issue.alert_management_alerts.any?, - canUpdateTimelineEvent: can?(current_user, :admin_incident_management_timeline_event, issue), - currentPath: url_for(safe_params), - currentTab: safe_params[:incident_tab] - } - end - - def path_data(parent) - return { groupPath: parent.path } if parent.is_a?(Group) - - { - projectPath: ref_project.path, - projectId: ref_project.id, - projectNamespace: ref_project.namespace.full_path - } - end - - def updated_at_by(issuable) - return {} unless issuable.edited? - - { - updatedAt: issuable.last_edited_at.to_time.iso8601, - updatedBy: { - name: issuable.last_edited_by.name, - path: user_path(issuable.last_edited_by) - } - } - end - def issuables_count_for_state(issuable_type, state) Gitlab::IssuablesCountForState.new(finder, fast_fail: true, store_in_redis_cache: true)[state] end @@ -333,15 +212,6 @@ module IssuablesHelper issuable.author == current_user end - def issuable_display_type(issuable) - case issuable - when Issue - issuable.issue_type.downcase - when MergeRequest - issuable.model_name.human.downcase - end - end - def has_filter_bar_param? finder.class.scalar_params.any? { |p| params[p].present? } end @@ -353,12 +223,6 @@ module IssuablesHelper end end - def reviewer_sidebar_data(reviewer, merge_request: nil) - { avatar_url: reviewer.avatar_url, name: reviewer.name, username: reviewer.username }.tap do |data| - data[:can_merge] = merge_request.can_be_merged_by?(reviewer) if merge_request - end - end - def issuable_squash_option?(issuable, project) if issuable.persisted? issuable.squash @@ -428,27 +292,6 @@ module IssuablesHelper cookies[:collapsed_gutter] == 'true' end - def issuable_todo_button_data(issuable, is_collapsed) - { - todo_text: _('Add a to do'), - mark_text: _('Mark as done'), - todo_icon: sprite_icon('todo-add'), - mark_icon: sprite_icon('todo-done', css_class: 'todo-undone'), - issuable_id: issuable[:id], - issuable_type: issuable[:type], - create_path: issuable[:create_todo_path], - delete_path: issuable.dig(:current_user, :todo, :delete_path), - placement: is_collapsed ? 'left' : nil, - container: is_collapsed ? 'body' : nil, - boundary: 'viewport', - is_collapsed: is_collapsed, - track_label: "right_sidebar", - track_property: "update_todo", - track_action: "click_button", - track_value: "" - } - end - def close_reopen_params(issuable, action) { issuable.model_name.to_s.underscore => { state_event: action } @@ -520,6 +363,86 @@ module IssuablesHelper number_with_delimiter(count) end end + + def issue_only_initial_data(issuable) + return {} unless issuable.is_a?(Issue) + + { + canCreateIncident: create_issue_type_allowed?(issuable.project, :incident), + fullPath: issuable.project.full_path, + iid: issuable.iid, + issuableId: issuable.id, + issueType: issuable.issue_type, + isHidden: issue_hidden?(issuable), + sentryIssueIdentifier: SentryIssue.find_by(issue: issuable)&.sentry_issue_identifier, # rubocop:disable CodeReuse/ActiveRecord + zoomMeetingUrl: ZoomMeeting.canonical_meeting_url(issuable), + **incident_only_initial_data(issuable), + **issue_header_data(issuable), + **work_items_data + } + end + + def incident_only_initial_data(issue) + return {} unless issue.incident_type_issue? + + { + hasLinkedAlerts: issue.alert_management_alerts.any?, + canUpdateTimelineEvent: can?(current_user, :admin_incident_management_timeline_event, issue), + currentPath: url_for(safe_params), + currentTab: safe_params[:incident_tab] + } + end + + def issue_header_data(issuable) + data = { + authorId: issuable.author.id, + authorName: issuable.author.name, + authorUsername: issuable.author.username, + authorWebUrl: url_for(user_path(issuable.author)), + createdAt: issuable.created_at.to_time.iso8601, + isFirstContribution: issuable.first_contribution?, + serviceDeskReplyTo: issuable.present(current_user: current_user).service_desk_reply_to + } + + data.tap do |d| + if issuable.duplicated? && can?(current_user, :read_issue, issuable.duplicated_to) + d[:duplicatedToIssueUrl] = url_for([issuable.duplicated_to.project, issuable.duplicated_to, { only_path: false }]) + end + + if issuable.moved? && can?(current_user, :read_issue, issuable.moved_to) + d[:movedToIssueUrl] = url_for([issuable.moved_to.project, issuable.moved_to, { only_path: false }]) + end + end + end + + def work_items_data + { + registerPath: new_user_registration_path(redirect_to_referer: 'yes'), + signInPath: new_session_path(:user, redirect_to_referer: 'yes') + } + end + + def path_data(parent) + return { groupPath: parent.path } if parent.is_a?(Group) + + { + projectPath: ref_project.path, + projectId: ref_project.id, + projectNamespace: ref_project.namespace.full_path + } + end + + def updated_at_by(issuable) + return {} unless issuable.edited? + + { + updatedAt: issuable.last_edited_at.to_time.iso8601, + updatedBy: { + name: issuable.last_edited_by.name, + path: user_path(issuable.last_edited_by) + } + } + end end IssuablesHelper.prepend_mod_with('IssuablesHelper') |