debian-mirror-gitlab/app/helpers/ide_helper.rb

81 lines
3.4 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
module IdeHelper
2023-05-27 22:25:52 +05:30
# Overridden in EE
def ide_data(project:, fork_info:, params:)
base_data = {
2022-11-25 23:54:43 +05:30
'use-new-web-ide' => use_new_web_ide?.to_s,
2023-01-13 00:05:48 +05:30
'new-web-ide-help-page-path' => help_page_path('user/project/web_ide/index.md', anchor: 'vscode-reimplementation'),
2023-06-20 00:43:36 +05:30
'sign-in-path' => new_session_path(current_user),
2022-11-25 23:54:43 +05:30
'user-preferences-path' => profile_preferences_path,
2023-04-23 21:23:45 +05:30
'editor-font-src-url' => font_url('jetbrains-mono/JetBrainsMono.woff2'),
'editor-font-family' => 'JetBrains Mono',
2023-05-27 22:25:52 +05:30
'editor-font-format' => 'woff2'
2023-04-23 21:23:45 +05:30
}.merge(use_new_web_ide? ? new_ide_data(project: project) : legacy_ide_data(project: project))
2023-05-27 22:25:52 +05:30
return base_data unless project
base_data.merge(
'fork-info' => fork_info&.to_json,
'branch-name' => params[:branch],
'file-path' => params[:path],
'merge-request' => params[:merge_request_id]
)
2022-11-25 23:54:43 +05:30
end
def use_new_web_ide?
2023-07-09 08:55:56 +05:30
Feature.enabled?(:vscode_web_ide, current_user)
2022-11-25 23:54:43 +05:30
end
private
2023-04-23 21:23:45 +05:30
def new_ide_data(project:)
2022-11-25 23:54:43 +05:30
{
2023-04-23 21:23:45 +05:30
'project-path' => project&.path_with_namespace,
2023-03-04 22:38:38 +05:30
'csp-nonce' => content_security_policy_nonce,
# We will replace these placeholders in the FE
'ide-remote-path' => ide_remote_path(remote_host: ':remote_host', remote_path: ':remote_path')
2022-11-25 23:54:43 +05:30
}
end
2023-04-23 21:23:45 +05:30
def legacy_ide_data(project:)
2019-02-15 15:39:39 +05:30
{
2021-04-17 20:07:23 +05:30
'empty-state-svg-path' => image_path('illustrations/multi_file_editor_empty.svg'),
'no-changes-state-svg-path' => image_path('illustrations/multi-editor_no_changes_empty.svg'),
'committed-state-svg-path' => image_path('illustrations/multi-editor_all_changes_committed_empty.svg'),
2023-07-09 08:55:56 +05:30
'pipelines-empty-state-svg-path': image_path('illustrations/empty-state/empty-pipeline-md.svg'),
2023-01-13 00:05:48 +05:30
'switch-editor-svg-path': image_path('illustrations/rocket-launch-md.svg'),
2021-04-17 20:07:23 +05:30
'promotion-svg-path': image_path('illustrations/web-ide_promotion.svg'),
2021-10-27 15:23:28 +05:30
'ci-help-page-path' => help_page_path('ci/quick_start/index'),
2021-04-17 20:07:23 +05:30
'web-ide-help-page-path' => help_page_path('user/project/web_ide/index.md'),
'render-whitespace-in-code': current_user.render_whitespace_in_code.to_s,
2023-04-23 21:23:45 +05:30
'default-branch' => project && project.default_branch,
'project' => convert_to_project_entity_json(project),
'enable-environments-guidance' => enable_environments_guidance?(project).to_s,
'preview-markdown-path' => project && preview_markdown_path(project),
2022-06-21 17:19:12 +05:30
'web-terminal-svg-path' => image_path('illustrations/web-ide_promotion.svg'),
'web-terminal-help-path' => help_page_path('user/project/web_ide/index.md', anchor: 'interactive-web-terminals-for-the-web-ide'),
'web-terminal-config-help-path' => help_page_path('user/project/web_ide/index.md', anchor: 'web-ide-configuration-file'),
2022-11-25 23:54:43 +05:30
'web-terminal-runners-help-path' => help_page_path('user/project/web_ide/index.md', anchor: 'runner-configuration')
2019-02-15 15:39:39 +05:30
}
end
2021-04-17 20:07:23 +05:30
def convert_to_project_entity_json(project)
return unless project
2022-01-26 12:08:38 +05:30
API::Entities::Project.represent(project, current_user: current_user).to_json
2021-04-17 20:07:23 +05:30
end
2021-06-08 01:23:25 +05:30
2023-04-23 21:23:45 +05:30
def enable_environments_guidance?(project)
experiment(:in_product_guidance_environments_webide, project: project) do |e|
2022-04-04 11:22:00 +05:30
e.candidate { !has_dismissed_ide_environments_callout? }
2021-06-08 01:23:25 +05:30
e.run
end
end
def has_dismissed_ide_environments_callout?
current_user.dismissed_callout?(feature_name: 'web_ide_ci_environments_guidance')
end
2019-02-15 15:39:39 +05:30
end