Class: ProjectPresenter
Defined Under Namespace
Classes: AnchorData
Constant Summary
collapse
- MAX_TOPICS_TO_SHOW =
3
Constants included
from IconsHelper
IconsHelper::DEFAULT_ICON_SIZE
Instance Method Summary
collapse
#clear_memoization, #strong_memoize, #strong_memoized?
#can_collaborate_with_project?, #user_access
Methods included from BlobHelper
#blob_editor_paths, #blob_icon, #blob_raw_path, #blob_raw_url, #blob_render_error_options, #blob_render_error_reason, #can_modify_blob?, #contribution_options, #copy_blob_source_button, #copy_file_path_button, #delete_blob_link, #dockerfile_names, #download_blob_button, #edit_blob_button, #edit_blob_fork_params, #edit_blob_path, #edit_button_tag, #edit_disabled_button_tag, #edit_fork_button_tag, #edit_link_tag, #edit_modify_file_fork_params, #editing_ci_config?, #editing_preview_title, #encode_ide_path, #fork_and_edit_path, #fork_path_for_current_user, #gitignore_names, #gitlab_ci_ymls, #human_access, #ide_edit_path, #ide_fork_and_edit_path, #ide_merge_request_path, #leave_edit_message, #licenses_for_select, #metrics_dashboard_ymls, #modify_file_button, #open_raw_blob_button, #parent_dir_raw_path, #readable_blob, #ref_project, #replace_blob_link, #sanitize_svg_data, #show_suggest_pipeline_creation_celebration?, #suggest_pipeline_commit_cookie_name
#audit_icon, #boolean_to_icon, #custom_icon, #external_snippet_icon, #file_type_icon_class, #gl_loading_icon, #sprite_file_icons_path, #sprite_icon, #sprite_icon_path, #visibility_level_icon
Methods included from TreeHelper
#breadcrumb_data_attributes, #can_edit_tree?, #commit_in_fork_help, #commit_in_single_accessible_branch, #directory_download_links, #edit_in_new_fork_notice, #edit_in_new_fork_notice_action, #edit_in_new_fork_notice_now, #flatten_tree, #fork_modal_options, #on_top_of_branch?, #patch_branch_name, #path_breadcrumbs, #relative_url_root, #selected_branch, #tree_edit_branch, #tree_edit_project, #tree_icon, #tree_join, #up_dir_path, #vue_file_list_data, #web_ide_button_data
#can_collaborate?, #can_create_mr_from_fork?, #can_push_code?, #edit_url, #fork?, #gitpod_url, #needs_to_fork?, #project_fork, #project_to_use, #readable_blob?, #show_edit_button?, #show_gitpod_button?, #show_pipeline_editor_button?, #show_web_ide_button?, #web_ide_url
#storage_counter, #storage_counters_details, #storage_enforcement_banner_info
#masked_page_url
#graphql_etag_pipeline_path, #graphql_etag_pipeline_sha_path, #graphql_etag_project_on_demand_scan_counts_path
#wiki_page_path, #wiki_path
#gitlab_dashboard_snippets_path, #gitlab_raw_snippet_blob_path, #gitlab_raw_snippet_blob_url, #gitlab_raw_snippet_path, #gitlab_raw_snippet_url, #gitlab_snippet_note_path, #gitlab_snippet_note_url, #gitlab_snippet_notes_path, #gitlab_snippet_notes_url, #gitlab_snippet_path, #gitlab_snippet_url, #gitlab_toggle_award_emoji_snippet_note_path, #gitlab_toggle_award_emoji_snippet_note_url, #gitlab_toggle_award_emoji_snippet_path, #gitlab_toggle_award_emoji_snippet_url, #preview_markdown_path, #toggle_award_emoji_personal_snippet_path, #toggle_award_emoji_project_project_snippet_path, #toggle_award_emoji_project_project_snippet_url
#edit_pipeline_schedule_path, #pipeline_schedule_path, #pipeline_schedules_path, #play_pipeline_schedule_path, #take_ownership_pipeline_schedule_path
#artifacts_action_path, #expose_fast_artifacts_path, #fast_browse_project_job_artifacts_path, #fast_download_project_job_artifacts_path, #fast_keep_project_job_artifacts_path
#source_members_url
#approve_access_request_group_member_path, #group_member_path, #group_members_url, #leave_group_members_path, #request_access_group_members_path, #resend_invite_group_member_path
#approve_access_request_project_member_path, #leave_project_members_path, #project_member_path, #project_members_url, #request_access_project_members_path, #resend_invite_project_member_path
#commit_url, #commits_url, #edit_milestone_path, #environment_delete_path, #environment_path, #issue_path, #issue_url, #merge_request_path, #merge_request_url, #pipeline_job_url, #pipeline_path, #pipeline_url, #project_commits_path, #project_ref_path, #project_tree_path, #release_url, #toggle_subscription_path
#expose_path, #expose_url, #issues_available?, #mrs_available?
#all_protocols_enabled?, #allowed_protocols_present?, #deprecated_attributes, #enabled_protocol, #enabled_protocol_button, #expanded_by_default?, #external_authorization_client_certificate_help_text, #external_authorization_client_key_help_text, #external_authorization_client_pass_help_text, #external_authorization_client_url_help_text, #external_authorization_description, #external_authorization_service_attributes, #external_authorization_timeout_help_text, #external_authorization_url_help_text, #http_enabled?, #import_sources_checkboxes, #instance_clusters_enabled?, #integration_expanded?, #key_restriction_options_for_select, #kroki_available_formats, #oauth_providers_checkboxes, #omnibus_protected_paths_throttle?, #pending_user_count, #registration_features_can_be_prompted?, #repository_storages_options_json, #restricted_level_checkboxes, #self_monitoring_project_data, #sidekiq_job_limiter_mode_help_text, #sidekiq_job_limiter_modes_for_select, #signup_enabled?, #ssh_enabled?, #storage_weights, #user_oauth_applications?, #valid_runner_registrars, #visible_attributes
#able_to_see_issues?, #able_to_see_merge_requests?, #any_projects?, #author_content_tag, #autodeploy_flash_notice, #can_admin_project_member?, #can_change_visibility_level?, #can_disable_emails?, #delete_confirm_phrase, #directory?, #error_tracking_setting_project_json, #explore_projects_tab?, #external_classification_label_help_message, #fork_button_disabled_tooltip, #grafana_integration_enabled?, #grafana_integration_masked_token, #grafana_integration_url, #import_from_bitbucket_message, #import_from_gitlab_message, #last_push_event, #link_to_autodeploy_doc, #link_to_member, #link_to_member_avatar, #link_to_project, #load_pipeline_status, #membership_locked?, #metrics_dashboard_timezone, #metrics_external_dashboard_url, #no_password_message, #project_can_be_shared?, #project_classes, #project_incident_management_setting, #project_license_name, #project_list_cache_key, #project_permissions_panel_data, #project_search_tabs?, #project_title, #push_to_create_project_command, #remove_fork_project_confirm_json, #remove_fork_project_description_message, #remove_fork_project_warning_message, #remove_project_message, #share_project_description, #show_auto_devops_implicitly_enabled_banner?, #show_issue_count?, #show_merge_request_count?, #show_no_password_message?, #show_no_ssh_key_message?, #show_projects?, #show_terraform_banner?, #show_xcode_link?, #transfer_project_message, #visible_fork_source, #xcode_uri_to_repo
#initialize
#delegator_override, #delegator_override_with, #delegator_target, validator, validators, verify!
#__subject__, #can?, #declarative_policy_delegate, #is_a?, #present, #url_builder, #web_path, #web_url
#can?
add_helpers, includes_helpers, redirect_legacy_paths, url_helpers
Instance Method Details
#add_changelog_ide_path ⇒ Object
119
120
121
|
# File 'app/presenters/project_presenter.rb', line 119
def add_changelog_ide_path
ide_edit_path(project, default_branch_or_main, 'CHANGELOG')
end
|
#add_changelog_path ⇒ Object
115
116
117
|
# File 'app/presenters/project_presenter.rb', line 115
def add_changelog_path
add_special_file_path(file_name: 'CHANGELOG')
end
|
#add_contribution_guide_ide_path ⇒ Object
127
128
129
|
# File 'app/presenters/project_presenter.rb', line 127
def add_contribution_guide_ide_path
ide_edit_path(project, default_branch_or_main, 'CONTRIBUTING.md')
end
|
#add_contribution_guide_path ⇒ Object
123
124
125
|
# File 'app/presenters/project_presenter.rb', line 123
def add_contribution_guide_path
add_special_file_path(file_name: 'CONTRIBUTING.md', commit_message: 'Add CONTRIBUTING')
end
|
#add_license_ide_path ⇒ Object
111
112
113
|
# File 'app/presenters/project_presenter.rb', line 111
def add_license_ide_path
ide_edit_path(project, default_branch_or_main, 'LICENSE')
end
|
#add_license_path ⇒ Object
107
108
109
|
# File 'app/presenters/project_presenter.rb', line 107
def add_license_path
add_special_file_path(file_name: 'LICENSE')
end
|
#add_readme_ide_path ⇒ Object
135
136
137
|
# File 'app/presenters/project_presenter.rb', line 135
def add_readme_ide_path
ide_edit_path(project, default_branch_or_main, 'README.md')
end
|
#add_readme_path ⇒ Object
131
132
133
|
# File 'app/presenters/project_presenter.rb', line 131
def add_readme_path
add_special_file_path(file_name: 'README.md')
end
|
#all_clusters_empty? ⇒ Boolean
405
406
407
408
409
|
# File 'app/presenters/project_presenter.rb', line 405
def all_clusters_empty?
strong_memoize(:all_clusters_empty) do
project.all_clusters.empty?
end
end
|
#autodevops_anchor_data(show_auto_devops_callout: false) ⇒ Object
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
|
# File 'app/presenters/project_presenter.rb', line 330
def autodevops_anchor_data(show_auto_devops_callout: false)
if current_user && can?(current_user, :admin_pipeline, project) && repository.gitlab_ci_yml.blank? && !show_auto_devops_callout
if auto_devops_enabled?
AnchorData.new(false,
statistic_icon('settings') + _('Auto DevOps enabled'),
project_settings_ci_cd_path(project, anchor: 'autodevops-settings'),
'btn-default')
else
AnchorData.new(false,
statistic_icon + _('Enable Auto DevOps'),
project_settings_ci_cd_path(project, anchor: 'autodevops-settings'))
end
elsif auto_devops_enabled?
AnchorData.new(false,
_('Auto DevOps enabled'),
nil)
end
end
|
#branches_anchor_data ⇒ Object
213
214
215
216
217
218
219
220
221
222
|
# File 'app/presenters/project_presenter.rb', line 213
def branches_anchor_data
AnchorData.new(true,
statistic_icon('branch') +
n_('%{strong_start}%{branch_count}%{strong_end} Branch', '%{strong_start}%{branch_count}%{strong_end} Branches', repository.branch_count).html_safe % {
branch_count: number_with_delimiter(repository.branch_count),
strong_start: '<strong class="project-stat-value">'.html_safe,
strong_end: '</strong>'.html_safe
},
empty_repo? ? nil : project_branches_path(project))
end
|
#can_current_user_push_code? ⇒ Boolean
144
145
146
147
148
149
150
151
152
|
# File 'app/presenters/project_presenter.rb', line 144
def can_current_user_push_code?
strong_memoize(:can_current_user_push_code) do
if empty_repo?
can?(current_user, :push_code, project)
else
can_current_user_push_to_branch?(default_branch)
end
end
end
|
#can_current_user_push_to_branch?(branch) ⇒ Boolean
154
155
156
157
158
|
# File 'app/presenters/project_presenter.rb', line 154
def can_current_user_push_to_branch?(branch)
return false unless current_user
user_access(project).can_push_to_branch?(branch)
end
|
#can_current_user_push_to_default_branch? ⇒ Boolean
160
161
162
|
# File 'app/presenters/project_presenter.rb', line 160
def can_current_user_push_to_default_branch?
can_current_user_push_to_branch?(default_branch)
end
|
#can_setup_review_app? ⇒ Boolean
399
400
401
402
403
|
# File 'app/presenters/project_presenter.rb', line 399
def can_setup_review_app?
strong_memoize(:can_setup_review_app) do
(can_instantiate_cluster? && all_clusters_empty?) || cicd_missing?
end
end
|
#changelog_anchor_data ⇒ Object
281
282
283
284
285
286
287
288
289
290
291
292
|
# File 'app/presenters/project_presenter.rb', line 281
def changelog_anchor_data
if can_current_user_push_to_default_branch? && repository.changelog.blank?
AnchorData.new(false,
statistic_icon + _('Add CHANGELOG'),
empty_repo? ? add_changelog_ide_path : add_changelog_path)
elsif repository.changelog.present?
AnchorData.new(false,
statistic_icon('doc-text') + _('CHANGELOG'),
changelog_path,
'btn-default')
end
end
|
#changelog_path ⇒ Object
89
90
91
|
# File 'app/presenters/project_presenter.rb', line 89
def changelog_path
filename_path(repository.changelog&.name)
end
|
#commits_anchor_data ⇒ Object
202
203
204
205
206
207
208
209
210
211
|
# File 'app/presenters/project_presenter.rb', line 202
def commits_anchor_data
AnchorData.new(true,
statistic_icon('commit') +
n_('%{strong_start}%{commit_count}%{strong_end} Commit', '%{strong_start}%{commit_count}%{strong_end} Commits', statistics.commit_count).html_safe % {
commit_count: number_with_delimiter(statistics.commit_count),
strong_start: '<strong class="project-stat-value">'.html_safe,
strong_end: '</strong>'.html_safe
},
empty_repo? ? nil : project_commits_path(project, default_branch_or_main))
end
|
#contribution_guide_anchor_data ⇒ Object
317
318
319
320
321
322
323
324
325
326
327
328
|
# File 'app/presenters/project_presenter.rb', line 317
def contribution_guide_anchor_data
if can_current_user_push_to_default_branch? && repository.contribution_guide.blank?
AnchorData.new(false,
statistic_icon + _('Add CONTRIBUTING'),
empty_repo? ? add_contribution_guide_ide_path : add_contribution_guide_path)
elsif repository.contribution_guide.present?
AnchorData.new(false,
statistic_icon('doc-text') + _('CONTRIBUTING'),
contribution_guide_path,
'btn-default')
end
end
|
#contribution_guide_path ⇒ Object
97
98
99
100
101
102
103
104
105
|
# File 'app/presenters/project_presenter.rb', line 97
def contribution_guide_path
if project && contribution_guide = repository.contribution_guide
project_blob_path(
project,
tree_join(project.default_branch,
contribution_guide.name)
)
end
end
|
387
388
389
390
391
392
393
|
# File 'app/presenters/project_presenter.rb', line 387
def
if project_topic_list.count > MAX_TOPICS_TO_SHOW
project_topic_list.count - MAX_TOPICS_TO_SHOW
else
0
end
end
|
#default_view ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'app/presenters/project_presenter.rb', line 67
def default_view
return anonymous_project_view unless current_user
user_view = current_user.project_view
if can?(current_user, :download_code, project)
user_view
elsif user_view == 'activity'
'activity'
elsif project.wiki_repository_exists? && can?(current_user, :read_wiki, project)
'wiki'
elsif can?(current_user, :read_issue, project)
'projects/issues/issues'
else
'activity'
end
end
|
#empty_repo_statistics_anchors ⇒ Object
50
51
52
|
# File 'app/presenters/project_presenter.rb', line 50
def empty_repo_statistics_anchors
[]
end
|
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'app/presenters/project_presenter.rb', line 54
def empty_repo_statistics_buttons
[
upload_anchor_data,
new_file_anchor_data,
readme_anchor_data,
license_anchor_data,
changelog_anchor_data,
contribution_guide_anchor_data,
gitlab_ci_anchor_data,
integrations_anchor_data
].compact.reject { |item| item.is_link }
end
|
#files_anchor_data ⇒ Object
164
165
166
167
168
169
170
171
172
173
|
# File 'app/presenters/project_presenter.rb', line 164
def files_anchor_data
AnchorData.new(true,
statistic_icon('doc-code') +
_('%{strong_start}%{human_size}%{strong_end} Files').html_safe % {
human_size: storage_counter(statistics.total_repository_size),
strong_start: '<strong class="project-stat-value">'.html_safe,
strong_end: '</strong>'.html_safe
},
empty_repo? ? nil : project_tree_path(project))
end
|
#gitlab_ci_anchor_data ⇒ Object
366
367
368
369
370
371
372
373
374
375
376
377
|
# File 'app/presenters/project_presenter.rb', line 366
def gitlab_ci_anchor_data
if cicd_missing?
AnchorData.new(false,
statistic_icon + _('Set up CI/CD'),
project_ci_pipeline_editor_path(project))
elsif repository.gitlab_ci_yml.present?
AnchorData.new(false,
statistic_icon('doc-text') + _('CI/CD configuration'),
project_ci_pipeline_editor_path(project),
'btn-default')
end
end
|
395
396
397
|
# File 'app/presenters/project_presenter.rb', line 395
def
> 0
end
|
#kubernetes_cluster_anchor_data ⇒ Object
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
|
# File 'app/presenters/project_presenter.rb', line 349
def kubernetes_cluster_anchor_data
if can_instantiate_cluster?
if clusters.empty?
AnchorData.new(false,
statistic_icon + _('Add Kubernetes cluster'),
project_clusters_path(project))
else
cluster_link = clusters.count == 1 ? project_cluster_path(project, clusters.first) : project_clusters_path(project)
AnchorData.new(false,
_('Kubernetes'),
cluster_link,
'btn-default')
end
end
end
|
#license_anchor_data ⇒ Object
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
|
# File 'app/presenters/project_presenter.rb', line 294
def license_anchor_data
icon = statistic_icon('scale')
if repository.license_blob.present?
AnchorData.new(false,
icon + content_tag(:span, license_short_name, class: 'project-stat-value'),
license_path,
'btn-default',
nil,
'license')
else
if can_current_user_push_to_default_branch?
AnchorData.new(false,
content_tag(:span, statistic_icon + _('Add LICENSE'), class: 'add-license-link d-flex'),
empty_repo? ? add_license_ide_path : add_license_path)
else
AnchorData.new(false,
icon + content_tag(:span, _('No license. All rights reserved'), class: 'project-stat-value'),
nil)
end
end
end
|
#license_path ⇒ Object
93
94
95
|
# File 'app/presenters/project_presenter.rb', line 93
def license_path
filename_path(repository.license_blob&.name)
end
|
#license_short_name ⇒ Object
139
140
141
142
|
# File 'app/presenters/project_presenter.rb', line 139
def license_short_name
license = repository.license
license&.nickname || license&.name || 'LICENSE'
end
|
#new_file_anchor_data ⇒ Object
256
257
258
259
260
261
262
263
264
265
|
# File 'app/presenters/project_presenter.rb', line 256
def new_file_anchor_data
if can_current_user_push_to_default_branch?
new_file_path = empty_repo? ? ide_edit_path(project, default_branch_or_main) : project_new_blob_path(project, default_branch_or_main)
AnchorData.new(false,
statistic_icon + _('New file'),
new_file_path,
'btn-dashed')
end
end
|
#readme_anchor_data ⇒ Object
267
268
269
270
271
272
273
274
275
276
277
278
279
|
# File 'app/presenters/project_presenter.rb', line 267
def readme_anchor_data
if can_current_user_push_to_default_branch? && readme_path.nil?
AnchorData.new(false,
statistic_icon + _('Add README'),
empty_repo? ? add_readme_ide_path : add_readme_path)
elsif readme_path
AnchorData.new(false,
statistic_icon('doc-text') + _('README'),
default_view != 'readme' ? readme_path : '#readme',
'btn-default',
'doc-text')
end
end
|
#readme_path ⇒ Object
85
86
87
|
# File 'app/presenters/project_presenter.rb', line 85
def readme_path
filename_path(repository.readme_path)
end
|
#releases_anchor_data ⇒ Object
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
# File 'app/presenters/project_presenter.rb', line 186
def releases_anchor_data
return unless can?(current_user, :read_release, project)
releases_count = project.releases.count
return if releases_count < 1
AnchorData.new(true,
statistic_icon('rocket') +
n_('%{strong_start}%{release_count}%{strong_end} Release', '%{strong_start}%{release_count}%{strong_end} Releases', releases_count).html_safe % {
release_count: number_with_delimiter(releases_count),
strong_start: '<strong class="project-stat-value">'.html_safe,
strong_end: '</strong>'.html_safe
},
project_releases_path(project))
end
|
#statistic_icon(icon_name = 'plus-square-o') ⇒ Object
22
23
24
|
# File 'app/presenters/project_presenter.rb', line 22
def statistic_icon(icon_name = 'plus-square-o')
sprite_icon(icon_name, css_class: 'icon gl-mr-2 gl-text-gray-500')
end
|
#statistics_anchors(show_auto_devops_callout:) ⇒ Object
26
27
28
29
30
31
32
33
34
35
|
# File 'app/presenters/project_presenter.rb', line 26
def statistics_anchors(show_auto_devops_callout:)
[
commits_anchor_data,
branches_anchor_data,
tags_anchor_data,
files_anchor_data,
storage_anchor_data,
releases_anchor_data
].compact.select(&:is_link)
end
|
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'app/presenters/project_presenter.rb', line 37
def statistics_buttons(show_auto_devops_callout:)
[
readme_anchor_data,
license_anchor_data,
changelog_anchor_data,
contribution_guide_anchor_data,
autodevops_anchor_data(show_auto_devops_callout: show_auto_devops_callout),
kubernetes_cluster_anchor_data,
gitlab_ci_anchor_data,
integrations_anchor_data
].compact.reject(&:is_link).sort_by.with_index { |item, idx| [item.class_modifier ? 0 : 1, idx] }
end
|
#storage_anchor_data ⇒ Object
175
176
177
178
179
180
181
182
183
184
|
# File 'app/presenters/project_presenter.rb', line 175
def storage_anchor_data
AnchorData.new(true,
statistic_icon('disk') +
_('%{strong_start}%{human_size}%{strong_end} Storage').html_safe % {
human_size: storage_counter(statistics.storage_size),
strong_start: '<strong class="project-stat-value">'.html_safe,
strong_end: '</strong>'.html_safe
},
empty_repo? ? nil : project_tree_path(project))
end
|
224
225
226
227
228
229
230
231
232
233
|
# File 'app/presenters/project_presenter.rb', line 224
def tags_anchor_data
AnchorData.new(true,
statistic_icon('label') +
n_('%{strong_start}%{tag_count}%{strong_end} Tag', '%{strong_start}%{tag_count}%{strong_end} Tags', repository.tag_count).html_safe % {
tag_count: number_with_delimiter(repository.tag_count),
strong_start: '<strong class="project-stat-value">'.html_safe,
strong_end: '</strong>'.html_safe
},
empty_repo? ? nil : project_tags_path(project))
end
|
#topics_not_shown ⇒ Object
383
384
385
|
# File 'app/presenters/project_presenter.rb', line 383
def topics_not_shown
project_topic_list - topics_to_show
end
|
#topics_to_show ⇒ Object
379
380
381
|
# File 'app/presenters/project_presenter.rb', line 379
def topics_to_show
project_topic_list.take(MAX_TOPICS_TO_SHOW) end
|
#upload_anchor_data ⇒ Object
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
# File 'app/presenters/project_presenter.rb', line 235
def upload_anchor_data
strong_memoize(:upload_anchor_data) do
next unless can_current_user_push_to_default_branch?
AnchorData.new(false,
statistic_icon('upload') + _('Upload file'),
'#modal-upload-blob',
'js-upload-file-trigger',
nil,
nil,
{
'target_branch' => default_branch_or_main,
'original_branch' => default_branch_or_main,
'can_push_code' => 'true',
'path' => project_create_blob_path(project, default_branch_or_main),
'project_path' => project.full_path
}
)
end
end
|