Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorNihad Abbasov <narkoz.2008@gmail.com>2011-10-27 10:46:21 +0400
committerNihad Abbasov <narkoz.2008@gmail.com>2011-10-27 10:46:21 +0400
commit8e1e17763f169f63dc99c7a0f109fe98c87b4064 (patch)
tree7be09d97cfecfa9b0158da2cf08675580b14f4e1 /app
parent117d1e90fdef3aaf64901ba18a5ce5bab4c668d8 (diff)
implement snippets lifetime
Diffstat (limited to 'app')
-rw-r--r--app/helpers/snippets_helper.rb9
-rw-r--r--app/models/snippet.rb4
-rw-r--r--app/views/snippets/_form.html.haml3
-rw-r--r--app/views/snippets/_snippet.html.haml23
-rw-r--r--app/views/snippets/show.html.haml40
5 files changed, 50 insertions, 29 deletions
diff --git a/app/helpers/snippets_helper.rb b/app/helpers/snippets_helper.rb
index 236b6c8c23a..cd7b03593c8 100644
--- a/app/helpers/snippets_helper.rb
+++ b/app/helpers/snippets_helper.rb
@@ -1,2 +1,11 @@
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
diff --git a/app/models/snippet.rb b/app/models/snippet.rb
index 0f488a8c94a..acffc76cf0d 100644
--- a/app/models/snippet.rb
+++ b/app/models/snippet.rb
@@ -33,6 +33,10 @@ class Snippet < ActiveRecord::Base
def colorize
system_colorize(content, file_name)
end
+
+ def expired?
+ expires_at && expires_at < Time.current
+ end
end
# == Schema Information
#
diff --git a/app/views/snippets/_form.html.haml b/app/views/snippets/_form.html.haml
index 7a34ae8e03f..2c9680c028d 100644
--- a/app/views/snippets/_form.html.haml
+++ b/app/views/snippets/_form.html.haml
@@ -13,6 +13,9 @@
%td= f.label :file_name
%td= f.text_field :file_name, :placeholder => "example.rb"
%tr
+ %td= f.label "Lifetime"
+ %td= f.select :expires_at, snippet_lifetime_select_options
+ %tr
%td{:colspan => 2}
= f.label :content, "Code"
%br
diff --git a/app/views/snippets/_snippet.html.haml b/app/views/snippets/_snippet.html.haml
index 483ff42cbb6..ddfba6bf80f 100644
--- a/app/views/snippets/_snippet.html.haml
+++ b/app/views/snippets/_snippet.html.haml
@@ -1,11 +1,12 @@
-%tr{ :id => dom_id(snippet), :class => "snippet", :url => project_snippet_path(@project, snippet) }
- %td
- = image_tag gravatar_icon(snippet.author.email), :class => "left", :width => 40, :style => "padding:0 5px;"
- = truncate snippet.author.name, :lenght => 20
- %td= html_escape snippet.title
- %td= html_escape snippet.file_name
- %td
- - if can?(current_user, :admin_snippet, @project) || snippet.author == current_user
- = link_to 'Edit', edit_project_snippet_path(@project, snippet), :class => "lbutton positive"
- - 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}"
+- unless snippet.expired?
+ %tr{ :id => dom_id(snippet), :class => "snippet", :url => project_snippet_path(@project, snippet) }
+ %td
+ = image_tag gravatar_icon(snippet.author.email), :class => "left", :width => 40, :style => "padding:0 5px;"
+ = truncate snippet.author.name, :lenght => 20
+ %td= html_escape snippet.title
+ %td= html_escape snippet.file_name
+ %td
+ - if can?(current_user, :admin_snippet, @project) || snippet.author == current_user
+ = link_to 'Edit', edit_project_snippet_path(@project, snippet), :class => "lbutton positive"
+ - 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}"
diff --git a/app/views/snippets/show.html.haml b/app/views/snippets/show.html.haml
index 899950b7c36..bfa1bf456e3 100644
--- a/app/views/snippets/show.html.haml
+++ b/app/views/snippets/show.html.haml
@@ -1,22 +1,26 @@
-%h2
- = "Snippet ##{@snippet.id} - #{@snippet.title}"
+- if !@snippet.expired?
+ %h2
+ = "Snippet ##{@snippet.id} - #{@snippet.title}"
-.view_file
- .view_file_header
- %strong
- = @snippet.file_name
- %br/
- .view_file_content
- :erb
- <%= raw @snippet.colorize %>
+ .view_file
+ .view_file_header
+ %strong
+ = @snippet.file_name
+ %br/
+ .view_file_content
+ :erb
+ <%= raw @snippet.colorize %>
-- if can?(current_user, :admin_snippet, @project) || @snippet.author == current_user
- = link_to 'Edit', edit_project_snippet_path(@project, @snippet), :class => "lbutton positive"
-- 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}"
-.clear
-%br
-.snippet_notes= render "notes/notes"
+ - if can?(current_user, :admin_snippet, @project) || @snippet.author == current_user
+ = link_to 'Edit', edit_project_snippet_path(@project, @snippet), :class => "lbutton positive"
+ - 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}"
+ .clear
+ %br
+ .snippet_notes= render "notes/notes"
-.clear
+ .clear
+- else
+ %h2
+ Sorry, this snipped is no longer exists