From 9be5425a887d96aaf603dd537d36f410eb663e4f Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sat, 14 Jun 2014 12:36:46 +0300 Subject: Refactor snippets views Signed-off-by: Dmitriy Zaporozhets --- app/assets/stylesheets/sections/snippets.scss | 3 ++ app/views/projects/snippets/_blob.html.haml | 13 ------ app/views/projects/snippets/_form.html.haml | 42 ------------------- app/views/projects/snippets/edit.html.haml | 5 ++- app/views/projects/snippets/new.html.haml | 5 ++- app/views/projects/snippets/show.html.haml | 34 ++++++++++++++-- app/views/shared/snippets/_blob.html.haml | 14 +++++++ app/views/shared/snippets/_form.html.haml | 55 +++++++++++++++++++++++++ app/views/snippets/_blob.html.haml | 13 ------ app/views/snippets/_blob_content.html.haml | 14 ------- app/views/snippets/_form.html.haml | 58 --------------------------- app/views/snippets/edit.html.haml | 5 ++- app/views/snippets/new.html.haml | 5 ++- app/views/snippets/show.html.haml | 14 ++++++- features/project/snippets.feature | 1 - features/snippets/snippets.feature | 1 - features/steps/project/snippets.rb | 2 +- features/steps/snippets/snippets.rb | 2 +- 18 files changed, 133 insertions(+), 153 deletions(-) delete mode 100644 app/views/projects/snippets/_blob.html.haml delete mode 100644 app/views/projects/snippets/_form.html.haml create mode 100644 app/views/shared/snippets/_blob.html.haml create mode 100644 app/views/shared/snippets/_form.html.haml delete mode 100644 app/views/snippets/_blob.html.haml delete mode 100644 app/views/snippets/_blob_content.html.haml delete mode 100644 app/views/snippets/_form.html.haml diff --git a/app/assets/stylesheets/sections/snippets.scss b/app/assets/stylesheets/sections/snippets.scss index 84404b6ee36..d79591d9915 100644 --- a/app/assets/stylesheets/sections/snippets.scss +++ b/app/assets/stylesheets/sections/snippets.scss @@ -3,3 +3,6 @@ padding-top: 0; } +.snippet-form-holder .file-holder .file-title { + padding: 2px; +} diff --git a/app/views/projects/snippets/_blob.html.haml b/app/views/projects/snippets/_blob.html.haml deleted file mode 100644 index c6350cb7d1b..00000000000 --- a/app/views/projects/snippets/_blob.html.haml +++ /dev/null @@ -1,13 +0,0 @@ -.file-holder - .file-title - %i.icon-file - %span.file_name - = @snippet.file_name - .options - .btn-group - - if can?(current_user, :modify_project_snippet, @snippet) - = link_to "edit", edit_project_snippet_path(@project, @snippet), class: "btn btn-small", title: 'Edit Snippet' - = link_to "raw", raw_project_snippet_path(@project, @snippet), class: "btn btn-small", target: "_blank" - - if can?(current_user, :admin_project_snippet, @snippet) - = link_to "remove", project_snippet_path(@project, @snippet), method: :delete, data: { confirm: "Are you sure?" }, class: "btn btn-small btn-remove", title: 'Delete Snippet' - = render 'snippets/blob_content' diff --git a/app/views/projects/snippets/_form.html.haml b/app/views/projects/snippets/_form.html.haml deleted file mode 100644 index 866346990d3..00000000000 --- a/app/views/projects/snippets/_form.html.haml +++ /dev/null @@ -1,42 +0,0 @@ -%h3.page-title - = @snippet.new_record? ? "New Snippet" : "Edit Snippet ##{@snippet.id}" -%hr -.snippet-form-holder - = form_for [@project, @snippet], as: :project_snippet, url: url, html: {class: "form-horizontal snippet-form"} do |f| - -if @snippet.errors.any? - .alert.alert-danger - %ul - - @snippet.errors.full_messages.each do |msg| - %li= msg - - .form-group - = f.label :title, class: 'control-label' - .col-sm-10= f.text_field :title, placeholder: "Example Snippet", class: 'form-control', required: true - .form-group - .file-editor - = f.label :file_name, "File", class: 'control-label' - .col-sm-10 - .file-holder.snippet - .file-title - = f.text_field :file_name, placeholder: "example.rb", class: 'form-control snippet-file-name', required: true - .file-content.code - %pre#editor= @snippet.content - = f.hidden_field :content, class: 'snippet-file-content' - - .form-actions - - if @snippet.new_record? - = f.submit 'Create snippet', class: "btn-create btn" - - else - = f.submit 'Save', class: "btn-save btn" - - - unless @snippet.new_record? - .pull-right.prepend-left-20 - = link_to 'Remove snippet', project_snippet_path(@project, @snippet), data: { confirm: 'Are you sure?' }, method: :delete, class: "btn pull-right btn-remove delete-snippet prepend-left-10", id: "destroy_snippet_#{@snippet.id}" - = link_to "Cancel", project_snippets_path(@project), class: "btn btn-cancel" - -:javascript - var editor = ace.edit("editor"); - $(".snippet-form-holder form").submit(function(){ - $(".snippet-file-content").val(editor.getValue()); - }); - diff --git a/app/views/projects/snippets/edit.html.haml b/app/views/projects/snippets/edit.html.haml index e28b7d4937e..f6a5bf9e4ff 100644 --- a/app/views/projects/snippets/edit.html.haml +++ b/app/views/projects/snippets/edit.html.haml @@ -1 +1,4 @@ -= render "projects/snippets/form", url: project_snippet_path(@project, @snippet) +%h3.page-title + Edit snippet +%hr += render "shared/snippets/form", url: project_snippet_path(@project, @snippet) diff --git a/app/views/projects/snippets/new.html.haml b/app/views/projects/snippets/new.html.haml index 460af34f676..10f684b6316 100644 --- a/app/views/projects/snippets/new.html.haml +++ b/app/views/projects/snippets/new.html.haml @@ -1 +1,4 @@ -= render "projects/snippets/form", url: project_snippets_path(@project, @snippet) +%h3.page-title + New snippet +%hr += render "shared/snippets/form", url: project_snippets_path(@project, @snippet) diff --git a/app/views/projects/snippets/show.html.haml b/app/views/projects/snippets/show.html.haml index ac32f4866b6..e4fdbd868c3 100644 --- a/app/views/projects/snippets/show.html.haml +++ b/app/views/projects/snippets/show.html.haml @@ -1,11 +1,37 @@ %h3.page-title = @snippet.title - %small.pull-right + .pull-right + = link_to new_project_snippet_path(@project), class: "btn btn-new", title: "New Snippet" do + Add new snippet + +%hr + +.append-bottom-20 + .pull-right = "##{@snippet.id}" %span.light by - = image_tag avatar_icon(@snippet.author_email), class: "avatar avatar-inline s16" - = @snippet.author_name -%div= render 'projects/snippets/blob' + = link_to user_path(@snippet.author) do + = image_tag avatar_icon(@snippet.author_email), class: "avatar avatar-inline s16" + = @snippet.author_name + + .back-link + = link_to project_snippets_path(@project) do + ← project snippets + +.file-holder + .file-title + %i.icon-file + %span.file_name + = @snippet.file_name + .options + .btn-group + - if can?(current_user, :modify_project_snippet, @snippet) + = link_to "edit", edit_project_snippet_path(@project, @snippet), class: "btn btn-small", title: 'Edit Snippet' + = link_to "raw", raw_project_snippet_path(@project, @snippet), class: "btn btn-small", target: "_blank" + - if can?(current_user, :admin_project_snippet, @snippet) + = link_to "remove", project_snippet_path(@project, @snippet), method: :delete, data: { confirm: "Are you sure?" }, class: "btn btn-small btn-remove", title: 'Delete Snippet' + = render 'shared/snippets/blob' + %div#notes= render "projects/notes/notes_with_form" diff --git a/app/views/shared/snippets/_blob.html.haml b/app/views/shared/snippets/_blob.html.haml new file mode 100644 index 00000000000..8cec6168ab8 --- /dev/null +++ b/app/views/shared/snippets/_blob.html.haml @@ -0,0 +1,14 @@ +- unless @snippet.content.empty? + - if gitlab_markdown?(@snippet.file_name) + .file-content.wiki + = preserve do + = markdown(@snippet.data) + - elsif markup?(@snippet.file_name) + .file-content.wiki + = render_markup(@snippet.file_name, @snippet.data) + - else + .file-content.code + = render 'shared/file_hljs', blob: @snippet +- else + .file-content.code + .nothing-here-block Empty file diff --git a/app/views/shared/snippets/_form.html.haml b/app/views/shared/snippets/_form.html.haml new file mode 100644 index 00000000000..49ea8460e7d --- /dev/null +++ b/app/views/shared/snippets/_form.html.haml @@ -0,0 +1,55 @@ +.snippet-form-holder + = form_for @snippet, url: url, html: { class: "form-horizontal snippet-form" } do |f| + - if @snippet.errors.any? + .alert.alert-danger + %ul + - @snippet.errors.full_messages.each do |msg| + %li= msg + + .form-group + = f.label :title, class: 'control-label' + .col-sm-10= f.text_field :title, placeholder: "Example Snippet", class: 'form-control', required: true + + - unless @snippet.respond_to?(:project) + .form-group + = f.label "Access", class: 'control-label' + .col-sm-10 + = f.label :private_true, class: 'radio-label' do + = f.radio_button :private, true + %span + %strong Private + (only you can see this snippet) + %br + = f.label :private_false, class: 'radio-label' do + = f.radio_button :private, false + %span + %strong Public + (GitLab users can see this snippet) + + .form-group + .file-editor + = f.label :file_name, "File", class: 'control-label' + .col-sm-10 + .file-holder.snippet + .file-title + = f.text_field :file_name, placeholder: "example.rb", class: 'form-control snippet-file-name', required: true + .file-content.code + %pre#editor= @snippet.content + = f.hidden_field :content, class: 'snippet-file-content' + + .form-actions + - if @snippet.new_record? + = f.submit 'Create snippet', class: "btn-create btn" + - else + = f.submit 'Save', class: "btn-save btn" + + - if @snippet.respond_to?(:project) + = link_to "Cancel", project_snippets_path(@project), class: "btn btn-cancel" + - else + = link_to "Cancel", snippets_path(@project), class: "btn btn-cancel" + +:javascript + var editor = ace.edit("editor"); + $(".snippet-form-holder form").submit(function(){ + $(".snippet-file-content").val(editor.getValue()); + }); diff --git a/app/views/snippets/_blob.html.haml b/app/views/snippets/_blob.html.haml deleted file mode 100644 index 4a907011ad1..00000000000 --- a/app/views/snippets/_blob.html.haml +++ /dev/null @@ -1,13 +0,0 @@ -.file-holder - .file-title - %i.icon-file - %span.file_name - = @snippet.file_name - .options - .btn-group - - if can?(current_user, :modify_personal_snippet, @snippet) - = link_to "edit", edit_snippet_path(@snippet), class: "btn btn-small", title: 'Edit Snippet' - = link_to "raw", raw_snippet_path(@snippet), class: "btn btn-small", target: "_blank" - - if can?(current_user, :admin_personal_snippet, @snippet) - = link_to "remove", snippet_path(@snippet), method: :delete, data: { confirm: "Are you sure?" }, class: "btn btn-small btn-remove", title: 'Delete Snippet' - = render 'snippets/blob_content' diff --git a/app/views/snippets/_blob_content.html.haml b/app/views/snippets/_blob_content.html.haml deleted file mode 100644 index 8cec6168ab8..00000000000 --- a/app/views/snippets/_blob_content.html.haml +++ /dev/null @@ -1,14 +0,0 @@ -- unless @snippet.content.empty? - - if gitlab_markdown?(@snippet.file_name) - .file-content.wiki - = preserve do - = markdown(@snippet.data) - - elsif markup?(@snippet.file_name) - .file-content.wiki - = render_markup(@snippet.file_name, @snippet.data) - - else - .file-content.code - = render 'shared/file_hljs', blob: @snippet -- else - .file-content.code - .nothing-here-block Empty file diff --git a/app/views/snippets/_form.html.haml b/app/views/snippets/_form.html.haml deleted file mode 100644 index d466dc1af14..00000000000 --- a/app/views/snippets/_form.html.haml +++ /dev/null @@ -1,58 +0,0 @@ -%h3.page-title - = @snippet.new_record? ? "New Snippet" : "Edit Snippet ##{@snippet.id}" -%hr -.snippet-form-holder - = form_for @snippet, as: :personal_snippet, url: url, html: { class: "form-horizontal snippet-form" } do |f| - -if @snippet.errors.any? - .alert.alert-danger - %ul - - @snippet.errors.full_messages.each do |msg| - %li= msg - - .form-group - = f.label :title, class: 'control-label' - .col-sm-10= f.text_field :title, placeholder: "Example Snippet", class: 'form-control', required: true - .form-group - = f.label "Access", class: 'control-label' - .col-sm-10 - = f.label :private_true, class: 'radio-label' do - = f.radio_button :private, true - %span - %strong Private - (only you can see this snippet) - %br - = f.label :private_false, class: 'radio-label' do - = f.radio_button :private, false - %span - %strong Public - (GitLab users can see this snippet) - - .form-group - .file-editor - = f.label :file_name, "File", class: 'control-label' - .col-sm-10 - .file-holder.snippet - .file-title - = f.text_field :file_name, placeholder: "example.rb", class: 'form-control snippet-file-name', required: true - .file-content.code - %pre#editor= @snippet.content - = f.hidden_field :content, class: 'snippet-file-content' - - .form-actions - - if @snippet.new_record? - = f.submit 'Create snippet', class: "btn-create btn" - - else - = f.submit 'Save', class: "btn-save btn" - - - unless @snippet.new_record? - .pull-right.prepend-left-20 - = link_to 'Remove', snippet_path(@snippet), data: { confirm: 'Removed snippet cannot be restored! Are you sure?'}, method: :delete, class: "btn btn-remove delete-snippet", id: "destroy_snippet_#{@snippet.id}" - = link_to "Cancel", snippets_path(@project), class: "btn btn-cancel" - - -:javascript - var editor = ace.edit("editor"); - $(".snippet-form-holder form").submit(function(){ - $(".snippet-file-content").val(editor.getValue()); - }); - diff --git a/app/views/snippets/edit.html.haml b/app/views/snippets/edit.html.haml index 1b88a85faf1..7042d07d5e8 100644 --- a/app/views/snippets/edit.html.haml +++ b/app/views/snippets/edit.html.haml @@ -1 +1,4 @@ -= render "snippets/form", url: snippet_path(@snippet) +%h3.page-title + Edit snippet +%hr += render "shared/snippets/form", url: snippet_path(@snippet) diff --git a/app/views/snippets/new.html.haml b/app/views/snippets/new.html.haml index 90e0a1f79da..694d7058317 100644 --- a/app/views/snippets/new.html.haml +++ b/app/views/snippets/new.html.haml @@ -1 +1,4 @@ -= render "snippets/form", url: snippets_path(@snippet) +%h3.page-title + New snippet +%hr += render "shared/snippets/form", url: snippets_path(@snippet) diff --git a/app/views/snippets/show.html.haml b/app/views/snippets/show.html.haml index 655ff947d20..1d2e3d5ae4a 100644 --- a/app/views/snippets/show.html.haml +++ b/app/views/snippets/show.html.haml @@ -28,4 +28,16 @@ = link_to snippets_path do ← discover snippets -%div= render 'blob' +.file-holder + .file-title + %i.icon-file + %span.file_name + = @snippet.file_name + .options + .btn-group + - if can?(current_user, :modify_personal_snippet, @snippet) + = link_to "edit", edit_snippet_path(@snippet), class: "btn btn-small", title: 'Edit Snippet' + = link_to "raw", raw_snippet_path(@snippet), class: "btn btn-small", target: "_blank" + - if can?(current_user, :admin_personal_snippet, @snippet) + = link_to "remove", snippet_path(@snippet), method: :delete, data: { confirm: "Are you sure?" }, class: "btn btn-small btn-remove", title: 'Delete Snippet' + = render 'shared/snippets/blob' diff --git a/features/project/snippets.feature b/features/project/snippets.feature index dfaa02663a0..77e42a1a38b 100644 --- a/features/project/snippets.feature +++ b/features/project/snippets.feature @@ -30,6 +30,5 @@ Feature: Project Snippets Scenario: I destroy "Snippet one" Given I visit snippet page "Snippet one" - And I click link "Edit" And I click link "Remove Snippet" Then I should not see "Snippet one" in snippets diff --git a/features/snippets/snippets.feature b/features/snippets/snippets.feature index 3ee8720ddd5..38216dd5b7b 100644 --- a/features/snippets/snippets.feature +++ b/features/snippets/snippets.feature @@ -24,6 +24,5 @@ Feature: Snippets Feature Scenario: I destroy "Personal snippet one" Given I visit snippet page "Personal snippet one" - And I click link "Edit" And I click link "Destroy" Then I should not see "Personal snippet one" in snippets diff --git a/features/steps/project/snippets.rb b/features/steps/project/snippets.rb index c3a76bea269..feae535fbea 100644 --- a/features/steps/project/snippets.rb +++ b/features/steps/project/snippets.rb @@ -48,7 +48,7 @@ class ProjectSnippets < Spinach::FeatureSteps end And 'I click link "Remove Snippet"' do - click_link "Remove snippet" + click_link "remove" end And 'I submit new snippet "Snippet three"' do diff --git a/features/steps/snippets/snippets.rb b/features/steps/snippets/snippets.rb index fed54659ebc..040b5390a5a 100644 --- a/features/steps/snippets/snippets.rb +++ b/features/steps/snippets/snippets.rb @@ -19,7 +19,7 @@ class SnippetsFeature < Spinach::FeatureSteps end And 'I click link "Destroy"' do - click_link "Remove" + click_link "remove" end And 'I submit new snippet "Personal snippet three"' do -- cgit v1.2.1