BigW Consortium Gitlab

Commit 90f95f2b by Sean McGivern

Merge branch 'move_markdown_preview_to_concern' into 'master'

Add support for markdown preview to group milestones Closes #30241 See merge request gitlab-org/gitlab-ce!14806
parents 565a2d73 64bb1906
module PreviewMarkdown
extend ActiveSupport::Concern
def preview_markdown
result = PreviewMarkdownService.new(@project, current_user, params).execute
markdown_params =
case controller_name
when 'wikis' then { pipeline: :wiki, project_wiki: @project_wiki, page_slug: params[:id] }
when 'snippets' then { skip_project_check: true }
else {}
end
render json: {
body: view_context.markdown(result[:text], markdown_params),
references: {
users: result[:users],
commands: view_context.markdown(result[:commands])
}
}
end
end
......@@ -2,6 +2,7 @@ class GroupsController < Groups::ApplicationController
include IssuesAction
include MergeRequestsAction
include ParamsBackwardCompatibility
include PreviewMarkdown
respond_to :html
......
class Projects::WikisController < Projects::ApplicationController
include PreviewMarkdown
before_action :authorize_read_wiki!
before_action :authorize_create_wiki!, only: [:edit, :create, :history]
before_action :authorize_admin_wiki!, only: :destroy
......@@ -92,17 +94,6 @@ class Projects::WikisController < Projects::ApplicationController
def git_access
end
def preview_markdown
result = PreviewMarkdownService.new(@project, current_user, params).execute
render json: {
body: view_context.markdown(result[:text], pipeline: :wiki, project_wiki: @project_wiki, page_slug: params[:id]),
references: {
users: result[:users]
}
}
end
private
def load_project_wiki
......
class ProjectsController < Projects::ApplicationController
include IssuableCollections
include ExtractsPath
include PreviewMarkdown
before_action :authenticate_user!, except: [:index, :show, :activity, :refs]
before_action :project, except: [:index, :new, :create]
......@@ -258,18 +259,6 @@ class ProjectsController < Projects::ApplicationController
render json: options.to_json
end
def preview_markdown
result = PreviewMarkdownService.new(@project, current_user, params).execute
render json: {
body: view_context.markdown(result[:text]),
references: {
users: result[:users],
commands: view_context.markdown(result[:commands])
}
}
end
private
# Render project landing depending of which features are available
......
......@@ -4,6 +4,7 @@ class SnippetsController < ApplicationController
include SpammableActions
include SnippetsActions
include RendersBlob
include PreviewMarkdown
before_action :snippet, only: [:show, :edit, :destroy, :update, :raw]
......@@ -87,17 +88,6 @@ class SnippetsController < ApplicationController
redirect_to snippets_path, status: 302
end
def preview_markdown
result = PreviewMarkdownService.new(@project, current_user, params).execute
render json: {
body: view_context.markdown(result[:text], skip_project_check: true),
references: {
users: result[:users]
}
}
end
protected
def snippet
......
......@@ -10,7 +10,7 @@
.form-group.milestone-description
= f.label :description, "Description", class: "control-label"
.col-sm-10
= render layout: 'projects/md_preview', locals: { url: '' } do
= render layout: 'projects/md_preview', locals: { url: group_preview_markdown_path } do
= render 'projects/zen', f: f, attr: :description, classes: 'note-textarea', placeholder: 'Write milestone description...'
.clearfix
.error-alert
......
---
title: Add support for markdown preview to group milestones
merge_request: 14806
author: Vitaliy @blackst0ne Klachkov
type: fixed
require 'constraints/group_url_constrainer'
resources :groups, only: [:index, :new, :create]
resources :groups, only: [:index, :new, :create] do
post :preview_markdown
end
scope(path: 'groups/*group_id',
module: :groups,
......
......@@ -18,6 +18,27 @@ feature 'Group milestones', :js do
visit new_group_milestone_path(group)
end
it 'renders description preview' do
form = find('.gfm-form')
form.fill_in(:milestone_description, with: '')
click_link('Preview')
preview = find('.js-md-preview')
expect(preview).to have_content('Nothing to preview.')
click_link('Write')
form.fill_in(:milestone_description, with: ':+1: Nice')
click_link('Preview')
expect(preview).to have_css('gl-emoji')
expect(find('#milestone_description', visible: false)).not_to be_visible
end
it 'creates milestone with start date' do
fill_in 'Title', with: 'testing'
find('#milestone_start_date').click
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment