Commit 9be5425a authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Refactor snippets views

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 600f4c68
...@@ -3,3 +3,6 @@ ...@@ -3,3 +3,6 @@
padding-top: 0; padding-top: 0;
} }
.snippet-form-holder .file-holder .file-title {
padding: 2px;
}
.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'
= 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)
= 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)
%h3.page-title %h3.page-title
= @snippet.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}" = "##{@snippet.id}"
%span.light %span.light
by by
= link_to user_path(@snippet.author) do
= image_tag avatar_icon(@snippet.author_email), class: "avatar avatar-inline s16" = image_tag avatar_icon(@snippet.author_email), class: "avatar avatar-inline s16"
= @snippet.author_name = @snippet.author_name
%div= render 'projects/snippets/blob'
.back-link
= link_to project_snippets_path(@project) do
&larr; 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" %div#notes= render "projects/notes/notes_with_form"
%h3.page-title
= @snippet.new_record? ? "New Snippet" : "Edit Snippet ##{@snippet.id}"
%hr
.snippet-form-holder .snippet-form-holder
= form_for [@project, @snippet], as: :project_snippet, url: url, html: {class: "form-horizontal snippet-form"} do |f| = form_for @snippet, url: url, html: { class: "form-horizontal snippet-form" } do |f|
-if @snippet.errors.any? - if @snippet.errors.any?
.alert.alert-danger .alert.alert-danger
%ul %ul
- @snippet.errors.full_messages.each do |msg| - @snippet.errors.full_messages.each do |msg|
...@@ -12,6 +9,23 @@ ...@@ -12,6 +9,23 @@
.form-group .form-group
= f.label :title, class: 'control-label' = f.label :title, class: 'control-label'
.col-sm-10= f.text_field :title, placeholder: "Example Snippet", class: 'form-control', required: true .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 .form-group
.file-editor .file-editor
= f.label :file_name, "File", class: 'control-label' = f.label :file_name, "File", class: 'control-label'
...@@ -29,14 +43,13 @@ ...@@ -29,14 +43,13 @@
- else - else
= f.submit 'Save', class: "btn-save btn" = f.submit 'Save', class: "btn-save btn"
- unless @snippet.new_record? - if @snippet.respond_to?(:project)
.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" = link_to "Cancel", project_snippets_path(@project), class: "btn btn-cancel"
- else
= link_to "Cancel", snippets_path(@project), class: "btn btn-cancel"
:javascript :javascript
var editor = ace.edit("editor"); var editor = ace.edit("editor");
$(".snippet-form-holder form").submit(function(){ $(".snippet-form-holder form").submit(function(){
$(".snippet-file-content").val(editor.getValue()); $(".snippet-file-content").val(editor.getValue());
}); });
.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'
%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());
});
= render "snippets/form", url: snippet_path(@snippet) %h3.page-title
Edit snippet
%hr
= render "shared/snippets/form", url: snippet_path(@snippet)
= render "snippets/form", url: snippets_path(@snippet) %h3.page-title
New snippet
%hr
= render "shared/snippets/form", url: snippets_path(@snippet)
...@@ -28,4 +28,16 @@ ...@@ -28,4 +28,16 @@
= link_to snippets_path do = link_to snippets_path do
&larr; discover snippets &larr; 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'
...@@ -30,6 +30,5 @@ Feature: Project Snippets ...@@ -30,6 +30,5 @@ Feature: Project Snippets
Scenario: I destroy "Snippet one" Scenario: I destroy "Snippet one"
Given I visit snippet page "Snippet one" Given I visit snippet page "Snippet one"
And I click link "Edit"
And I click link "Remove Snippet" And I click link "Remove Snippet"
Then I should not see "Snippet one" in snippets Then I should not see "Snippet one" in snippets
...@@ -24,6 +24,5 @@ Feature: Snippets Feature ...@@ -24,6 +24,5 @@ Feature: Snippets Feature
Scenario: I destroy "Personal snippet one" Scenario: I destroy "Personal snippet one"
Given I visit snippet page "Personal snippet one" Given I visit snippet page "Personal snippet one"
And I click link "Edit"
And I click link "Destroy" And I click link "Destroy"
Then I should not see "Personal snippet one" in snippets Then I should not see "Personal snippet one" in snippets
...@@ -48,7 +48,7 @@ class ProjectSnippets < Spinach::FeatureSteps ...@@ -48,7 +48,7 @@ class ProjectSnippets < Spinach::FeatureSteps
end end
And 'I click link "Remove Snippet"' do And 'I click link "Remove Snippet"' do
click_link "Remove snippet" click_link "remove"
end end
And 'I submit new snippet "Snippet three"' do And 'I submit new snippet "Snippet three"' do
......
...@@ -19,7 +19,7 @@ class SnippetsFeature < Spinach::FeatureSteps ...@@ -19,7 +19,7 @@ class SnippetsFeature < Spinach::FeatureSteps
end end
And 'I click link "Destroy"' do And 'I click link "Destroy"' do
click_link "Remove" click_link "remove"
end end
And 'I submit new snippet "Personal snippet three"' do And 'I submit new snippet "Personal snippet three"' do
......
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