Project snippets moved to /projects
This commit is contained in:
		
							parent
							
								
									cc869d5dc1
								
							
						
					
					
						commit
						b49cfbc1d5
					
				|  | @ -1,4 +1,4 @@ | |||
| class SnippetsController < ProjectResourceController | ||||
| class Projects::SnippetsController < Projects::ApplicationController | ||||
|   before_filter :module_enabled | ||||
|   before_filter :snippet, only: [:show, :edit, :destroy, :update, :raw] | ||||
| 
 | ||||
|  |  | |||
|  | @ -0,0 +1,12 @@ | |||
| .file_holder | ||||
|   .file_title | ||||
|     %i.icon-file | ||||
|     %strong= @snippet.file_name | ||||
|     %span.options | ||||
|       = link_to "raw", raw_project_snippet_path(@project, @snippet), class: "btn btn-tiny", target: "_blank" | ||||
|   .file_content.code | ||||
|     - unless @snippet.content.empty? | ||||
|       %div{class: user_color_scheme_class} | ||||
|         = raw @snippet.colorize(formatter: :gitlab) | ||||
|     - else | ||||
|       %p.nothing_here_message Empty file | ||||
|  | @ -0,0 +1,41 @@ | |||
| %h3.page_title | ||||
|   = @snippet.new_record? ? "New Snippet" : "Edit Snippet ##{@snippet.id}" | ||||
| %hr | ||||
| .snippet-form-holder | ||||
|   = form_for [@project, @snippet] do |f| | ||||
|     -if @snippet.errors.any? | ||||
|       .alert.alert-error | ||||
|         %ul | ||||
|           - @snippet.errors.full_messages.each do |msg| | ||||
|             %li= msg | ||||
| 
 | ||||
|     .clearfix | ||||
|       = f.label :title | ||||
|       .input= f.text_field :title, placeholder: "Example Snippet", class: 'input-xlarge', required: true | ||||
|     .clearfix | ||||
|       = f.label "Lifetime" | ||||
|       .input= f.select :expires_at, lifetime_select_options, {}, {class: 'chosen span2'} | ||||
|     .clearfix | ||||
|       .file-editor | ||||
|         = f.label :file_name, "File" | ||||
|         .input | ||||
|           .file_holder.snippet | ||||
|             .file_title | ||||
|               = f.text_field :file_name, placeholder: "example.rb", class: 'snippet-file-name', required: true | ||||
|             .file_content.code | ||||
|               %pre#editor= @snippet.content | ||||
|               = f.hidden_field :content, class: 'snippet-file-content' | ||||
| 
 | ||||
|     .form-actions | ||||
|       = f.submit 'Save', class: "btn-save btn" | ||||
|       = link_to "Cancel", project_snippets_path(@project), class: " btn" | ||||
|       - unless @snippet.new_record? | ||||
|         .pull-right= link_to 'Destroy', [@project, @snippet], confirm: 'Are you sure?', method: :delete, class: "btn pull-right danger delete-snippet", id: "destroy_snippet_#{@snippet.id}" | ||||
| 
 | ||||
| 
 | ||||
| :javascript | ||||
|   var editor = ace.edit("editor"); | ||||
|   $(".snippet-form-holder form").submit(function(){ | ||||
|     $(".snippet-file-content").val(editor.getValue()); | ||||
|   }); | ||||
| 
 | ||||
|  | @ -0,0 +1,13 @@ | |||
| %tr | ||||
|   %td | ||||
|     = image_tag gravatar_icon(snippet.author_email), class: "avatar s24" | ||||
|     %a{href: project_snippet_path(snippet.project, snippet)} | ||||
|       %strong= truncate(snippet.title, length: 60) | ||||
|   %td | ||||
|     = snippet.file_name | ||||
|   %td | ||||
|     %span.cgray | ||||
|       - if snippet.expires_at | ||||
|         = snippet.expires_at.to_date.to_s(:short) | ||||
|       - else | ||||
|         Never | ||||
|  | @ -0,0 +1 @@ | |||
| = render "snippets/form" | ||||
|  | @ -0,0 +1,19 @@ | |||
| %h3.page_title | ||||
|   Snippets | ||||
|   %small share code pastes with others out of git repository | ||||
| 
 | ||||
|   - if can? current_user, :write_snippet, @project | ||||
|     = link_to new_project_snippet_path(@project), class: "btn btn-small add_new pull-right", title: "New Snippet" do | ||||
|       Add new snippet | ||||
| %br | ||||
| %table | ||||
|   %thead | ||||
|     %tr | ||||
|       %th Title | ||||
|       %th File Name | ||||
|       %th Expires At | ||||
|   = render @snippets | ||||
|   - if @snippets.empty? | ||||
|     %tr | ||||
|       %td{colspan: 3} | ||||
|         %h3.nothing_here_message Nothing here. | ||||
|  | @ -0,0 +1 @@ | |||
| = render "snippets/form" | ||||
|  | @ -0,0 +1,9 @@ | |||
| %h3.page_title | ||||
|   = @snippet.title | ||||
|   %small= @snippet.file_name | ||||
|   - if can?(current_user, :admin_snippet, @project) || @snippet.author == current_user | ||||
|     = link_to "Edit", edit_project_snippet_path(@project, @snippet), class: "btn btn-small pull-right", title: 'Edit Snippet' | ||||
| 
 | ||||
| %br | ||||
| %div= render 'blob' | ||||
| %div#notes= render "notes/notes_with_form" | ||||
|  | @ -244,9 +244,11 @@ Gitlab::Application.routes.draw do | |||
|       end | ||||
|     end | ||||
| 
 | ||||
|     resources :snippets do | ||||
|       member do | ||||
|         get "raw" | ||||
|     scope module: :projects do | ||||
|       resources :snippets do | ||||
|         member do | ||||
|           get "raw" | ||||
|         end | ||||
|       end | ||||
|     end | ||||
| 
 | ||||
|  |  | |||
|  | @ -249,13 +249,37 @@ end | |||
| #      project_snippet GET    /:project_id/snippets/:id(.:format)      snippets#show | ||||
| #                      PUT    /:project_id/snippets/:id(.:format)      snippets#update | ||||
| #                      DELETE /:project_id/snippets/:id(.:format)      snippets#destroy | ||||
| describe SnippetsController, "routing" do | ||||
| describe Project::SnippetsController, "routing" do | ||||
|   it "to #raw" do | ||||
|     get("/gitlabhq/snippets/1/raw").should route_to('snippets#raw', project_id: 'gitlabhq', id: '1') | ||||
|     get("/gitlabhq/snippets/1/raw").should route_to('projects/snippets#raw', project_id: 'gitlabhq', id: '1') | ||||
|   end | ||||
| 
 | ||||
|   it_behaves_like "RESTful project resources" do | ||||
|     let(:controller) { 'snippets' } | ||||
|   it "to #index" do | ||||
|     get("/gitlabhq/snippets").should route_to("projects/snippets#index", project_id: 'gitlabhq') | ||||
|   end | ||||
| 
 | ||||
|   it "to #create" do | ||||
|     post("/gitlabhq/snippets").should route_to("projects/snippets#create", project_id: 'gitlabhq') | ||||
|   end | ||||
| 
 | ||||
|   it "to #new" do | ||||
|     get("/gitlabhq/snippets/new").should route_to("projects/snippets#new", project_id: 'gitlabhq') | ||||
|   end | ||||
| 
 | ||||
|   it "to #edit" do | ||||
|     get("/gitlabhq/snippets/1/edit").should route_to("projects/snippets#edit", project_id: 'gitlabhq', id: '1') | ||||
|   end | ||||
| 
 | ||||
|   it "to #show" do | ||||
|     get("/gitlabhq/snippets/1").should route_to("projects/snippets#show", project_id: 'gitlabhq', id: '1') | ||||
|   end | ||||
| 
 | ||||
|   it "to #update" do | ||||
|     put("/gitlabhq/snippets/1").should route_to("projects/snippets#update", project_id: 'gitlabhq', id: '1') | ||||
|   end | ||||
| 
 | ||||
|   it "to #destroy" do | ||||
|     delete("/gitlabhq/snippets/1").should route_to("projects/snippets#destroy", project_id: 'gitlabhq', id: '1') | ||||
|   end | ||||
| end | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue