Merge branch 'feature-discover'

This commit is contained in:
pixeldesu 2015-05-14 00:47:23 +02:00
commit 773b2917cb
12 changed files with 107 additions and 0 deletions

View File

@ -190,3 +190,7 @@ body {
.heading-showcase {
margin-top: 5px;
}
.discover {
padding-top: 20px;
}

View File

@ -0,0 +1,20 @@
class DiscoverController < ApplicationController
before_filter :authenticate_user!
def index
top_x = 10 # only display the top X items
@popular_answers = Answer.where("created_at > ?", Time.now.ago(1.week)).order(:smile_count).reverse_order.limit(top_x)
@popular_questions = Question.where("created_at > ?", Time.now.ago(1.week)).order(:answer_count).reverse_order.limit(top_x)
@new_users = User.order(:id).reverse_order.limit(top_x)
# .user = the user
# .question_count = how many questions did the user ask
@users_with_most_questions = Question.select('user_id, COUNT(*) AS question_count').
where("created_at > ?", Time.now.ago(1.week)).
where(author_is_anonymous: false).
group(:user_id).
order('question_count').
reverse_order.limit(10)
end
end

View File

@ -0,0 +1,2 @@
module DiscoverHelper
end

View File

@ -0,0 +1,3 @@
.tab-pane.active.fade.in{role: "tabpanel", id: "answers"}
- answers.each do |a|
= render 'shared/answerbox', a: a

View File

@ -0,0 +1,3 @@
.tab-pane.fade{role: "tabpanel", id: "asked"}
- asked.each do |user|
= render 'discover/userbox', u: user.user, type: "asked", q: user.question_count

View File

@ -0,0 +1,3 @@
.tab-pane.active.fade.in{role: "tabpanel", id: "new"}
- new.each do |user|
= render 'discover/userbox', u: user, type: "new"

View File

@ -0,0 +1,3 @@
.tab-pane.fade{role: "tabpanel", id: "questions"}
- questions.each do |q|
= render 'shared/question', q: q, type: "discover"

View File

@ -0,0 +1,23 @@
.panel.panel-default.questionbox{data: { id: u.id }}
.panel-body
.media
.pull-left
%a{href: show_user_profile_path(u.screen_name)}
%img.answerbox--img{src: u.profile_picture.url(:medium)}
.media-body
%h6.media-heading
- if u.display_name.blank?
%a{href: show_user_profile_path(u.screen_name)}
%span= "@#{u.screen_name}"
- else
%a{href: show_user_profile_path(u.screen_name)}
%span= u.display_name
%span.text-muted= "@#{u.screen_name}"
%p.answerbox--question-text
- if type == "new"
registered
= time_ago_in_words(u.created_at)
ago
- else
asked
= pluralize(q, "question")

View File

@ -0,0 +1,40 @@
- provide(:title, "Discover | #{APP_CONFIG['site_name']}")
.jumbotron.j2-jumbo.text-center.particle-jumbotron
#particles
.particle-content
%h1 Discover
%p
The perfect place to find interesting content from the last week on
= succeed '!' do
= APP_CONFIG['site_name']
.container
.row
.col-md-8.col-sm-6
%h2 Popular Content
%p Most answered questions and answers with most smiles!
%div{role: "tabpanel"}
%ul.nav.nav-tabs{role: "tablist"}
%li.active{role: "presentation"}
%a{href: "#answers", role: "tab", aria: {controls: "answers"}, data: {toggle: "tab"}}
Answers
%li{role: "presentation"}
%a{href: "#questions", role: "tab", aria: {controls: "questions"}, data: {toggle: "tab"}}
Questions
.tab-content.discover
= render 'discover/tab_answers', answers: @popular_answers
= render 'discover/tab_questions', questions: @popular_questions
.col-md-4.col-sm-6
%h2 Users
%p Users that ask the most questions and new users!
%div{role: "tabpanel"}
%ul.nav.nav-tabs{role: "tablist"}
%li.active{role: "presentation"}
%a{href: "#new", role: "tab", aria: {controls: "new"}, data: {toggle: "tab"}}
New Users
%li{role: "presentation"}
%a{href: "#asked", role: "tab", aria: {controls: "asked"}, data: {toggle: "tab"}}
Most Asked Questions
.tab-content.discover
= render 'discover/tab_new', new: @new_users
= render 'discover/tab_asked', asked: @users_with_most_questions
= render 'shared/links'

View File

@ -22,6 +22,7 @@
%ul.nav.navbar-nav
= nav_entry "Timeline", root_path
= nav_entry "Inbox", "/inbox", badge: inbox_count
= nav_entry "Discover", discover_path
%ul.nav.navbar-nav.navbar-right
= render "layouts/notifications"
%li.hidden-xs{"data-toggle" => "tooltip", "data-placement" => "bottom", title: "Ask a question"}

View File

@ -1,6 +1,10 @@
.panel.panel-default.questionbox{data: { id: q.id }}
.panel-body
.media
- if type == "discover"
.pull-left
%a{href: show_user_profile_path(q.user.screen_name)}
%img.answerbox--img{src: q.user.profile_picture.url(:medium)}
.media-body
- if user_signed_in?
.pull-right

View File

@ -90,6 +90,7 @@ Rails.application.routes.draw do
match '/unsubscribe', to: 'subscription#unsubscribe', via: :post, as: :unsubscribe_answer
end
match '/discover', to: 'discover#index', via: :get, as: :discover
match '/public', to: 'public#index', via: :get, as: :public_timeline
match '/group/:group_name', to: 'group#index', via: :get, as: :group_timeline