diff --git a/app/assets/stylesheets/generic/files.scss b/app/assets/stylesheets/generic/files.scss index 5aeccfe1d14e4c79d425a550a892e22e179ed726..1412277ffb6c1cc158e3f8554c84a6391b3e08b0 100644 --- a/app/assets/stylesheets/generic/files.scss +++ b/app/assets/stylesheets/generic/files.scss @@ -20,7 +20,7 @@ .options { float: right; - margin-top: -5px; + margin-top: -3px; } .left-options { diff --git a/app/assets/stylesheets/sections/snippets.scss b/app/assets/stylesheets/sections/snippets.scss index 84404b6ee36ca7b0b8d1aa0fc91c13e4292232e5..d79591d99156ffbfef51dec3772452777c6d53f8 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/assets/stylesheets/sections/tree.scss b/app/assets/stylesheets/sections/tree.scss index d0e03d5b66214b59f14bb4c7ca8ece58b1cedd72..18a5f6204feb66c3f91b291a27356a197e2058b9 100644 --- a/app/assets/stylesheets/sections/tree.scss +++ b/app/assets/stylesheets/sections/tree.scss @@ -117,15 +117,6 @@ } } -.tree-btn-group { - top: 2px; - - .btn { - margin-right: 0px; - padding: 2px 10px; - } -} - .tree-download-holder .btn { padding: 4px 12px; } diff --git a/app/models/ability.rb b/app/models/ability.rb index c60aa2d622e841e912a1544f117fb49e5b61fad0..234578b5e18b65dd9b32154fc05326d7a5ab89be 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -236,7 +236,11 @@ class Ability :"modify_#{name}", ] else - subject.respond_to?(:project) ? project_abilities(user, subject.project) : [] + if subject.respond_to?(:project) + project_abilities(user, subject.project) + else + [] + end end end end diff --git a/app/views/projects/blob/_actions.html.haml b/app/views/projects/blob/_actions.html.haml index 2f82bfe52f32122bba85be41760e395f1319bb36..cabef3c19fe66b30329b59ca423317889abf5b4d 100644 --- a/app/views/projects/blob/_actions.html.haml +++ b/app/views/projects/blob/_actions.html.haml @@ -14,6 +14,6 @@ = link_to "blame", project_blame_path(@project, @id), class: "btn btn-small" unless @blob.empty? = link_to "history", project_commits_path(@project, @id), class: "btn btn-small" - - if allowed_tree_edit? - = link_to '#modal-remove-blob', class: "remove-blob btn btn-small btn-remove", "data-toggle" => "modal" do - remove +- if allowed_tree_edit? + = link_to '#modal-remove-blob', class: "remove-blob btn btn-small btn-remove", "data-toggle" => "modal" do + remove diff --git a/app/views/projects/snippets/_blob.html.haml b/app/views/projects/snippets/_blob.html.haml deleted file mode 100644 index af326a1a99affcefafb5cb75753eae8e9a04fee0..0000000000000000000000000000000000000000 --- a/app/views/projects/snippets/_blob.html.haml +++ /dev/null @@ -1,10 +0,0 @@ -.file-holder - .file-title - %i.icon-file - %strong= @snippet.file_name - %span.options - .btn-group.tree-btn-group.pull-right - - if can?(current_user, :admin_project_snippet, @project) || @snippet.author == current_user - = link_to "Edit", edit_project_snippet_path(@project, @snippet), class: "btn btn-tiny", title: 'Edit Snippet' - = link_to "Raw", raw_project_snippet_path(@project, @snippet), class: "btn btn-tiny", target: "_blank" - = render 'snippets/blob_content' diff --git a/app/views/projects/snippets/edit.html.haml b/app/views/projects/snippets/edit.html.haml index e28b7d4937e9cff41b0d996ff6e0af0ab04974db..f6a5bf9e4ff74d508e454d18d81c41565a7eb255 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 460af34f67605d0d4efc5eeb9cb0a26768b0097e..10f684b63162650109bf1d747a4d5cc8e66ace7e 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 ac32f4866b6cc4792689b8f233d4e7c82f02da58..e4fdbd868c3a8786d9863dd65c5d64e7e2e9b700 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/snippets/_blob_content.html.haml b/app/views/shared/snippets/_blob.html.haml similarity index 100% rename from app/views/snippets/_blob_content.html.haml rename to app/views/shared/snippets/_blob.html.haml diff --git a/app/views/projects/snippets/_form.html.haml b/app/views/shared/snippets/_form.html.haml similarity index 55% rename from app/views/projects/snippets/_form.html.haml rename to app/views/shared/snippets/_form.html.haml index 866346990d3d65ff9430f5058149c59e7b127588..49ea8460e7dd32fbef3516047a391075320e0d51 100644 --- a/app/views/projects/snippets/_form.html.haml +++ b/app/views/shared/snippets/_form.html.haml @@ -1,9 +1,6 @@ -%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? + = 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| @@ -12,6 +9,23 @@ .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' @@ -29,14 +43,13 @@ - 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" + - 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 15867f071ef487a732014d9f7fdfee98d6d7c40d..0000000000000000000000000000000000000000 --- a/app/views/snippets/_blob.html.haml +++ /dev/null @@ -1,11 +0,0 @@ -.file-holder - .file-title - %i.icon-file - %strong= @snippet.file_name - %span.options - .btn-group.tree-btn-group.pull-right - - if @snippet.author == current_user - = link_to "Edit", edit_snippet_path(@snippet), class: "btn btn-tiny", title: 'Edit Snippet' - = link_to "Delete", snippet_path(@snippet), method: :delete, data: { confirm: "Are you sure?" }, class: "btn btn-tiny", title: 'Delete Snippet' - = link_to "Raw", raw_snippet_path(@snippet), class: "btn btn-tiny", target: "_blank" - = render 'snippets/blob_content' diff --git a/app/views/snippets/_form.html.haml b/app/views/snippets/_form.html.haml deleted file mode 100644 index d466dc1af14036fe6f6c88d657fb4b1dbe632f10..0000000000000000000000000000000000000000 --- 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 1b88a85faf1e4add09fdeb94acd3ca1d14d3029b..7042d07d5e8bbacf6ba445639e92ecf83a722480 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 90e0a1f79dac2414e41861f156fa58f772ca49e6..694d70583173a69cc826c54d853bf2b51f1a9d8a 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 a680e5eb5b79df96bb56e72d5431212ffa061058..1d2e3d5ae4a63f8a8f47aad1708a9734254fca43 100644 --- a/app/views/snippets/show.html.haml +++ b/app/views/snippets/show.html.haml @@ -7,9 +7,9 @@ private .pull-right - = link_to new_snippet_path, class: "btn btn-new btn-small", title: "New Snippet" do + = link_to new_snippet_path, class: "btn btn-new", title: "New Snippet" do Add new snippet - +%hr .append-bottom-20 .pull-right @@ -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/db/fixtures/development/12_snippets.rb b/db/fixtures/development/12_snippets.rb index dced2706264f9c0e098f042b14818a7fc9ca8764..ff91e8430a48433bebc67ce8fabaeec4b306376f 100644 --- a/db/fixtures/development/12_snippets.rb +++ b/db/fixtures/development/12_snippets.rb @@ -1,8 +1,8 @@ Gitlab::Seeder.quiet do contents = [ - `curl https://gist.github.com/randx/4275756/raw/da2f262920c96d1a970d48bf2e99147954b1f4bd/glus1204.sh`, - `curl https://gist.github.com/randx/3754594/raw/11026a295e6ef3a151c635707a3e1e8e15fc4725/gitlab_setup.sh `, - `curl https://gist.github.com/randx/3065552/raw/29fbd09f4605a5ea22a5a9095e35fd1938dea4d6/gistfile1.sh`, + `curl https://gist.githubusercontent.com/randx/4275756/raw/da2f262920c96d1a970d48bf2e99147954b1f4bd/glus1204.sh`, + `curl https://gist.githubusercontent.com/randx/3754594/raw/11026a295e6ef3a151c635707a3e1e8e15fc4725/gitlab_setup.sh`, + `curl https://gist.githubusercontent.com/randx/3065552/raw/29fbd09f4605a5ea22a5a9095e35fd1938dea4d6/gistfile1.sh`, ] (1..50).each do |i| diff --git a/features/project/snippets.feature b/features/project/snippets.feature index dfaa02663a03b38934f38df23df828cad3cdad94..77e42a1a38b93bc146942348a9b24e33d730713a 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 3ee8720ddd5fa963be353c5ac40da798e8762ef1..38216dd5b7bf805dbfc1e622852cd613a6c24d5b 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 c3a76bea269e9e8c20cf2250e198c8ee875155c8..feae535fbea7ac4a1df97bc97cda75a1ec44d528 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 fed54659ebca3281fa2b827c36f00e9787cc5aae..040b5390a5a96933f42d204fd6b94ca045e3554f 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