Correctly loads gfm autocomplete source on pages where it is required

This commit is contained in:
Phil Hughes 2016-09-05 16:38:19 +01:00
parent 3531032e16
commit a5035ed310
6 changed files with 27 additions and 7 deletions

View file

@ -57,6 +57,8 @@ v 8.12.0 (unreleased)
- Optimistic locking for Issues and Merge Requests (title and description overriding prevention)
- Add `wiki_page_events` to project hook APIs (Ben Boeckel)
- Remove Gitorious import
- Loads GFM autocomplete source only when required
- Fix issue with slash commands not loading on new issue page
- Fix inconsistent background color for filter input field (ClemMakesApps)
- Remove prefixes from transition CSS property (ClemMakesApps)
- Add Sentry logging to API calls

View file

@ -1,10 +1,6 @@
- project = @target_project || @project
- noteable_type = @noteable.class if @noteable.present?
- if noteable_type
:javascript
GitLab.GfmAutoComplete.dataLoading = false;
:javascript
GitLab.GfmAutoComplete.dataSource = "#{autocomplete_sources_namespace_project_path(project.namespace, project, type: noteable_type, type_id: params[:id])}"
GitLab.GfmAutoComplete.cachedData = undefined;

View file

@ -10,4 +10,5 @@
= render "layouts/header/default", title: header_title
= render 'layouts/page', sidebar: sidebar, nav: nav
= render "layouts/init_auto_complete" if current_user && @load_gfm
= yield :scripts_body

View file

@ -14,9 +14,6 @@
window.project_uploads_path = "#{namespace_project_uploads_path project.namespace,project}";
window.preview_markdown_path = "#{preview_markdown_path}";
- content_for :scripts_body do
= render "layouts/init_auto_complete" if current_user
- content_for :header_content do
.js-dropdown-menu-projects
.dropdown-menu.dropdown-select.dropdown-menu-projects

View file

@ -1,3 +1,4 @@
- @load_gfm = true
- supports_slash_commands = local_assigns.fetch(:supports_slash_commands, false)
.zen-backdrop
- classes << ' js-gfm-input js-autosize markdown-area'

View file

@ -0,0 +1,23 @@
require 'spec_helper'
describe 'GFM autocomplete loading', feature: true, js: true do
let(:user) { create(:user) }
let(:project) { create(:project) }
before do
project.team << [user, :master]
login_as user
visit namespace_project_path(project.namespace, project)
end
it 'does not load on project#show' do
expect(evaluate_script('GitLab.GfmAutoComplete.dataSource')).to eq('')
end
it 'loads on new issue page' do
visit new_namespace_project_issue_path(project.namespace, project)
expect(evaluate_script('GitLab.GfmAutoComplete.dataSource')).not_to eq('')
end
end