diff --git a/app/models/snippet.rb b/app/models/snippet.rb index 6db5e2dde70..d849a1d3f61 100644 --- a/app/models/snippet.rb +++ b/app/models/snippet.rb @@ -28,6 +28,7 @@ class Snippet < ActiveRecord::Base scope :fresh, order("created_at DESC") scope :non_expired, where(["expires_at IS NULL OR expires_at > ?", Time.current]) + scope :expired, where(["expires_at IS NOT NULL AND expires_at < ?", Time.current]) def self.content_types [ diff --git a/app/views/snippets/_form.html.haml b/app/views/snippets/_form.html.haml index b7bebbee753..af058fbfa0f 100644 --- a/app/views/snippets/_form.html.haml +++ b/app/views/snippets/_form.html.haml @@ -1,36 +1,53 @@ -%div - .ui-box.width-100p - %h3 - = @snippet.new_record? ? "New snippet" : "Edit snippet ##{@snippet.id}" - = form_for [@project, @snippet] do |f| - .data.no-padding - %table.no-borders - -if @snippet.errors.any? - %tr - %td Errors - %td - #error_explanation - - @snippet.errors.full_messages.each do |msg| - %span= msg - %br += form_for [@project, @snippet] do |f| + %div + %span.entity-info + - if @snippet.new_record? + = link_to project_snippets_path(@project) do + .entity-button + Back + %i + - else + = link_to project_snippet_path(@project, @snippet) do + .entity-button + Back + %i + %h2= @snippet.new_record? ? "New Snippet" : "Edit Snippet ##{@snippet.id}" - %tr - %td= f.label :title - %td= f.text_field :title, :placeholder => "Example Snippet" - %tr - %td= f.label :file_name - %td= f.text_field :file_name, :placeholder => "example.rb" - %tr - %td= f.label "Lifetime" - %td= f.select :expires_at, lifetime_select_options - %tr - %td{:colspan => 2} - = f.label :content, "Code" + %hr + %table.no-borders + -if @snippet.errors.any? + %tr + %td{:colspan => 2} + #error_explanation + - @snippet.errors.full_messages.each do |msg| + %span= msg %br - %br - = f.text_area :content - .buttons - = f.submit 'Save', :class => "grey-button" - - if can?(current_user, :admin_snippet, @project) || @snippet.author == current_user - .right= link_to 'Destroy', [@project, @snippet], :confirm => 'Are you sure?', :method => :delete, :class => "grey-button delete-snippet negative", :id => "destroy_snippet_#{@snippet.id}" + %tr + %td= f.label :title + %td= f.text_field :title, :placeholder => "Example Snippet" + %tr + %td= f.label :file_name + %td= f.text_field :file_name, :placeholder => "example.rb" + %tr + %td= f.label "Lifetime" + %td= f.select :expires_at, lifetime_select_options, {}, :style => "width:200px;" + %tr + %td{:colspan => 2} + = f.label :content, "Code" + %br + %br + = f.text_area :content + + .merge-tabs + = f.submit 'Save', :class => "grey-button" + - unless @snippet.new_record? + .right= link_to 'Destroy', [@project, @snippet], :confirm => 'Are you sure?', :method => :delete, :class => "red-button delete-snippet", :id => "destroy_snippet_#{@snippet.id}" + + + +:javascript + $(function(){ + $('select#snippet_expires_at').chosen(); + }); + diff --git a/app/views/snippets/_snippet.html.haml b/app/views/snippets/_snippet.html.haml index dc45e132c9f..f8a483085ea 100644 --- a/app/views/snippets/_snippet.html.haml +++ b/app/views/snippets/_snippet.html.haml @@ -1,18 +1,12 @@ -- 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;" - %span - %strong= html_escape snippet.title - %br - %br - %div.author - %strong= truncate snippet.author.name, :lenght => 20 - %cite.cgray - = time_ago_in_words(snippet.updated_at) - ago - .right.action-links - - if can?(current_user, :admin_snippet, @project) || snippet.author == current_user - = link_to 'Edit', edit_project_snippet_path(@project, snippet), :class => "cgray" - - 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 => "cred delete-snippet negative", :id => "destroy_snippet_#{snippet.id}" +%a.update-item{:href => project_snippet_path(snippet.project, snippet)} + = image_tag gravatar_icon(snippet.author_email), :class => "left", :width => 40 + %span.update-title + = truncate(snippet.title, :length => 60) + %span.update-author + %strong= snippet.author_name + authored + = time_ago_in_words(snippet.created_at) + ago + .right + %span.tag.commit= snippet.file_name + diff --git a/app/views/snippets/index.html.haml b/app/views/snippets/index.html.haml index 677fe9de8b1..f08a3d1d673 100644 --- a/app/views/snippets/index.html.haml +++ b/app/views/snippets/index.html.haml @@ -4,9 +4,7 @@ - if can? current_user, :write_snippet, @project .right= link_to 'New Snippet', new_project_snippet_path(@project), :class => "grey-button append-bottom-10" -%table#snippets-table - = render @snippets.fresh - -:javascript - $('.delete-snippet').live('ajax:success', function() { - $(this).closest('tr').fadeOut(); }); +- unless @snippets.fresh.empty? + %div{ :class => "update-data ui-box ui-box-small ui-box-big" } + .data + = render @snippets.fresh