New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question Controller and views for Expanded Q & A system #550
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,7 +103,11 @@ def create | |
else | ||
flash[:notice] = "Research note published. Get the word out on <a href='/lists'>the discussion lists</a>!" | ||
end | ||
redirect_to @node.path | ||
if params[:redirect] && params[:redirect] == 'question' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of doing this here, can we do it inside the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yes we can surely do that by changing the path for questions in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see! Great to know this was considered. I'm interested in how this can be clearly communicated in how the code is implemented, and also keep path generation code centralized. Do you think we could have |
||
redirect_to '/questions/'+@node.author.name+'/'+Time.at(@node.created).strftime("%m-%d-%Y")+'/'+@node.title.parameterize | ||
else | ||
redirect_to @node.path | ||
end | ||
else | ||
render :template => "editor/post" | ||
end | ||
|
@@ -159,7 +163,11 @@ def update | |
end | ||
@node.save! | ||
flash[:notice] = "Edits saved." | ||
redirect_to @node.path | ||
if params[:redirect] && params[:redirect] == 'question' | ||
redirect_to '/questions/'+@node.author.name+'/'+Time.at(@node.created).strftime("%m-%d-%Y")+'/'+@node.title.parameterize | ||
else | ||
redirect_to @node.path | ||
end | ||
else | ||
flash[:error] = "Your edit could not be saved." | ||
render :action => :edit | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
class QuestionsController < ApplicationController | ||
|
||
def index | ||
@title = "Recent Questions" | ||
@notes = DrupalNode.where(status: 1, type: 'note') | ||
.joins(:drupal_tag) | ||
.where('term_data.name LIKE ?', 'question:%') | ||
.order('node.nid DESC') | ||
.paginate(:page => params[:page], :per_page => 30) | ||
@wikis = DrupalNode.limit(10) | ||
.where(type: 'page', status: 1) | ||
.order("nid DESC") | ||
end | ||
|
||
def show | ||
if params[:author] && params[:date] | ||
@node = DrupalNode.where(path: "/notes/#{params[:author]}/#{params[:date]}/#{params[:id]}").first | ||
@node = @node || DrupalNode.where(path: "/report/#{params[:id]}").first | ||
else | ||
@node = DrupalNode.find params[:id] | ||
end | ||
|
||
unless @node.has_power_tag('question') | ||
flash[:error] = "Not a question" | ||
redirect_to "/" | ||
end | ||
|
||
if @node.author.status == 0 && !(current_user && (current_user.role == "admin" || current_user.role == "moderator")) | ||
flash[:error] = "The author of that note has been banned." | ||
redirect_to "/" | ||
elsif @node.status == 4 && (current_user && (current_user.role == "admin" || current_user.role == "moderator")) | ||
flash[:warning] = "First-time poster <a href='#{@node.author.name}'>#{@node.author.name}</a> submitted this #{time_ago_in_words(@node.created_at)} ago and it has not yet been approved by a moderator. <a class='btn btn-default btn-sm' href='/moderate/publish/#{@node.id}'>Approve</a> <a class='btn btn-default btn-sm' href='/moderate/spam/#{@node.id}'>Spam</a>" | ||
elsif @node.status == 4 && (current_user && current_user.id == @node.author.id) && !flash[:first_time_post] | ||
flash[:warning] = "Thank you for contributing open research, and thanks for your patience while your post is approved by <a href='/wiki/moderation'>community moderators</a> and we'll email you when it is published. In the meantime, if you have more to contribute, feel free to do so." | ||
elsif @node.status != 1 && !(current_user && (current_user.role == "admin" || current_user.role == "moderator")) | ||
# if it's spam or a draft | ||
# no notification; don't let people easily fish for existing draft titles; we should try to 404 it | ||
redirect_to "/" | ||
end | ||
|
||
@node.view | ||
@title = @node.latest.title | ||
@tags = @node.tags | ||
@tagnames = @tags.collect(&:name) | ||
|
||
set_sidebar :tags, @tagnames | ||
end | ||
|
||
def shortlink | ||
@node = DrupalNode.find params[:id] | ||
redirect_to '/questions/'+@node.author.name+'/'+Time.at(@node.created).strftime("%m-%d-%Y")+'/'+@node.title.parameterize | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This helps centralize where paths are generated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar answer as the previous thread. |
||
end | ||
|
||
def popular | ||
@title = "Popular Questions" | ||
@notes = DrupalNode.where(status: 1, type: 'note') | ||
.joins(:drupal_tag) | ||
.where('term_data.name LIKE ?', 'question:%') | ||
.order('node_counter.totalcount DESC') | ||
.includes(:drupal_node_counter) | ||
.limit(20) | ||
@wikis = DrupalNode.limit(10) | ||
.where(type: 'page', status: 1) | ||
.order("nid DESC") | ||
@unpaginated = true | ||
render :template => 'questions/index' | ||
end | ||
|
||
def liked | ||
@title = "Highly liked Questions" | ||
@notes = DrupalNode.where(status: 1, type: 'note') | ||
.joins(:drupal_tag) | ||
.where('term_data.name LIKE ?', 'question:%') | ||
.order("cached_likes DESC") | ||
.limit(20) | ||
@wikis = DrupalNode.limit(10) | ||
.where(type: 'page', status: 1) | ||
.order("nid DESC") | ||
@unpaginated = true | ||
render :template => 'questions/index' | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,10 @@ | |
<h3>Share your work</h3> | ||
<% end %> | ||
|
||
<% if params[:redirect] == 'question' %> | ||
<%= hidden_field_tag 'redirect', 'question' %> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we instead simply rely on the provided tagging? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is added to provide redirect to the question show path only when a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see -- so this is temporary? If so, let's leave a clear comment that it should be removed once question show template is complete. Something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok will add comments wherever necessary. |
||
<% end %> | ||
|
||
<div class="form-group"> | ||
<input id="title" tabindex="1" name="title" class="form-control" placeholder="Title" value="<%= if @node then @node.title else params[:title] end %><%= "Question: " if params[:template] == "question" %><%= 'Public Lab Community Newsletter '+ DateTime.now.to_date.to_s(:long) if params[:newsletter] %>"/> | ||
</div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ | |
<hr /> | ||
|
||
<div class='btn-group'> | ||
<% if node.type == 'note' %><a <% if current_user && current_user.uid != node.uid %>data-confirm='Please be aware that you are editing someone else\'s post, a privilege you have only because you are a moderator or admin.' <% end %>class='btn btn-default btn-sm' href='/notes/edit/<%= node.id %>?t=<%= Time.now.to_i %>'><i class='fa fa-pencil'></i><span class='hidden-xs hidden-sm'> Edit</span></a><% end %> | ||
<% if node.type == 'note' %><a <% if current_user && current_user.uid != node.uid %>data-confirm='Please be aware that you are editing someone else\'s post, a privilege you have only because you are a moderator or admin.' <% end %>class='btn btn-default btn-sm' href='/notes/edit/<%= node.id %>?t=<%= Time.now.to_i %><% if params[:controller] == "questions" %>&redirect=question<% end %>'><i class='fa fa-pencil'></i><span class='hidden-xs hidden-sm'> Edit</span></a><% end %> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should do this at the controller level, as it's relatively hidden here. Can we check for tagging at the controller and redirect there? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar answer as the last thread. Done so that user is not redirected to the questions show page while editing from the notes show page. |
||
<a href='/notes/delete/<%= node.id %>' class='btn btn-default btn-sm' data-confirm='Are you sure?'> | ||
<i class='fa fa-trash'></i><span class='hidden-xs hidden-sm' Delete</span> | ||
</a> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<%= render :partial => "sidebar/user" %> | ||
<% if params[:action] == 'popular' %> | ||
<h2>Popular Questions <small class="hidden-sm">Most viewed questions</small></h2> | ||
<% elsif params[:action] == 'liked' %> | ||
<h2>Liked Questions <small class="hidden-sm">Most liked questions</small></h2> | ||
<% else %> | ||
<h2>All Questions <small class="hidden-sm">Listing all recent questions</small></h2> | ||
<% end %> | ||
<div class="col-md-9"> | ||
<%= render :partial => "notes/format_toggle" %> | ||
<ul class="nav nav-tabs"> | ||
<li<% if params[:action] == "index" %> class="active"<% end %>><a href="/questions/">Recent</a></li> | ||
<li<% if params[:action] == "popular" %> class="active"<% end %>><a href="/questions/popular/">Popular</a></li> | ||
<li<% if params[:action] == "liked" %> class="active"<% end %>><a href="/questions/liked/"><i class="fa fa-star-o"></i><span class="hidden-sm"> Liked</span></a></li> | ||
</ul> | ||
<div id="notes"> | ||
<div class="row"> | ||
<% @notes.each_with_index do |node,i| %> | ||
<div class="<% if @widget %>col-xs-4 col-sm-4 <% end %>col-md-4 note note-container-question" style="margin-top:20px;"> | ||
<div class="note-pane note-question<% if node.status == 4 %> moderated<% end %>"> | ||
|
||
<div class="header-icon"><i class="fa fa-question-circle"></i></div> | ||
|
||
<%= render partial: 'dashboard/node_moderate', locals: { node: node } %> | ||
|
||
<h4><a <% if @widget %>target="_blank"<% end %> href="/questions/<%= node.author.name %>/<%= Time.at(node.created).strftime("%m-%d-%Y") %>/<%= node.title.parameterize %>"><%= node.title %></a></h4> | ||
|
||
<p class="meta">asked <%= render partial: "dashboard/node_meta", locals: { node: node } %></p> | ||
|
||
<span id="tags"> | ||
<% node.tags.limit(4).each do |tag| %> | ||
<span id="tag_<%= tag.id %>" class="label label-primary"><a href="/tag/<%= tag.name %>"><%= tag.name %></a></span> | ||
<% end %> | ||
</span> | ||
<p style="margin-top:30px;"><% if logged_in_as(['admin','moderator']) %><a class="btn btn-default btn-xs" href="/moderate/spam/<%= node.id %>"><i class="fa fa-ban"></i> Spam</a><% end %> | ||
<a href="#" class="btn btn-default btn-xs">Post an answer</a></p> | ||
</div> | ||
</div> | ||
|
||
<% unless @widget %><hr class="visible-xs visible-sm" /><% end %> | ||
<% if ((i+1)/3.0).to_i == ((i+1)/3.0) %> | ||
</div> | ||
<% unless @widget %><hr class="visible-xs visible-sm grid" /><% end %> | ||
<div class="row"> | ||
<% end %> | ||
<% end %> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="text-center"><%= will_paginate @notes, :renderer => BootstrapPagination::Rails unless @unpaginated %></div> | ||
|
||
<%= stylesheet_link_tag "dashboard" %> | ||
<%= javascript_include_tag "dashboard" %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<%= render :partial => "sidebar/related" %> | ||
<div class="col-md-9 note-show"> | ||
|
||
<div style="margin-top:10px;" class="hidden-print"> | ||
<%= render :partial => "like/like", :locals => {:node => @node, :tagnames => @tagnames } %> | ||
</div> | ||
|
||
<h1 style="margin-top: 40px;"><span class="question">Question:</span><a href="/questions/<%= @node.author.name %>/<%= Time.at(@node.created).strftime("%m-%d-%Y") %>/<%= @node.title.parameterize %>"><%= @node.title %></a></h1> | ||
<% pt = @node.power_tag('question') %> | ||
<div class="alert alert-warning"> | ||
<a href="/profile/<%= @node.author.name %>"> <%= @node.author.name %> </a> | ||
is asking a question about <b><%= pt %></b>: | ||
<a class="btn btn-default" target="_blank" href="/subscribe/tag/question:<%= pt %>"> | ||
Subscribe to answer questions on this topic | ||
</a> | ||
</div> | ||
<div class="inline"> | ||
<% if @node.author.user && @node.author.user.photo_file_name %> | ||
<img class="img-circle" src="<%= @node.author.user.photo_path(:thumb) %>" /> | ||
<% else %> | ||
<div class="img-circle"></div> | ||
<% end %> | ||
</div> | ||
<div class="inline"> | ||
<p><a href="/profile/<%= @node.author.name %>"><%= @node.author.name %></a> asked on <%= @node.created_at.to_s(:long) %> <% if @node.status == 0 || @node.status == 4 %><span class="label label-danger">| UNPUBLISHED</span><% end %> <br /> | ||
<small><i class="fa fa-eye"></i> <%= number_with_delimiter(@node.totalcount) %> <span class="hidden-xs hidden-sm hidden-print ">views</span> | <a href="/q/<%= @node.id %>">shortlink</a></small></p> | ||
</div> | ||
|
||
<hr style="margin-top:10px;" /> | ||
|
||
<div style="overflow:hidden;" id="content"> | ||
<%= raw auto_link(@node.latest.render_body, :sanitize => false) %> | ||
</div> | ||
|
||
<hr /> | ||
|
||
<%= render :partial => "home/social" %> | ||
|
||
<hr /> | ||
|
||
<%= render :partial => "tag/tagging" %> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,22 @@ | ||
<% if params[:controller] == 'questions' %> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to keep this template file simpler. Can we put this question button at the top of the questions index page? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok Jeff I will add the Ask a question button at the top of the question show page and index page. |
||
<a style="margin-bottom:6px;" rel="tooltip" title="Ask a question to the community" data-placement="bottom" href="/post?tags=question:question&template=question&redirect=question" class="btn btn-primary btn-lg btn-block hidden-md"><i class="fa fa-question-circle fa-white"></i> Ask a Question</a> | ||
<% else %> | ||
<a style="margin-bottom:6px;" rel="tooltip" title="Share your work with others" data-placement="bottom" href="/post" class="btn btn-primary btn-lg btn-block hidden-md"><i class="fa fa-pencil fa-white"></i> Write a research note</a> | ||
<% end%> | ||
<div class="btn-group visible-md" style="margin-bottom:6px;"> | ||
<% if params[:controller] == 'questions' %> | ||
<a rel="tooltip" title="Ask a question to the community" data-placement="bottom" href="/post?tags=question:question&template=question&redirect=question" class="btn btn-primary btn-lg"><i class="fa fa-question-circle fa-white"></i> Ask Question</a> | ||
<% else %> | ||
<a rel="tooltip" title="Share your work with others" data-placement="bottom" href="/post" class="btn btn-primary btn-lg"><i class="fa fa-pencil fa fa-white"></i> Post research</a> | ||
<% end %> | ||
<a class="btn btn-primary btn-lg dropdown-toggle" data-toggle="dropdown" href="#"><span class="caret"></span></a> | ||
|
||
<ul class="dropdown-menu"> | ||
<% if params[:controller] == 'questions' %> | ||
<li><a href="/post?tags=question:question&template=question&redirect=question"><i class="fa fa-question-circle"></i> <b>Ask a Question</b></a></li> | ||
<% else %> | ||
<li><a href="/post"><i class="fa fa-pencil"></i> <b>Post a research note</b></a></li> | ||
<% end %> | ||
<li><a href="/wiki/new"><i class="fa fa-book"></i> Create a wiki page</a></li> | ||
<li class="divider"></li> | ||
<li><a href="/wiki/about-posting" class="hidden-lg"><i class="fa fa-question-sign"></i> About posting</a></li> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,9 @@ chapter: | |
uid: 1 | ||
nid: 7 | ||
date: Time.now | ||
|
||
question: | ||
tid: 6 | ||
uid: 2 | ||
nid: 8 | ||
date: Time.now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, wait - why was this removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually the
store_location
method already stores the full path of the request in the session. See reference here: https://github.com/publiclab/plots2/pull/550/files#diff-55c5b7aecfb519d0e4880eaf2788eb6eL98. TheURI.encode(request.env['PATH_INFO'])
was actually returning the parameters but it was only available to\login
page. As soon it posted the login parameters of an user the parameters were no longer available and it didn't redirect to with no parameters in the/post
url. So it was an issue that I solved it here using the changes done in the user_sessions_controller: https://github.com/publiclab/plots2/pull/550/files#diff-0770692f348632e109afe78e3585bfe0R35There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see -- great, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future, perhaps smaller, independent changes could be submitted in separate pull requests, however, where possible. Thanks, though, this is a good catch and a welcome contribution!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this is a issue I should have handled separately raising a github issue.Will do it as per from the next time. Thanks Jeff!