Skip to content

Commit

Permalink
Add featured question section to shadow question page
Browse files Browse the repository at this point in the history
  • Loading branch information
CleverFool77 committed Jun 8, 2019
1 parent e634096 commit 9d5da34
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 24 deletions.
24 changes: 24 additions & 0 deletions app/controllers/questions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ def index
.paginate(page: params[:page], per_page: 24)
end

def index_shadow
@title = 'Questions and Answers'
set_sidebar
@questions = Node.questions
.where(status: 1)
.order('node.nid DESC')
.paginate(page: params[:page], per_page: 24)
end

# a form for new questions, at /questions/new
def new
# use another node body as a template
Expand Down Expand Up @@ -122,6 +131,21 @@ def popular
render template: 'questions/index'
end

def popular_shadow
@title = 'Popular Questions'
@questions = Node.questions
.where(status: 1)
@questions = filter_questions_by_tag(@questions, params[:tagnames])
.order('views DESC')
.limit(20)

@wikis = Node.limit(10)
.where(type: 'page', status: 1)
.order('nid DESC')
@unpaginated = true
render template: 'questions/index_shadow'
end

def liked
@title = 'Highly liked Questions'
@questions = Node.questions.where(status: 1)
Expand Down
19 changes: 19 additions & 0 deletions app/views/dashboard/_node_meta_shadow.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<% unless node.is_a?(Comment) || node.is_a?(Revision) || node.type == 'page' %>

<div class="profile-image text-center">
<img class="rounded-circle img-fluid" id="profile-photo" src="<%= node.author.profile_image %>" />
</div>

<a class="author" href="/profile/<%= node.author.name %>">@<%= node.author.name %></a> <%= node.author.new_contributor %>
<% if node.has_power_tag('with') %>
with
<% node.coauthors.each_with_index do |coauthor,i| %>
<a href="/profile/<%= coauthor.username %>">
<%= coauthor.username%> <%= coauthor.new_contributor %></a>
<%= ',' if i < node.coauthors.length-1 %>
<% end %>
<% end %>
<% end %>

asked:
</span>
84 changes: 84 additions & 0 deletions app/views/questions/_questions_shadow.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<% questions = questions || @questions # accept local if present, default to instance %>
<div id="notes" class="col-md-12">
<div class="row">
<div class="col-md-2">
</div>
<% questions.limit(2).each_with_index do |node,i| %>
<div class="card <% if @widget %>col-xs-3 col-sm-3 col-md-3 <% end %>col-lg-3 note note-container-question" style="margin-top:20px;">
<div class="card-body">
<div class="card-info">
<p class="meta"><%= render partial: "dashboard/node_meta_shadow", locals: { node: node } %></p>
<h4><a class="question" <% if @widget %>target="_blank"<% end %> href="<%= node.path(:question) %>"><%= node.title %></a></h4>
<div>
<div class="answer">
<% if params[:controller] == 'questions' %>
<a class="peopleResponse" href="<%= node.path(:question) %>#answers" title="Answers"><%= node.answers.length %> people responded</a>
<% end %>
</div>
</div>
<a class="btn btn-outline-secondary" href="/q/<%= node.id %>" >Read More</a>
</div>
</div>
</div>
<% end %>

<div class="col-md-2">
</div>
</div>
</div>

<style>

.card {
background-color: #fff;
border: 1px solid;
border-color: #D3D3D3;
border-radius: 6px;
margin:2em 1.5em 2em 1.5em;
}

.card-body {
margin: auto;
text-align: center;
padding: 0.8em;
}

.profile-image {
margin-bottom: 1em;
}

.author {
color: #333;
font-weight: bold;
font-size: 1.2em;
}

.question {
font-style: italic;
color: #A9A9A9;
}

.peopleResponse {
color: #A9A9A9;
}

.answer {
margin-bottom: 1em;
}

.meta {
color: #999;
}

#profile-photo {
width: 6.5em;
border-color:#555;
border: 1px solid lightgrey;
}

</style>
62 changes: 39 additions & 23 deletions app/views/questions/index_shadow.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="row" style="padding:2em;">
<div class="row col-md-12" style="padding:2em;">
<div class="col-md-5">
<div class="profile-image text-center">
<img class="rounded-circle img-fluid" style= "width:40%;" id="profile-photo" src="https://avatars2.githubusercontent.com/u/4621650?s=200&v=4" />
Expand All @@ -12,28 +12,39 @@
eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<a href="https://publiclab.org/wiki/public-lab-q-and-a" style="text-decoration: underline;">Learn More >></a>
</div>
</div>
<div class="question-area">
<div class= "question-header">
<h5>What's your question?</h5>
<% if !current_user %>
<p>To ask a question, please <a href="/login?return_to=/questions">log in</a> or <a href="/signup?return_to=/questions">sign up</a> first.</p>
<% end %>
</div>
<div class= "question-form">
<form id="questions_searchform" role="search" autocomplete="off" action="/post">
<div class="input-group">
<textarea tabindex="1" id="questions_searchform_input" type="text" name="title" class="<%= "disabled " if !current_user %>form-control search-query typeahead" qryType="questions" placeholder="type your question"></textarea>
<input type="hidden" name="tags" value="question:general">
<input type="hidden" name="template" value="question">
<input type="hidden" name="redirect" value="question">
</div>
<div class="input-group-append">
<button id="question_search" type="submit" rel="tooltip" title="Ask a question with the entered title" class="btn btn-primary">Continue</button>
</div>
</form>
</div>
</div>
</div>
<div class="question-area col-md-12">
<div class= "question-header">
<h5>What's your question?</h5>
<% if !current_user %>
<p>To ask a question, please <a href="/login?return_to=/questions">log in</a> or <a href="/signup?return_to=/questions">sign up</a> first.</p>
<% end %>
</div>
<div class= "question-form">
<form id="questions_searchform" role="search" autocomplete="off" action="/post">
<div class="input-group">
<textarea tabindex="1" id="questions_searchform_input" type="text" name="title" class="<%= "disabled " if !current_user %>form-control search-query typeahead" qryType="questions" placeholder="type your question"></textarea>
<input type="hidden" name="tags" value="question:general">
<input type="hidden" name="template" value="question">
<input type="hidden" name="redirect" value="question">
</div>
<div class="input-group-append" style="padding-bottom:15px;">
<button id="question_search" type="submit" rel="tooltip" title="Ask a question with the entered title" class="btn btn-primary">Continue</button>
</div>
</form>
</div>
</div>

<div class="FeaturedQuestions col-md-12">
<a class="<% if params[:action] == "popular_shadow" %><% end %>">
<span class="d-none d-lg-inline"><h2 href="/questions/popular/">Featured questions </h2></span>
<span><h6>see some of the great questions people have asked, and get a feel for how it works
</h6></span>
</a>
</div>

<%= render partial: "questions/questions_shadow" %>

<style>
.question-area{
margin:auto;
Expand Down Expand Up @@ -66,4 +77,9 @@
resize: none;
height: 170px;
}

.FeaturedQuestions {
text-align: center;
margin-top: 3em;
}
</style>
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@
get 'questions' => 'questions#index'
get 'questions_shadow' => 'questions#index_shadow'
get 'question' => 'questions#index'
get 'questions/:author/:date/:id' => 'questions#show'
get 'question_shadow' => 'questions#index_shadow'
get 'questions/:author/:date/:id' => 'questions#show'
get 'questions/show/:id' => 'questions#show'
get 'q/:id' => 'questions#shortlink'
get 'questions/answered(/:tagnames)' => 'questions#answered'
Expand Down

0 comments on commit 9d5da34

Please sign in to comment.