Commit 5fd0e7ba119d59a3e9f2ea3eed03ece1e8baeec3
Exists in
master
and in
4 other branches
Merge pull request #1198 from NARKOZ/preview_notes
ability to preview notes
Showing
4 changed files
with
35 additions
and
6 deletions
Show diff stats
app/assets/javascripts/application.js
| ... | ... | @@ -26,7 +26,6 @@ $(document).ready(function(){ |
| 26 | 26 | $(this).select(); |
| 27 | 27 | }); |
| 28 | 28 | |
| 29 | - | |
| 30 | 29 | $('body').on('ajax:complete, ajax:beforeSend, submit', 'form', function(e){ |
| 31 | 30 | var buttons = $('[type="submit"]', this); |
| 32 | 31 | switch( e.type ){ |
| ... | ... | @@ -70,6 +69,26 @@ $(document).ready(function(){ |
| 70 | 69 | $(".supp_diff_link").bind("click", function() { |
| 71 | 70 | showDiff(this); |
| 72 | 71 | }); |
| 72 | + | |
| 73 | + /** | |
| 74 | + * Note markdown preview | |
| 75 | + * | |
| 76 | + */ | |
| 77 | + $('#preview-link').on('click', function(e) { | |
| 78 | + $('#preview-note').text('Loading...'); | |
| 79 | + | |
| 80 | + var previewLinkText = ($(this).text() == 'Preview' ? 'Edit' : 'Preview'); | |
| 81 | + $(this).text(previewLinkText); | |
| 82 | + | |
| 83 | + var note = $('#note_note').val(); | |
| 84 | + if (note.trim().length === 0) { note = 'Nothing to preview'; } | |
| 85 | + $.post($(this).attr('href'), {note: note}, function(data) { | |
| 86 | + $('#preview-note').html(data); | |
| 87 | + }); | |
| 88 | + | |
| 89 | + $('#preview-note, #note_note').toggle(); | |
| 90 | + e.preventDefault(); | |
| 91 | + }); | |
| 73 | 92 | }); |
| 74 | 93 | |
| 75 | 94 | function focusSearch() { |
| ... | ... | @@ -108,6 +127,6 @@ function showDiff(link) { |
| 108 | 127 | })(jQuery); |
| 109 | 128 | |
| 110 | 129 | |
| 111 | -function ajaxGet(url) { | |
| 112 | - $.ajax({type: "GET", url: url, dataType: "script"}); | |
| 130 | +function ajaxGet(url) { | |
| 131 | + $.ajax({type: "GET", url: url, dataType: "script"}); | |
| 113 | 132 | } | ... | ... |
app/controllers/notes_controller.rb
| ... | ... | @@ -33,7 +33,11 @@ class NotesController < ApplicationController |
| 33 | 33 | end |
| 34 | 34 | end |
| 35 | 35 | |
| 36 | - protected | |
| 36 | + def preview | |
| 37 | + render :text => view_context.markdown(params[:note]) | |
| 38 | + end | |
| 39 | + | |
| 40 | + protected | |
| 37 | 41 | |
| 38 | 42 | def notes |
| 39 | 43 | @notes = Notes::LoadContext.new(project, current_user, params).execute | ... | ... |
app/views/notes/_form.html.haml
| ... | ... | @@ -7,10 +7,12 @@ |
| 7 | 7 | |
| 8 | 8 | = f.hidden_field :noteable_id |
| 9 | 9 | = f.hidden_field :noteable_type |
| 10 | - = f.text_area :note, :size => 255 | |
| 10 | + = f.text_area :note, :size => 255 | |
| 11 | + #preview-note.well.hide | |
| 11 | 12 | %p.hint |
| 12 | 13 | = link_to "Gitlab Markdown", help_markdown_path, :target => '_blank' |
| 13 | 14 | is enabled. |
| 15 | + = link_to 'Preview', preview_project_notes_path(@project), :id => 'preview-link' | |
| 14 | 16 | |
| 15 | 17 | .row.note_advanced_opts.hide |
| 16 | 18 | .span2 | ... | ... |
config/routes.rb
| ... | ... | @@ -203,7 +203,11 @@ Gitlab::Application.routes.draw do |
| 203 | 203 | get :search |
| 204 | 204 | end |
| 205 | 205 | end |
| 206 | - resources :notes, :only => [:index, :create, :destroy] | |
| 206 | + resources :notes, :only => [:index, :create, :destroy] do | |
| 207 | + collection do | |
| 208 | + post :preview | |
| 209 | + end | |
| 210 | + end | |
| 207 | 211 | end |
| 208 | 212 | root :to => "dashboard#index" |
| 209 | 213 | end | ... | ... |