From e7bcbb95c88a42fc31bc0ccbdf6a819780a612ec Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> Date: Wed, 5 Jun 2013 22:25:27 +0300 Subject: [PATCH] Restyle snippets --- app/controllers/snippets_controller.rb | 33 ++++++++----- app/helpers/snippets_helper.rb | 8 ++++ app/views/layouts/_head_panel.html.haml | 2 +- app/views/layouts/snippets.html.haml | 7 +-- app/views/projects/snippets/_blob.html.haml | 5 +- .../projects/snippets/_snippet.html.haml | 36 ++++++++++----- app/views/projects/snippets/index.html.haml | 14 ++---- app/views/projects/snippets/show.html.haml | 10 ++-- app/views/snippets/_blob.html.haml | 5 +- app/views/snippets/_snippet.html.haml | 46 +++++++++++-------- app/views/snippets/_snippets.html.haml | 14 ++---- .../snippets/current_user_index.html.haml | 21 +++++++++ app/views/snippets/show.html.haml | 13 ++++-- app/views/snippets/user_index.html.haml | 17 ++----- 14 files changed, 138 insertions(+), 93 deletions(-) create mode 100644 app/views/snippets/current_user_index.html.haml diff --git a/app/controllers/snippets_controller.rb b/app/controllers/snippets_controller.rb index 70525beea1..49b740af04 100644 --- a/app/controllers/snippets_controller.rb +++ b/app/controllers/snippets_controller.rb @@ -15,19 +15,28 @@ class SnippetsController < ApplicationController def user_index @user = User.find_by_username(params[:username]) - - @snippets = @current_user.snippets.fresh.non_expired - - @snippets = case params[:scope] - when 'public' then - @snippets.public - when 'private' then - @snippets.private - else - @snippets - end + @snippets = @user.snippets.fresh.non_expired + + if @user == current_user + @snippets = case params[:scope] + when 'public' then + @snippets.public + when 'private' then + @snippets.private + else + @snippets + end + else + @snippets = @snippets.public + end @snippets = @snippets.page(params[:page]).per(20) + + if @user == current_user + render 'current_user_index' + else + render 'user_index' + end end def new @@ -79,7 +88,7 @@ class SnippetsController < ApplicationController protected def snippet - @snippet ||= PersonalSnippet.find(params[:id]) + @snippet ||= PersonalSnippet.where('author_id = :user_id or private is false', user_id: current_user.id).find(params[:id]) end def authorize_modify_snippet! diff --git a/app/helpers/snippets_helper.rb b/app/helpers/snippets_helper.rb index 6a91d61672..b0abc2cae3 100644 --- a/app/helpers/snippets_helper.rb +++ b/app/helpers/snippets_helper.rb @@ -8,4 +8,12 @@ module SnippetsHelper ] options_for_select(options) end + + def reliable_snippet_path(snippet) + if snippet.project_id? + project_snippet_path(snippet.project, snippet) + else + snippet_path(snippet) + end + end end diff --git a/app/views/layouts/_head_panel.html.haml b/app/views/layouts/_head_panel.html.haml index b214d51bc2..f0b001f6ef 100644 --- a/app/views/layouts/_head_panel.html.haml +++ b/app/views/layouts/_head_panel.html.haml @@ -19,7 +19,7 @@ = link_to public_root_path, title: "Public area", class: 'has_bottom_tooltip', 'data-original-title' => 'Public area' do %i.icon-globe %li - = link_to snippets_path, title: "Snippets area", class: 'has_bottom_tooltip', 'data-original-title' => 'Public area' do + = link_to user_snippets_path(current_user), title: "My snippets", class: 'has_bottom_tooltip', 'data-original-title' => 'Public area' do %i.icon-paste - if current_user.is_admin? %li diff --git a/app/views/layouts/snippets.html.haml b/app/views/layouts/snippets.html.haml index d177709e08..f2696a0e98 100644 --- a/app/views/layouts/snippets.html.haml +++ b/app/views/layouts/snippets.html.haml @@ -7,15 +7,12 @@ %nav.main-nav .container %ul - = nav_link(path: 'dashboard#show', html_options: {class: 'home'}) do - = link_to root_path, title: "Back to dashboard" do + = nav_link(path: 'snippets#user_index', html_options: {class: 'home'}) do + = link_to user_snippets_path(current_user), title: "My Snippets" do %i.icon-home = nav_link(path: 'snippets#new') do = link_to new_snippet_path do New snippet - = nav_link(path: 'snippets#user_index') do - = link_to user_snippets_path(@current_user) do - My snippets = nav_link(path: 'snippets#index') do = link_to snippets_path do Discover snippets diff --git a/app/views/projects/snippets/_blob.html.haml b/app/views/projects/snippets/_blob.html.haml index 017a33b34f..e0d1669acb 100644 --- a/app/views/projects/snippets/_blob.html.haml +++ b/app/views/projects/snippets/_blob.html.haml @@ -3,7 +3,10 @@ %i.icon-file %strong= @snippet.file_name %span.options - = link_to "raw", raw_project_snippet_path(@project, @snippet), class: "btn btn-tiny", target: "_blank" + .btn-group.tree-btn-group.pull-right + - if can?(current_user, :admin_project_snippet, @project) || @snippet.author == current_user + = link_to "Edit", edit_project_snippet_path(@project, @snippet), class: "btn btn-tiny", title: 'Edit Snippet' + = link_to "raw", raw_project_snippet_path(@project, @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/projects/snippets/_snippet.html.haml b/app/views/projects/snippets/_snippet.html.haml index a576500c15..72865bf287 100644 --- a/app/views/projects/snippets/_snippet.html.haml +++ b/app/views/projects/snippets/_snippet.html.haml @@ -1,13 +1,25 @@ -%tr - %td - = image_tag gravatar_icon(snippet.author_email), class: "avatar s24" - %a{href: project_snippet_path(snippet.project, snippet)} - %strong= truncate(snippet.title, length: 60) - %td - = snippet.file_name - %td +%li + .snippet-title + - if snippet.private? + %i.icon-lock.cgreen + - else + %i.icon-globe.cblue + = link_to reliable_snippet_path(snippet) do + %h5.inline + = truncate(snippet.title, length: 60) %span.cgray - - if snippet.expires_at - = snippet.expires_at.to_date.to_s(:short) - - else - Never + = snippet.file_name + + %small.pull-right.cgray + Expires: + - if snippet.expires_at + = snippet.expires_at.to_date.to_s(:short) + - else + Never + + .snippet-info.prepend-left-20 + = "##{snippet.id}" + %span.light + by + = image_tag gravatar_icon(snippet.author_email), class: "avatar avatar-inline s16" + = snippet.author_name diff --git a/app/views/projects/snippets/index.html.haml b/app/views/projects/snippets/index.html.haml index 5971e3ffaa..ce36bed1e0 100644 --- a/app/views/projects/snippets/index.html.haml +++ b/app/views/projects/snippets/index.html.haml @@ -5,15 +5,9 @@ - if can? current_user, :write_project_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 +%hr +%ul.bordered-list = render partial: "projects/snippets/snippet", collection: @snippets - if @snippets.empty? - %tr - %td{colspan: 3} - %h3.nothing_here_message Nothing here. + %li + %h3.nothing_here_message Nothing here. diff --git a/app/views/projects/snippets/show.html.haml b/app/views/projects/snippets/show.html.haml index db5a721dc4..da93e4bdbb 100644 --- a/app/views/projects/snippets/show.html.haml +++ b/app/views/projects/snippets/show.html.haml @@ -1,9 +1,13 @@ %h3.page_title + %i.icon-lock.cgreen = @snippet.title - %small= @snippet.file_name - - if can?(current_user, :admin_project_snippet, @project) || @snippet.author == current_user - = link_to "Edit", edit_project_snippet_path(@project, @snippet), class: "btn btn-small pull-right", title: 'Edit Snippet' + %small.pull-right + = "##{@snippet.id}" + %span.light + by + = image_tag gravatar_icon(@snippet.author_email), class: "avatar avatar-inline s16" + = @snippet.author_name %br %div= render 'projects/snippets/blob' %div#notes= render "notes/notes_with_form" diff --git a/app/views/snippets/_blob.html.haml b/app/views/snippets/_blob.html.haml index 56e62f0d6b..6f62ea0520 100644 --- a/app/views/snippets/_blob.html.haml +++ b/app/views/snippets/_blob.html.haml @@ -3,7 +3,10 @@ %i.icon-file %strong= @snippet.file_name %span.options - = link_to "raw", raw_snippet_path(@snippet), class: "btn btn-tiny", target: "_blank" + .btn-group.tree-btn-group.pull-right + - if @snippet.author == current_user + = link_to "Edit", edit_snippet_path(@snippet), class: "btn btn-tiny", title: 'Edit Snippet' + = 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/_snippet.html.haml b/app/views/snippets/_snippet.html.haml index 77d9d211d8..1256236ed9 100644 --- a/app/views/snippets/_snippet.html.haml +++ b/app/views/snippets/_snippet.html.haml @@ -1,24 +1,30 @@ -%tr - %td +%li + .snippet-title - if snippet.private? - %i.icon-lock + %i.icon-lock.cgreen - else - %i.icon-globe - = image_tag gravatar_icon(snippet.author_email), class: "avatar s24" - - 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 + %i.icon-globe.cblue + = link_to reliable_snippet_path(snippet) do + %h5.inline + = truncate(snippet.title, length: 60) %span.cgray - - if snippet.expires_at - = snippet.expires_at.to_date.to_s(:short) - - else - Never - %td + = snippet.file_name + + %small.pull-right.cgray - if snippet.project_id? - = link_to snippet.project.name, project_path(snippet.project) + = link_to snippet.project.name_with_namespace, project_path(snippet.project) + %span + \| + Expires: + - if snippet.expires_at + = snippet.expires_at.to_date.to_s(:short) + - else + Never + + .snippet-info.prepend-left-20 + = "##{snippet.id}" + %span.light + by + = image_tag gravatar_icon(snippet.author_email), class: "avatar avatar-inline s16" + = snippet.author_name + diff --git a/app/views/snippets/_snippets.html.haml b/app/views/snippets/_snippets.html.haml index 192cb6aa94..636bf37f6d 100644 --- a/app/views/snippets/_snippets.html.haml +++ b/app/views/snippets/_snippets.html.haml @@ -1,15 +1,7 @@ -%table - %thead - %tr - %th Title - %th File Name - %th Expires At - %th Project - +%ul.bordered-list = render partial: 'snippet', collection: @snippets - if @snippets.empty? - %tr - %td{colspan: 4} - %h3.nothing_here_message Nothing here. + %li + %h3.nothing_here_message Nothing here. = paginate @snippets diff --git a/app/views/snippets/current_user_index.html.haml b/app/views/snippets/current_user_index.html.haml new file mode 100644 index 0000000000..912f4c77a4 --- /dev/null +++ b/app/views/snippets/current_user_index.html.haml @@ -0,0 +1,21 @@ +%h3.page_title + My 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 + +%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' + diff --git a/app/views/snippets/show.html.haml b/app/views/snippets/show.html.haml index 18348fb106..f425c4bd51 100644 --- a/app/views/snippets/show.html.haml +++ b/app/views/snippets/show.html.haml @@ -1,13 +1,16 @@ %h3.page_title - if @snippet.private? - %i.icon-lock + %i.icon-lock.cgreen - else - %i.icon-globe + %i.icon-globe.cblue = @snippet.title - %small= @snippet.file_name - - if @snippet.author == current_user - = link_to "Edit", edit_snippet_path(@snippet), class: "btn btn-small pull-right", title: 'Edit Snippet' + %small.pull-right + = "##{@snippet.id}" + %span.light + by + = image_tag gravatar_icon(@snippet.author_email), class: "avatar avatar-inline s16" + = @snippet.author_name %br %div= render 'blob' diff --git a/app/views/snippets/user_index.html.haml b/app/views/snippets/user_index.html.haml index 2f2cce26af..79e3ddf96f 100644 --- a/app/views/snippets/user_index.html.haml +++ b/app/views/snippets/user_index.html.haml @@ -1,20 +1,13 @@ %h3.page_title - Snippets by + = image_tag gravatar_icon(@user.email), class: "avatar s24" = @user.name + %span + \/ + 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 %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' += render 'snippets' -- 2.30.9