From c9a268ebdfb220e406e547b61cb01052325291c9 Mon Sep 17 00:00:00 2001 From: Georg G Date: Wed, 13 May 2015 20:39:04 +0200 Subject: [PATCH 1/7] added empty DiscoverController --- app/controllers/discover_controller.rb | 2 ++ app/helpers/discover_helper.rb | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 app/controllers/discover_controller.rb create mode 100644 app/helpers/discover_helper.rb diff --git a/app/controllers/discover_controller.rb b/app/controllers/discover_controller.rb new file mode 100644 index 00000000..282c69ef --- /dev/null +++ b/app/controllers/discover_controller.rb @@ -0,0 +1,2 @@ +class DiscoverController < ApplicationController +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 From 961ebfd2667686b3758ba16ac02e24e111da60b0 Mon Sep 17 00:00:00 2001 From: pixeldesu Date: Wed, 13 May 2015 20:56:51 +0200 Subject: [PATCH 2/7] add routes and empty index for discover --- app/controllers/discover_controller.rb | 5 +++++ app/views/discover/index.html.haml | 1 + config/routes.rb | 1 + 3 files changed, 7 insertions(+) create mode 100644 app/views/discover/index.html.haml diff --git a/app/controllers/discover_controller.rb b/app/controllers/discover_controller.rb index 282c69ef..880d3320 100644 --- a/app/controllers/discover_controller.rb +++ b/app/controllers/discover_controller.rb @@ -1,2 +1,7 @@ class DiscoverController < ApplicationController + before_filter :authenticate_user! + + def index + + end end diff --git a/app/views/discover/index.html.haml b/app/views/discover/index.html.haml new file mode 100644 index 00000000..8d1c8b69 --- /dev/null +++ b/app/views/discover/index.html.haml @@ -0,0 +1 @@ + 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 From 23583fab99c300bd89e0dce7bc5fe0160d2f5007 Mon Sep 17 00:00:00 2001 From: pixeldesu Date: Wed, 13 May 2015 21:20:20 +0200 Subject: [PATCH 3/7] add header and page title to discover page --- app/views/discover/index.html.haml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/views/discover/index.html.haml b/app/views/discover/index.html.haml index 8d1c8b69..3c563e34 100644 --- a/app/views/discover/index.html.haml +++ b/app/views/discover/index.html.haml @@ -1 +1,11 @@ - +- 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 on + = succeed '!' do + = APP_CONFIG['site_name'] +.container + %p TODO: Add content From 140e5bf51ecd0c1cb4c9dfe6356e828adb11ba6d Mon Sep 17 00:00:00 2001 From: Georg G Date: Wed, 13 May 2015 21:58:00 +0200 Subject: [PATCH 4/7] added some querying magic :neckbeard: --- app/controllers/discover_controller.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/controllers/discover_controller.rb b/app/controllers/discover_controller.rb index 880d3320..7eac7f55 100644 --- a/app/controllers/discover_controller.rb +++ b/app/controllers/discover_controller.rb @@ -2,6 +2,19 @@ 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 From 5c13dda5854273f54fdaf6c3c55170269ce8edf9 Mon Sep 17 00:00:00 2001 From: pixeldesu Date: Wed, 13 May 2015 22:29:37 +0200 Subject: [PATCH 5/7] add tab navigation --- app/views/discover/index.html.haml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/app/views/discover/index.html.haml b/app/views/discover/index.html.haml index 3c563e34..5fbab8d5 100644 --- a/app/views/discover/index.html.haml +++ b/app/views/discover/index.html.haml @@ -8,4 +8,27 @@ = 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 + .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: "#asked", role: "tab", aria: {controls: "asked"}, data: {toggle: "tab"}} + Most Asked Questions + %li{role: "presentation"} + %a{href: "#new", role: "tab", aria: {controls: "new"}, data: {toggle: "tab"}} + New Users %p TODO: Add content From 86b5e9933ef2a59f9833e93c6deec0de81e58eb7 Mon Sep 17 00:00:00 2001 From: pixeldesu Date: Wed, 13 May 2015 23:55:10 +0200 Subject: [PATCH 6/7] add basic functionality --- app/views/discover/_tab_answers.html.haml | 3 +++ app/views/discover/_tab_asked.html.haml | 3 +++ app/views/discover/_tab_new.html.haml | 3 +++ app/views/discover/_tab_questions.html.haml | 3 +++ app/views/discover/_userbox.html.haml | 20 ++++++++++++++++++++ app/views/discover/index.html.haml | 16 +++++++++++----- app/views/layouts/_header.html.haml | 1 + 7 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 app/views/discover/_tab_answers.html.haml create mode 100644 app/views/discover/_tab_asked.html.haml create mode 100644 app/views/discover/_tab_new.html.haml create mode 100644 app/views/discover/_tab_questions.html.haml create mode 100644 app/views/discover/_userbox.html.haml 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..6e8918d3 --- /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 diff --git a/app/views/discover/_userbox.html.haml b/app/views/discover/_userbox.html.haml new file mode 100644 index 00000000..556f8d78 --- /dev/null +++ b/app/views/discover/_userbox.html.haml @@ -0,0 +1,20 @@ +.panel.panel-default.questionbox{data: { id: u.id }} + .panel-body + .media + .pull-left + %img.answerbox--img{src: u.profile_picture.url(:medium)} + .media-body + %h6.media-heading + - if u.display_name.blank? + %span= u.screen_name + - else + %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 index 5fbab8d5..987c0826 100644 --- a/app/views/discover/index.html.haml +++ b/app/views/discover/index.html.haml @@ -4,7 +4,7 @@ .particle-content %h1 Discover %p - The perfect place to find interesting content on + The perfect place to find interesting content from the last week on = succeed '!' do = APP_CONFIG['site_name'] .container @@ -20,15 +20,21 @@ %li{role: "presentation"} %a{href: "#questions", role: "tab", aria: {controls: "questions"}, data: {toggle: "tab"}} Questions + .tab-content + = 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: "#asked", role: "tab", aria: {controls: "asked"}, data: {toggle: "tab"}} - Most Asked Questions - %li{role: "presentation"} %a{href: "#new", role: "tab", aria: {controls: "new"}, data: {toggle: "tab"}} New Users - %p TODO: Add content + %li{role: "presentation"} + %a{href: "#asked", role: "tab", aria: {controls: "asked"}, data: {toggle: "tab"}} + Most Asked Questions + .tab-content + = render 'discover/tab_new', new: @new_users + = render 'discover/tab_asked', asked: @users_with_most_questions + .tab-content 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"} From 023fe26e81c353ed422590f055d72534bffb9e3d Mon Sep 17 00:00:00 2001 From: pixeldesu Date: Thu, 14 May 2015 00:45:01 +0200 Subject: [PATCH 7/7] finish up Discover page --- app/assets/stylesheets/base.css.scss | 4 ++++ app/views/discover/_tab_questions.html.haml | 2 +- app/views/discover/_userbox.html.haml | 11 +++++++---- app/views/discover/index.html.haml | 6 +++--- app/views/shared/_question.html.haml | 4 ++++ 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/assets/stylesheets/base.css.scss b/app/assets/stylesheets/base.css.scss index 900d523d..af6bf8dc 100644 --- a/app/assets/stylesheets/base.css.scss +++ b/app/assets/stylesheets/base.css.scss @@ -189,3 +189,7 @@ body { .heading-showcase { margin-top: 5px; } + +.discover { + padding-top: 20px; +} diff --git a/app/views/discover/_tab_questions.html.haml b/app/views/discover/_tab_questions.html.haml index 6e8918d3..cd14a840 100644 --- a/app/views/discover/_tab_questions.html.haml +++ b/app/views/discover/_tab_questions.html.haml @@ -1,3 +1,3 @@ .tab-pane.fade{role: "tabpanel", id: "questions"} - questions.each do |q| - = render 'shared/question', q: q + = render 'shared/question', q: q, type: "discover" diff --git a/app/views/discover/_userbox.html.haml b/app/views/discover/_userbox.html.haml index 556f8d78..4332c0b5 100644 --- a/app/views/discover/_userbox.html.haml +++ b/app/views/discover/_userbox.html.haml @@ -2,14 +2,17 @@ .panel-body .media .pull-left - %img.answerbox--img{src: u.profile_picture.url(:medium)} + %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? - %span= u.screen_name + %a{href: show_user_profile_path(u.screen_name)} + %span= "@#{u.screen_name}" - else - %span= u.display_name - %span.text-muted= u.screen_name + %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 diff --git a/app/views/discover/index.html.haml b/app/views/discover/index.html.haml index 987c0826..09e1db87 100644 --- a/app/views/discover/index.html.haml +++ b/app/views/discover/index.html.haml @@ -20,7 +20,7 @@ %li{role: "presentation"} %a{href: "#questions", role: "tab", aria: {controls: "questions"}, data: {toggle: "tab"}} Questions - .tab-content + .tab-content.discover = render 'discover/tab_answers', answers: @popular_answers = render 'discover/tab_questions', questions: @popular_questions .col-md-4.col-sm-6 @@ -34,7 +34,7 @@ %li{role: "presentation"} %a{href: "#asked", role: "tab", aria: {controls: "asked"}, data: {toggle: "tab"}} Most Asked Questions - .tab-content + .tab-content.discover = render 'discover/tab_new', new: @new_users = render 'discover/tab_asked', asked: @users_with_most_questions - .tab-content + = render 'shared/links' 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