implement snippets lifetime
This commit is contained in:
parent
117d1e90fd
commit
8e1e17763f
5 changed files with 50 additions and 29 deletions
|
@ -1,2 +1,11 @@
|
||||||
module SnippetsHelper
|
module SnippetsHelper
|
||||||
|
def snippet_lifetime_select_options
|
||||||
|
options = [
|
||||||
|
['forever', nil],
|
||||||
|
['1 day', Date.strptime("#{Date.current.day}.#{Date.current.month}.#{Date.current.year}", "%d.%m.%Y") + 1.day],
|
||||||
|
['1 week', Date.strptime("#{Date.current.day}.#{Date.current.month}.#{Date.current.year}", "%d.%m.%Y") + 1.week],
|
||||||
|
['1 month', Date.strptime("#{Date.current.day}.#{Date.current.month}.#{Date.current.year}", "%d.%m.%Y") + 1.month]
|
||||||
|
]
|
||||||
|
options_for_select(options)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,6 +33,10 @@ class Snippet < ActiveRecord::Base
|
||||||
def colorize
|
def colorize
|
||||||
system_colorize(content, file_name)
|
system_colorize(content, file_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def expired?
|
||||||
|
expires_at && expires_at < Time.current
|
||||||
|
end
|
||||||
end
|
end
|
||||||
# == Schema Information
|
# == Schema Information
|
||||||
#
|
#
|
||||||
|
|
|
@ -12,6 +12,9 @@
|
||||||
%tr
|
%tr
|
||||||
%td= f.label :file_name
|
%td= f.label :file_name
|
||||||
%td= f.text_field :file_name, :placeholder => "example.rb"
|
%td= f.text_field :file_name, :placeholder => "example.rb"
|
||||||
|
%tr
|
||||||
|
%td= f.label "Lifetime"
|
||||||
|
%td= f.select :expires_at, snippet_lifetime_select_options
|
||||||
%tr
|
%tr
|
||||||
%td{:colspan => 2}
|
%td{:colspan => 2}
|
||||||
= f.label :content, "Code"
|
= f.label :content, "Code"
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
%tr{ :id => dom_id(snippet), :class => "snippet", :url => project_snippet_path(@project, snippet) }
|
- unless snippet.expired?
|
||||||
%td
|
%tr{ :id => dom_id(snippet), :class => "snippet", :url => project_snippet_path(@project, snippet) }
|
||||||
= image_tag gravatar_icon(snippet.author.email), :class => "left", :width => 40, :style => "padding:0 5px;"
|
%td
|
||||||
= truncate snippet.author.name, :lenght => 20
|
= image_tag gravatar_icon(snippet.author.email), :class => "left", :width => 40, :style => "padding:0 5px;"
|
||||||
%td= html_escape snippet.title
|
= truncate snippet.author.name, :lenght => 20
|
||||||
%td= html_escape snippet.file_name
|
%td= html_escape snippet.title
|
||||||
%td
|
%td= html_escape snippet.file_name
|
||||||
- if can?(current_user, :admin_snippet, @project) || snippet.author == current_user
|
%td
|
||||||
= link_to 'Edit', edit_project_snippet_path(@project, snippet), :class => "lbutton positive"
|
- if can?(current_user, :admin_snippet, @project) || snippet.author == current_user
|
||||||
- if can?(current_user, :admin_snippet, @project) || snippet.author == current_user
|
= link_to 'Edit', edit_project_snippet_path(@project, snippet), :class => "lbutton positive"
|
||||||
= link_to 'Destroy', [@project, snippet], :confirm => 'Are you sure?', :method => :delete, :remote => true, :class => "lbutton delete-snippet negative", :id => "destroy_snippet_#{snippet.id}"
|
- if can?(current_user, :admin_snippet, @project) || snippet.author == current_user
|
||||||
|
= link_to 'Destroy', [@project, snippet], :confirm => 'Are you sure?', :method => :delete, :remote => true, :class => "lbutton delete-snippet negative", :id => "destroy_snippet_#{snippet.id}"
|
||||||
|
|
|
@ -1,22 +1,26 @@
|
||||||
%h2
|
- if !@snippet.expired?
|
||||||
= "Snippet ##{@snippet.id} - #{@snippet.title}"
|
%h2
|
||||||
|
= "Snippet ##{@snippet.id} - #{@snippet.title}"
|
||||||
|
|
||||||
.view_file
|
.view_file
|
||||||
.view_file_header
|
.view_file_header
|
||||||
%strong
|
%strong
|
||||||
= @snippet.file_name
|
= @snippet.file_name
|
||||||
%br/
|
%br/
|
||||||
.view_file_content
|
.view_file_content
|
||||||
:erb
|
:erb
|
||||||
<%= raw @snippet.colorize %>
|
<%= raw @snippet.colorize %>
|
||||||
|
|
||||||
- if can?(current_user, :admin_snippet, @project) || @snippet.author == current_user
|
- if can?(current_user, :admin_snippet, @project) || @snippet.author == current_user
|
||||||
= link_to 'Edit', edit_project_snippet_path(@project, @snippet), :class => "lbutton positive"
|
= link_to 'Edit', edit_project_snippet_path(@project, @snippet), :class => "lbutton positive"
|
||||||
- if can?(current_user, :admin_snippet, @project) || @snippet.author == current_user
|
- if can?(current_user, :admin_snippet, @project) || @snippet.author == current_user
|
||||||
= link_to 'Destroy', [@project, @snippet], :confirm => 'Are you sure?', :method => :delete, :class => "lbutton delete-snippet negative", :id => "destroy_snippet_#{@snippet.id}"
|
= link_to 'Destroy', [@project, @snippet], :confirm => 'Are you sure?', :method => :delete, :class => "lbutton delete-snippet negative", :id => "destroy_snippet_#{@snippet.id}"
|
||||||
.clear
|
.clear
|
||||||
%br
|
%br
|
||||||
.snippet_notes= render "notes/notes"
|
.snippet_notes= render "notes/notes"
|
||||||
|
|
||||||
.clear
|
.clear
|
||||||
|
|
||||||
|
- else
|
||||||
|
%h2
|
||||||
|
Sorry, this snipped is no longer exists
|
||||||
|
|
Loading…
Reference in a new issue