summaryrefslogtreecommitdiff
path: root/app/presenters
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 11:18:50 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 11:18:50 +0000
commit8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch)
treea77e7fe7a93de11213032ed4ab1f33a3db51b738 /app/presenters
parent00b35af3db1abfe813a778f643dad221aad51fca (diff)
downloadgitlab-ce-8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781.tar.gz
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'app/presenters')
-rw-r--r--app/presenters/gitlab/blame_presenter.rb82
-rw-r--r--app/presenters/projects/prometheus/alert_presenter.rb8
-rw-r--r--app/presenters/release_presenter.rb2
-rw-r--r--app/presenters/snippet_presenter.rb8
4 files changed, 93 insertions, 7 deletions
diff --git a/app/presenters/gitlab/blame_presenter.rb b/app/presenters/gitlab/blame_presenter.rb
new file mode 100644
index 00000000000..db2fc52a88b
--- /dev/null
+++ b/app/presenters/gitlab/blame_presenter.rb
@@ -0,0 +1,82 @@
+# frozen_string_literal: true
+
+module Gitlab
+ class BlamePresenter < Gitlab::View::Presenter::Simple
+ include ActionView::Helpers::UrlHelper
+ include ActionView::Helpers::TranslationHelper
+ include ActionView::Context
+ include AvatarsHelper
+ include BlameHelper
+ include CommitsHelper
+ include ApplicationHelper
+ include TreeHelper
+ include IconsHelper
+
+ presents :blame
+
+ CommitData = Struct.new(
+ :author_avatar,
+ :age_map_class,
+ :commit_link,
+ :commit_author_link,
+ :project_blame_link,
+ :time_ago_tooltip)
+
+ def initialize(subject, **attributes)
+ super
+
+ @commits = {}
+ precalculate_data_by_commit!
+ end
+
+ def groups
+ @groups ||= blame.groups
+ end
+
+ def commit_data(commit)
+ @commits[commit.id] ||= get_commit_data(commit)
+ end
+
+ private
+
+ # Huge source files with a high churn rate (e.g. 'locale/gitlab.pot') could have
+ # 10x times more blame groups than unique commits across all the groups.
+ # That means we could cache per-commit data we need
+ # to avoid recalculating it multiple times.
+ # For such files, it could significantly improve the performance of the Blame.
+ def precalculate_data_by_commit!
+ groups.each { |group| commit_data(group[:commit]) }
+ end
+
+ def get_commit_data(commit)
+ CommitData.new.tap do |data|
+ data.author_avatar = author_avatar(commit, size: 36, has_tooltip: false)
+ data.age_map_class = age_map_class(commit.committed_date, project_duration)
+ data.commit_link = link_to commit.title, project_commit_path(project, commit.id), class: "cdark", title: commit.title
+ data.commit_author_link = commit_author_link(commit, avatar: false)
+ data.project_blame_link = project_blame_link(commit)
+ data.time_ago_tooltip = time_ago_with_tooltip(commit.committed_date)
+ end
+ end
+
+ def project_blame_link(commit)
+ previous_commit_id = commit.parent_id
+ return unless previous_commit_id
+
+ link_to project_blame_path(project, tree_join(previous_commit_id, path)),
+ title: _('View blame prior to this change'),
+ aria: { label: _('View blame prior to this change') },
+ data: { toggle: 'tooltip', placement: 'right', container: 'body' } do
+ versions_sprite_icon
+ end
+ end
+
+ def project_duration
+ @project_duration ||= age_map_duration(groups, project)
+ end
+
+ def versions_sprite_icon
+ @versions_sprite_icon ||= sprite_icon('doc-versions', size: 16, css_class: 'doc-versions align-text-bottom')
+ end
+ end
+end
diff --git a/app/presenters/projects/prometheus/alert_presenter.rb b/app/presenters/projects/prometheus/alert_presenter.rb
index 2114e06a8c5..6009ee4c7be 100644
--- a/app/presenters/projects/prometheus/alert_presenter.rb
+++ b/app/presenters/projects/prometheus/alert_presenter.rb
@@ -45,8 +45,8 @@ module Projects
project_issues_url(project, label_name: INCIDENT_LABEL_NAME)
end
- def starts_at
- super&.rfc3339
+ def start_time
+ starts_at&.strftime('%d %B %Y, %-l:%M%p (%Z)')
end
def issue_summary_markdown
@@ -73,7 +73,7 @@ module Projects
def metadata_list
metadata = []
- metadata << list_item('Start time', starts_at) if starts_at
+ metadata << list_item('Start time', start_time) if start_time
metadata << list_item('full_query', backtick(full_query)) if full_query
metadata << list_item(service.label.humanize, service.value) if service
metadata << list_item(monitoring_tool.label.humanize, monitoring_tool.value) if monitoring_tool
@@ -149,7 +149,7 @@ module Projects
end
def embed_time
- starts_at ? Time.rfc3339(starts_at) : Time.current
+ starts_at || Time.current
end
def alert_embed_window_params(time)
diff --git a/app/presenters/release_presenter.rb b/app/presenters/release_presenter.rb
index ea46f0a234b..7b0a3d1e7b9 100644
--- a/app/presenters/release_presenter.rb
+++ b/app/presenters/release_presenter.rb
@@ -5,7 +5,7 @@ class ReleasePresenter < Gitlab::View::Presenter::Delegated
presents :release
- delegate :project, :tag, to: :release
+ delegate :project, :tag, :assets_count, to: :release
def commit_path
return unless release.commit && can_download_code?
diff --git a/app/presenters/snippet_presenter.rb b/app/presenters/snippet_presenter.rb
index faaf7568c72..62a90025ce1 100644
--- a/app/presenters/snippet_presenter.rb
+++ b/app/presenters/snippet_presenter.rb
@@ -36,10 +36,14 @@ class SnippetPresenter < Gitlab::View::Presenter::Delegated
end
def blob
+ blobs.first
+ end
+
+ def blobs
if snippet.empty_repo?
- snippet.blob
+ [snippet.blob]
else
- snippet.blobs.first
+ snippet.blobs
end
end