Commit 8e1e17763f169f63dc99c7a0f109fe98c87b4064
1 parent
117d1e90
Exists in
master
and in
4 other branches
implement snippets lifetime
Showing
5 changed files
with
50 additions
and
29 deletions
Show diff stats
app/helpers/snippets_helper.rb
| 1 | 1 | module SnippetsHelper |
| 2 | + def snippet_lifetime_select_options | |
| 3 | + options = [ | |
| 4 | + ['forever', nil], | |
| 5 | + ['1 day', Date.strptime("#{Date.current.day}.#{Date.current.month}.#{Date.current.year}", "%d.%m.%Y") + 1.day], | |
| 6 | + ['1 week', Date.strptime("#{Date.current.day}.#{Date.current.month}.#{Date.current.year}", "%d.%m.%Y") + 1.week], | |
| 7 | + ['1 month', Date.strptime("#{Date.current.day}.#{Date.current.month}.#{Date.current.year}", "%d.%m.%Y") + 1.month] | |
| 8 | + ] | |
| 9 | + options_for_select(options) | |
| 10 | + end | |
| 2 | 11 | end | ... | ... |
app/models/snippet.rb
app/views/snippets/_form.html.haml
| ... | ... | @@ -13,6 +13,9 @@ |
| 13 | 13 | %td= f.label :file_name |
| 14 | 14 | %td= f.text_field :file_name, :placeholder => "example.rb" |
| 15 | 15 | %tr |
| 16 | + %td= f.label "Lifetime" | |
| 17 | + %td= f.select :expires_at, snippet_lifetime_select_options | |
| 18 | + %tr | |
| 16 | 19 | %td{:colspan => 2} |
| 17 | 20 | = f.label :content, "Code" |
| 18 | 21 | %br | ... | ... |
app/views/snippets/_snippet.html.haml
| 1 | -%tr{ :id => dom_id(snippet), :class => "snippet", :url => project_snippet_path(@project, snippet) } | |
| 2 | - %td | |
| 3 | - = image_tag gravatar_icon(snippet.author.email), :class => "left", :width => 40, :style => "padding:0 5px;" | |
| 4 | - = truncate snippet.author.name, :lenght => 20 | |
| 5 | - %td= html_escape snippet.title | |
| 6 | - %td= html_escape snippet.file_name | |
| 7 | - %td | |
| 8 | - - if can?(current_user, :admin_snippet, @project) || snippet.author == current_user | |
| 9 | - = link_to 'Edit', edit_project_snippet_path(@project, snippet), :class => "lbutton positive" | |
| 10 | - - if can?(current_user, :admin_snippet, @project) || snippet.author == current_user | |
| 11 | - = link_to 'Destroy', [@project, snippet], :confirm => 'Are you sure?', :method => :delete, :remote => true, :class => "lbutton delete-snippet negative", :id => "destroy_snippet_#{snippet.id}" | |
| 1 | +- unless snippet.expired? | |
| 2 | + %tr{ :id => dom_id(snippet), :class => "snippet", :url => project_snippet_path(@project, snippet) } | |
| 3 | + %td | |
| 4 | + = image_tag gravatar_icon(snippet.author.email), :class => "left", :width => 40, :style => "padding:0 5px;" | |
| 5 | + = truncate snippet.author.name, :lenght => 20 | |
| 6 | + %td= html_escape snippet.title | |
| 7 | + %td= html_escape snippet.file_name | |
| 8 | + %td | |
| 9 | + - if can?(current_user, :admin_snippet, @project) || snippet.author == current_user | |
| 10 | + = link_to 'Edit', edit_project_snippet_path(@project, snippet), :class => "lbutton positive" | |
| 11 | + - if can?(current_user, :admin_snippet, @project) || snippet.author == current_user | |
| 12 | + = link_to 'Destroy', [@project, snippet], :confirm => 'Are you sure?', :method => :delete, :remote => true, :class => "lbutton delete-snippet negative", :id => "destroy_snippet_#{snippet.id}" | ... | ... |
app/views/snippets/show.html.haml
| 1 | -%h2 | |
| 2 | - = "Snippet ##{@snippet.id} - #{@snippet.title}" | |
| 1 | +- if !@snippet.expired? | |
| 2 | + %h2 | |
| 3 | + = "Snippet ##{@snippet.id} - #{@snippet.title}" | |
| 3 | 4 | |
| 4 | -.view_file | |
| 5 | - .view_file_header | |
| 6 | - %strong | |
| 7 | - = @snippet.file_name | |
| 8 | - %br/ | |
| 9 | - .view_file_content | |
| 10 | - :erb | |
| 11 | - <%= raw @snippet.colorize %> | |
| 5 | + .view_file | |
| 6 | + .view_file_header | |
| 7 | + %strong | |
| 8 | + = @snippet.file_name | |
| 9 | + %br/ | |
| 10 | + .view_file_content | |
| 11 | + :erb | |
| 12 | + <%= raw @snippet.colorize %> | |
| 12 | 13 | |
| 13 | -- if can?(current_user, :admin_snippet, @project) || @snippet.author == current_user | |
| 14 | - = link_to 'Edit', edit_project_snippet_path(@project, @snippet), :class => "lbutton positive" | |
| 15 | -- if can?(current_user, :admin_snippet, @project) || @snippet.author == current_user | |
| 16 | - = link_to 'Destroy', [@project, @snippet], :confirm => 'Are you sure?', :method => :delete, :class => "lbutton delete-snippet negative", :id => "destroy_snippet_#{@snippet.id}" | |
| 17 | -.clear | |
| 18 | -%br | |
| 19 | -.snippet_notes= render "notes/notes" | |
| 14 | + - if can?(current_user, :admin_snippet, @project) || @snippet.author == current_user | |
| 15 | + = link_to 'Edit', edit_project_snippet_path(@project, @snippet), :class => "lbutton positive" | |
| 16 | + - if can?(current_user, :admin_snippet, @project) || @snippet.author == current_user | |
| 17 | + = link_to 'Destroy', [@project, @snippet], :confirm => 'Are you sure?', :method => :delete, :class => "lbutton delete-snippet negative", :id => "destroy_snippet_#{@snippet.id}" | |
| 18 | + .clear | |
| 19 | + %br | |
| 20 | + .snippet_notes= render "notes/notes" | |
| 20 | 21 | |
| 21 | -.clear | |
| 22 | + .clear | |
| 22 | 23 | |
| 24 | +- else | |
| 25 | + %h2 | |
| 26 | + Sorry, this snipped is no longer exists | ... | ... |