Skip to content

Commit

Permalink
Merge pull request #178 from askaway/embed-question
Browse files Browse the repository at this point in the history
Embed question
  • Loading branch information
skyriverbend committed Sep 12, 2014
2 parents 00f2ce7 + ad20706 commit 9d604e1
Show file tree
Hide file tree
Showing 18 changed files with 94 additions and 56 deletions.
3 changes: 3 additions & 0 deletions app/assets/stylesheets/answer.css.scss
Expand Up @@ -37,3 +37,6 @@
height: 100px;
}
}
.answers-count {
margin-top: 10px;
}
5 changes: 2 additions & 3 deletions app/assets/stylesheets/comments.css.scss
@@ -1,11 +1,10 @@
.comment-count {
color: $gray-light;
font-size: $font-size-small;
}
.list-group-item.comment-count {
font-size: 12px;
font-size: 13px;
border-top: 0;
border-bottom-color: #dadada;
margin-bottom: 8px;
}
.comment {
font-family: $font-family-helvetica;
Expand Down
4 changes: 0 additions & 4 deletions app/assets/stylesheets/list-group.css.scss
@@ -1,7 +1,3 @@
.list-group-item.comment-count {
padding-top: 5px;
padding-bottom: 5px;
}
.list-group-item-clickable {
color: #333;
}
Expand Down
17 changes: 15 additions & 2 deletions app/controllers/embed/questions_controller.rb
@@ -1,6 +1,6 @@
class Embed::QuestionsController < ApplicationController
after_action :verify_authorized, except: [:trending]
after_action :allow_iframe, only: :trending
after_action :verify_authorized, except: [:trending, :show]
after_action :allow_iframe

def trending
@questions = policy_scope(Question).trending
Expand All @@ -9,9 +9,22 @@ def trending
render layout: 'embedded'
end

def show
fetch_question
@answers = @question.answers
@question = @question.decorate
render layout: 'embedded'
end

private
def allow_iframe
response.headers.except! 'X-Frame-Options'
end

def fetch_question
@question ||= Question.common_includes
.includes(comments: [user: [:identities, :placeholder]])
.friendly.find(params[:id])
end
end

7 changes: 0 additions & 7 deletions app/views/answers/_answers_expanded.html.haml
Expand Up @@ -21,10 +21,3 @@
·
%a(ng-href="{{answer.convert_path}}" data-method="put" data-confirm="Are you sure you want to convert this answer into a comment?") Convert

.answer-form-container(ng-show="question.can_answer")
%div.media.comment.answer.answer-form
%span.pull-left.hidden-xs
%img.media-object.avatar.comment-avatar{src: current_user.try(:avatar_url) }
.media-body
= render 'answers/form'

21 changes: 13 additions & 8 deletions app/views/answers/_form.html.haml
@@ -1,9 +1,14 @@
%form(ng-controller='AnswerFormCtrl' ng-submit="addAnswer()" name="new_answer" dirtyconfirm="new_answer")
.form-group
%textarea.form-control.required#answer-text(ng-model="question.answerText" placeholder='Write your answer...' ng-disabled="question.error_message" name="answer_body")
%charcounter(for_model="question.answerText" maxlength="350")
.alert.alert-warning(ng-show="question.error_message")
{{question.error_message}}
%a(href ng-show="question.error_message" ng-click="loadQuestion()") (Reload question)
.answer-form-container(ng-show="question.can_answer")
%div.media.comment.answer.answer-form
%span.pull-left.hidden-xs
%img.media-object.avatar.comment-avatar{src: current_user.try(:avatar_url) }
.media-body
%form(ng-controller='AnswerFormCtrl' ng-submit="addAnswer()" name="new_answer" dirtyconfirm="new_answer")
.form-group
%textarea.form-control.required#answer-text(ng-model="question.answerText" placeholder='Write your answer...' ng-disabled="question.error_message" name="answer_body")
%charcounter(for_model="question.answerText" maxlength="350")
.alert.alert-warning(ng-show="question.error_message")
{{question.error_message}}
%a(href ng-show="question.error_message" ng-click="loadQuestion()") (Reload question)

%input.btn.btn-primary#post-answer(type="submit" ng-disabled="!question.answerText" ng-hide="question.error_message" data-disable-with="Post answer" value='Post answer')
%input.btn.btn-primary#post-answer(type="submit" ng-disabled="!question.answerText" ng-hide="question.error_message" data-disable-with="Post answer" value='Post answer')
8 changes: 8 additions & 0 deletions app/views/embed/questions/show.html.haml
@@ -0,0 +1,8 @@
%script#question-data(type="application/json")
=render(:template => "questions/show.json").html_safe
.row(ng-controller='QuestionCtrl')
.col-xs-12.col-question-list(ng-cloak='')
.panel.panel-default
.panel-body.question
= render 'questions/show/heading'
= render 'questions/show/answers'
6 changes: 3 additions & 3 deletions app/views/questions/_question_list.html.haml
Expand Up @@ -22,11 +22,11 @@
= render 'questions/question_up_vote'
.col-xs-10.col-sm-10.question-col-main
.row
.col-xs-12= render 'questions/question_body'
.col-xs-12= render 'questions/question_list/question_body'
.row.question-asker-row
.col-xs-12= render 'questions/asker'
.col-xs-12= render 'questions/question_list/asker'
.row
.col-xs-12= render 'questions/answers'
.col-xs-12= render 'questions/question_list/answers'
%li.list-group-item.loading-spinner.questions-loading-spinner(ng-show="loadingQuestions")
= image_tag "ajax-loader.gif"

Expand Down
Expand Up @@ -14,11 +14,13 @@
.answers-preview-party-avatar
%img(ng-src="{{answer.party_avatar}}")
.col-sm-2.hidden-xs(ng-show="question.answers_count > 0")
= render 'questions/expand_question'
= render 'questions/question_list/expand_question'

.answers-expanded-container.slide-down(ng-show="question.expanded")
%hr(ng-show="question.answers_count > 0")
= render 'answers/answers_expanded'
= render 'answers/form'


%a.btn.btn-grey.btn-block(href="{{question.path}}" ng-class="{'answers-expanded-see-comments-padded': question.answers_count === 0}")
%i.fa.fa-arrow-circle-right
Expand Down
Expand Up @@ -24,4 +24,4 @@
.share-question-btn.share-question-btn-twitter
%span(id="share-question-btn-twitter-{{question.id}}")
.col-sm-2.hidden-xs(ng-show="question.answers_count === 0")
= render 'questions/expand_question'
= render 'questions/question_list/expand_question'
31 changes: 5 additions & 26 deletions app/views/questions/show.html.haml
@@ -1,36 +1,15 @@
%script#question-data(type="application/json")
=render(:template => "questions/show.json").html_safe
.row(ng-controller='QuestionCtrl')
.col-xs-12.col-md-8.col-md-offset-2(ng-cloak='')
.col-question-list.col-xs-12.col-md-8.col-md-offset-2(ng-cloak='')
.panel.panel-default
.see-more-questions
= link_to '← See more questions', root_path
.panel-body.question
.row
.col-xs-2.col-sm-2
= render 'question_up_vote'
.col-xs-10.col-sm-10
=render 'questions/question_body'
.text-detail
{{question.created_at}} ago
by
%span(ng-show="question.is_anonymous") {{question.user}}
%a.emphasized(ng-hide="question.is_anonymous" ng-href="{{question.user_path}}") {{question.user}}
.panel-body
= render 'answers/answers_expanded'
%li.list-group-item.comment-count
%ng-pluralize(count="question.comments_count" when="{ '1': '1 COMMENT', 'other': '{} COMMENTS' }")
.panel-body
.row.comment-list
.col-xs-12
- unless current_user.try(:can_answer?, @question)
- if user_signed_in?
= render 'comments/form'
- else
= link_to 'Log in', new_user_session_path
to comment

= render partial: 'comments/item'
= render 'questions/show/heading'
= render 'questions/show/answers'
= render 'answers/form'
= render 'questions/show/comments'

- if current_user.try(:can_answer?, @question)
= render 'answers/share'
4 changes: 4 additions & 0 deletions app/views/questions/show/_answers.html.haml
@@ -0,0 +1,4 @@
.comment-count.answers-count
%ng-pluralize(count="question.answers_count" when="{ '1': '1 ANSWER', 'other': '{} ANSWERS' }")
= render 'answers/answers_expanded'

12 changes: 12 additions & 0 deletions app/views/questions/show/_comments.html.haml
@@ -0,0 +1,12 @@
.comment-count
%ng-pluralize(count="question.comments_count" when="{ '1': '1 COMMENT', 'other': '{} COMMENTS' }")
.row.comment-list
.col-xs-12
- unless current_user.try(:can_answer?, @question)
- if user_signed_in?
= render 'comments/form'
- else
= link_to 'Log in', new_user_session_path
to comment

= render partial: 'comments/item'
10 changes: 10 additions & 0 deletions app/views/questions/show/_heading.html.haml
@@ -0,0 +1,10 @@
.row
.col-xs-2.col-sm-2
= render 'questions/question_up_vote'
.col-xs-10.col-sm-10
=render 'questions/question_list/question_body'
.text-detail
{{question.created_at}} ago
by
%span(ng-show="question.is_anonymous") {{question.user}}
%a.emphasized(ng-hide="question.is_anonymous" ng-href="{{question.user_path}}") {{question.user}}
2 changes: 1 addition & 1 deletion config/routes.rb
Expand Up @@ -59,7 +59,7 @@
end

scope '/embed', module: :embed, as: 'embed' do
resources :questions, only: [] do
resources :questions, only: [:show] do
collection do
get :trending
end
Expand Down
14 changes: 14 additions & 0 deletions spec/controllers/embed/questions_controller_spec.rb
@@ -0,0 +1,14 @@
require 'rails_helper'

RSpec.describe Embed::QuestionsController, :type => :controller do
# Just a simple test to make sure the embed controller/views are still working
describe "GET #show" do
render_views
let(:question) { FactoryGirl.create(:question) }
let(:response) { get :show, id: question.id }

it "shows question" do
expect(response).to be_success
end
end
end

0 comments on commit 9d604e1

Please sign in to comment.