From 30c8654a277f4cc35d2af5c9e5ef597ccc03d517 Mon Sep 17 00:00:00 2001 From: nilsding Date: Mon, 8 Dec 2014 17:03:06 +0100 Subject: [PATCH] added follower/following pages --- app/controllers/user_controller.rb | 14 +++++++++ app/views/shared/_userbox.html.haml | 26 ++++++++++++++++ app/views/user/_profile_info.html.haml | 40 +++++++++++++++++++++++++ app/views/user/show.html.haml | 41 +------------------------- app/views/user/show_follow.html.haml | 17 +++++++++++ app/views/user/show_follow.js.erb | 8 +++++ config/routes.rb | 4 +++ 7 files changed, 110 insertions(+), 40 deletions(-) create mode 100644 app/views/shared/_userbox.html.haml create mode 100644 app/views/user/_profile_info.html.haml create mode 100644 app/views/user/show_follow.html.haml create mode 100644 app/views/user/show_follow.js.erb diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 185a3bbe..431546af 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -20,4 +20,18 @@ class UserController < ApplicationController end redirect_to edit_user_profile_path end + + def followers + @title = 'Followers' + @user = User.find_by_screen_name!(params[:username]) + @users = @user.followers.paginate(page: params[:page]) + render 'show_follow' + end + + def following + @title = 'Following' + @user = User.find_by_screen_name!(params[:username]) + @users = @user.followers.paginate(page: params[:page]) + render 'show_follow' + end end diff --git a/app/views/shared/_userbox.html.haml b/app/views/shared/_userbox.html.haml new file mode 100644 index 00000000..206a5eab --- /dev/null +++ b/app/views/shared/_userbox.html.haml @@ -0,0 +1,26 @@ +/ TODO: pixeldesu pls +.panel.panel-default + .panel-body + .media + .pull-left + %img.img-rounded.img-profile{src: gravatar_url(user)} + .media-body + - if user.display_name.blank? + %h2= user.screen_name + - else + %h2.user-displayname= user.display_name + %h4.text-muted.user-username= user.screen_name + - if user.admin? + %p.user-admin + %i.fa.fa-flask + Admin + - unless user.bio.blank? + %p.user-profiletext= user.bio + .row + .col-md-6.col-sm-6.col-xs-6 + %h4.entry-text#asked-count= user.asked_count + %h6.entry-subtext Questions + .col-md-6.col-sm-6.col-xs-6 + %h4.entry-text#answered-count= user.answered_count + %h6.entry-subtext Answers + = render 'user/actions' \ No newline at end of file diff --git a/app/views/user/_profile_info.html.haml b/app/views/user/_profile_info.html.haml new file mode 100644 index 00000000..6f7091bd --- /dev/null +++ b/app/views/user/_profile_info.html.haml @@ -0,0 +1,40 @@ +.panel.panel-default + .panel-body + .media + .pull-left + %img.img-rounded.img-profile{src: gravatar_url(@user)} + .media-body + - if @user.display_name.blank? + %h2= @user.screen_name + - else + %h2.user-displayname= @user.display_name + %h4.text-muted.user-username= @user.screen_name + - if @user.admin? + %p.user-admin + %i.fa.fa-flask + Admin + - unless @user.bio.blank? + %p.user-profiletext= @user.bio + - unless @user.website.blank? + %p.user-profiletext + %i.fa.fa-globe + %a{href: @user.website}= @user.display_website + - unless @user.location.blank? + %p.user-profiletext + %i.fa.fa-location-arrow + = @user.location + .row + .col-md-6.col-sm-6.col-xs-6 + %h4.entry-text#follower-count= @user.follower_count + %h6.entry-subtext Follower + .col-md-6.col-sm-6.col-xs-6 + %h4.entry-text#friend-count= @user.friend_count + %h6.entry-subtext Following + .row + .col-md-6.col-sm-6.col-xs-6 + %h4.entry-text#asked-count= @user.asked_count + %h6.entry-subtext Questions + .col-md-6.col-sm-6.col-xs-6 + %h4.entry-text#answered-count= @user.answered_count + %h6.entry-subtext Answers + = render 'user/actions' \ No newline at end of file diff --git a/app/views/user/show.html.haml b/app/views/user/show.html.haml index e0e95543..8fa41102 100644 --- a/app/views/user/show.html.haml +++ b/app/views/user/show.html.haml @@ -1,45 +1,6 @@ .container.j2-page .col-md-3.col-xs-12.col-sm-3 - .panel.panel-default - .panel-body - .media - .pull-left - %img.img-rounded.img-profile{src: gravatar_url(@user)} - .media-body - - if @user.display_name.blank? - %h2= @user.screen_name - - else - %h2.user-displayname= @user.display_name - %h4.text-muted.user-username= @user.screen_name - - if @user.admin? - %p.user-admin - %i.fa.fa-flask - Admin - - unless @user.bio.blank? - %p.user-profiletext= @user.bio - - unless @user.website.blank? - %p.user-profiletext - %i.fa.fa-globe - %a{href: @user.website}= @user.display_website - - unless @user.location.blank? - %p.user-profiletext - %i.fa.fa-location-arrow - = @user.location - .row - .col-md-6.col-sm-6.col-xs-6 - %h4.entry-text#follower-count= @user.follower_count - %h6.entry-subtext Follower - .col-md-6.col-sm-6.col-xs-6 - %h4.entry-text#friend-count= @user.friend_count - %h6.entry-subtext Following - .row - .col-md-6.col-sm-6.col-xs-6 - %h4.entry-text#asked-count= @user.asked_count - %h6.entry-subtext Questions - .col-md-6.col-sm-6.col-xs-6 - %h4.entry-text#answered-count= @user.answered_count - %h6.entry-subtext Answers - = render 'user/actions' + = render 'user/profile_info' .hidden-xs= render 'shared/links' .col-md-9.col-xs-12.col-sm-9 = render 'shared/questionbox' diff --git a/app/views/user/show_follow.html.haml b/app/views/user/show_follow.html.haml new file mode 100644 index 00000000..a93a0f61 --- /dev/null +++ b/app/views/user/show_follow.html.haml @@ -0,0 +1,17 @@ +.container.j2-page + .col-md-3.col-xs-12.col-sm-3 + = render 'user/profile_info' + .hidden-xs= render 'shared/links' + .col-md-9.col-xs-12.col-sm-9 + %h1= @title + #users + - @users.each do |user| + .col-sm-6 + = render 'shared/userbox', user: user + + #pagination= will_paginate @users, renderer: BootstrapPagination::Rails, page_links: false + + - if @users.next_page + %button#load-more-btn.btn.btn-default{type: :button, data: { current_page: @users.current_page }} + Load more + .visible-xs= render 'shared/links' diff --git a/app/views/user/show_follow.js.erb b/app/views/user/show_follow.js.erb new file mode 100644 index 00000000..9a507edf --- /dev/null +++ b/app/views/user/show_follow.js.erb @@ -0,0 +1,8 @@ +$('#users').append('<% @users.each do |user| + %>
<%= j render 'shared/userbox', user: user +%>
<% end %>'); +<% if @users.next_page %> + $('#pagination').html('<%= j will_paginate @users, renderer: BootstrapPagination::Rails, page_links: false %>'); +<% else %> + $('#pagination, #load-more-btn').remove(); +<% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 58976d6c..6163309e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -42,7 +42,11 @@ Rails.application.routes.draw do match '/@:username(/p/:page)', to: 'user#show', via: 'get', as: :show_user_profile, defaults: {page: 1} match '/@:username/a/:id', to: 'answer#show', via: 'get', as: :show_user_answer match '/@:username/q/:id', to: 'question#show', via: 'get', as: :show_user_question + match '/@:username/followers(/p/:page)', to: 'user#followers', via: 'get', as: :show_user_followers, defaults: {page: 1} + match '/@:username/following(/p/:page)', to: 'user#following', via: 'get', as: :show_user_following, defaults: {page: 1} match '/:username(/p/:page)', to: 'user#show', via: 'get', as: :show_user_profile_alt, defaults: {page: 1} match '/:username/a/:id', to: 'answer#show', via: 'get', as: :show_user_answer_alt match '/:username/q/:id', to: 'question#show', via: 'get', as: :show_user_question_alt + match '/:username/followers(/p/:page)', to: 'user#followers', via: 'get', as: :show_user_followers_alt, defaults: {page: 1} + match '/:username/following(/p/:page)', to: 'user#following', via: 'get', as: :show_user_following_alt, defaults: {page: 1} end