diff --git a/app/assets/stylesheets/base.css.scss b/app/assets/stylesheets/base.css.scss index df55838d..6c41e941 100644 --- a/app/assets/stylesheets/base.css.scss +++ b/app/assets/stylesheets/base.css.scss @@ -190,3 +190,7 @@ body { .heading-showcase { margin-top: 5px; } + +.discover { + padding-top: 20px; +} diff --git a/app/controllers/discover_controller.rb b/app/controllers/discover_controller.rb new file mode 100644 index 00000000..7eac7f55 --- /dev/null +++ b/app/controllers/discover_controller.rb @@ -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 diff --git a/app/helpers/discover_helper.rb b/app/helpers/discover_helper.rb new file mode 100644 index 00000000..6d7d2ed7 --- /dev/null +++ b/app/helpers/discover_helper.rb @@ -0,0 +1,2 @@ +module DiscoverHelper +end diff --git a/app/views/discover/_tab_answers.html.haml b/app/views/discover/_tab_answers.html.haml new file mode 100644 index 00000000..ed290d50 --- /dev/null +++ b/app/views/discover/_tab_answers.html.haml @@ -0,0 +1,3 @@ +.tab-pane.active.fade.in{role: "tabpanel", id: "answers"} + - answers.each do |a| + = render 'shared/answerbox', a: a diff --git a/app/views/discover/_tab_asked.html.haml b/app/views/discover/_tab_asked.html.haml new file mode 100644 index 00000000..95136d6c --- /dev/null +++ b/app/views/discover/_tab_asked.html.haml @@ -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 diff --git a/app/views/discover/_tab_new.html.haml b/app/views/discover/_tab_new.html.haml new file mode 100644 index 00000000..261f904c --- /dev/null +++ b/app/views/discover/_tab_new.html.haml @@ -0,0 +1,3 @@ +.tab-pane.active.fade.in{role: "tabpanel", id: "new"} + - new.each do |user| + = render 'discover/userbox', u: user, type: "new" diff --git a/app/views/discover/_tab_questions.html.haml b/app/views/discover/_tab_questions.html.haml new file mode 100644 index 00000000..cd14a840 --- /dev/null +++ b/app/views/discover/_tab_questions.html.haml @@ -0,0 +1,3 @@ +.tab-pane.fade{role: "tabpanel", id: "questions"} + - questions.each do |q| + = render 'shared/question', q: q, type: "discover" diff --git a/app/views/discover/_userbox.html.haml b/app/views/discover/_userbox.html.haml new file mode 100644 index 00000000..4332c0b5 --- /dev/null +++ b/app/views/discover/_userbox.html.haml @@ -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") diff --git a/app/views/discover/index.html.haml b/app/views/discover/index.html.haml new file mode 100644 index 00000000..09e1db87 --- /dev/null +++ b/app/views/discover/index.html.haml @@ -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' diff --git a/app/views/layouts/_header.html.haml b/app/views/layouts/_header.html.haml index dbacfbe9..b1fe5ed5 100644 --- a/app/views/layouts/_header.html.haml +++ b/app/views/layouts/_header.html.haml @@ -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"} diff --git a/app/views/shared/_question.html.haml b/app/views/shared/_question.html.haml index 2a592f5b..ea90fa2a 100644 --- a/app/views/shared/_question.html.haml +++ b/app/views/shared/_question.html.haml @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 9b8c648f..8cb2a9ca 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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