Snippet restyle
This commit is contained in:
parent
ca4e2ad135
commit
0712e78597
4 changed files with 67 additions and 57 deletions
|
@ -28,6 +28,7 @@ class Snippet < ActiveRecord::Base
|
||||||
|
|
||||||
scope :fresh, order("created_at DESC")
|
scope :fresh, order("created_at DESC")
|
||||||
scope :non_expired, where(["expires_at IS NULL OR expires_at > ?", Time.current])
|
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
|
def self.content_types
|
||||||
[
|
[
|
||||||
|
|
|
@ -1,14 +1,23 @@
|
||||||
%div
|
|
||||||
.ui-box.width-100p
|
|
||||||
%h3
|
|
||||||
= @snippet.new_record? ? "New snippet" : "Edit snippet ##{@snippet.id}"
|
|
||||||
= form_for [@project, @snippet] do |f|
|
= form_for [@project, @snippet] do |f|
|
||||||
.data.no-padding
|
%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}"
|
||||||
|
|
||||||
|
%hr
|
||||||
%table.no-borders
|
%table.no-borders
|
||||||
-if @snippet.errors.any?
|
-if @snippet.errors.any?
|
||||||
%tr
|
%tr
|
||||||
%td Errors
|
%td{:colspan => 2}
|
||||||
%td
|
|
||||||
#error_explanation
|
#error_explanation
|
||||||
- @snippet.errors.full_messages.each do |msg|
|
- @snippet.errors.full_messages.each do |msg|
|
||||||
%span= msg
|
%span= msg
|
||||||
|
@ -22,7 +31,7 @@
|
||||||
%td= f.text_field :file_name, :placeholder => "example.rb"
|
%td= f.text_field :file_name, :placeholder => "example.rb"
|
||||||
%tr
|
%tr
|
||||||
%td= f.label "Lifetime"
|
%td= f.label "Lifetime"
|
||||||
%td= f.select :expires_at, lifetime_select_options
|
%td= f.select :expires_at, lifetime_select_options, {}, :style => "width:200px;"
|
||||||
%tr
|
%tr
|
||||||
%td{:colspan => 2}
|
%td{:colspan => 2}
|
||||||
= f.label :content, "Code"
|
= f.label :content, "Code"
|
||||||
|
@ -30,7 +39,15 @@
|
||||||
%br
|
%br
|
||||||
= f.text_area :content
|
= f.text_area :content
|
||||||
|
|
||||||
.buttons
|
.merge-tabs
|
||||||
= f.submit 'Save', :class => "grey-button"
|
= f.submit 'Save', :class => "grey-button"
|
||||||
- if can?(current_user, :admin_snippet, @project) || @snippet.author == current_user
|
- unless @snippet.new_record?
|
||||||
.right= link_to 'Destroy', [@project, @snippet], :confirm => 'Are you sure?', :method => :delete, :class => "grey-button delete-snippet negative", :id => "destroy_snippet_#{@snippet.id}"
|
.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();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,12 @@
|
||||||
- unless snippet.expired?
|
%a.update-item{:href => project_snippet_path(snippet.project, snippet)}
|
||||||
%tr{ :id => dom_id(snippet), :class => "snippet", :url => project_snippet_path(@project, snippet) }
|
= image_tag gravatar_icon(snippet.author_email), :class => "left", :width => 40
|
||||||
%td
|
%span.update-title
|
||||||
= image_tag gravatar_icon(snippet.author.email), :class => "left", :width => 40, :style => "padding:0 5px;"
|
= truncate(snippet.title, :length => 60)
|
||||||
%span
|
%span.update-author
|
||||||
%strong= html_escape snippet.title
|
%strong= snippet.author_name
|
||||||
%br
|
authored
|
||||||
%br
|
= time_ago_in_words(snippet.created_at)
|
||||||
%div.author
|
|
||||||
%strong= truncate snippet.author.name, :lenght => 20
|
|
||||||
%cite.cgray
|
|
||||||
= time_ago_in_words(snippet.updated_at)
|
|
||||||
ago
|
ago
|
||||||
.right.action-links
|
.right
|
||||||
- if can?(current_user, :admin_snippet, @project) || snippet.author == current_user
|
%span.tag.commit= snippet.file_name
|
||||||
= 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}"
|
|
||||||
|
|
|
@ -4,9 +4,7 @@
|
||||||
- if can? current_user, :write_snippet, @project
|
- if can? current_user, :write_snippet, @project
|
||||||
.right= link_to 'New Snippet', new_project_snippet_path(@project), :class => "grey-button append-bottom-10"
|
.right= link_to 'New Snippet', new_project_snippet_path(@project), :class => "grey-button append-bottom-10"
|
||||||
|
|
||||||
%table#snippets-table
|
- unless @snippets.fresh.empty?
|
||||||
|
%div{ :class => "update-data ui-box ui-box-small ui-box-big" }
|
||||||
|
.data
|
||||||
= render @snippets.fresh
|
= render @snippets.fresh
|
||||||
|
|
||||||
:javascript
|
|
||||||
$('.delete-snippet').live('ajax:success', function() {
|
|
||||||
$(this).closest('tr').fadeOut(); });
|
|
||||||
|
|
Loading…
Reference in a new issue