diff --git a/TODO b/TODO index aa89c911..6cad8ff6 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,5 @@ [001| 0%] user blocking (prohibits blocked user from asking question to that person and seeing their answers) -[002| 0%] asking modal (ask all followers/one person a question with a modal you can open over the navbar) +[002| 90%] asking modal (ask all followers/one person a question with a modal you can open over the navbar) [003| 0%] file uploads (for now only avatars, file uploads for embedding images in questions MAYBE LATER) [004| 0%] admin status page (like the one from justask2 in Python) [005| 0%] make the hamburger menu button glow or something if there are new questions in the inbox @@ -10,4 +10,4 @@ [010| 0%] locales (these can wait for now) [011| 0%] auto-posting to other services (twatter, fakelook) [012| 0%] open source the entire thing – in late 2015 or 2016 maybe. -[013| 0%] restructure questions (has_many :answers) for less redundancy in the DB when implementing #002 +[013|100%] restructure questions (has_many :answers) for less redundancy in the DB when implementing #002 diff --git a/app/assets/javascripts/application.js.erb.coffee b/app/assets/javascripts/application.js.erb.coffee index 812af5e0..04da9c24 100644 --- a/app/assets/javascripts/application.js.erb.coffee +++ b/app/assets/javascripts/application.js.erb.coffee @@ -26,9 +26,9 @@ $(document).on "click", "button[name=qb-ask]", -> promote = btn[0].dataset.promote == "true" $("textarea[name=qb-question]").attr "readonly", "readonly" anonymousQuestion = if $("input[name=qb-anonymous]")[0] != undefined - $("input[name=qb-anonymous]")[0].checked - else - true + $("input[name=qb-anonymous]")[0].checked + else + true $.ajax url: '/ajax/ask' # TODO: find a way to use rake routes instead of hardcoding them here type: 'POST' @@ -50,6 +50,30 @@ $(document).on "click", "button[name=qb-ask]", -> btn.button "reset" $("textarea[name=qb-question]").removeAttr "readonly" +$(document).on "click", "button[name=qb-all-ask]", -> + btn = $(this) + btn.button "loading" + $("textarea[name=qb-all-question]").attr "readonly", "readonly" + + $.ajax + url: '/ajax/ask' + type: 'POST' + data: + rcpt: "followers" + question: $("textarea[name=qb-all-question]").val() + anonymousQuestion: false + success: (data, status, jqxhr) -> + if data.success + $("textarea[name=qb-all-question]").val '' + $('#modal-ask-followers').modal('hide') + showNotification data.message, data.success + error: (jqxhr, status, error) -> + console.log jqxhr, status, error + showNotification "An error occurred, a developer should check the console for details", false + complete: (jqxhr, status) -> + btn.button "reset" + $("textarea[name=qb-question]").removeAttr "readonly" + $(document).on "keydown", "textarea[name=ib-answer]", (evt) -> iid = $(this)[0].dataset.id if evt.keyCode == 13 and evt.ctrlKey diff --git a/app/controllers/ajax/question_controller.rb b/app/controllers/ajax/question_controller.rb index 3fa2ecf4..98df8d72 100644 --- a/app/controllers/ajax/question_controller.rb +++ b/app/controllers/ajax/question_controller.rb @@ -12,7 +12,15 @@ class Ajax::QuestionController < ApplicationController current_user.increment! :asked_count unless params[:anonymousQuestion] == 'true' end - Inbox.create!(user_id: params[:rcpt], question_id: question.id, new: true) + if params[:rcpt] == 'followers' + unless current_user.nil? + current_user.followers.each do |f| + Inbox.create!(user_id: f.id, question_id: question.id, new: true) + end + end + else + Inbox.create!(user_id: params[:rcpt], question_id: question.id, new: true) + end @status = :okay @message = "Question asked successfully." diff --git a/app/models/inbox.rb b/app/models/inbox.rb index 6d0e835b..46f995a5 100644 --- a/app/models/inbox.rb +++ b/app/models/inbox.rb @@ -12,10 +12,10 @@ class Inbox < ActiveRecord::Base def remove unless self.question.user.nil? - self.question.user.decrement! :asked_count + self.question.user.decrement! :asked_count if self.question.answers.count == 1 end - self.question.destroy + self.question.destroy if self.question.answers.count == 1 self.destroy end end diff --git a/app/models/question.rb b/app/models/question.rb index c2f8b633..76bdb939 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -1,4 +1,4 @@ class Question < ActiveRecord::Base belongs_to :user - has_one :answer + has_many :answers end diff --git a/app/views/layouts/_header.html.haml b/app/views/layouts/_header.html.haml index e74223e3..e65d839b 100644 --- a/app/views/layouts/_header.html.haml +++ b/app/views/layouts/_header.html.haml @@ -13,6 +13,10 @@ = nav_entry "Timeline", root_path %ul.nav.navbar-nav = nav_entry "Inbox", "/inbox", badge: inbox_count + %ul.nav.navbar-right + %button.btn.btn-primary.navbar-btn.btn-sm{"data-target" => "#modal-ask-followers", "data-toggle" => "modal", :type => "button"} + %i.fa.fa-pencil-square-o.fa-spin + %span.visible-xs Ask your followers %ul.nav.navbar-nav.navbar-right %li.dropdown %a.dropdown-toggle{href: "#", "data-toggle" => "dropdown"} @@ -27,3 +31,5 @@ %ul.nav.navbar-nav.navbar-right = nav_entry "Sign in", new_user_session_path = nav_entry "Sign up", new_user_registration_path + += render 'shared/modal_ask_followers' \ No newline at end of file diff --git a/app/views/user/show.html.haml b/app/views/user/show.html.haml index d8bdc708..7df07969 100644 --- a/app/views/user/show.html.haml +++ b/app/views/user/show.html.haml @@ -39,13 +39,6 @@ .col-md-6.col-sm-6.col-xs-6 %h4.entry-text#answered-count= @user.answered_count %h6.entry-subtext Answers - .row - .col-md-6.col-sm-6.col-xs-6 - %h4.entry-text#asked-count= @user.commented_count - %h6.entry-subtext Comments - .col-md-6.col-sm-6.col-xs-6 - %h4.entry-text#answered-count= @user.smiled_count - %h6.entry-subtext Smiles = render 'user/actions' .hidden-xs= render 'shared/links' .col-md-9.col-xs-12.col-sm-9