From 9710e42d798556ecaf0ffeaf4806a117c1b3530c Mon Sep 17 00:00:00 2001
From: Andrew8xx8 <avk@8xx8.ru>
Date: Mon, 25 Mar 2013 01:16:52 +0400
Subject: [PATCH] Layuot and templates for personal snippets added

---
 app/views/snippets/_blob.html.haml      |  2 +-
 app/views/snippets/_form.html.haml      |  9 +++++---
 app/views/snippets/_snippet.html.haml   | 15 +++++++++++--
 app/views/snippets/_snippets.html.haml  | 13 ++++++++++++
 app/views/snippets/edit.html.haml       |  2 +-
 app/views/snippets/index.html.haml      | 28 ++++++++++++-------------
 app/views/snippets/new.html.haml        |  2 +-
 app/views/snippets/show.html.haml       | 10 ++++++---
 app/views/snippets/user_index.html.haml | 20 ++++++++++++++++++
 9 files changed, 75 insertions(+), 26 deletions(-)
 create mode 100644 app/views/snippets/_snippets.html.haml
 create mode 100644 app/views/snippets/user_index.html.haml

diff --git a/app/views/snippets/_blob.html.haml b/app/views/snippets/_blob.html.haml
index 017a33b34f3..56e62f0d6b3 100644
--- a/app/views/snippets/_blob.html.haml
+++ b/app/views/snippets/_blob.html.haml
@@ -3,7 +3,7 @@
     %i.icon-file
     %strong= @snippet.file_name
     %span.options
-      = link_to "raw", raw_project_snippet_path(@project, @snippet), class: "btn btn-tiny", target: "_blank"
+      = link_to "raw", raw_snippet_path(@snippet), class: "btn btn-tiny", target: "_blank"
   .file_content.code
     - unless @snippet.content.empty?
       %div{class: user_color_scheme_class}
diff --git a/app/views/snippets/_form.html.haml b/app/views/snippets/_form.html.haml
index 77162cdcde3..d9514890b20 100644
--- a/app/views/snippets/_form.html.haml
+++ b/app/views/snippets/_form.html.haml
@@ -2,7 +2,7 @@
   = @snippet.new_record? ? "New Snippet" : "Edit Snippet ##{@snippet.id}"
 %hr
 .snippet-form-holder
-  = form_for [@project, @snippet] do |f|
+  = form_for @snippet, as: :personal_snippet, url: url do |f|
     -if @snippet.errors.any?
       .alert.alert-error
         %ul
@@ -12,6 +12,9 @@
     .clearfix
       = f.label :title
       .input= f.text_field :title, placeholder: "Example Snippet", class: 'input-xlarge', required: true
+    .clearfix
+      = f.label "Private?"
+      .input= f.check_box :private, {class: ''}
     .clearfix
       = f.label "Lifetime"
       .input= f.select :expires_at, lifetime_select_options, {}, {class: 'chosen span2'}
@@ -28,9 +31,9 @@
 
     .form-actions
       = f.submit 'Save', class: "btn-save btn"
-      = link_to "Cancel", project_snippets_path(@project), class: " btn"
+      = link_to "Cancel", snippets_path(@project), class: " btn"
       - unless @snippet.new_record?
-        .pull-right= link_to 'Destroy', [@project, @snippet], confirm: 'Are you sure?', method: :delete, class: "btn pull-right danger delete-snippet", id: "destroy_snippet_#{@snippet.id}"
+        .pull-right= link_to 'Destroy', snippet_path(@snippet), confirm: 'Are you sure?', method: :delete, class: "btn pull-right danger delete-snippet", id: "destroy_snippet_#{@snippet.id}"
 
 
 :javascript
diff --git a/app/views/snippets/_snippet.html.haml b/app/views/snippets/_snippet.html.haml
index a576500c15d..77d9d211d8d 100644
--- a/app/views/snippets/_snippet.html.haml
+++ b/app/views/snippets/_snippet.html.haml
@@ -1,8 +1,16 @@
 %tr
   %td
+    - if snippet.private?
+      %i.icon-lock
+    - else
+      %i.icon-globe
     = image_tag gravatar_icon(snippet.author_email), class: "avatar s24"
-    %a{href: project_snippet_path(snippet.project, snippet)}
-      %strong= truncate(snippet.title, length: 60)
+    - if snippet.project_id?
+      %a{href: project_snippet_path(snippet.project, snippet)}
+        %strong= truncate(snippet.title, length: 60)
+    - else
+      %a{href: snippet_path(snippet)}
+        %strong= truncate(snippet.title, length: 60)
   %td
     = snippet.file_name
   %td
@@ -11,3 +19,6 @@
         = snippet.expires_at.to_date.to_s(:short)
       - else
         Never
+  %td
+    - if snippet.project_id?
+      = link_to snippet.project.name, project_path(snippet.project)
diff --git a/app/views/snippets/_snippets.html.haml b/app/views/snippets/_snippets.html.haml
new file mode 100644
index 00000000000..8162c546ea7
--- /dev/null
+++ b/app/views/snippets/_snippets.html.haml
@@ -0,0 +1,13 @@
+%table
+  %thead
+    %tr
+      %th Title
+      %th File Name
+      %th Expires At
+      %th Project
+
+  = render partial: 'snippet', collection: @snippets
+  - if @snippets.empty?
+    %tr
+      %td{colspan: 4}
+        %h3.nothing_here_message Nothing here.
diff --git a/app/views/snippets/edit.html.haml b/app/views/snippets/edit.html.haml
index f81c0b8bc64..1b88a85faf1 100644
--- a/app/views/snippets/edit.html.haml
+++ b/app/views/snippets/edit.html.haml
@@ -1 +1 @@
-= render "snippets/form"
+= render "snippets/form", url: snippet_path(@snippet)
diff --git a/app/views/snippets/index.html.haml b/app/views/snippets/index.html.haml
index bacf23d8f8d..2c00dd465db 100644
--- a/app/views/snippets/index.html.haml
+++ b/app/views/snippets/index.html.haml
@@ -1,19 +1,17 @@
 %h3.page_title
   Snippets
   %small share code pastes with others out of git repository
+  = link_to new_snippet_path, class: "btn btn-small add_new pull-right", title: "New Snippet" do
+    Add new snippet
 
-  - if can? current_user, :write_snippet, @project
-    = link_to new_project_snippet_path(@project), class: "btn btn-small add_new pull-right", title: "New Snippet" do
-      Add new snippet
-%br
-%table
-  %thead
-    %tr
-      %th Title
-      %th File Name
-      %th Expires At
-  = render @snippets
-  - if @snippets.empty?
-    %tr
-      %td{colspan: 3}
-        %h3.nothing_here_message Nothing here.
+%hr
+.row
+  .span3
+    %ul.nav.nav-pills.nav-stacked
+      = nav_tab :scope, nil do
+        = link_to "All", snippets_path
+      = nav_tab :scope, 'projects' do
+        = link_to "Projects", snippets_path(scope: 'projects')
+
+  .span9
+    = render 'snippets'
diff --git a/app/views/snippets/new.html.haml b/app/views/snippets/new.html.haml
index f81c0b8bc64..90e0a1f79da 100644
--- a/app/views/snippets/new.html.haml
+++ b/app/views/snippets/new.html.haml
@@ -1 +1 @@
-= render "snippets/form"
+= render "snippets/form", url: snippets_path(@snippet)
diff --git a/app/views/snippets/show.html.haml b/app/views/snippets/show.html.haml
index 12534edf8ba..18348fb1067 100644
--- a/app/views/snippets/show.html.haml
+++ b/app/views/snippets/show.html.haml
@@ -1,9 +1,13 @@
 %h3.page_title
+  - if @snippet.private?
+    %i.icon-lock
+  - else
+    %i.icon-globe
+
   = @snippet.title
   %small= @snippet.file_name
-  - if can?(current_user, :admin_snippet, @project) || @snippet.author == current_user
-    = link_to "Edit", edit_project_snippet_path(@project, @snippet), class: "btn btn-small pull-right", title: 'Edit Snippet'
+  - if @snippet.author == current_user
+    = link_to "Edit", edit_snippet_path(@snippet), class: "btn btn-small pull-right", title: 'Edit Snippet'
 
 %br
 %div= render 'blob'
-%div#notes= render "notes/notes_with_form"
diff --git a/app/views/snippets/user_index.html.haml b/app/views/snippets/user_index.html.haml
new file mode 100644
index 00000000000..2f2cce26af4
--- /dev/null
+++ b/app/views/snippets/user_index.html.haml
@@ -0,0 +1,20 @@
+%h3.page_title
+  Snippets by
+  = @user.name
+  %small share code pastes with others out of git repository
+  = link_to new_snippet_path, class: "btn btn-small add_new pull-right", title: "New Snippet" do
+    Add new snippet
+
+%hr
+.row
+  .span3
+    %ul.nav.nav-pills.nav-stacked
+      = nav_tab :scope, nil do
+        = link_to "All", user_snippets_path(@user)
+      = nav_tab :scope, 'private' do
+        = link_to "Private", user_snippets_path(@user, scope: 'private')
+      = nav_tab :scope, 'public' do
+        = link_to "Public", user_snippets_path(@user, scope: 'public')
+
+  .span9
+    = render 'snippets'
-- 
GitLab